Skip to content

Commit

Permalink
test: update transaction tests
Browse files Browse the repository at this point in the history
  • Loading branch information
braydonf committed Apr 15, 2016
1 parent f87bdea commit c68b9e1
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 81 deletions.
2 changes: 1 addition & 1 deletion lib/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ TxController.prototype.transformOutput = function(output, index) {
//reqSigs: null, // TODO
},
spentTxId: output.__spentTxId || null,
spentIndex: output.__spentIndex || null,
spentIndex: _.isUndefined(output.__spentIndex) ? null : output.__spentIndex,
spentHeight: output.__spentHeight || null
//spentTs: undefined // TODO
};
Expand Down
158 changes: 78 additions & 80 deletions test/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ describe('Transactions', function() {
'addresses': [
'mnQ4ZaGessNgdxmWPxbTHcfx4b8R6eUr1X'
]
}
},
'spentTxId': null,
'spentIndex': null,
'spentHeight': null
},
{
'value': '0.13677426',
Expand All @@ -76,6 +79,7 @@ describe('Transactions', function() {
},
'spentTxId': '614fe1708825f9c21732394e4784cc6808ac1d8b939736bfdead970567561eec',
'spentIndex': 1,
'spentHeight': 10,
'spentTs': 1440997099
}
],
Expand Down Expand Up @@ -168,29 +172,16 @@ describe('Transactions', function() {
bitcoreTx.populateInputs = sinon.stub().callsArg(2);
bitcoreTx.toObject = sinon.stub().returns(bitcoreTxObj);

bitcoreTx.outputs[1].__spentTxId = spentTxId;
bitcoreTx.outputs[1].__spentIndex = spentIndex;
bitcoreTx.outputs[1].__spentHeight = 10;

var node = {
getTransactionWithBlockInfo: sinon.stub().callsArgWith(2, null, bitcoreTx),
getTransactionWithBlockInfo: sinon.stub().callsArgWith(1, null, bitcoreTx),
services: {
db: {
tip: {
__height: 534203
}
bitcoind: {
height: 534203
},
address: {
getInputForOutput: function(txid, outputIndex, options, callback) {
var data = false;
if (txid === 'b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0' &&
outputIndex === 1) {
data = {
inputTxId: spentTxId,
inputIndex: spentIndex
}
}
setImmediate(function() {
callback(null, data);
});
}
}
},
network: 'testnet'
};
Expand All @@ -210,13 +201,17 @@ describe('Transactions', function() {
});

describe('/txs', function() {
var sandbox = sinon.sandbox.create();
afterEach(function() {
sandbox.restore();
});
it('by block hash', function(done) {
var blockHex = '07000020a491892cca9f143f7f00b8d65bbce0204bb32e17e914325fa5010000000000003e28f0519ecf01f7f01ea8da61084b2e4741a18ce1f3738117b84458353764b06fb9e35567f20c1a78eb626f0301000000010000000000000000000000000000000000000000000000000000000000000000ffffffff2303d6250800feb0aae355fe263600000963676d696e6572343208ae5800000000000000ffffffff01c018824a000000001976a91468bedce8982d25c3b6b03f6238cbad00378b8ead88ac000000000100000002ad5a14ae9d0f3221b790c4fc590fddceea1456e5692d8c4bf1ff7175f2b0c987000000008b4830450221008e5df62719cd92d7b137d00bbd27f153f2909bcad3a300960bc1020ec6d5e961022039df51600ff4fb5da5a794d1648c6b47c1f7d277fd5877fb5e52a730a3595f8c014104eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307ffffffff9621ac65bc22ea593ca9a61a8d63e461bf3d3f277989df5d3bd33ddfae0aa1d8000000008a4730440220761464d7bab9515d92260762a97af82a9b25d202d8f7197b1aaec81b6fed541f022059f99606de6b06e17b2cd102dceb3807ebdd9e777a5b77c9a0b3672f5eabcb31014104eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307ffffffff02dc374401000000001976a9144b7b335f978f130269fe661423258ae9642df8a188ac72b3d000000000001976a9146efcf883b4b6f9997be9a0600f6c095fe2bd2d9288ac000000000100000002060d3cb6dfb7ffe85e2908010fea63190c9707e96fc7448128eb895b5e222771030000006b483045022100f67cffc0ae23adb236ff3edb4a9736e277605db30cc7708dfab8cf1e1483bbce022052396aa5d664ec1cb65992c423fd9a17e94dc7af328d2d559e90746dd195ca5901210346134da14907581d8190d3980caaf46d95e4eb9c1ca8e70f1fc6007fefb1909dfeffffff7b2d8a8263cffbdb722e2a5c74166e6f2258634e277c0b08f51b578b667e2fba000000006a473044022077222a91cda23af69179377c62d84a176fb12caff6c5cbf6ae9e5957ff3b1afe0220768edead76819228dcba18cca3c9a5a5d4c32919720f21df21a297ba375bbe5c012103371ea5a4dfe356b3ea4042a537d7ab7ee0faabd43e21b6cc076fda2240629eeefeffffff02209a1d00000000001976a9148e451eec7ca0a1764b4ab119274efdd2727b3c8588ac40420f00000000001976a914d0fce8f064cd1059a6a11501dd66fe42368572b088accb250800';
var blockIndex = {
'hash': '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7',
'blockheight': 533974,
'chainWork': '0000000000000000000000000000000000000000000000054626b1839ade284a',
'prevHash': '00000000000001a55f3214e9172eb34b20e0bc5bd6b8007f3f149fca2c8991a4',
'chainwork': '0000000000000000000000000000000000000000000000054626b1839ade284a',
'previousblockhash': '00000000000001a55f3214e9172eb34b20e0bc5bd6b8007f3f149fca2c8991a4',
'height': 533974
};

Expand All @@ -226,21 +221,33 @@ describe('Transactions', function() {
getBlock: sinon.stub().callsArgWith(1, null, block),
services: {
bitcoind: {
getBlockIndex: sinon.stub().returns(blockIndex)
},
db: {
tip: {
__height: 534209
}
},
address: {
getInputForOutput: sinon.stub().callsArgWith(3, null, false),
getBlockHeader: sinon.stub().callsArgWith(1, null, blockIndex),
height: 534209
}
},
network: 'testnet'
};

bitcore.Transaction.prototype.populateInputs = function(db, pool, callback) {
bitcore.Transaction.prototype.populateSpentInfo = _.noop();
sandbox.stub(bitcore.Transaction.prototype, 'populateSpentInfo', function(db, options, callback) {
if (this.hash === 'b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0') {
this.outputs[1].__spentTxId = '614fe1708825f9c21732394e4784cc6808ac1d8b939736bfdead970567561eec';
this.outputs[1].__spentIndex = 1;
this.outputs[1].__spentHeight = 200;
} else if (this.hash === '2e01c7a4a0e335112236b711c4aaddd02e8dc59ba2cda416e8f80ff06dddd7e1') {
this.outputs[0].__spentTxId = '9a213b879da9073a9a30606f9046f35f36f268cbf03f6242993a97c4c07c00b9';
this.outputs[0].__spentIndex = 1;
this.outputs[0].__spentHeight = 200;

this.outputs[1].__spentTxId = '418d3eb60275957b3456b96902e908abf962e71be4c4f09486564254664951bc';
this.outputs[1].__spentIndex = 34;
this.outputs[1].__spentHeight = 200;
}
callback();
});

bitcore.Transaction.prototype.populateInputs = _.noop();
sandbox.stub(bitcore.Transaction.prototype, 'populateInputs', function(db, pool, callback) {
if(this.hash === 'b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0') {
this.inputs[0].output = new bitcore.Transaction.Output({
satoshis: 18535505,
Expand All @@ -263,7 +270,7 @@ describe('Transactions', function() {
}

callback();
};
});

var transactions = new TxController(node);

Expand Down Expand Up @@ -293,7 +300,10 @@ describe('Transactions', function() {
'addresses': [
'mq4oDPjmNWnBxbzx7qouzhpCSTMePUtYDF'
]
}
},
'spentTxId': null,
'spentIndex': null,
'spentHeight': null
}
],
'blockhash': '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7',
Expand Down Expand Up @@ -351,7 +361,10 @@ describe('Transactions', function() {
'addresses': [
'mnQ4ZaGessNgdxmWPxbTHcfx4b8R6eUr1X'
]
}
},
'spentTxId': null,
'spentIndex': null,
'spentHeight': null
},
{
'value': '0.13677426',
Expand All @@ -367,6 +380,7 @@ describe('Transactions', function() {
},
'spentTxId': '614fe1708825f9c21732394e4784cc6808ac1d8b939736bfdead970567561eec',
'spentIndex': 1,
'spentHeight': 200,
'spentTs': 1440997099
}
],
Expand Down Expand Up @@ -429,6 +443,7 @@ describe('Transactions', function() {
},
'spentTxId': '9a213b879da9073a9a30606f9046f35f36f268cbf03f6242993a97c4c07c00b9',
'spentIndex': 1,
'spentHeight': 200,
'spentTs': 1440992946
},
{
Expand All @@ -445,6 +460,7 @@ describe('Transactions', function() {
},
'spentTxId': '418d3eb60275957b3456b96902e908abf962e71be4c4f09486564254664951bc',
'spentIndex': 34,
'spentHeight': 200,
'spentTs': 1440999118
}
],
Expand Down Expand Up @@ -485,9 +501,7 @@ describe('Transactions', function() {
scriptPubKey: {
reqSigs: 1
},
spentIndex: 1,
spentTs: 1440997099,
spentTxId: '614fe1708825f9c21732394e4784cc6808ac1d8b939736bfdead970567561eec'
spentTs: 1440997099
}
]
},
Expand All @@ -499,17 +513,13 @@ describe('Transactions', function() {
scriptPubKey: {
reqSigs: 1
},
spentIndex: 1,
spentTs: 1440992946,
spentTxId: '9a213b879da9073a9a30606f9046f35f36f268cbf03f6242993a97c4c07c00b9'
spentTs: 1440992946
},
{
scriptPubKey: {
reqSigs: 1
},
spentIndex: 34,
spentTs: 1440999118,
spentTxId: '418d3eb60275957b3456b96902e908abf962e71be4c4f09486564254664951bc'
spentTs: 1440999118
}
]
}
Expand All @@ -524,7 +534,7 @@ describe('Transactions', function() {

var res = {
jsonp: function(data) {
var merged = _.merge(data, todos);
_.merge(data, todos);
should(data).eql(insight);
done();
}
Expand Down Expand Up @@ -610,41 +620,23 @@ describe('Transactions', function() {
txinfos[1].tx.__timestamp = 1441072817;
txinfos[1].tx.__height = 534110;

txinfos[0].tx.outputs[0].__spentTxId = '01f700df84c466f2a389440e5eeacdc47d04f380c39e5d19dce2ce91a11ecba3';
txinfos[0].tx.outputs[0].__spentIndex = 0;
txinfos[0].tx.outputs[0].__spentHeight = 199;

txinfos[1].tx.outputs[0].__spentTxId = '661194e5533a395ce9076f292b7e0fb28fe94cd8832a81b4aa0517ff58c1ddd2';
txinfos[1].tx.outputs[0].__spentIndex = 0;
txinfos[1].tx.outputs[0].__spentHeight = 134;

txinfos[1].tx.outputs[1].__spentTxId = '71a9e60c0341c9c258367f1a6d4253276f16e207bf84f41ff7412d8958a81bed';
txinfos[1].tx.outputs[1].__spentIndex = 0;
txinfos[1].tx.outputs[1].__spentHeight = 112;

var node = {
getAddressHistory: sinon.stub().callsArgWith(2, null, historyResult),
services: {
db: {
tip: {
__height: 534223
}
},
address: {
getInputForOutput: function(txid, outputIndex, options, callback) {
var data = false;
if (txid === 'bb0ec3b96209fac9529570ea6f83a86af2cceedde4aaf2bfcc4796680d23f1c7') {
if (outputIndex === 0) {
data = {
inputTxId: '01f700df84c466f2a389440e5eeacdc47d04f380c39e5d19dce2ce91a11ecba3',
inputIndex: 0
};
}
} else if (txid === '01f700df84c466f2a389440e5eeacdc47d04f380c39e5d19dce2ce91a11ecba3') {
if (outputIndex === 0) {
data = {
inputTxId: '661194e5533a395ce9076f292b7e0fb28fe94cd8832a81b4aa0517ff58c1ddd2',
inputIndex: 0
};
} else if (outputIndex === 1) {
data = {
inputTxId: '71a9e60c0341c9c258367f1a6d4253276f16e207bf84f41ff7412d8958a81bed',
inputIndex: 0
};
}
}
setImmediate(function() {
callback(null, data);
});
}
bitcoind: {
height: 534223
}
},
network: 'testnet'
Expand Down Expand Up @@ -688,6 +680,7 @@ describe('Transactions', function() {
},
'spentTxId': '01f700df84c466f2a389440e5eeacdc47d04f380c39e5d19dce2ce91a11ecba3',
'spentIndex': 0,
'spentHeight': 199,
'spentTs': 1441072817
},
{
Expand All @@ -701,7 +694,10 @@ describe('Transactions', function() {
'addresses': [
'muHmEsjhjmATf9i3T9gHyeQoce9LXe2dWz'
]
}
},
'spentTxId': null,
'spentIndex': null,
'spentHeight': null
}
],
'blockhash': '00000000000001001aba15de213648f370607fb048288dd27b96f7e833a73520',
Expand Down Expand Up @@ -749,6 +745,7 @@ describe('Transactions', function() {
},
'spentTxId': '661194e5533a395ce9076f292b7e0fb28fe94cd8832a81b4aa0517ff58c1ddd2',
'spentIndex': 0,
'spentHeight': 134,
'spentTs': 1441077236
},
{
Expand All @@ -765,6 +762,7 @@ describe('Transactions', function() {
},
'spentTxId': '71a9e60c0341c9c258367f1a6d4253276f16e207bf84f41ff7412d8958a81bed',
'spentIndex': 0,
'spentHeight': 112,
'spentTs': 1441069523
}
],
Expand Down Expand Up @@ -845,7 +843,7 @@ describe('Transactions', function() {
var hex = '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff2303d6250800feb0aae355fe263600000963676d696e6572343208ae5800000000000000ffffffff01c018824a000000001976a91468bedce8982d25c3b6b03f6238cbad00378b8ead88ac00000000';

var node = {
getTransaction: sinon.stub().callsArgWith(2, null, bitcore.Transaction().fromBuffer(new Buffer(hex, 'hex')))
getTransaction: sinon.stub().callsArgWith(1, null, bitcore.Transaction().fromBuffer(new Buffer(hex, 'hex')))
};

var transactions = new TxController(node);
Expand Down

0 comments on commit c68b9e1

Please sign in to comment.