From 53c997dbe0afb61606d70df3aa40409d84ea15c5 Mon Sep 17 00:00:00 2001 From: emidev98 Date: Wed, 25 Oct 2023 19:14:51 +0200 Subject: [PATCH] feat: icav1 test --- Makefile | 5 +- go.mod | 1 + go.sum | 4 +- integration-tests/package-lock.json | 14 +- integration-tests/package.json | 2 +- integration-tests/src/modules/icav1.test.ts | 196 ++++++++++++++++++-- 6 files changed, 190 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index d7bbfaa9..e18b6487 100644 --- a/Makefile +++ b/Makefile @@ -202,15 +202,12 @@ install: go.sum ############################################################################### integration-test-all: init-test-framework \ - test-relayer \ test-ibc-hooks \ test-tokenfactory init-test-framework: clean-testing-data install @echo "Initializing both blockchains..." ./scripts/tests/init-test-framework.sh - -test-relayer: @echo "Testing relayer..." ./scripts/tests/relayer/interchain-acc-config/rly-init.sh @@ -236,7 +233,7 @@ clean-testing-data: -@rm -rf ./_build -.PHONY: integration-test-all init-test-framework test-relayer test-ica test-ibc-hooks test-tokenfactory clean-testing-data +.PHONY: integration-test-all init-test-framework test-ibc-hooks test-tokenfactory clean-testing-data ############################################################################### ### Protobuf ### diff --git a/go.mod b/go.mod index b0f32c08..c981178b 100644 --- a/go.mod +++ b/go.mod @@ -189,6 +189,7 @@ replace ( // This is a temporary fix since the latest version updated some function signatures. To remove when updating to cosmos 47 github.com/ChainSafe/go-schnorrkel => github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d github.com/cosmos/cosmos-sdk => github.com/terra-money/cosmos-sdk v0.47.5-terra.2 + github.com/cosmos/ibc-go/v7 => github.com/terra-money/ibc-go/v7 v7.0.0-20231025094952-d0d14bc2e7ae github.com/cosmos/ledger-cosmos-go => github.com/terra-money/ledger-terra-go v0.11.2 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 diff --git a/go.sum b/go.sum index 411d5872..f71b2c52 100644 --- a/go.sum +++ b/go.sum @@ -406,8 +406,6 @@ github.com/cosmos/ibc-apps/modules/async-icq/v7 v7.0.0 h1:mMHedP3Q+mz5gpOWNz0P+X github.com/cosmos/ibc-apps/modules/async-icq/v7 v7.0.0/go.mod h1:/P6l2bWo2AR3rrsfs0DHuFZO3Imzb93sxFD3ihrIgw4= github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20230803181732-7c8f814d3b79 h1:pCxyhIxgWTabAQC5UerkITraHG3SwajdLKKMCFDWCv4= github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20230803181732-7c8f814d3b79/go.mod h1:JwHFbo1oX/ht4fPpnPvmhZr+dCkYK1Vihw+vZE9umR4= -github.com/cosmos/ibc-go/v7 v7.3.0 h1:QtGeVMi/3JeLWuvEuC60sBHpAF40Oenx/y+bP8+wRRw= -github.com/cosmos/ibc-go/v7 v7.3.0/go.mod h1:mUmaHFXpXrEdcxfdXyau+utZf14pGKVUiXwYftRZZfQ= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/ledger-go v0.9.2/go.mod h1:oZJ2hHAZROdlHiwTg4t7kP+GKIIkBT+o6c9QWFanOyI= @@ -1133,6 +1131,8 @@ github.com/terra-money/alliance v0.3.2 h1:MuL3RBw+jXFv4io5PhaBn7jRUBvlJLUzgpD6gx github.com/terra-money/alliance v0.3.2/go.mod h1:HDiUexeXRUkLkLRw5jLQcHuVt1Sx43HfyVl0kfwW3JM= github.com/terra-money/cosmos-sdk v0.47.5-terra.2 h1:wMqM+qGsymt/gPnl+51y/ADGXPVVn04rJU7pBia/ut8= github.com/terra-money/cosmos-sdk v0.47.5-terra.2/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c= +github.com/terra-money/ibc-go/v7 v7.0.0-20231025094952-d0d14bc2e7ae h1:ICyrA16j5H0E/XNEWa0S2gzSTrq1cfg1G6mAzcQEWe0= +github.com/terra-money/ibc-go/v7 v7.0.0-20231025094952-d0d14bc2e7ae/go.mod h1:wvx4pPBofe5ZdMNV3OFRxSI4auEP5Qfqf8JXLLNV04g= github.com/terra-money/ledger-terra-go v0.11.2 h1:BVXZl+OhJOri6vFNjjVaTabRLApw9MuG7mxWL4V718c= github.com/terra-money/ledger-terra-go v0.11.2/go.mod h1:ClJ2XMj1ptcnONzKH+GhVPi7Y8pXIT+UzJ0TNt0tfZE= github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg= diff --git a/integration-tests/package-lock.json b/integration-tests/package-lock.json index 03c3e387..3ee109e3 100644 --- a/integration-tests/package-lock.json +++ b/integration-tests/package-lock.json @@ -9,7 +9,7 @@ "version": "v2.7.0", "license": "MIT", "dependencies": { - "@terra-money/feather.js": "^2.0.0-beta.2", + "@terra-money/feather.js": "^2.0.0-beta.3", "@terra-money/terra.proto": "^4.0.1", "moment": "^2.29.4" }, @@ -1803,9 +1803,9 @@ } }, "node_modules/@terra-money/feather.js": { - "version": "2.0.0-beta.2", - "resolved": "https://registry.npmjs.org/@terra-money/feather.js/-/feather.js-2.0.0-beta.2.tgz", - "integrity": "sha512-DzKFauWBMeBpRYHyIozlhy0ju/WSwvhiZORL2wyr9qUJtz2WQzZ2iiMSSI0bTjWiMPShBaW2Ad/Mf9JmusmxBQ==", + "version": "2.0.0-beta.3", + "resolved": "https://registry.npmjs.org/@terra-money/feather.js/-/feather.js-2.0.0-beta.3.tgz", + "integrity": "sha512-5yWdL/v9UgN8DuSExl9r71HeksgSpLjO9YPJF2PMqZhzAJEGZmgCXa+H7wDcMfDqLy/kZPI0dbASG0OWa6UApg==", "dependencies": { "@ethersproject/bytes": "^5.7.0", "@terra-money/legacy.proto": "npm:@terra-money/terra.proto@^0.1.7", @@ -7008,9 +7008,9 @@ } }, "@terra-money/feather.js": { - "version": "2.0.0-beta.2", - "resolved": "https://registry.npmjs.org/@terra-money/feather.js/-/feather.js-2.0.0-beta.2.tgz", - "integrity": "sha512-DzKFauWBMeBpRYHyIozlhy0ju/WSwvhiZORL2wyr9qUJtz2WQzZ2iiMSSI0bTjWiMPShBaW2Ad/Mf9JmusmxBQ==", + "version": "2.0.0-beta.3", + "resolved": "https://registry.npmjs.org/@terra-money/feather.js/-/feather.js-2.0.0-beta.3.tgz", + "integrity": "sha512-5yWdL/v9UgN8DuSExl9r71HeksgSpLjO9YPJF2PMqZhzAJEGZmgCXa+H7wDcMfDqLy/kZPI0dbASG0OWa6UApg==", "requires": { "@ethersproject/bytes": "^5.7.0", "@terra-money/legacy.proto": "npm:@terra-money/terra.proto@^0.1.7", diff --git a/integration-tests/package.json b/integration-tests/package.json index c988f3a1..72f1a947 100644 --- a/integration-tests/package.json +++ b/integration-tests/package.json @@ -30,7 +30,7 @@ "typescript": "^5.2.2" }, "dependencies": { - "@terra-money/feather.js": "^2.0.0-beta.2", + "@terra-money/feather.js": "^2.0.0-beta.3", "@terra-money/terra.proto": "^4.0.1", "moment": "^2.29.4" } diff --git a/integration-tests/src/modules/icav1.test.ts b/integration-tests/src/modules/icav1.test.ts index a03afa90..03a1b38b 100644 --- a/integration-tests/src/modules/icav1.test.ts +++ b/integration-tests/src/modules/icav1.test.ts @@ -1,7 +1,10 @@ -//import { Coin, MsgTransfer } from "@terra-money/feather.js"; +import { AccAddress, Coin, MsgTransfer, MsgSend } from "@terra-money/feather.js"; import { blockInclusion, getLCDClient, getMnemonics } from "../helpers"; -//import { Height } from "@terra-money/feather.js/dist/core/ibc/core/client/Height"; -import { MsgRegisterInterchainAccount } from "@terra-money/feather.js/dist/core/ica/controller/v1/msgs"; +import { MsgRegisterInterchainAccount, MsgSendTx } from "@terra-money/feather.js/dist/core/ica/controller/v1/msgs"; +import { Height } from "@terra-money/feather.js/dist/core/ibc/core/client/Height"; +import { InterchainAccountPacketData } from "@terra-money/feather.js/dist/core/ica/controller/v1/InterchainAccountPacketData"; +import Long from "long"; +import { MsgSend as MsgSend_pb } from "@terra-money/terra.proto/cosmos/bank/v1beta1/tx"; describe("ICA Module (https://github.com/cosmos/ibc-go/tree/release/v7.3.x/modules/apps/27-interchain-accounts)", () => { // Prepare environment clients, accounts and wallets @@ -9,6 +12,8 @@ describe("ICA Module (https://github.com/cosmos/ibc-go/tree/release/v7.3.x/modul const { icaMnemonic } = getMnemonics(); const chain1Wallet = LCD.chain1.wallet(icaMnemonic); const externalAccAddr = icaMnemonic.accAddress("terra"); + let ibcCoinDenom: string | undefined; + let intechainAccountAddr: AccAddress | undefined; test('Must contain the expected module params', async () => { // Query ica host module params @@ -54,9 +59,20 @@ describe("ICA Module (https://github.com/cosmos/ibc-go/tree/release/v7.3.x/modul }); }); - test('Must create an interchain account from chain1 to chain2', async () => { - try { + test('Must query the interchain account to determine its existance', async () => { + let res = await LCD.chain1.icaV1.controllerAccountAddress(externalAccAddr, "connection-0") + .catch(e => { + const expectMsg = "failed to retrieve account address for icacontroller-"; + expect(e.response.data.message.startsWith(expectMsg)).toBeTruthy(); + }) + if (res !== undefined) { + expect(res.address).toBeDefined(); + intechainAccountAddr = res.address; + } + }); + + test('Must creat the interchain account if des not already exist', async () => { let tx = await chain1Wallet.createAndSignTx({ msgs: [new MsgRegisterInterchainAccount( externalAccAddr, @@ -64,21 +80,165 @@ describe("ICA Module (https://github.com/cosmos/ibc-go/tree/release/v7.3.x/modul "" )], chainID: "test-1", + }).catch(e => { + const expectedMsg = "failed to execute message; message index: 0: existing active channel channel-1 for portID icacontroller-terra1p4kcrttuxj9kyyvv5px5ccgwf0yrw74yp7jqm6 on connection connection-0: active channel already set for this owner"; + expect(e.response.data.message.startsWith(expectedMsg)) + .toBeTruthy(); }); - console.log(tx); - let result = await LCD.chain1.tx.broadcastSync(tx, "test-1"); - console.log("result",JSON.stringify(result)); - await blockInclusion(); - let txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1") as any; - expect(txResult).toBeDefined(); - console.log("txResult",JSON.stringify(txResult)); - let res = await LCD.chain1.icaV1.controllerAccountAddress(externalAccAddr, "connection-0"); - console.log("Res",JSON.stringify(res)) - } - catch(e) { - console.log("Error",e) - expect(e).toBeUndefined(); + if (tx !== undefined) { + let result = await LCD.chain1.tx.broadcastSync(tx, "test-1"); + await blockInclusion(); + let txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1") as any; + expect(txResult.logs[0].events) + .toStrictEqual([{ + "type": "message", + "attributes": [{ + "key": "action", + "value": "/ibc.applications.interchain_accounts.controller.v1.MsgRegisterInterchainAccount" + }, { + "key": "sender", + "value": "terra1p4kcrttuxj9kyyvv5px5ccgwf0yrw74yp7jqm6" + }] + }, + { + "type": "channel_open_init", + "attributes": [{ + "key": "port_id", + "value": "icacontroller-terra1p4kcrttuxj9kyyvv5px5ccgwf0yrw74yp7jqm6" + }, { + "key": "channel_id", + "value": "channel-1" + }, { + "key": "counterparty_port_id", + "value": "icahost" + }, { + "key": "counterparty_channel_id", + "value": "" + }, { + "key": "connection_id", + "value": "connection-0" + }, { + "key": "version", + "value": "{\"fee_version\":\"ics29-1\",\"app_version\":\"{\\\"version\\\":\\\"ics27-1\\\",\\\"controller_connection_id\\\":\\\"connection-0\\\",\\\"host_connection_id\\\":\\\"connection-0\\\",\\\"address\\\":\\\"\\\",\\\"encoding\\\":\\\"proto3\\\",\\\"tx_type\\\":\\\"sdk_multi_msg\\\"}\"}" + }] + }, + { + "type": "message", + "attributes": [{ + "key": "module", + "value": "ibc_channel" + }] + }]) + + // Check during 5 blocks for the receival + // of the IBC coin on chain-2 + for (let i = 0; i <= 5; i++) { + await blockInclusion(); + let res = await LCD.chain1.icaV1.controllerAccountAddress(externalAccAddr, "connection-0") + .catch((e) => { + const expectMsg = "failed to retrieve account address for icacontroller-"; + expect(e.response.data.message.startsWith(expectMsg)).toBeTruthy(); + }) + if (res) { + expect(res.address).toBeDefined(); + intechainAccountAddr = res.address; + break; + } + } } }); + + describe('After assuring the interchain account exists', () => { + test("Must send funds to the interchain account from chain-1 to chain-2", async () => { + if (typeof intechainAccountAddr === "string") { + let blockHeight = (await LCD.chain1.tendermint.blockInfo("test-1")).block.header.height; + let tx = await chain1Wallet.createAndSignTx({ + msgs: [new MsgTransfer( + "transfer", + "channel-0", + Coin.fromString("100000000uluna"), + externalAccAddr, + intechainAccountAddr as string, + new Height(2, parseInt(blockHeight) + 100), + undefined, + "" + )], + chainID: "test-1", + }); + + let result = await LCD.chain1.tx.broadcastSync(tx, "test-1"); + await blockInclusion(); + let txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1") as any; + expect(txResult).toBeDefined(); + // Check during 5 blocks for the receival + // of the IBC coin on chain-2 + for (let i = 0; i <= 5; i++) { + await blockInclusion(); + let _ibcCoin = (await LCD.chain2.bank.balance(intechainAccountAddr))[0].find(c => c.denom.startsWith("ibc/")); + if (_ibcCoin) { + expect(_ibcCoin.denom.startsWith("ibc/")).toBeTruthy(); + ibcCoinDenom = _ibcCoin.denom + break; + } + } + } else { + // This case should never happen but if something goes wrong + // this is a check to fail. + expect(intechainAccountAddr).toBeDefined() + } + }); + + test("Must control the interchain account from chain-1 to send funds on chain-2 from the account address to a random account", async () => { + try { + const burnAddress = "terra1zdpgj8am5nqqvht927k3etljyl6a52kwqup0je"; + let msgSend = new MsgSend( + intechainAccountAddr as string, + burnAddress, + [Coin.fromString("100000000" + ibcCoinDenom)], + ) + let ibcPacket = new InterchainAccountPacketData( + MsgSend_pb.encode(msgSend.toProto()).string("base64").finish() as any, + ) + let tx = await chain1Wallet.createAndSignTx({ + msgs: [new MsgSendTx( + externalAccAddr, + "connection-0", + Long.fromString((new Date().getTime() * 1000000 + 600000000).toString()), + ibcPacket, + )], + chainID: "test-1", + }); + + let result = await LCD.chain1.tx.broadcastSync(tx, "test-1"); + await blockInclusion(); + let txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1") as any; + const events = txResult.logs[0].events; + expect(events[0]) + .toStrictEqual({ + "type": "message", + "attributes": [{ + "key": "action", + "value": "/ibc.applications.interchain_accounts.controller.v1.MsgSendTx" + }, { + "key": "sender", + "value": "terra1p4kcrttuxj9kyyvv5px5ccgwf0yrw74yp7jqm6" + }] + }); + + expect(events[2]) + .toStrictEqual({ + "type": "message", + "attributes": [{ + "key": "module", + "value": "ibc_channel" + }] + }) + } + catch (e) { + console.log(e) + expect(e).toBeUndefined() + } + }) + }); });