Skip to content

Commit c071640

Browse files
committed
fix packageId normalization issue in tests
1 parent 0ce9afc commit c071640

File tree

8 files changed

+43
-30
lines changed

8 files changed

+43
-30
lines changed

packages/sui/test/e2e/clients/jsonRpc/coin-metadata.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('Test Coin Metadata', () => {
1111

1212
beforeAll(async () => {
1313
toolbox = await setup();
14-
packageId = await toolbox.getPackage('coin_metadata');
14+
packageId = await toolbox.getPackage('coin_metadata', { normalized: false });
1515
});
1616

1717
it('Test accessing coin metadata', async () => {

packages/sui/test/e2e/clients/jsonRpc/coin-read.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('CoinRead API', () => {
1313

1414
beforeAll(async () => {
1515
[toolbox, publishToolbox] = await Promise.all([setup(), setup()]);
16-
packageId = await publishToolbox.getPackage('coin_metadata');
16+
packageId = await publishToolbox.getPackage('coin_metadata', { normalized: false });
1717
testType = packageId + '::test::TEST';
1818
});
1919

packages/sui/test/e2e/clients/jsonRpc/coin-with-balance.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('coinWithBalance', () => {
2020

2121
beforeAll(async () => {
2222
[toolbox, publishToolbox] = await Promise.all([setup(), setup()]);
23-
packageId = await publishToolbox.getPackage('coin_metadata');
23+
packageId = await publishToolbox.getPackage('coin_metadata', { normalized: false });
2424
testType = normalizeSuiAddress(packageId) + '::test::TEST';
2525
testTypeZero = normalizeSuiAddress(packageId) + '::test_zero::TEST_ZERO';
2626
});

packages/sui/test/e2e/clients/jsonRpc/dev-inspect.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('Test dev inspect', () => {
1414

1515
beforeAll(async () => {
1616
toolbox = await setup();
17-
packageId = await toolbox.getPackage('serializer');
17+
packageId = await toolbox.getPackage('serializer', { normalized: false });
1818
});
1919

2020
it('Dev inspect split + transfer', async () => {

packages/sui/test/e2e/clients/jsonRpc/dynamic-fields.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('Dynamic Fields Reading API', () => {
1313

1414
beforeAll(async () => {
1515
toolbox = await setup();
16-
packageId = await toolbox.getPackage('dynamic_fields');
16+
packageId = await toolbox.getPackage('dynamic_fields', { normalized: false });
1717

1818
await toolbox.jsonRpcClient
1919
.getOwnedObjects({

packages/sui/test/e2e/clients/jsonRpc/object-display-standard.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Test Object Display Standard', () => {
1212

1313
beforeAll(async () => {
1414
toolbox = await setup();
15-
packageId = await toolbox.getPackage('display_test');
15+
packageId = await toolbox.getPackage('display_test', { normalized: false });
1616
});
1717

1818
it('Test getting Display fields with error object', async () => {

packages/sui/test/e2e/object-cache.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('CachingTransactionExecutor', { retry: 3 }, async () => {
1919

2020
beforeAll(async () => {
2121
toolbox = await setup();
22-
rawPackageId = packageId = await toolbox.getPackage('tto');
22+
rawPackageId = await toolbox.getPackage('tto', { normalized: false });
2323
packageId = normalizeSuiAddress(rawPackageId);
2424
});
2525

packages/sui/test/e2e/utils/setup.ts

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from '../../../src/faucet/index.js';
2525
import { Ed25519Keypair } from '../../../src/keypairs/ed25519/index.js';
2626
import { Transaction, UpgradePolicy } from '../../../src/transactions/index.js';
27-
import { SUI_TYPE_ARG } from '../../../src/utils/index.js';
27+
import { SUI_TYPE_ARG, normalizeSuiAddress } from '../../../src/utils/index.js';
2828
import type { ClientWithCoreApi } from '../../../src/client/core.js';
2929

3030
const DEFAULT_FAUCET_URL = import.meta.env.FAUCET_URL ?? getFaucetHost('localnet');
@@ -57,27 +57,38 @@ class TestPackageRegistry {
5757
this.#pendingPublishes = new Map();
5858
}
5959

60-
async getPackage(name: string, toolbox?: TestToolbox) {
60+
async getPackage(
61+
name: string,
62+
toolbox?: TestToolbox,
63+
options?: { normalized?: boolean },
64+
): Promise<string> {
65+
const { normalized = true } = options ?? {};
66+
67+
let packageId: string;
6168
if (this.#packages.has(name)) {
62-
return this.#packages.get(name)!;
69+
packageId = this.#packages.get(name)!;
70+
} else if (this.#pendingPublishes.has(name)) {
71+
packageId = await this.#pendingPublishes.get(name)!;
72+
} else {
73+
const publishPromise = (async () => {
74+
try {
75+
const { packageId } = await publishPackage(name, toolbox);
76+
this.#packages.set(name, packageId);
77+
return packageId;
78+
} finally {
79+
this.#pendingPublishes.delete(name);
80+
}
81+
})();
82+
83+
this.#pendingPublishes.set(name, publishPromise);
84+
packageId = await publishPromise;
6385
}
6486

65-
if (this.#pendingPublishes.has(name)) {
66-
return await this.#pendingPublishes.get(name)!;
87+
if (normalized) {
88+
return packageId;
6789
}
68-
69-
const publishPromise = (async () => {
70-
try {
71-
const { packageId } = await publishPackage(name, toolbox);
72-
this.#packages.set(name, packageId);
73-
return packageId;
74-
} finally {
75-
this.#pendingPublishes.delete(name);
76-
}
77-
})();
78-
79-
this.#pendingPublishes.set(name, publishPromise);
80-
return await publishPromise;
90+
// Strip leading zeros for JSON RPC compatibility
91+
return packageId.replace(/^(0x)(0+)/, '0x');
8192
}
8293
}
8394

@@ -127,8 +138,8 @@ export class TestToolbox {
127138
return (await this.jsonRpcClient.getLatestSuiSystemState()).activeValidators;
128139
}
129140

130-
public async getPackage(path: string) {
131-
return this.registry.getPackage(path, this);
141+
public async getPackage(path: string, options?: { normalized?: boolean }) {
142+
return this.registry.getPackage(path, this, options);
132143
}
133144

134145
async mintNft(name: string = 'Test NFT') {
@@ -363,9 +374,11 @@ export async function publishPackage(packageName: string, toolbox?: TestToolbox)
363374

364375
expect(publishTxn.effects?.status.status).toEqual('success');
365376

366-
const packageId = ((publishTxn.objectChanges?.filter(
367-
(a) => a.type === 'published',
368-
) as SuiObjectChangePublished[]) ?? [])[0]?.packageId.replace(/^(0x)(0+)/, '0x') as string;
377+
const packageId = normalizeSuiAddress(
378+
((publishTxn.objectChanges?.filter(
379+
(a) => a.type === 'published',
380+
) as SuiObjectChangePublished[]) ?? [])[0]?.packageId,
381+
);
369382

370383
expect(packageId).toBeTypeOf('string');
371384

0 commit comments

Comments
 (0)