Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk/js: handling valid exceptions #3590

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions sdk/js/src/token_bridge/__tests__/algorand-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ describe("Algorand tests", () => {
vaaBytes
);
} catch (e) {
success = false;
if(e instanceof Error && e.message.includes("wrapped asset already exists")){
success = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be the other way around?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes. Fixed. Will push soon.

} else {
success = false;
}
}
if (!success) {
try {
Expand Down Expand Up @@ -370,7 +374,12 @@ describe("Algorand tests", () => {
vaaBytes
);
} catch (e) {
success = false;
//@notice
if(e instanceof Error && e.message.includes("wrapped asset already exists")){
success = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one too

} else {
success = false;
}
}
if (!success) {
try {
Expand Down
10 changes: 10 additions & 0 deletions sdk/js/src/token_bridge/__tests__/aptos-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ describe("Aptos SDK tests", () => {
await createWrappedOnEth(ethTokenBridge, recipient, attestVAA);
} catch (e) {
// this could fail because the token is already attested (in an unclean env)
if(e instanceof Error && e.message.includes("wrapped asset already exists")){
console.log("wrapped asset already exists");
} else {
throw e;
}
}

// check attestation on ethereum
Expand Down Expand Up @@ -420,6 +425,11 @@ describe("Aptos SDK tests", () => {
await createWrappedOnEth(ethTokenBridge, recipient, attestVAA);
} catch (e) {
// this could fail because the token is already attested (in an unclean env)
if(e instanceof Error && e.message.includes("wrapped asset already exists")){
Copy link
Contributor

@kcsongor kcsongor Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the error message actually look like this?

console.log("wrapped asset already exists");
} else {
throw e;
}
}

// check attestation on ethereum
Expand Down
10 changes: 10 additions & 0 deletions sdk/js/src/token_bridge/__tests__/solana-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ describe("Solana to Ethereum", () => {
);
} catch (e) {
// this could fail because the token is already attested (in an unclean env)
if(e instanceof Error && e.message.includes("wrapped asset already exists")){
console.log("wrapped asset already exists");
} else {
console.log(e);
}
}
provider.destroy();
done();
Expand Down Expand Up @@ -328,6 +333,11 @@ describe("Solana to Ethereum", () => {
);
} catch (e) {
// this could fail because the token is already attested (in an unclean env)
if(e instanceof Error && e.message.includes("wrapped asset already exists")){
console.log("wrapped asset already exists");
} else {
console.log(e);
}
}
provider.destroy();
done();
Expand Down
7 changes: 6 additions & 1 deletion sdk/js/src/token_bridge/__tests__/sui-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,12 @@ describe("Sui SDK tests", () => {
try {
await createWrappedOnEth(ETH_TOKEN_BRIDGE_ADDRESS, ethSigner, attestVAA);
} catch (e) {
// this could fail because the token is already attested (in an unclean env)
// this could fail because the token is already attested (in an unclean env)
if(e instanceof Error && e.message.includes("wrapped asset already exists")){
console.log("wrapped asset already exists");
} else {
console.error(e);
}
}
const { tokenAddress } = parseAttestMetaVaa(attestVAA);
expect(
Expand Down
12 changes: 10 additions & 2 deletions sdk/js/src/token_bridge/__tests__/terra-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,11 @@ describe.skip("Terra Integration Tests", () => {
signedVaa
);
} catch (e) {
success = false;
if(e instanceof Error && e.message.includes("wrapped asset already exists")){
success = true;
} else {
success = false;
}
}
if (!success) {
const cr = await updateWrappedOnEth(
Expand Down Expand Up @@ -916,7 +920,11 @@ describe.skip("Terra Integration Tests", () => {
signedVaa
);
} catch (e) {
success = false;
if(e instanceof Error && e.message.includes("wrapped asset already exists")){
success = true;
} else {
success = false;
}
}
if (!success) {
const cr = await updateWrappedOnEth(
Expand Down
Loading