Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mvares committed Jul 7, 2024
1 parent 3200928 commit 8b4b5b3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion apps/docs-snippets/src/guide/provider/querying-the-chain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,27 @@ describe('querying the chain', () => {
// #region Message-getMessages
// #import { TestMessage, launchTestNode };

// Creates a test message with an amount of 100
const testMessage = new TestMessage({ amount: 100 });

// Launches a test node with the test message configured
using launched = await launchTestNode({ walletsConfig: { messages: [testMessage] } });
const {
wallets: [wallet],
} = launched;

// Retrieves messages from the wallet
const [message] = await wallet.getMessages();
// #endregion Message-getMessages

expect(message.nonce).toEqual(testMessage.nonce);
});

it('can getResourcesToSpend', async () => {
// #region Message-getResourcesToSpend
// #import { launchTestNode, AssetId };

// Launches a test node with pre-configured assets
using launched = await launchTestNode({
walletsConfig: {
assets: [AssetId.A, AssetId.B],
Expand All @@ -155,18 +160,21 @@ describe('querying the chain', () => {
},
});

// Defines asset IDs
const assetIdA = '0x0101010101010101010101010101010101010101010101010101010101010101';
const assetIdB = '0x0202020202020202020202020202020202020202020202020202020202020202';

const {
wallets: [wallet],
} = launched;

// Retrieves spendable resources for the specified asset amounts
const spendableResources = await wallet.getResourcesToSpend([
{ amount: 40, assetId: assetIdA },
{ amount: 50, assetId: assetIdB },
]);
// #endregion Message-getResourcesToSpend

expect(spendableResources[0].amount).toEqual(bn(100));
expect(spendableResources[1].amount).toEqual(bn(100));
});
Expand All @@ -175,6 +183,7 @@ describe('querying the chain', () => {
// #region Message-getMessageProof
// #import { launchTestNode, TransactionResultMessageOutReceipt };

// Launches a test node with two wallets established
using launched = await launchTestNode({
walletsConfig: {
count: 2,
Expand All @@ -186,18 +195,23 @@ describe('querying the chain', () => {
provider,
} = launched;

// Defines the recipient address
const recipientAddress = recipient.address.toB256();

// Performs a withdrawal transaction from sender to recipient
const tx = await sender.withdrawToBaseLayer(recipientAddress, 100);
const result = await tx.waitForResult();

// Retrieves the message out receipt from the transaction result
const messageOutReceipt = result.receipts[0] as TransactionResultMessageOutReceipt;

// Retrieves the message proof for the transaction ID and nonce
const messageProof = await provider.getMessageProof(
result.gqlTransaction.id,
messageOutReceipt.nonce
);

// #endregion Message-getMessageProof

expect(messageProof?.amount.toNumber()).toEqual(100);
expect(messageProof?.sender.toHexString()).toEqual(result.id);
});
Expand Down

0 comments on commit 8b4b5b3

Please sign in to comment.