Skip to content

Commit

Permalink
[ts sdk] Fix formatting when parsing addresses with bcs.Address (Myst…
Browse files Browse the repository at this point in the history
…enLabs#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
  • Loading branch information
hayes-mysten authored Oct 31, 2023
1 parent 1abfa10 commit 30b47b7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/six-ways-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@mysten/sui.js': patch
---

Fix formatting when parsing addresses with bcs.Address
2 changes: 1 addition & 1 deletion sdk/typescript/src/bcs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function enumKind<T extends object, Input extends object>(type: BcsType<T, Input
const Address = bcs.bytes(SUI_ADDRESS_LENGTH).transform({
input: (val: string | Uint8Array) =>
typeof val === 'string' ? fromHEX(normalizeSuiAddress(val)) : val,
output: (val) => toHEX(val),
output: (val) => normalizeSuiAddress(toHEX(val)),
});

const ObjectDigest = bcs.vector(bcs.u8()).transform({
Expand Down
6 changes: 3 additions & 3 deletions sdk/typescript/src/builder/__tests__/bcs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ it('can serialize Option<T> 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()],
Expand Down
13 changes: 8 additions & 5 deletions sdk/typescript/test/e2e/read-transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 30b47b7

Please sign in to comment.