Fixed tests for network type.

This commit is contained in:
Chris Kleeschulte 2017-09-26 11:02:18 -04:00
parent 4f6eb68c50
commit 827470fd71
No known key found for this signature in database
GPG Key ID: 33195D27EF6BDB7F
2 changed files with 9 additions and 9 deletions

View File

@ -14,6 +14,7 @@ function TxController(node) {
this._block = this.node.services.block;
this._transaction = this.node.services.transaction;
this._address = this.node.services.address;
this._network = this.node.network;
if (this.node.network === 'livenet') {
this._network = 'main';
}
@ -131,7 +132,7 @@ TxController.prototype.transformInput = function(options, input, index) {
var address = input.getAddress();
if (address) {
address.network = this._network || 'main';
address.network = this._network;
transformed.addr = address.toString();
} else {
transformed.addr = null;
@ -168,7 +169,7 @@ TxController.prototype.transformOutput = function(options, output, index) {
var address = output.getAddress();
if (address) {
address.network = this._network || 'main';
address.network = this._network;
transformed.scriptPubKey.addresses = [address.toString()];
transformed.scriptPubKey.type = address.getType();
}

View File

@ -1,7 +1,6 @@
'use strict';
var should = require('should');
var sinon = require('sinon');
var bitcore = require('bitcore-lib');
var TxController = require('../lib/transactions');
var bcoin = require('bcoin');
var _ = require('lodash');
@ -354,11 +353,11 @@ describe('Transactions', function() {
};
var rawTx = '01000000011760bc271a397bfb65b7506d430d96ebb1faff467ed957516238a9670e806a86010000006b483045022100f0056ae68a34cdb4194d424bd727c18f82653bca2a198e0d55ab6b4ee88bbdb902202a5745af4f72a5dbdca1e3d683af4667728a8b20e8001e0f8308a4d329ce3f96012102f3af6e66b61c9d99c74d9a9c3c1bec014a8c05d28bf339c8f5f395b5ce319e7dffffffff02c8af00000000000017a9148083b541ea15f1d18c5ca5e1fd47f9035cce24ed87206b1e00000000001976a91410a0e70cd91a45e0e6e409e227ab285bd61592b188ac00000000';
var tx = bitcore.Transaction().fromBuffer(new Buffer(rawTx, 'hex'));
var tx = bcoin.tx.fromRaw(rawTx, 'hex');
var node = {
services: { block: { getTip: sinon.stub().returns({ height: 534233 }) } },
network: bitcore.Networks.livenet
network: 'livenet'
};
var transactions = new TxController(node);
@ -380,11 +379,11 @@ describe('Transactions', function() {
};
var rawTx = '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0403ebc108ffffffff04a0ca814a000000001976a914fdb9fb622b0db8d9121475a983288a0876f4de4888ac0000000000000000226a200000000000000000000000000000000000000000000000000000ffff0000000000000000000000001b6a1976a914fdb9fb622b0db8d9121475a983288a0876f4de4888ac0000000000000000326a303a791c8e85200500d89769b4f958e4db6b3ec388ddaa30233c4517d942d440c24ae903bff40d97ca06465fcf2714000000000000';
var tx = bitcore.Transaction().fromBuffer(new Buffer(rawTx, 'hex'));
var tx = bcoin.tx.fromRaw(rawTx, 'hex');
var node = {
services: { block: { getTip: sinon.stub().returns({ height: 534233 }) } },
network: bitcore.Networks.testnet
network: 'testnet'
};
var transactions = new TxController(node);
@ -406,13 +405,13 @@ describe('Transactions', function() {
var node = {
services: { block: { getTip: sinon.stub().returns({ height: 534233 }) } },
network: bitcore.Networks.livenet
network: 'livenet'
};
var transactions = new TxController(node);
_.each(testCases, function(tc) {
var tx = bitcore.Transaction().fromBuffer(new Buffer(tc.rawTx, 'hex'));
var tx = bcoin.tx.fromRaw(tc.rawTx, 'hex');
var result = transactions.transformInvTransaction(tx);
should.exist(result.isRBF);
result.isRBF.should.equal(tc.expected);