Skip to content

Commit

Permalink
chore: refactor scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Nov 6, 2023
1 parent d359be2 commit 57c5894
Show file tree
Hide file tree
Showing 29 changed files with 619 additions and 57 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions packages/axelar-local-dev-cosmos/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
# Docker
docker/**/.*
config.json
channel.json
connection.json
info/*

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sed -i '/\[api\]/,/\[/ s/swagger = false/swagger = true/' "$HOME"/config/app.tom
# staking/governance token is hardcoded in config, change this
sed -i "s/\"stake\"/\"$DENOM\"/" "$HOME"/config/genesis.json && echo "Updated staking token to $DENOM"


# Adding a new key named 'owner' with a test keyring-backend in the specified home directory
# and storing the mnemonic in the mnemonic.txt file
mnemonic=$(axelard keys add owner ${DEFAULT_KEYS_FLAGS} 2>&1 | tail -n 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHAIN_ID=axelar
HOME=/root/private/.axelar
DEFAULT_KEYS_FLAGS="--keyring-backend test --home ${HOME}"
CHAIN=$1
DIR="$(dirname "$0")"

if [ -z "$CHAIN" ]
then
Expand All @@ -18,4 +19,4 @@ docker exec -it axelar /bin/sh -c "axelard tx nexus activate-chain ${CHAIN} --ge
echo "Activated chain ${CHAIN}"
docker exec -t axelar /bin/sh -c "cat ${HOME}/unsigned_msg.json"

sh broadcast-unsigned-tx.sh
sh "$DIR/broadcast-unsigned-multi-tx.sh"
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[[axelar_bridge_evm]]
name = "Ethereum"
rpc_addr = "localhost:8500/0"
start-with-bridge = false

[[axelar_bridge_evm]]
name = "Avalanche"
rpc_addr = "localhost:8500/1"
start-with-bridge = false

[[axelar_bridge_evm]]
name = "Fantom"
rpc_addr = "localhost:8500/2"
start-with-bridge = false

[[axelar_bridge_evm]]
name = "Moonbeam"
rpc_addr = "localhost:8500/3"
start-with-bridge = false

[[axelar_bridge_evm]]
name = "Polygon"
rpc_addr = "localhost:8500/4"
start-with-bridge = false
13 changes: 13 additions & 0 deletions packages/axelar-local-dev-cosmos/docker/axelar/bin/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

EVM_CHAIN=ethereum
COSMOS_CHAIN=wasm

# 1. Add EVM chain
sh ./steps/01-add-chain.sh ${EVM_CHAIN}

# # 2. Add cosmos-based chain
sh ./steps/02-add-cosmos-chain.sh ${COSMOS_CHAIN}

# # 3. Register Broadcaster Account and Maintainer
# sh ./steps/04-register-broadcaster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ CHAIN_ID=axelar
HOME=/root/private/.axelar
DEFAULT_KEYS_FLAGS="--keyring-backend test --home ${HOME}"
CHAIN=$1
DIR="$(dirname "$0")"

if [ -z "$CHAIN" ]
then
echo "Chain name is required"
exit 1
fi

docker exec -it axelar /bin/sh -c "axelard tx evm add-chain ${CHAIN} /root/private/bin/params.json --generate-only \
docker exec -it axelar /bin/sh -c "axelard tx evm add-chain ${CHAIN} /root/private/bin/libs/params.json --generate-only \
--chain-id ${CHAIN_ID} --from \$(axelard keys show governance -a ${DEFAULT_KEYS_FLAGS}) --home ${HOME} \
--output json --gas 500000 &> ${HOME}/unsigned_msg.json"
echo "Added evm chain"
docker exec -t axelar /bin/sh -c "cat ${HOME}/unsigned_msg.json"

sh broadcast-unsigned-tx.sh
sh "$DIR/../libs/broadcast-unsigned-multi-tx.sh"

sh "$DIR/../libs/activate-chain.sh" ${CHAIN}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ HOME=/root/private/.axelar
DEFAULT_KEYS_FLAGS="--keyring-backend test --home ${HOME}"
CHAIN=$1
CHANNEL_ID=${2:-channel-0}
DIR="$(dirname "$0")"

if [ -z "$CHAIN" ]
then
Expand All @@ -21,4 +22,6 @@ docker exec -it axelar /bin/sh -c "axelard tx axelarnet add-cosmos-based-chain $
echo "Added cosmos-based chain"
docker exec -t axelar /bin/sh -c "cat ${HOME}/unsigned_msg.json"

sh broadcast-unsigned-tx.sh
sh "$DIR/../libs/broadcast-unsigned-multi-tx.sh"

sh "$DIR/../libs/activate-chain.sh" ${CHAIN}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ HOME=/root/private/.axelar
DEFAULT_KEYS_FLAGS="--keyring-backend test --home ${HOME}"
CHAIN=$1
DENOM=${2:-uwasm}
DIR="$(dirname "$0")"

if [ -z "$CHAIN" ]
then
Expand All @@ -19,4 +20,4 @@ docker exec -it axelar /bin/sh -c "axelard tx axelarnet register-asset ${CHAIN}
docker exec -t axelar /bin/sh -c "cat ${HOME}/unsigned_msg.json"
echo "Registered asset ${CHAIN} ${DENOM}"

sh broadcast-unsigned-tx.sh
sh "$DIR/../libs/broadcast-unsigned-multi-tx.sh"
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

#!/bin/sh

CHAIN_ID=axelar
HOME=/root/private/.axelar
DEFAULT_KEYS_FLAGS="--keyring-backend test --home ${HOME}"
DIR="$(dirname "$0")"

# 1. Register broadcaster
echo "Registering broadcaster"
docker exec -it axelar /bin/sh -c "axelard tx snapshot register-proxy \$(axelard keys show gov1 -a ${DEFAULT_KEYS_FLAGS}) \
--chain-id ${CHAIN_ID} --from owner ${DEFAULT_KEYS_FLAGS} \
--output json --gas 1000000"
echo "Registered broadcaster"

# Read the content of the local file and append it to the file inside the Docker container
docker exec -t axelar /bin/sh -c "cat /root/private/bin/libs/evm-rpc.toml >> "$HOME"/config/config.toml"
echo "Added evm-rpc.toml to config.toml"

# 2. Register broadcaster as a maintainerf
echo "Registering maintainer"
docker exec -it axelar /bin/sh -c "axelard tx nexus register-chain-maintainer avalanche ethereum fantom moonbeam polygon \
--chain-id ${CHAIN_ID} --from gov1 ${DEFAULT_KEYS_FLAGS} \
--output json --gas 1000000"

echo "Registered maintainer"




3 changes: 2 additions & 1 deletion packages/axelar-local-dev-cosmos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"prettier": "prettier --write 'src/**/*.ts'",
"build": "npm run clean && npm run build-ts",
"build-ts": "tsc",
"start": "ts-node scripts/start.ts",
"start": "./scripts/clean.sh && ts-node scripts/start.ts",
"stop": "ts-node scripts/stop.ts"
},
"dependencies": {
Expand All @@ -23,6 +23,7 @@
"@cosmjs/cosmwasm-stargate": "^0.31.1",
"@cosmjs/stargate": "^0.31.1",
"@types/sinon": "^10.0.20",
"reconnecting-websocket": "^4.4.0",
"sinon": "^17.0.0"
},
"author": "[email protected]",
Expand Down
7 changes: 7 additions & 0 deletions packages/axelar-local-dev-cosmos/scripts/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Get the directory of the current script
DIR="$(dirname "$0")"

# Remove the directory relative to the script's location
rm -rf "$DIR/../info"
3 changes: 3 additions & 0 deletions packages/axelar-local-dev-cosmos/scripts/start.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { startAll } from "../src/docker";
const path = require("path");
import childProcess from "child_process";
// clean up info json

startAll();
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IBCRelayerClient } from "../clients/IBCRelayerClient";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";

describe("IBCRelayerClient", () => {
it.skip("should be able to create a connection and channel", async () => {
Expand All @@ -15,4 +16,20 @@ describe("IBCRelayerClient", () => {
expect(response2!.src).toBeDefined();
expect(response2!.dest).toBeDefined();
});

it("should create a wallet from a mnemonic if provided", async () => {
const mockMnemonic = await DirectSecp256k1HdWallet.generate(12).then(
(w) => w.mnemonic
);
const result = await IBCRelayerClient.create(mockMnemonic);

expect(result.relayerAccount.mnemonic).toEqual(mockMnemonic);
});

it("should generate a new wallet if no mnemonic is provided", async () => {
const result = await IBCRelayerClient.create();

expect(result).toBeDefined();
expect(result.relayerAccount.mnemonic).toBeDefined();
});
});
69 changes: 61 additions & 8 deletions packages/axelar-local-dev-cosmos/src/__tests__/listener.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,53 @@ describe("E2E - Listener", () => {
"illness step primary sibling donkey body sphere pigeon inject antique head educate";

async function executeContractCall() {
// Upload the wasm contract
const _path = path.resolve(__dirname, "../..", "wasm/send_receive.wasm");
const response = await wasmClient.uploadWasm(_path).catch((err) => {
console.log(err);

throw err;
});
console.log(response);
console.log("Uploaded wasm:", response.codeId);

// 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"
);
console.log("Deployed contract:", contractAddress);

const denom = wasmClient.chainInfo.denom;

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

// console.log(JSON.stringify(execution, null, 2));

await relayerClient.relayPackets();
}

async function executeContractCallWithToken() {
// Upload the wasm contract
const _path = path.resolve(__dirname, "../..", "wasm/multi_send.wasm");
const response = await wasmClient.uploadWasm(_path);
Expand Down Expand Up @@ -82,19 +129,25 @@ describe("E2E - Listener", () => {

it("should receive ibc events from call contract", (done) => {
(async () => {
axelarListener.listen(AxelarIBCEvent, (args) => {
console.log("Any event", args);
});
// axelarListener.listen(AxelarIBCEvent, (args) => {
// console.log("Any event", args);
// });
axelarListener.listen(AxelarCosmosContractCallEvent, (args) => {
console.log("Received ContractCall", args);
done();
});
axelarListener.listen(AxelarCosmosContractCallWithTokenEvent, (args) => {
console.log("Received ContractCallWithToken:", args);
done();
});
// axelarListener.listen(AxelarCosmosContractCallWithTokenEvent, (args) => {
// console.log("Received ContractCallWithToken:", args);
// done();
// });

await executeContractCall();
try {
await executeContractCall();
} catch (e) {
console.log(e);
done();
}
await executeContractCallWithToken();
})();
});
});
2 changes: 2 additions & 0 deletions packages/axelar-local-dev-cosmos/src/clients/CosmosClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class CosmosClient {
denom: config.denom || defaultDenom,
lcdUrl: config.lcdUrl || `http://localhost/${chain}-lcd`,
rpcUrl: config.rpcUrl || `http://localhost/${chain}-rpc`,
wsUrl: config.wsUrl || `ws://localhost/${chain}-rpc/websocket`,
};

const walletOptions = {
Expand Down Expand Up @@ -96,6 +97,7 @@ export class CosmosClient {
denom: this.chainInfo.denom,
lcdUrl: this.chainInfo.lcdUrl,
rpcUrl: this.chainInfo.rpcUrl,
wsUrl: this.chainInfo.wsUrl,
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ReconnectingWebSocket from "reconnecting-websocket";
import { CosmosChainInfo } from "../types";

export class CosmosRelayerClient {
private wsMap: Map<string, ReconnectingWebSocket>;

private constructor(config: Omit<CosmosChainInfo, "owner">) {
this.wsMap = new Map();
}

async listenIncomingIBCEvents() {}
}
Loading

0 comments on commit 57c5894

Please sign in to comment.