From 69e9844f82c936a33a793a5f390ffd5f01bacd04 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 17 Apr 2019 17:50:52 -0700 Subject: [PATCH] test: cleanup and add txindex tests --- lib/indexer/txindexer.js | 3 --- test/indexer-test.js | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/lib/indexer/txindexer.js b/lib/indexer/txindexer.js index 15e73f53..4c1d5eb0 100644 --- a/lib/indexer/txindexer.js +++ b/lib/indexer/txindexer.js @@ -124,9 +124,6 @@ class TxRecord { this.height = br.readU32(); this.index = br.readU32(); - if (this.index === 0x7fffffff) - this.index = -1; - this.offset = br.readU32(); this.length = br.readU32(); diff --git a/test/indexer-test.js b/test/indexer-test.js index 8f8bb2f0..e2600302 100644 --- a/test/indexer-test.js +++ b/test/indexer-test.js @@ -80,10 +80,14 @@ describe('Indexer', function() { }); describe('index 10 blocks', function() { + let addr = null; + before(async () => { miner.addresses.length = 0; miner.addAddress(wallet.getReceive()); + addr = miner.getAddress(); + for (let i = 0; i < 10; i++) { const block = await cpu.mineBlock(); assert(block); @@ -101,13 +105,11 @@ describe('Indexer', function() { }); it('should get txs by address (limit)', async () => { - const addr = miner.getAddress(); const hashes = await addrindexer.getHashesByAddress(addr, {limit: 1}); assert.strictEqual(hashes.length, 1); }); it('should get txs by address (reverse)', async () => { - const addr = miner.getAddress(); const hashes = await addrindexer.getHashesByAddress( addr, {reverse: false}); @@ -122,8 +124,7 @@ describe('Indexer', function() { assert.deepEqual(hashes[i], reversed[9 - i]); }); - it('should txs by address after txid', async () => { - const addr = miner.getAddress(); + it('should get txs by address after txid', async () => { const hashes = await addrindexer.getHashesByAddress(addr, {limit: 5}); assert.strictEqual(hashes.length, 5); @@ -141,8 +142,7 @@ describe('Indexer', function() { assert.deepEqual(hashes.concat(next), all); }); - it('should txs by address after txid (reverse)', async () => { - const addr = miner.getAddress(); + it('should get txs by address after txid (reverse)', async () => { const hashes = await addrindexer.getHashesByAddress( addr, {limit: 5, reverse: true}); @@ -162,6 +162,31 @@ describe('Indexer', function() { assert.deepEqual(hashes.concat(next), all); }); + + it('should get tx and meta', async () => { + const hashes = await addrindexer.getHashesByAddress(addr, {limit: 1}); + assert.equal(hashes.length, 1); + const hash = hashes[0]; + + const tx = await txindexer.getTX(hash); + const meta = await txindexer.getMeta(hash); + + assert(meta.height); + assert(meta.block); + assert(meta.time); + + assert.deepEqual(meta.tx, tx); + }); + + it('should get null if not found for tx and meta', async () => { + const hash = Buffer.alloc(32); + + const tx = await txindexer.getTX(hash); + const meta = await txindexer.getMeta(hash); + + assert.strictEqual(tx, null); + assert.strictEqual(meta, null); + }); }); describe('rescan and reorg', function() {