Network estimateFee tests no longer relies on fixtures
This commit is contained in:
parent
c4285d9da2
commit
5dcefc5329
1 changed files with 40 additions and 36 deletions
|
@ -1,23 +1,31 @@
|
|||
var assert = require('assert')
|
||||
var networks = require('../src/networks')
|
||||
var sinon = require('sinon')
|
||||
var Transaction = require('../src/transaction')
|
||||
|
||||
var fixtureTxes = require('./fixtures/mainnet_tx')
|
||||
var fixtureTx1Hex = fixtureTxes.prevTx
|
||||
var fixtureTxBigHex = fixtureTxes.bigTx
|
||||
|
||||
describe('networks', function() {
|
||||
var txToBuffer
|
||||
before(function(){
|
||||
txToBuffer = sinon.stub(Transaction.prototype, "toBuffer")
|
||||
})
|
||||
|
||||
after(function(){
|
||||
Transaction.prototype.toBuffer.restore()
|
||||
})
|
||||
|
||||
describe('bitcoin', function() {
|
||||
describe('estimateFee', function() {
|
||||
var estimateFee = networks.bitcoin.estimateFee
|
||||
|
||||
it('works for fixture tx 1', function() {
|
||||
var tx = Transaction.fromHex(fixtureTx1Hex)
|
||||
it('works at boundry', function() {
|
||||
txToBuffer.returns(new Buffer(1000))
|
||||
var tx = new Transaction()
|
||||
assert.equal(estimateFee(tx), 10000)
|
||||
})
|
||||
|
||||
it('works for fixture big tx', function() {
|
||||
var tx = Transaction.fromHex(fixtureTxBigHex)
|
||||
it('rounds up to the closest kb for estimation', function() {
|
||||
txToBuffer.returns(new Buffer(2800))
|
||||
var tx = new Transaction()
|
||||
assert.equal(estimateFee(tx), 30000)
|
||||
})
|
||||
})
|
||||
|
@ -28,28 +36,26 @@ describe('networks', function() {
|
|||
var estimateFee = networks.dogecoin.estimateFee
|
||||
|
||||
it('regular fee per kb applies when every output has value no less than DUST_SOFT_LIMIT', function() {
|
||||
var tx = Transaction.fromHex(fixtureTx1Hex)
|
||||
tx.outs.forEach(function(e){
|
||||
e.value = 100000000
|
||||
})
|
||||
txToBuffer.returns(new Buffer(1000))
|
||||
var tx = new Transaction()
|
||||
tx.outs[0] = { value: 100000000 }
|
||||
|
||||
assert.equal(estimateFee(tx), 100000000)
|
||||
})
|
||||
|
||||
it('applies additional fee on every output with value below DUST_SOFT_LIMIT', function() {
|
||||
var tx = Transaction.fromHex(fixtureTx1Hex)
|
||||
tx.outs.forEach(function(e){
|
||||
e.value = 99999999
|
||||
txToBuffer.returns(new Buffer(1000))
|
||||
var tx = new Transaction()
|
||||
tx.outs[0] = { value: 99999999 }
|
||||
tx.outs[1] = { value: 99999999 }
|
||||
|
||||
assert.equal(estimateFee(tx), 3 * 100000000)
|
||||
})
|
||||
|
||||
assert.equal(estimateFee(tx), 4 * 100000000) // 3 outs in total
|
||||
})
|
||||
it('rounds up to the closest kb for estimation', function() {
|
||||
txToBuffer.returns(new Buffer(2800))
|
||||
var tx = new Transaction()
|
||||
|
||||
it('works for fixture big tx', function() {
|
||||
var tx = Transaction.fromHex(fixtureTxBigHex)
|
||||
tx.outs.forEach(function(e){
|
||||
e.value = 100000000
|
||||
})
|
||||
assert.equal(estimateFee(tx), 300000000)
|
||||
})
|
||||
})
|
||||
|
@ -60,28 +66,26 @@ describe('networks', function() {
|
|||
var estimateFee = networks.litecoin.estimateFee
|
||||
|
||||
it('regular fee per kb applies when every output has value no less than DUST_SOFT_LIMIT', function() {
|
||||
var tx = Transaction.fromHex(fixtureTx1Hex)
|
||||
tx.outs.forEach(function(e){
|
||||
e.value = 100000
|
||||
})
|
||||
txToBuffer.returns(new Buffer(1000))
|
||||
var tx = new Transaction()
|
||||
tx.outs[0] = { value: 100000 }
|
||||
|
||||
assert.equal(estimateFee(tx), 100000)
|
||||
})
|
||||
|
||||
it('applies additional fee on every output with value below DUST_SOFT_LIMIT', function() {
|
||||
var tx = Transaction.fromHex(fixtureTx1Hex)
|
||||
tx.outs.forEach(function(e){
|
||||
e.value = 99999
|
||||
txToBuffer.returns(new Buffer(1000))
|
||||
var tx = new Transaction()
|
||||
tx.outs[0] = { value: 99999 }
|
||||
tx.outs[1] = { value: 99999 }
|
||||
|
||||
assert.equal(estimateFee(tx), 3 * 100000)
|
||||
})
|
||||
|
||||
assert.equal(estimateFee(tx), 4 * 100000) // 3 outs in total
|
||||
})
|
||||
it('rounds up to the closest kb for estimation', function() {
|
||||
txToBuffer.returns(new Buffer(2800))
|
||||
var tx = new Transaction()
|
||||
|
||||
it('works for fixture big tx', function() {
|
||||
var tx = Transaction.fromHex(fixtureTxBigHex)
|
||||
tx.outs.forEach(function(e){
|
||||
e.value = 100000
|
||||
})
|
||||
assert.equal(estimateFee(tx), 300000)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue