Network estimateFee tests no longer relies on fixtures

This commit is contained in:
Wei Lu 2014-06-17 23:35:40 +08:00
parent c4285d9da2
commit 5dcefc5329

View file

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