2015-02-23 00:36:57 +01:00
|
|
|
/* global describe, it, before, after */
|
|
|
|
|
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-11-27 07:10:26 +01:00
|
|
|
|
|
|
|
var HDNode = require('../src/hdnode')
|
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')
|
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
describe('networks', function () {
|
2015-03-16 00:51:21 +01:00
|
|
|
var txByteLength
|
2015-02-23 00:36:57 +01:00
|
|
|
before(function () {
|
2015-03-16 00:51:21 +01:00
|
|
|
txByteLength = sinon.stub(Transaction.prototype, 'byteLength')
|
2014-06-17 17:35:40 +02:00
|
|
|
})
|
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
after(function () {
|
2015-03-16 00:51:21 +01:00
|
|
|
Transaction.prototype.byteLength.restore()
|
2014-06-17 17:35:40 +02:00
|
|
|
})
|
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
describe('constants', function () {
|
|
|
|
fixtures.valid.constants.forEach(function (f) {
|
2014-06-18 09:27:36 +02:00
|
|
|
var network = networks[f.network]
|
2014-06-17 10:23:09 +02:00
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
Object.keys(f.bip32).forEach(function (name) {
|
2014-11-27 07:10:26 +01:00
|
|
|
var extb58 = f.bip32[name]
|
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
it('resolves ' + extb58 + ' to ' + f.network, function () {
|
2015-03-16 01:26:16 +01:00
|
|
|
assert.equal(HDNode.fromBase58(extb58).network, network)
|
2014-11-27 07:10:26 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
describe('estimateFee', function () {
|
|
|
|
fixtures.valid.estimateFee.forEach(function (f) {
|
|
|
|
describe('(' + f.network + ')', function () {
|
2014-11-27 07:10:26 +01:00
|
|
|
var network = networks[f.network]
|
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
it('calculates the fee correctly for ' + f.description, function () {
|
2015-03-16 00:51:21 +01:00
|
|
|
txByteLength.returns(f.txSize)
|
2014-06-17 08:48:06 +02:00
|
|
|
|
2014-11-27 07:10:26 +01:00
|
|
|
var estimateFee = network.estimateFee
|
|
|
|
var tx = new Transaction()
|
|
|
|
tx.outs = f.outputs || []
|
2014-06-17 17:35:40 +02:00
|
|
|
|
2014-11-27 07:10:26 +01:00
|
|
|
assert.equal(estimateFee(tx), f.fee)
|
|
|
|
})
|
2014-06-17 10:23:09 +02:00
|
|
|
})
|
2014-06-17 08:48:06 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|