From 3668a26faafb5b61399b9ef665bf58fd77b0452b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Mon, 16 Sep 2024 18:36:23 -0300 Subject: [PATCH] fix: add missing receipts properties (#3156) --- .changeset/three-hairs-approve.md | 6 +++++ .../transaction-summary/operations.test.ts | 1 + .../providers/transaction-summary/receipt.ts | 22 ++----------------- .../src/providers/utils/receipts.test.ts | 4 ++++ .../account/src/providers/utils/receipts.ts | 4 ++++ .../test/fixtures/transaction-summary.ts | 1 + .../transactions/src/coders/receipt.test.ts | 3 +++ packages/transactions/src/coders/receipt.ts | 15 +++++++++++++ 8 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 .changeset/three-hairs-approve.md diff --git a/.changeset/three-hairs-approve.md b/.changeset/three-hairs-approve.md new file mode 100644 index 00000000000..61642445ff1 --- /dev/null +++ b/.changeset/three-hairs-approve.md @@ -0,0 +1,6 @@ +--- +"@fuel-ts/transactions": patch +"@fuel-ts/account": patch +--- + +fix: add missing receipts properties diff --git a/packages/account/src/providers/transaction-summary/operations.test.ts b/packages/account/src/providers/transaction-summary/operations.test.ts index 623c29e928e..9a00406afc2 100644 --- a/packages/account/src/providers/transaction-summary/operations.test.ts +++ b/packages/account/src/providers/transaction-summary/operations.test.ts @@ -915,6 +915,7 @@ describe('operations', () => { nonce: '0x66c4d70c08ff30cd2d9dae0b6fd05972997579328529bb0605dd604afedfdf93', recipient: '0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266', sender: '0x4aec2335430f52d0314a03b244d285c675d790dfbf0bc853fd31e39548ad8b7d', + len: 0, type: 10, }; diff --git a/packages/account/src/providers/transaction-summary/receipt.ts b/packages/account/src/providers/transaction-summary/receipt.ts index 85561e77cce..b5f8d7662e5 100644 --- a/packages/account/src/providers/transaction-summary/receipt.ts +++ b/packages/account/src/providers/transaction-summary/receipt.ts @@ -6,26 +6,8 @@ import { assembleReceiptByType } from '../utils'; import type { BurnedAsset, MintedAsset } from './types'; -export const processGqlReceipt = (gqlReceipt: GqlReceiptFragment): TransactionResultReceipt => { - const receipt = assembleReceiptByType(gqlReceipt); - - switch (receipt.type) { - case ReceiptType.ReturnData: { - return { - ...receipt, - data: gqlReceipt.data || '0x', - }; - } - case ReceiptType.LogData: { - return { - ...receipt, - data: gqlReceipt.data || '0x', - }; - } - default: - return receipt; - } -}; +export const processGqlReceipt = (gqlReceipt: GqlReceiptFragment): TransactionResultReceipt => + assembleReceiptByType(gqlReceipt); export const extractMintedAssetsFromReceipts = ( receipts: Array diff --git a/packages/account/src/providers/utils/receipts.test.ts b/packages/account/src/providers/utils/receipts.test.ts index cc9b6b86c0f..5da13b10377 100644 --- a/packages/account/src/providers/utils/receipts.test.ts +++ b/packages/account/src/providers/utils/receipts.test.ts @@ -72,6 +72,7 @@ describe('assembleReceiptByType', () => { expect(receipt.len).toStrictEqual(new BN(MOCK_GQL_RECEIPT_FRAGMENT.len)); expect(receipt.is).toStrictEqual(new BN(MOCK_GQL_RECEIPT_FRAGMENT.is)); expect(receipt.pc).toStrictEqual(new BN(MOCK_GQL_RECEIPT_FRAGMENT.pc)); + expect(receipt.data).toStrictEqual(MOCK_GQL_RECEIPT_FRAGMENT.data); expect(receipt.ptr).toStrictEqual(new BN(MOCK_GQL_RECEIPT_FRAGMENT.ptr)); }); @@ -133,6 +134,7 @@ describe('assembleReceiptByType', () => { expect(receipt.len).toStrictEqual(new BN(MOCK_GQL_RECEIPT_FRAGMENT.len)); expect(receipt.val0).toStrictEqual(new BN(MOCK_GQL_RECEIPT_FRAGMENT.ra)); expect(receipt.val1).toStrictEqual(new BN(MOCK_GQL_RECEIPT_FRAGMENT.rb)); + expect(receipt.data).toStrictEqual(MOCK_GQL_RECEIPT_FRAGMENT.data); }); it('should return a ReceiptTransfer receipt when GqlReceiptType.Transfer is provided', () => { @@ -218,6 +220,7 @@ describe('assembleReceiptByType', () => { const amount = bn(MOCK_GQL_RECEIPT_FRAGMENT.amount); const data = arrayify(MOCK_GQL_RECEIPT_FRAGMENT.data || ''); const digest = MOCK_GQL_RECEIPT_FRAGMENT.digest; + const len = Number(MOCK_GQL_RECEIPT_FRAGMENT.len); const messageId = ReceiptMessageOutCoder.getMessageId({ sender, @@ -234,6 +237,7 @@ describe('assembleReceiptByType', () => { expect(receipt.nonce).toStrictEqual(nonce); expect(receipt.recipient).toStrictEqual(recipient); expect(receipt.sender).toStrictEqual(sender); + expect(receipt.len).toStrictEqual(len); expect(receipt.data).toStrictEqual(data); }); diff --git a/packages/account/src/providers/utils/receipts.ts b/packages/account/src/providers/utils/receipts.ts index ea3d181773a..bfc1ec9b85f 100644 --- a/packages/account/src/providers/utils/receipts.ts +++ b/packages/account/src/providers/utils/receipts.ts @@ -102,6 +102,7 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) { len: bn(receipt.len), digest: hexOrZero(receipt.digest), pc: bn(receipt.pc), + data: hexOrZero(receipt.data), is: bn(receipt.is), }; @@ -157,6 +158,7 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) { len: bn(receipt.len), digest: hexOrZero(receipt.digest), pc: bn(receipt.pc), + data: hexOrZero(receipt.data), is: bn(receipt.is), }; return logDataReceipt; @@ -206,6 +208,7 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) { const amount = bn(receipt.amount); const data = receipt.data ? arrayify(receipt.data) : Uint8Array.from([]); const digest = hexOrZero(receipt.digest); + const len = bn(receipt.len).toNumber(); const messageId = InputMessageCoder.getMessageId({ sender, @@ -221,6 +224,7 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) { recipient, amount, nonce, + len, data, digest, messageId, diff --git a/packages/account/test/fixtures/transaction-summary.ts b/packages/account/test/fixtures/transaction-summary.ts index 9e954446590..10054eef528 100644 --- a/packages/account/test/fixtures/transaction-summary.ts +++ b/packages/account/test/fixtures/transaction-summary.ts @@ -177,6 +177,7 @@ export const MOCK_RECEIPT_MESSAGE_OUT: TransactionResultMessageOutReceipt = { amount: bn.parseUnits('0.001'), nonce: '0x66c4d70c08ff30cd2d9dae0b6fd05972997579328529bb0605dd604afedfdf93', digest: '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', + len: 0, data: new Uint8Array(), }; diff --git a/packages/transactions/src/coders/receipt.test.ts b/packages/transactions/src/coders/receipt.test.ts index 1e2db2b91be..77b185c1957 100644 --- a/packages/transactions/src/coders/receipt.test.ts +++ b/packages/transactions/src/coders/receipt.test.ts @@ -72,6 +72,7 @@ describe('ReceiptCoder', () => { digest: B256, pc: bn(0), is: bn(0), + data: '0x', }; const encoded = hexlify(new ReceiptCoder().encode(receipt)); @@ -164,6 +165,7 @@ describe('ReceiptCoder', () => { digest: B256, pc: bn(0), is: bn(0), + data: '0x', }; const encoded = hexlify(new ReceiptCoder().encode(receipt)); @@ -232,6 +234,7 @@ describe('ReceiptCoder', () => { recipient: B256_ALT2, amount: bn(4000), nonce: B256_ALT3, + len: 12, digest: B256_ALT4, data: Uint8Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), }; diff --git a/packages/transactions/src/coders/receipt.ts b/packages/transactions/src/coders/receipt.ts index cb25b5bed29..f5ce228dd69 100644 --- a/packages/transactions/src/coders/receipt.ts +++ b/packages/transactions/src/coders/receipt.ts @@ -184,6 +184,8 @@ export type ReceiptReturnData = { digest: string; /** Value of register $pc (u64) */ pc: BN; + /** Value of the memory range MEM[$rA, $rB]. */ + data: string; /** Value of register $is (u64) */ is: BN; }; @@ -207,6 +209,7 @@ export class ReceiptReturnDataCoder extends Coder { parts.push(new B256Coder().encode(value.digest)); parts.push(new BigNumberCoder('u64').encode(value.pc)); parts.push(new BigNumberCoder('u64').encode(value.is)); + parts.push(new ByteArrayCoder(value.len.toNumber()).encode(value.data)); return concat(parts); } @@ -509,6 +518,8 @@ export class ReceiptLogDataCoder extends Coder { const pc = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); const is = decoded; + [decoded, o] = new ByteArrayCoder(len.toNumber()).decode(data, o); + const logData = decoded; return [ { @@ -521,6 +532,7 @@ export class ReceiptLogDataCoder extends Coder { digest, pc, is, + data: logData, }, o, ]; @@ -728,6 +740,8 @@ export type ReceiptMessageOut = { amount: BN; /** Hexadecimal string representation of the 256-bit (32-byte) message nonce */ nonce: string; + /** Decimal string representation of a 16-bit unsigned integer; value of register $rC. */ + len: number; /** Hexadecimal string representation of 256-bit (32-byte), hash of MEM[$rA + 32, $rB] */ digest: string; /** Hexadecimal string representation of the value of the memory range MEM[$rA + 32, $rB] */ @@ -802,6 +816,7 @@ export class ReceiptMessageOutCoder extends Coder