|
1 | 1 | import * as testData from '../resources/apt'; |
2 | 2 | import should from 'should'; |
3 | 3 | import utils from '../../src/lib/utils'; |
4 | | -import { SignedTransaction, TransactionAuthenticatorFeePayer } from '@aptos-labs/ts-sdk'; |
| 4 | +import { |
| 5 | + SignedTransaction, |
| 6 | + TransactionAuthenticatorFeePayer, |
| 7 | + TransactionPayloadEntryFunction, |
| 8 | +} from '@aptos-labs/ts-sdk'; |
5 | 9 |
|
6 | 10 | describe('Aptos util library', function () { |
7 | 11 | describe('isValidAddress', function () { |
@@ -48,4 +52,36 @@ describe('Aptos util library', function () { |
48 | 52 | // without 0x prefix |
49 | 53 | should.equal(true, utils.isValidPublicKey('9b4e96086d111500259f9b38680b0509a405c1904da18976455a20c691d3bb07')); |
50 | 54 | }); |
| 55 | + |
| 56 | + it('deserializeFeePayerRawTransaction', function () { |
| 57 | + const signablePayloadHex = |
| 58 | + '5efa3c4f02f83a0f4b2d69fc95c607cc02825cc4e7be536ef0992df050d9e67c01f22fa009b6473cdc539ecbd570d00d0585682f5939ffe256a90ddee0d616292f000000000000000002000000000000000000000000000000000000000000000000000000000000000104636f696e087472616e73666572010700000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e000220da22bdc19f873fd6ce48c32912965c8a9dde578b2a3cf4fae3dd85dfaac784c908e803000000000000a8610000000000006400000000000000901cdd68000000000200adba44b46722b8da1797645f71ddcdab28626c06acd36b88d5198a684966306c'; |
| 59 | + const feePayerRawTransactionHex = signablePayloadHex.slice(66); // remove the first 33 bytes (66 hex characters) |
| 60 | + const feePayerRawTransaction = utils.deserializeFeePayerRawTransaction(feePayerRawTransactionHex); |
| 61 | + const rawTxn = feePayerRawTransaction.raw_txn; |
| 62 | + |
| 63 | + const sender = rawTxn.sender.toString(); |
| 64 | + const sequenceNumber = utils.castToNumber(rawTxn.sequence_number); |
| 65 | + const maxGasAmount = utils.castToNumber(rawTxn.max_gas_amount); |
| 66 | + const gasUnitPrice = utils.castToNumber(rawTxn.gas_unit_price); |
| 67 | + const expirationTime = utils.castToNumber(rawTxn.expiration_timestamp_secs); |
| 68 | + should.equal(sender, '0xf22fa009b6473cdc539ecbd570d00d0585682f5939ffe256a90ddee0d616292f'); |
| 69 | + should.equal(sequenceNumber, 0); |
| 70 | + should.equal(maxGasAmount, 25000); |
| 71 | + should.equal(gasUnitPrice, 100); |
| 72 | + should.equal(expirationTime, 1759321232); |
| 73 | + |
| 74 | + const entryFunction = (rawTxn.payload as TransactionPayloadEntryFunction).entryFunction; |
| 75 | + const functionName = `${entryFunction.module_name.address.toString()}::${entryFunction.module_name.name.identifier.toString()}::${entryFunction.function_name.identifier.toString()}`; |
| 76 | + should.equal(functionName, '0x1::coin::transfer'); |
| 77 | + const assetId = entryFunction.type_args[0].toString(); |
| 78 | + should.equal(assetId, '0x1::aptos_coin::AptosCoin'); |
| 79 | + |
| 80 | + const addressArg = entryFunction.args[0]; |
| 81 | + const amountArg = entryFunction.args[1]; |
| 82 | + const recipients = utils.parseRecipients(addressArg, amountArg); |
| 83 | + should.equal(recipients.length, 1); |
| 84 | + should.equal(recipients[0].address, '0xda22bdc19f873fd6ce48c32912965c8a9dde578b2a3cf4fae3dd85dfaac784c9'); |
| 85 | + should.equal(recipients[0].amount, '1000'); |
| 86 | + }); |
51 | 87 | }); |
0 commit comments