-
Notifications
You must be signed in to change notification settings - Fork 809
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
base: master
Are you sure you want to change the base?
Node RPC Tests #810
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Probably worth adding tests for |
I can do those test in this PR as well, I was considering doing it in separate PR. |
|
||
before(async () => { | ||
await node.open(); | ||
await fullnode.open(); |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
test/node-rpc-test.js
Outdated
@@ -236,6 +236,90 @@ describe('RPC', function() { | |||
}); | |||
}); | |||
|
|||
describe('getblockchaininfo', function() { | |||
const check = (info, options) => { | |||
assert.ok(info); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 .ok
s.
But can go back to assert
s.
test/node-rpc-test.js
Outdated
const info = await nclient.execute('getblockchaininfo'); | ||
const height = fullnode.chain.height; | ||
|
||
await check(info, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: unnecessary await?
There was a problem hiding this comment.
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.
test/node-rpc-test.js
Outdated
}); | ||
}); | ||
|
||
function isHex(string) { | ||
const hexCheck = /^([0-9a-f]{2})*$/i; |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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/util
s), it's just a habit/convention at this point. :)
test/node-rpc-test.js
Outdated
|
||
const tweaked = mblock.toRaw().toString('hex'); | ||
|
||
// should fail in fullnode or in pruned mode (if there's block available). |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
- Blocks that are shared are only coinbase blocks and is managed by miner wallet/address/mining api.
- 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.
RPC tests:
help help
help
testsgetinfo
.getblockchaininfo
.getnetworkinfo
.verifytxoutproof
to check totalTX count if possible. (performance degrades)gettxoutproof
andverifytxoutproof
.