2014-06-17 08:48:06 +02:00
|
|
|
var assert = require('assert')
|
|
|
|
var networks = require('../src/networks')
|
2014-06-17 17:35:40 +02:00
|
|
|
var sinon = require('sinon')
|
2014-06-17 08:48:06 +02:00
|
|
|
var Transaction = require('../src/transaction')
|
|
|
|
|
2014-06-18 09:27:36 +02:00
|
|
|
var fixtures = require('./fixtures/network')
|
|
|
|
|
2014-06-17 10:23:09 +02:00
|
|
|
describe('networks', function() {
|
2014-06-17 17:35:40 +02:00
|
|
|
var txToBuffer
|
|
|
|
before(function(){
|
|
|
|
txToBuffer = sinon.stub(Transaction.prototype, "toBuffer")
|
|
|
|
})
|
|
|
|
|
|
|
|
after(function(){
|
|
|
|
Transaction.prototype.toBuffer.restore()
|
|
|
|
})
|
|
|
|
|
2014-06-18 09:27:36 +02:00
|
|
|
fixtures.valid.forEach(function(f) {
|
|
|
|
describe(f.network + ' estimateFee', function() {
|
|
|
|
var network = networks[f.network]
|
2014-06-17 10:23:09 +02:00
|
|
|
|
2014-06-18 09:27:36 +02:00
|
|
|
it('calculates the fee correctly for ' + f.description, function() {
|
|
|
|
var buffer = new Buffer(f.txSize)
|
|
|
|
txToBuffer.returns(buffer)
|
2014-06-17 08:48:06 +02:00
|
|
|
|
2014-06-18 09:27:36 +02:00
|
|
|
var estimateFee = network.estimateFee
|
2014-06-17 17:35:40 +02:00
|
|
|
var tx = new Transaction()
|
2014-06-18 09:27:36 +02:00
|
|
|
tx.outs = f.outputs || []
|
2014-06-17 17:35:40 +02:00
|
|
|
|
2014-06-18 09:27:36 +02:00
|
|
|
assert.equal(estimateFee(tx), f.fee)
|
2014-06-17 10:23:09 +02:00
|
|
|
})
|
2014-06-17 08:48:06 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|