Skip to content

Commit

Permalink
return txn data on success and txn failure reason on failure (#9433)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmaayan authored and xbtmatt committed Aug 13, 2023
1 parent 00dc1c9 commit f86e60a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions ecosystem/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to the Aptos Node SDK will be captured in this file. This ch
## Unreleased

- Add support for a fee payer transaction
- Return transaction message error when transaction has failed when `checkSuccess` is set to true

## 1.16.0 (2023-08-02)

Expand Down
2 changes: 1 addition & 1 deletion ecosystem/typescript/sdk/src/providers/aptos_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ export class AptosClient {
}
if (!(lastTxn as any)?.success) {
throw new FailedTransactionError(
`Transaction ${txnHash} committed to the blockchain but execution failed`,
`Transaction ${txnHash} failed with an error: ${(lastTxn as any).vm_status}`,
lastTxn,
);
}
Expand Down
53 changes: 53 additions & 0 deletions ecosystem/typescript/sdk/src/tests/e2e/aptos_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,59 @@ test(
longTestTimeout,
);

test(
"it returns succeed transaction data",
async () => {
const client = new AptosClient(NODE_URL);
const faucetClient = getFaucetClient();
const sender = new AptosAccount();
const receiver = new AptosAccount();
await faucetClient.fundAccount(sender.address(), 100_000_000);
const entryFunctionPayload = new TxnBuilderTypes.TransactionPayloadEntryFunction(
TxnBuilderTypes.EntryFunction.natural(
"0x1::aptos_account",
"transfer",
[],
[bcsToBytes(TxnBuilderTypes.AccountAddress.fromHex(receiver.address())), bcsSerializeUint64(1000)],
),
);
const txn = await client.generateSignSubmitWaitForTransaction(sender, entryFunctionPayload, { checkSuccess: true });
expect((txn as any).success).toBeTruthy();
expect(txn as any).toHaveProperty("changes");
expect((txn as any).vm_status).toEqual("Executed successfully");
},
longTestTimeout,
);

test(
"it returns failed transaction reason",
async () => {
const client = new AptosClient(NODE_URL);
const faucetClient = getFaucetClient();
const sender = new AptosAccount();
const receiver = new AptosAccount();
await faucetClient.fundAccount(sender.address(), 100_000_000);
const entryFunctionPayload = new TxnBuilderTypes.TransactionPayloadEntryFunction(
TxnBuilderTypes.EntryFunction.natural(
"0x1::aptos_account",
"transfer",
[],
[bcsToBytes(TxnBuilderTypes.AccountAddress.fromHex(receiver.address()))],
),
);

const rawTxn = await client.generateRawTransaction(sender.address(), entryFunctionPayload);
const bcsTxn = AptosClient.generateBCSTransaction(sender, rawTxn);
const txn = await client.submitSignedBCSTransaction(bcsTxn);
expect(async () => {
await client.waitForTransactionWithResult(txn.hash, { checkSuccess: true });
}).rejects.toThrow(
`Transaction ${txn.hash} failed with an error: Transaction Executed and Committed with Error NUMBER_OF_ARGUMENTS_MISMATCH`,
);
},
longTestTimeout,
);

test(
"submits bcs transaction simulation",
async () => {
Expand Down

0 comments on commit f86e60a

Please sign in to comment.