Skip to content

Commit

Permalink
chore: added IBCRelayerClient
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Oct 31, 2023
1 parent 412038a commit 9fece3f
Show file tree
Hide file tree
Showing 18 changed files with 889 additions and 166 deletions.
473 changes: 430 additions & 43 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ mnemonic=$(axelard keys add owner --keyring-backend test --home ${HOME} 2>&1 | t
echo ${mnemonic} | tr -d "\n" > ${HOME}/mnemonic.txt
echo "Added new key 'owner'"

# Adding a new genesis account named 'owner' with an initial balance of 100000000stake in the blockchain
axelard add-genesis-account owner 100000000${DENOM} \
# Adding a new genesis account named 'owner' with an initial balance of 100000000000000000000 in the blockchain
axelard add-genesis-account owner 100000000000000000000${DENOM} \
--home ${HOME} \
--keyring-backend test > /dev/null 2>&1 && echo "Added 'owner' to genesis account"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "3.8"
services:
ibc-relayer:
container_name: ibc-relayer
image: node:18-alpine
working_dir: /app
volumes:
- ./ibc-setup:/app/.ibc-setup
# command:
# - npm i -g @confio/[email protected]
entrypoint:
- sh
- -c
- |
npm i -g @confio/[email protected] &&
ibc-setup init &&
ibc-setup ics20 -v &&
/bin/sh
# depends_on: [axelar, wasm]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 1

chains:
wasm:
chain_id: wasm
prefix: wasm
gas_price: 0.025uwasm
hd_path: m/44'/1234'/0'/2'
estimated_block_time: 400
estimated_indexer_time: 60
rpc:
- http://localhost/wasm-rpc
axelar:
chain_id: axelar
prefix: axelar
gas_price: 0.025uaxl
hd_path: m/44'/1234'/0'/2'
estimated_block_time: 400
estimated_indexer_time: 60
rpc:
- http://localhost/axelar-rpc
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ mnemonic=$(wasmd keys add owner --keyring-backend test --home ${HOME} 2>&1 | tai
echo ${mnemonic} | tr -d "\n" > ${HOME}/mnemonic.txt
echo "Added new key 'owner'"

# Adding a new genesis account named 'owner' with an initial balance of 100000000stake in the blockchain
wasmd genesis add-genesis-account owner 100000000${DENOM} \
# Adding a new genesis account named 'owner' with an initial balance of 100000000000000000000uwasm in the blockchain
wasmd genesis add-genesis-account owner 100000000000000000000${DENOM} \
--home ${HOME} \
--keyring-backend test > /dev/null 2>&1 && echo "Added 'owner' to genesis account"

# Generating a new genesis transaction for 'owner' delegating 70000000${DENOM} in the blockchain with the specified chain-id
wasmd genesis gentx owner 70000000${DENOM} \
wasmd genesis gentx owner 60000000${DENOM} \
--home ${HOME} \
--keyring-backend test \
--moniker ${MONIKER} \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: "3.8"
services:
wasm:
image: cosmwasm/wasmd
image: cosmwasm/wasmd:v0.42.0
container_name: wasm
env_file: ".env"
command: "/root/private/bin/init_and_add_keys.sh"
command: "/root/private/bin/init_wasm.sh"
volumes:
- "./bin:/root/private/bin"
- "./.wasm:/root/private/.wasm"
Expand Down
12 changes: 10 additions & 2 deletions packages/axelar-local-dev-cosmos/jest/jest.global-setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { stopAll, startAll } from "../src/docker";
import { stopAll, startAll, waitForRpc } from "../src/docker";

export default async () => {
// await startAll();
try {
await waitForRpc("axelar", 5000);
await waitForRpc("wasm", 5000);
} catch (e) {
console.error(
"\nPlease make sure you have started the docker containers by running `npm start` before running tests"
);
throw e;
}
};
8 changes: 6 additions & 2 deletions packages/axelar-local-dev-cosmos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"!dist/artifacts"
],
"scripts": {
"test": "jest",
"test": "jest --testMatch='**/*.spec.ts' --runInBand",
"test:e2e": "jest --testMatch='**/*.e2e.ts' --runInBand",
"clean": "rm -rf src/types dist artifacts",
"prettier": "prettier --write 'src/**/*.ts'",
"build": "npm run clean && npm run build-ts",
Expand All @@ -18,8 +19,11 @@
},
"dependencies": {
"@axelar-network/axelar-local-dev": "2.1.1",
"@confio/relayer": "^0.10.0",
"@cosmjs/cosmwasm-stargate": "^0.31.1",
"@cosmjs/stargate": "^0.31.1"
"@cosmjs/stargate": "^0.31.1",
"@types/sinon": "^10.0.20",
"sinon": "^17.0.0"
},
"author": "[email protected]",
"license": "ISC",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import path from "path";
import { CosmosClient } from "..";

describe("CosmosClient", () => {
let wasmClient: CosmosClient;
let axelarClient: CosmosClient;

beforeAll(async () => {
wasmClient = await CosmosClient.create("wasm");
axelarClient = await CosmosClient.create("axelar");
});

it("should be able to upload wasm contract", async () => {
const _path = path.resolve(__dirname, "../..", "wasm/multi_send.wasm");
const response = await wasmClient.uploadWasm(_path);
expect(response).toBeDefined();
});

it("should be able to send tokens to given address on wasm", async () => {
const recipient = "wasm1puut77ku823785u3c7aalwqdrawe3lnjgwt89v";
const amount = "1000000";
const initialBalance = await wasmClient.getBalance(recipient);
await wasmClient.fundWallet(recipient, amount);
const balance = await wasmClient.getBalance(recipient);
expect(parseInt(balance)).toBe(parseInt(initialBalance) + parseInt(amount));
});

it("should be able to send tokens to given address on axelar", async () => {
const recipient = "axelar1puut77ku823785u3c7aalwqdrawe3lnjxuv68x";
const amount = "1000000";
const initialBalance = await axelarClient.getBalance(recipient);
await axelarClient.fundWallet(recipient, amount);
const balance = await axelarClient.getBalance(recipient);
expect(parseInt(balance)).toBe(parseInt(initialBalance) + parseInt(amount));
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IBCRelayerClient } from "../clients/IBCRelayerClient";

describe("IBCRelayerClient", () => {
it.skip("should be able to create a connection and channel", async () => {
const relayerClient = await IBCRelayerClient.create();

const response = await relayerClient.initConnection();

expect(response.axelar).toBeDefined();
expect(response.wasm).toBeDefined();

const response2 = await relayerClient.createChannel("B");

expect(response2).toBeDefined();
expect(response2!.src).toBeDefined();
expect(response2!.dest).toBeDefined();
});
});
88 changes: 88 additions & 0 deletions packages/axelar-local-dev-cosmos/src/__tests__/ibc.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import path from "path";
import { CosmosClient, IBCRelayerClient } from "..";
import { ChannelInfo } from "@confio/relayer/build/lib/ibcclient";

describe("E2E - IBC", () => {
let wasmClient: CosmosClient;
let axelarClient: CosmosClient;
let relayerClient: IBCRelayerClient;
let srcChannelId: string;
let destChannelId: string;

beforeAll(async () => {
wasmClient = await CosmosClient.create("wasm");
axelarClient = await CosmosClient.create("axelar");

// Initialize the connection and channel
relayerClient = await IBCRelayerClient.create();
await relayerClient.initConnection();
const { dest, src } = await relayerClient.createChannel("B");
srcChannelId = src.channelId;
destChannelId = dest.channelId;
console.log("Created IBC Channel:", src, dest);
});

it("ibc transfer", async () => {
const ownerAddress = await wasmClient.getOwnerAccount();
const recipient = "axelar1puut77ku823785u3c7aalwqdrawe3lnjxuv68x";

// Send tokens to the recipient
await wasmClient.ibcTransfer(
ownerAddress,
recipient,
srcChannelId,
"10000"
);

// Get the ibc denom
const ibcDenom = axelarClient.getIBCDenom(destChannelId, "uwasm");

// Relay the packet
await relayerClient.relayPackets();

// Check the balance on axelar chain
const ibcAmount = await axelarClient.getBalance(recipient, ibcDenom);
expect(parseInt(ibcAmount)).toBeGreaterThan(0);
});

// Usually takes 2-3 minutes to run
it("should be able to execute the wasm contract from wasm to axelar chain", async () => {
// Upload the wasm contract
const _path = path.resolve(__dirname, "../..", "wasm/multi_send.wasm");
const response = await wasmClient.uploadWasm(_path);

// Instantiate the contract
const { client } = wasmClient;
const ownerAddress = await wasmClient.getOwnerAccount();
const { contractAddress } = await client.instantiate(
ownerAddress,
response.codeId,
{
channel: srcChannelId,
},
"amazing random contract",
"auto"
);

const denom = wasmClient.chainInfo.denom;

const execution = await client.execute(
ownerAddress,
contractAddress,
{
multi_send_to_evm: {
destination_chain: "ethereum",
destination_address: "0x49324C7f83568861AB1b66E547BB1B66431f1070",
recipients: ["0x49324C7f83568861AB1b66E547BB1B66431f1070"],
},
},
"auto",
"test",
[{ amount: "1000000", denom }]
);

await relayerClient.relayPackets();

expect(execution).toBeDefined();
});
});
Loading

0 comments on commit 9fece3f

Please sign in to comment.