Skip to content

Conversation

@timstackblock
Copy link
Owner

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

chore: addtest
Copy link

@rafaelcr rafaelcr left a 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);

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.

Copy link
Owner Author

@timstackblock timstackblock Jan 25, 2023

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);

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

Copy link
Owner Author

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')

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

Copy link
Owner Author

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`

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

Copy link
Owner Author

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.

@timstackblock
Copy link
Owner Author

@rafaelcr Thank you for your feed back it was very valuable I will make the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants