@@ -24,7 +24,7 @@ import {
2424} from '../../../src/faucet/index.js' ;
2525import { Ed25519Keypair } from '../../../src/keypairs/ed25519/index.js' ;
2626import { 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' ;
2828import type { ClientWithCoreApi } from '../../../src/client/core.js' ;
2929
3030const 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 ( / ^ ( 0 x ) ( 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 ( / ^ ( 0 x ) ( 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