-
Notifications
You must be signed in to change notification settings - Fork 0
API test - Verify transaction from Microblock to anchorblock #2
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
base: main
Are you sure you want to change the base?
Conversation
chore: addtest
rafaelcr
left a comment
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.
Looks good so far, adding a few comments
| if (!foundMicroBlock) { | ||
| await wait(10000); | ||
| console.log("Calling microblock API..."); | ||
| const isTXIDExistMB = await checkTXIDInMicroBlock(txid); |
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.
There could be some situations when the transaction doesn't get picked up by any microblock but only by an anchor block.
I know you're currently not failing the test if you don't see the tx in a microblock, but I wanted to point that out in case you wanted to create a secondary test later surrounding microblocks.
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.
That is a great point I can definitely create a better check for that I have an assertion for it currently but let me make sure it works accurately.
|
|
||
| // step 4: CURL the Anchor block API to make sure that TXID exist | ||
| console.log("Calling Anchor block API..."); | ||
| const isTXIDExistAB = await checkTXIDInAnchorBlock(txid); |
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 think another valuable API request would be to check if https://stacks-node-api.mainnet.stacks.co/extended/v1/tx/{tx_id} confirms the transaction exists in the same anchor block and with the correct properties
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 can add that as well
| export async function getAnchorBlock(): Promise<any> { | ||
| return new Promise((resolve, reject) => { | ||
| axios | ||
| .get('https://stacks-node-api.testnet.stacks.co/extended/v1/tx?limit=200') |
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.
A block may contain more than 200 transactions, there could be cases where you don't see the transaction because of this paging limit.
A better approach would be to record the current block_height before sending the tx, and then trying to retrieve the next blocks via /extended/v1/block until you see the tx_id listed
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.
Could you please elaborate a bit on how to do this, this is my first time taking this approach and I want to make sure I clearly understand the steps.
|
|
||
| async function sendTokens(nonce: number, recipient: string): Promise<any> { | ||
| const { stdout, stderr } = await exec( | ||
| `stx -t send_tokens ${recipient} 12345 999 ${nonce} fd3609e8b9352facf360c950d362afe8f0f108b9041750f54b017efc479efeb001` |
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'm not too familiar with the stx cli... is any of these inputs sensitive info? In that case you could save it as a Github actions secret in the repo and use it as an input via an ENV var
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.
Sure I can do that this is a test account so I just threw the private key into the script but I do see your point.
|
@rafaelcr Thank you for your feed back it was very valuable I will make the changes. |
Please take a look at my first pass at API test if this works I can continue to increase coverage but I wanted to get your feed back before I moved forward.
I am hit the API to get the balance and taking the NONCE.
I then use that NONCE to send a transaction.
I then verify the transaction is pulled into a microblock.
I then verify the transaction is confirmed into a anchorblock.
This is my first pass at creating test to verify the API response data, if this aligns with your needs I will continue down this path.
@zone117x
@rafaelcr