From 8ccebb39c1190039afa0b3a69dff089191c4e767 Mon Sep 17 00:00:00 2001 From: trung2891 Date: Mon, 7 Oct 2024 11:08:51 +0700 Subject: [PATCH] chore: test build msg bridge to evm missing params --- .../src/msg/chains/oraichain.ts | 6 +- .../tests/msg/oraichain-msg.spec.ts | 86 ++++++++++++------- 2 files changed, 56 insertions(+), 36 deletions(-) diff --git a/packages/universal-swap/src/msg/chains/oraichain.ts b/packages/universal-swap/src/msg/chains/oraichain.ts index a83ca9ce..7e7969be 100644 --- a/packages/universal-swap/src/msg/chains/oraichain.ts +++ b/packages/universal-swap/src/msg/chains/oraichain.ts @@ -177,7 +177,7 @@ export class OraichainMsg extends ChainMsg { let isBridgeToEvm = isEthAddress(this.receiver); if (isBridgeToEvm) { if (!this.destPrefix || !this.obridgeAddress) - throw generateError("Missing prefix os Obridge address for bridge to EVM"); + throw generateError("Missing prefix or Obridge address for bridge to EVM"); prefix = this.destPrefix; } @@ -258,7 +258,7 @@ export class OraichainMsg extends ChainMsg { let isBridgeToEvm = isEthAddress(this.receiver); if (isBridgeToEvm) { if (!this.destPrefix || !this.obridgeAddress) - throw generateError("Missing prefix os Obridge address for bridge to EVM"); + throw generateError("Missing prefix or Obridge address for bridge to EVM"); prefix = this.destPrefix; } @@ -387,7 +387,7 @@ export class OraichainMsg extends ChainMsg { let isBridgeToEvm = isEthAddress(this.receiver); if (isBridgeToEvm) { if (!this.destPrefix || !this.obridgeAddress) - throw generateError("Missing prefix os Obridge address for bridge to EVM"); + throw generateError("Missing prefix or Obridge address for bridge to EVM"); prefix = this.destPrefix; } diff --git a/packages/universal-swap/tests/msg/oraichain-msg.spec.ts b/packages/universal-swap/tests/msg/oraichain-msg.spec.ts index 9bc44680..5f33908d 100644 --- a/packages/universal-swap/tests/msg/oraichain-msg.spec.ts +++ b/packages/universal-swap/tests/msg/oraichain-msg.spec.ts @@ -670,37 +670,57 @@ describe("test build oraichain msg", () => { }); }); - // it("Invalid path not ibc transfer", () => { - // const nextMemo = "{}"; - - // const invalidPathNotIbcTransfer = { - // chainId: "osmosis-1", - // tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", - // tokenInAmount: "999000", - // tokenOut: "uatom", - // tokenOutAmount: "999000", - // tokenOutChainId: "cosmoshub-4", - // actions: [ - // { - // type: "Bridge", - // protocol: "Bridge", - // tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", - // tokenInAmount: "999000", - // tokenOut: "uatom", - // tokenOutAmount: "999000", - // tokenOutChainId: "cosmoshub-4", - // bridgeInfo: { - // port: "wasm.osmo123", - // channel: "channel-0" - // } - // } - // ] - // }; - // let osmosis = new OsmosisMsg(invalidPathNotIbcTransfer, "1", receiver, currentAddress, nextMemo); - // try { - // osmosis.genMemoAsMiddleware(); - // } catch (err) { - // expect(err).toEqual(generateError(`Only support IBC bridge on ${invalidPathNotIbcTransfer.chainId}`)); - // } - // }); + it("Valid path but missing obridge address or destPrefix on bridge to evm", () => { + const nextMemo = "{}"; + const validPath = { + chainId: "Oraichain", + tokenIn: "orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh", + tokenInAmount: "936043", + tokenOut: "0x55d398326f99059fF775485246999027B3197955", + tokenOutAmount: "306106", + tokenOutChainId: "0x38", + actions: [ + { + type: "Bridge", + protocol: "Bridge", + tokenIn: "orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh", + tokenInAmount: "936043", + tokenOut: "0x55d398326f99059fF775485246999027B3197955", + tokenOutAmount: "306106", + tokenOutChainId: "0x38", + bridgeInfo: { + port: "wasm.orai195269awwnt5m6c843q6w7hp8rt0k7syfu9de4h0wz384slshuzps8y7ccm", + channel: "channel-29" + } + } + ] + }; + let receiver = "0x0000000000000000000000000000000000000000"; + const currentAddress = "orai1hvr9d72r5um9lvt0rpkd4r75vrsqtw6yujhqs2"; + const oraiBridgeAddr = "oraib1hvr9d72r5um9lvt0rpkd4r75vrsqtw6ytnnvpf"; + const destPrefix = "oraib"; + // missing oraibridge address + try { + let oraichainMsg = new OraichainMsg(validPath, "1", receiver, currentAddress, nextMemo, destPrefix); + oraichainMsg.genExecuteMsg(); + } catch (err) { + expect(err).toEqual(generateError(`Missing prefix or Obridge address for bridge to EVM`)); + } + + // missing destPrefix + try { + let oraichainMsg = new OraichainMsg( + validPath, + "1", + receiver, + currentAddress, + nextMemo, + undefined, + oraiBridgeAddr + ); + oraichainMsg.genExecuteMsg(); + } catch (err) { + expect(err).toEqual(generateError(`Missing prefix or Obridge address for bridge to EVM`)); + } + }); });