Skip to content

Commit d847b4d

Browse files
authored
sui: getCoinType native token address fix (#734)
* sui: getCoinType native token address fix Fixes #730 * change error msg
1 parent 9396746 commit d847b4d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

platforms/sui/__tests__/unit/address.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,26 @@ describe("Sui Address Tests", () => {
99
expect(address.toString()).toEqual(
1010
"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
1111
);
12+
expect(address.getCoinType()).toEqual(SUI_COIN);
1213

1314
const acctAddress = "0xc90949fd7ff3c13fd0b586a10547b5ca1212edc2c170e368d1dea00c01fea62b";
1415
address = new SuiAddress(acctAddress);
1516
expect(address).toBeTruthy();
1617
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);
1732
});
1833

1934
test("An invalid address is rejected", () => {

platforms/sui/src/address.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ export class SuiAddress implements Address {
113113
if (this.module === "sui::SUI") {
114114
return SUI_COIN;
115115
}
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();
117122
}
118123

119124
static instanceof(address: any): address is SuiAddress {

0 commit comments

Comments
 (0)