network: moves tests to fixtures
This commit is contained in:
parent
77b68a52a6
commit
ebe670475e
2 changed files with 96 additions and 71 deletions
84
test/fixtures/network.json
vendored
Normal file
84
test/fixtures/network.json
vendored
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
{
|
||||||
|
"valid": [
|
||||||
|
{
|
||||||
|
"description": "when txSize < 1kb",
|
||||||
|
"network": "bitcoin",
|
||||||
|
"txSize": 1,
|
||||||
|
"fee": 10000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "when txSize >= 1kb",
|
||||||
|
"network": "bitcoin",
|
||||||
|
"txSize": 1000,
|
||||||
|
"fee": 10000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "rounding",
|
||||||
|
"network": "bitcoin",
|
||||||
|
"txSize": 2800,
|
||||||
|
"fee": 30000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "when outputs.value > DUST_SOFT_LIMIT, feePerKb is used",
|
||||||
|
"network": "dogecoin",
|
||||||
|
"txSize": 1000,
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"value": 100000000
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fee": 100000000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "when not every outputs.value > DUST_SOFT_LIMIT",
|
||||||
|
"network": "dogecoin",
|
||||||
|
"txSize": 1000,
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"value": 99999999
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": 99999999
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fee": 300000000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "rounding",
|
||||||
|
"network": "dogecoin",
|
||||||
|
"txSize": 2800,
|
||||||
|
"fee": 300000000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "when outputs.value > DUST_SOFT_LIMIT, feePerKb is used",
|
||||||
|
"network": "litecoin",
|
||||||
|
"txSize": 1000,
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"value": 100000
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fee": 100000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "when not every outputs.value > DUST_SOFT_LIMIT",
|
||||||
|
"network": "litecoin",
|
||||||
|
"txSize": 1000,
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"value": 99999
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": 99999
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fee": 300000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "rounding",
|
||||||
|
"network": "litecoin",
|
||||||
|
"txSize": 2800,
|
||||||
|
"fee": 300000
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -3,6 +3,8 @@ var networks = require('../src/networks')
|
||||||
var sinon = require('sinon')
|
var sinon = require('sinon')
|
||||||
var Transaction = require('../src/transaction')
|
var Transaction = require('../src/transaction')
|
||||||
|
|
||||||
|
var fixtures = require('./fixtures/network')
|
||||||
|
|
||||||
describe('networks', function() {
|
describe('networks', function() {
|
||||||
var txToBuffer
|
var txToBuffer
|
||||||
before(function(){
|
before(function(){
|
||||||
|
@ -13,80 +15,19 @@ describe('networks', function() {
|
||||||
Transaction.prototype.toBuffer.restore()
|
Transaction.prototype.toBuffer.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('bitcoin', function() {
|
fixtures.valid.forEach(function(f) {
|
||||||
describe('estimateFee', function() {
|
describe(f.network + ' estimateFee', function() {
|
||||||
var estimateFee = networks.bitcoin.estimateFee
|
var network = networks[f.network]
|
||||||
|
|
||||||
it('works at boundry', function() {
|
it('calculates the fee correctly for ' + f.description, function() {
|
||||||
txToBuffer.returns(new Buffer(1000))
|
var buffer = new Buffer(f.txSize)
|
||||||
|
txToBuffer.returns(buffer)
|
||||||
|
|
||||||
|
var estimateFee = network.estimateFee
|
||||||
var tx = new Transaction()
|
var tx = new Transaction()
|
||||||
assert.equal(estimateFee(tx), 10000)
|
tx.outs = f.outputs || []
|
||||||
})
|
|
||||||
|
|
||||||
it('rounds up to the closest kb for estimation', function() {
|
assert.equal(estimateFee(tx), f.fee)
|
||||||
txToBuffer.returns(new Buffer(2800))
|
|
||||||
var tx = new Transaction()
|
|
||||||
assert.equal(estimateFee(tx), 30000)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('dogecoin', function() {
|
|
||||||
describe('estimateFee', function() {
|
|
||||||
var estimateFee = networks.dogecoin.estimateFee
|
|
||||||
|
|
||||||
it('regular fee per kb applies when every output has value no less than DUST_SOFT_LIMIT', function() {
|
|
||||||
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() {
|
|
||||||
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)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('rounds up to the closest kb for estimation', function() {
|
|
||||||
txToBuffer.returns(new Buffer(2800))
|
|
||||||
var tx = new Transaction()
|
|
||||||
|
|
||||||
assert.equal(estimateFee(tx), 300000000)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('litecoin', function() {
|
|
||||||
describe('estimateFee', function() {
|
|
||||||
var estimateFee = networks.litecoin.estimateFee
|
|
||||||
|
|
||||||
it('regular fee per kb applies when every output has value no less than DUST_SOFT_LIMIT', function() {
|
|
||||||
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() {
|
|
||||||
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)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('rounds up to the closest kb for estimation', function() {
|
|
||||||
txToBuffer.returns(new Buffer(2800))
|
|
||||||
var tx = new Transaction()
|
|
||||||
|
|
||||||
assert.equal(estimateFee(tx), 300000)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue