Skip to content

Commit

Permalink
test: initial http tests for indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
braydonf committed Mar 26, 2019
1 parent 4394ddf commit 4dd0a9c
Showing 1 changed file with 116 additions and 0 deletions.
116 changes: 116 additions & 0 deletions test/indexer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ const MemWallet = require('./util/memwallet');
const TXIndexer = require('../lib/indexer/txindexer');
const AddrIndexer = require('../lib/indexer/addrindexer');
const BlockStore = require('../lib/blockstore/level');
const FullNode = require('../lib/node/fullnode');
const Network = require('../lib/protocol/network');
const network = Network.get('regtest');
const {NodeClient, WalletClient} = require('bclient');

const workers = new WorkerPool({
enabled: true
Expand Down Expand Up @@ -198,4 +200,118 @@ describe('Indexer', function() {
}
});
});

describe('http', function() {
let node, nclient, wclient = null;

const vectors = [
// Secret for the vectors:
// cVDJUtDjdaM25yNVVDLLX3hcHUfth4c7tY3rSc4hy9e8ibtCuj6G
// {addr: 'bcrt1qngw83fg8dz0k749cg7k3emc7v98wy0c7azaa6h', amount: 19.99},
{addr: 'muZpTpBYhxmRFuCjLc7C6BBDF32C8XVJUi', amount: 1.99}
];

const txids = [];

const ports = {
p2p: 49331,
node: 49332,
wallet: 49333
};

before(async () => {
// Setup a testing node with txindex and addrindex
// both enabled.
node = new FullNode({
network: 'regtest',
apiKey: 'foo',
walletAuth: true,
memory: true,
workers: true,
indexTX: true,
indexAddress: true,
port: ports.p2p,
httpPort: ports.node,
plugins: [require('../lib/wallet/plugin')],
env: {
'BCOIN_WALLET_HTTP_PORT': ports.wallet.toString()
}
});

await node.open();

// Setup the node client to make calls to the node
// to generate blocks and other tasks.
nclient = new NodeClient({
port: ports.node,
apiKey: 'foo'
});

await nclient.open();

// Setup a test wallet to generate transactions for
// testing various scenarios.
wclient = new WalletClient({
port: ports.wallet,
apiKey: 'foo'
});

await wclient.open();

// Generate initial set of transactions and
// send the coinbase to alice.
const coinbase = await wclient.execute(
'getnewaddress', ['default']);

const blocks = await nclient.execute(
'generatetoaddress', [120, coinbase]);

assert.equal(blocks.length, 120);

// Send to the vector addresses for several blocks.
for (let i = 0; i < 10; i++) {
for (const v of vectors) {
const txid = await wclient.execute(
'sendtoaddress', [v.addr, v.amount]);

txids.push(txid);
}

const blocks = await nclient.execute(
'generatetoaddress', [1, coinbase]);

assert.equal(blocks.length, 1);
}
});

after(async () => {
await nclient.close();
await wclient.close();
await node.close();
});

it('will get txs by address', async () => {
for (const v of vectors) {
const res = await nclient.request(
'GET', `/tx/address/${v.addr}`, {});

assert.equal(res.length, 10);

for (const tx of res)
assert(txids.includes(tx.hash));
}
});

it.skip('will get txs by address (limit)', async () => {
});

it.skip('will get txs by address (reverse)', async () => {
});

it.skip('will get txs by address after txid', async () => {
});

it.skip('will get txs by address after txid (reverse)', async () => {
});
});
});

0 comments on commit 4dd0a9c

Please sign in to comment.