Skip to content

Commit

Permalink
feat: icav1 test
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Oct 25, 2023
1 parent 375d2ab commit 53c997d
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 32 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 ###
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
14 changes: 7 additions & 7 deletions integration-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
196 changes: 178 additions & 18 deletions integration-tests/src/modules/icav1.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
//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
const LCD = getLCDClient();
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
Expand Down Expand Up @@ -54,31 +59,186 @@ 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,
"connection-0",
""
)],
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()
}
})
});
});

0 comments on commit 53c997d

Please sign in to comment.