Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node RPC Tests #810

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Node RPC Tests #810

wants to merge 10 commits into from

Conversation

nodech
Copy link
Member

@nodech nodech commented Jul 2, 2019

RPC tests:

  • Fix help help
  • help tests
  • remove getinfo.
  • test for getblockchaininfo.
  • test for getnetworkinfo.
  • Change verifytxoutproof to check totalTX count if possible. (performance degrades)
    • If performance is an issue we could index this information separately or with headers(entry).
  • Add tests for gettxoutproof and verifytxoutproof.

@codecov-io
Copy link

codecov-io commented Jul 2, 2019

Codecov Report

Merging #810 into master will increase coverage by 4.76%.
The diff coverage is 93.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #810      +/-   ##
==========================================
+ Coverage   62.01%   66.78%   +4.76%     
==========================================
  Files         147      147              
  Lines       25379    25384       +5     
==========================================
+ Hits        15740    16953    +1213     
+ Misses       9639     8431    -1208
Impacted Files Coverage Δ
lib/node/rpc.js 33.16% <93.33%> (+6.31%) ⬆️
lib/primitives/mtx.js 61.56% <0%> (+0.12%) ⬆️
lib/wallet/walletdb.js 77.7% <0%> (+0.25%) ⬆️
lib/mempool/mempool.js 65.76% <0%> (+0.33%) ⬆️
lib/coins/coinview.js 75.17% <0%> (+0.7%) ⬆️
lib/net/bip152.js 86.1% <0%> (+1.01%) ⬆️
lib/primitives/abstractblock.js 89.88% <0%> (+1.12%) ⬆️
lib/node/node.js 76.25% <0%> (+1.43%) ⬆️
lib/net/packets.js 80% <0%> (+2.04%) ⬆️
lib/primitives/block.js 75.1% <0%> (+2.4%) ⬆️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4542ec5...828a269. Read the comment docs.

@nodech nodech added api HTTP, RPC, authentication ready for review Ready to be reviewed tests Has tests for code change is just an addtional test labels Jul 2, 2019
@braydonf
Copy link
Contributor

braydonf commented Jul 2, 2019

Probably worth adding tests for getblockchaininfo and other info related methods getnetworkinfo and getmininginfo that were added as replacement in addition to getinfo. As far as deprecating getinfo, it would probably be good to do, since it's mostly stubbed out currently.

@nodech
Copy link
Member Author

nodech commented Jul 2, 2019

I can do those test in this PR as well, I was considering doing it in separate PR.
At least deprecation can happen here

@nodech nodech changed the title rpc test - getinfo, help Node RPC Tests Jul 3, 2019

before(async () => {
await node.open();
await fullnode.open();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can modify/improve on test/util/node-context for managing multiple connected nodes.

await wclient.execute('selectwallet', [MINER_WALLET]);

// setup miner wallet
const address = await wclient.execute('getnewaddress');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For miner we could have MinerContext which will manage funds specifically to miner that will only act as faucet.

name: 'Error',
type: 'RPCError',
message: /SPV/,
code: -1 >>> 0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This trick here, help with the bug in bcurl: bcoin-org/bcurl#16

@braydonf braydonf added rpc and removed api HTTP, RPC, authentication labels Jul 9, 2019
test/node-rpc-test.js Outdated Show resolved Hide resolved
test/node-rpc-test.js Outdated Show resolved Hide resolved
@nodech nodech removed the ready for review Ready to be reviewed label Jul 12, 2019
@@ -236,6 +236,90 @@ describe('RPC', function() {
});
});

describe('getblockchaininfo', function() {
const check = (info, options) => {
assert.ok(info);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: assert() === assert.ok(), shorter to use assert() and more consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, but .ok kinda felt for testing was more descriptive. That's the only reason for .oks.
But can go back to asserts.

const info = await nclient.execute('getblockchaininfo');
const height = fullnode.chain.height;

await check(info, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unnecessary await?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it was async before and forgot to remove.

});
});

function isHex(string) {
const hexCheck = /^([0-9a-f]{2})*$/i;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could be a one-liner:

return /^([0-9a-f]{2})*$/i.test(string);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mostly prefer non-one-liners, if they are not arrow functions. It's easier to quickly modify and debug what's going on.

This case can be rewritten in one-liner it wont change (it can even move to test/utils), it's just a habit/convention at this point. :)


const tweaked = mblock.toRaw().toString('hex');

// should fail in fullnode or in pruned mode (if there's block available).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Comments generally have capitalization of comments (especially for sentences).

await wclient.execute('selectwallet', [MINER_WALLET]);
const minerAddr = await wclient.execute('getnewaddress');

{ // block 0 - This block will have 2 txs (including coinbase)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are generating blocks on the chain shared by all tests. Should the setup be a part of the before for all tests? It could potentially be generic enough. Currently this is the last test, so no other tests depend on it, however as more tests are added, they would always need to be added before the test to not depend state changes within these tests. Also, I don't think these tests require having all sets of different nodes, spv and etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though chain is same for the testsuite, this test generates its own blocks.

I was having several conventions that I have not described in the document.

  1. Blocks that are shared are only coinbase blocks and is managed by miner wallet/address/mining api.
  2. If test needs to generate blocks, or specific blocks are necessary to test the api then it can generate blocks in its context and only use general blocks as faucet (miner).

I even considered doing reset in the test case in after, but have not used it so far because there was no apparent problem with current approach. Still any test messes up another test case we can use reset.

This is highly unlikely though. Each describe can figure out relevant state before starting the test and describe it as a starting point and do tests relative to the current state regardless which tests were skipped or chosen.

Even though SPV and Prune node tests currently have small usage, for some APIs difference gets bigger so described it in the beginning with minor tests and other tests can use it. We can remove if after everything is done, they don't provide value.

@nodech nodech mentioned this pull request Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rpc tests Has tests for code change is just an addtional test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants