Skip to content

Commit

Permalink
sui: getCoinType native token address fix (#734)
Browse files Browse the repository at this point in the history
* sui: getCoinType native token address fix

Fixes #730

* change error msg
  • Loading branch information
kev1n-peters authored Nov 8, 2024
1 parent 9396746 commit d847b4d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions platforms/sui/__tests__/unit/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@ describe("Sui Address Tests", () => {
expect(address.toString()).toEqual(
"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
);
expect(address.getCoinType()).toEqual(SUI_COIN);

const acctAddress = "0xc90949fd7ff3c13fd0b586a10547b5ca1212edc2c170e368d1dea00c01fea62b";
address = new SuiAddress(acctAddress);
expect(address).toBeTruthy();
expect(address.toString()).toEqual(acctAddress);

const wrappedTokenAddress =
"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN";
address = new SuiAddress(wrappedTokenAddress);
expect(address).toBeTruthy();
expect(address.toString()).toEqual(wrappedTokenAddress);
expect(address.getCoinType()).toEqual(wrappedTokenAddress);

const nativeTokenAddress =
"0xfa7ac3951fdca92c5200d468d31a365eb03b2be9936fde615e69f0c1274ad3a0::BLUB::BLUB";
address = new SuiAddress(nativeTokenAddress);
expect(address).toBeTruthy();
expect(address.toString()).toEqual(nativeTokenAddress);
expect(address.getCoinType()).toEqual(nativeTokenAddress);
});

test("An invalid address is rejected", () => {
Expand Down
7 changes: 6 additions & 1 deletion platforms/sui/src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ export class SuiAddress implements Address {
if (this.module === "sui::SUI") {
return SUI_COIN;
}
return [this.getPackageId(), "coin", "COIN"].join(SUI_SEPARATOR);

if (!this.module) {
throw new Error("No module present in Sui token address");
}

return this.unwrap();
}

static instanceof(address: any): address is SuiAddress {
Expand Down

0 comments on commit d847b4d

Please sign in to comment.