From 30b47b7584ad69de84e4eef6d4918af90000513c Mon Sep 17 00:00:00 2001 From: hayes-mysten <135670682+hayes-mysten@users.noreply.github.com> Date: Tue, 31 Oct 2023 16:45:37 -0700 Subject: [PATCH] [ts sdk] Fix formatting when parsing addresses with bcs.Address (#14491) ## Description Describe the changes or additions included in this PR. ## Test Plan How did you test the new or updated feature? --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes --- .changeset/six-ways-destroy.md | 5 +++++ sdk/typescript/src/bcs/index.ts | 2 +- sdk/typescript/src/builder/__tests__/bcs.test.ts | 6 +++--- sdk/typescript/test/e2e/read-transactions.test.ts | 13 ++++++++----- 4 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 .changeset/six-ways-destroy.md diff --git a/.changeset/six-ways-destroy.md b/.changeset/six-ways-destroy.md new file mode 100644 index 0000000000000..19a60771b03ac --- /dev/null +++ b/.changeset/six-ways-destroy.md @@ -0,0 +1,5 @@ +--- +'@mysten/sui.js': patch +--- + +Fix formatting when parsing addresses with bcs.Address diff --git a/sdk/typescript/src/bcs/index.ts b/sdk/typescript/src/bcs/index.ts index b55d150af7c21..1975a72053ec2 100644 --- a/sdk/typescript/src/bcs/index.ts +++ b/sdk/typescript/src/bcs/index.ts @@ -182,7 +182,7 @@ function enumKind(type: BcsType typeof val === 'string' ? fromHEX(normalizeSuiAddress(val)) : val, - output: (val) => toHEX(val), + output: (val) => normalizeSuiAddress(toHEX(val)), }); const ObjectDigest = bcs.vector(bcs.u8()).transform({ diff --git a/sdk/typescript/src/builder/__tests__/bcs.test.ts b/sdk/typescript/src/builder/__tests__/bcs.test.ts index ae9a0333c0f25..5ce5f6ee2da14 100644 --- a/sdk/typescript/src/builder/__tests__/bcs.test.ts +++ b/sdk/typescript/src/builder/__tests__/bcs.test.ts @@ -63,17 +63,17 @@ it('can serialize Option types using the legacy registry API', () => { function ref(): { objectId: string; version: string; digest: string } { return { - objectId: (Math.random() * 100000).toFixed(0).padEnd(64, '0'), + objectId: normalizeSuiAddress((Math.random() * 100000).toFixed(0).padEnd(64, '0')), version: String((Math.random() * 10000).toFixed(0)), digest: toB58(new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9])), }; } it('can serialize transaction data with a programmable transaction', () => { - let sui = normalizeSuiAddress('0x2').replace('0x', ''); + let sui = normalizeSuiAddress('0x2'); let txData = { V1: { - sender: normalizeSuiAddress('0xBAD').replace('0x', ''), + sender: normalizeSuiAddress('0xBAD'), expiration: { None: true }, gasData: { payment: [ref()], diff --git a/sdk/typescript/test/e2e/read-transactions.test.ts b/sdk/typescript/test/e2e/read-transactions.test.ts index 064f79b740f3f..fc9ca46eedbbc 100644 --- a/sdk/typescript/test/e2e/read-transactions.test.ts +++ b/sdk/typescript/test/e2e/read-transactions.test.ts @@ -115,16 +115,19 @@ describe('Transaction Reading API', () => { showObjectChanges: true, showBalanceChanges: true, }; - const resp = await toolbox.client.queryTransactionBlocks({ + const { + // comparing checkpoint causes a race condition resulting in flaky tests + data: [{ checkpoint: _, ...response1 }], + } = await toolbox.client.queryTransactionBlocks({ options, limit: 1, }); - const digest = resp.data[0].digest; - const response2 = await toolbox.client.getTransactionBlock({ - digest, + + const { checkpoint, ...response2 } = await toolbox.client.getTransactionBlock({ + digest: response1.digest, options, }); - expect(resp.data[0]).toEqual(response2); + expect(response1).toEqual(response2); }); it('Get Transactions', async () => {