File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -9,11 +9,26 @@ describe("Sui Address Tests", () => {
9
9
expect ( address . toString ( ) ) . toEqual (
10
10
"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI" ,
11
11
) ;
12
+ expect ( address . getCoinType ( ) ) . toEqual ( SUI_COIN ) ;
12
13
13
14
const acctAddress = "0xc90949fd7ff3c13fd0b586a10547b5ca1212edc2c170e368d1dea00c01fea62b" ;
14
15
address = new SuiAddress ( acctAddress ) ;
15
16
expect ( address ) . toBeTruthy ( ) ;
16
17
expect ( address . toString ( ) ) . toEqual ( acctAddress ) ;
18
+
19
+ const wrappedTokenAddress =
20
+ "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN" ;
21
+ address = new SuiAddress ( wrappedTokenAddress ) ;
22
+ expect ( address ) . toBeTruthy ( ) ;
23
+ expect ( address . toString ( ) ) . toEqual ( wrappedTokenAddress ) ;
24
+ expect ( address . getCoinType ( ) ) . toEqual ( wrappedTokenAddress ) ;
25
+
26
+ const nativeTokenAddress =
27
+ "0xfa7ac3951fdca92c5200d468d31a365eb03b2be9936fde615e69f0c1274ad3a0::BLUB::BLUB" ;
28
+ address = new SuiAddress ( nativeTokenAddress ) ;
29
+ expect ( address ) . toBeTruthy ( ) ;
30
+ expect ( address . toString ( ) ) . toEqual ( nativeTokenAddress ) ;
31
+ expect ( address . getCoinType ( ) ) . toEqual ( nativeTokenAddress ) ;
17
32
} ) ;
18
33
19
34
test ( "An invalid address is rejected" , ( ) => {
Original file line number Diff line number Diff line change @@ -113,7 +113,12 @@ export class SuiAddress implements Address {
113
113
if ( this . module === "sui::SUI" ) {
114
114
return SUI_COIN ;
115
115
}
116
- return [ this . getPackageId ( ) , "coin" , "COIN" ] . join ( SUI_SEPARATOR ) ;
116
+
117
+ if ( ! this . module ) {
118
+ throw new Error ( "No module present in Sui token address" ) ;
119
+ }
120
+
121
+ return this . unwrap ( ) ;
117
122
}
118
123
119
124
static instanceof ( address : any ) : address is SuiAddress {
You can’t perform that action at this time.
0 commit comments