Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: setup cosmos examples #163

Merged
merged 31 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
56fd2d9
chore: add basic start local cosmos chains script
npty Nov 27, 2023
935376a
chore: update local.json to local-evm.json
npty Nov 27, 2023
117d81f
feat: add sol and wasm contracts
npty Nov 27, 2023
c652dfa
chore: update contract example
npty Nov 27, 2023
5cee378
chore: write channel id to local config json
npty Nov 27, 2023
a47bf0c
chore: fix local config path
npty Nov 27, 2023
d1b1ab8
chore: fix evm contract import issue
npty Nov 27, 2023
5c05869
feat: add deploy step
npty Nov 27, 2023
7847f7f
chore: (wip) add set json to deploy step
npty Nov 29, 2023
fb4bb69
chore: record wasm contract address to config file
npty Nov 29, 2023
afc6f76
chore: rename `preDeploy` to `deployOnAltChain`
npty Nov 29, 2023
91254a2
chore: fix merge config data
npty Nov 29, 2023
f00e407
feat: update execute step
npty Nov 29, 2023
cd83a64
chore: update to use local dep for debugging
npty Nov 30, 2023
7a6319d
chore: update axelar-local-dev-cosmos version
npty Dec 1, 2023
3d65bf3
chore: update source chain to Ethereum on example
npty Dec 1, 2023
af05ae4
chore: update examples
npty Dec 1, 2023
92f901d
chore: fix missing ethers
npty Dec 1, 2023
960a512
chore: refactor example
npty Dec 1, 2023
33755ca
chore: add some comments
npty Dec 1, 2023
64691f7
chore: add cosmos examples test
npty Dec 1, 2023
426be7b
chore: fix example
npty Dec 1, 2023
4eb6aff
chore: update README.md
npty Dec 12, 2023
f469eb9
chore: update axelar-local-dev-cosmos
npty Dec 12, 2023
c47d22d
chore: update cosmos version
npty Dec 12, 2023
5f92c70
chore: increase sleep duration
npty Dec 12, 2023
0a5bcf3
chore: update package-lock.json
npty Dec 12, 2023
3383c2c
chore: mkdir before access
npty Dec 14, 2023
6d83761
chore: refactor test actions
npty Dec 14, 2023
26a2126
chore: refactor README.md
npty Dec 14, 2023
e97b655
chore: add cosmos link in root README
npty Dec 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 78 additions & 15 deletions .github/workflows/verify-cli-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,83 @@ name: Verify Cli Examples
on: pull_request

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04]
arch: [amd64]
test-cosmos-examples:
runs-on: ubuntu-22.04
name: 'Test Cosmos Examples'
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'

- name: Install Dependencies
run: npm ci

- name: Create .env file
run: |
# Dummy private key created for testing purpose only, it is not secret
npm run setup

- name: Compile EVM Smart Contracts
run: npm run build

- name: Override config/ci.json
run: |
echo '{"aptos": {"enabled": false},"cosmos": {"enabled": true}}' > config/ci.json

- name: Test
run: |
NODE_ENV=ci npm run test:cosmos

test-evm-examples:
runs-on: ubuntu-22.04
name: 'Test EVM Examples'
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'

- name: Install Dependencies
run: npm ci

- name: Create .env file
run: |
# Dummy private key created for testing purpose only, it is not secret
npm run setup

- name: Compile EVM Smart Contracts
run: |
npm run build

- name: Override config/ci.json
run: |
echo '{"aptos": {"enabled": false},"cosmos": {"enabled": false}}' > config/ci.json

- name: Test
run: |
NODE_ENV=ci npm run test:evm

test-aptos-examples:
runs-on: ubuntu-22.04
name: 'Test Aptos Examples'
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'

- name: Prerequisites
run: |
Expand All @@ -25,14 +88,18 @@ jobs:
chmod +x aptos
cp aptos /usr/local/bin

- name: Install
- name: Install Dependencies
run: npm ci

- name: Create .env file
run: |
# Dummy private key created for testing purpose only, it is not secret
npm run setup

- name: Override config/ci.json
run: |
echo '{"aptos": {"enabled": true},"cosmos": {"enabled": false}}' > config/ci.json

- name: Compile EVM Smart Contracts
run: |
npm run build
Expand All @@ -41,12 +108,8 @@ jobs:
run: |
npm run build-aptos

- name: Override config/ci.json
run: |
echo '{"aptos": {"enabled": true}}' > config/ci.json

- name: Test
run: |
nohup sh -c "aptos node run-local-testnet --with-faucet" > nohup.out 2> nohup.err < /dev/null &
sleep 10
NODE_ENV=ci npm run test
sleep 30
NODE_ENV=ci npm run test:aptos
6 changes: 3 additions & 3 deletions .github/workflows/verify-web-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

- name: Override config/ci.json
run: |
echo '{"aptos": {"enabled": false}}' > config/ci.json
echo '{"aptos": {"enabled": false}, "cosmos": {"enabled": false}}' > config/ci.json

- name: Install Dependencies for Cli Examples
run: npm ci
Expand All @@ -33,7 +33,7 @@ jobs:
run: |
# Dummy private key created for testing purpose only, it is not secret
npm run setup
nohup npm run start &
NODE_ENV=ci nohup npm run start &
sleep 5

- name: Setup Web Examples
Expand All @@ -42,7 +42,7 @@ jobs:
npm ci
npm run setup

- name: Compile EVM Smart Contracts and Deploy
- name: Deploy
run: |
cd examples-web
npm run deploy
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build
artifacts
cache
yarn-error.log
local.json
local*.json
gasLogs.json
scripts/deployConst.js

Expand All @@ -14,3 +14,4 @@ aptos-artifacts
.vscode
chain-config/*.json
.aptos
!./**/artifacts/send_receive.wasm
3 changes: 1 addition & 2 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module.exports = {
recursive: true,
timeout: 20000,
timeout: 600000,
slow: 15000,
file: ['examples/tests/checkExamples.js'],
};
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ If not specified, this will print balances of the wallet for testnet.

- [Evm Examples](/examples/evm/)
- [Aptos Examples](/examples/aptos/)
- [Cosmos Examples](/examples/cosmos/)
- [Web Examples](/examples-web/)
6 changes: 6 additions & 0 deletions build-wasm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# !/bin/bash

docker run --rm -v "$(pwd)/examples/cosmos/call-contract/wasm-contract":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer:0.12.13
9 changes: 6 additions & 3 deletions config/ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"aptos": {
"enabled": true
}
"aptos": {
"enabled": true
},
"cosmos": {
"enabled": false
}
}
3 changes: 3 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"aptos": {
"enabled": false
},
"cosmos": {
"enabled": false
}
}
10 changes: 10 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const path = require('path');

const configPath = {
localEvmChains: path.resolve(__dirname, '..', 'chain-config', 'local-evm.json'),
localCosmosChains: path.resolve(__dirname, '..', 'chain-config', 'local-cosmos.json'),
};

module.exports = {
configPath,
};
8 changes: 6 additions & 2 deletions examples-web/package-lock.json

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

40 changes: 24 additions & 16 deletions examples-web/scripts/deploy-contracts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import "dotenv/config";
import fs from "fs/promises";
import { existsSync, mkdirSync } from "fs";
import path from "path";
import { Wallet } from "ethers";
import chains from "../../chain-config/local.json";
import { configPath } from "../../config";
import { deploy as deployCallContract } from "./call-contract";
import { deploy as deployCallContractWithToken } from "./call-contract-with-token";
import { deploy as deployNftLinker } from "./nft-linker";
Expand All @@ -11,8 +12,11 @@ import { deploy as deployNftLinker } from "./nft-linker";
const privateKey = process.env.NEXT_PUBLIC_EVM_PRIVATE_KEY as string;
const wallet = new Wallet(privateKey);

const ethereumChain = chains.find((chain: any) => chain.name === "Ethereum") || chains[0] as any;
const avalancheChain = chains.find((chain: any) => chain.name === "Avalanche") || chains[1] as any;
const chains = require(configPath.localEvmChains);
const ethereumChain =
chains.find((chain: any) => chain.name === "Ethereum") || (chains[0] as any);
const avalancheChain =
chains.find((chain: any) => chain.name === "Avalanche") || (chains[1] as any);

function print(chain: any) {
console.log(`Deployed example contracts on ${chain.name}`);
Expand All @@ -22,26 +26,30 @@ function print(chain: any) {
}

async function main() {
const [chainA, chainB] = await deployCallContract(wallet, ethereumChain, avalancheChain)
.then(() => deployCallContractWithToken(wallet, ethereumChain, avalancheChain))
const [chainA, chainB] = await deployCallContract(
wallet,
ethereumChain,
avalancheChain
)
.then(() =>
deployCallContractWithToken(wallet, ethereumChain, avalancheChain)
)
.then(() => deployNftLinker(wallet, ethereumChain, avalancheChain));

print(chainA);
console.log("")
console.log("");
print(chainB);

// update chains
const updatedChains = [chainA, chainB];
const _path = path.resolve(__dirname, '../../chain-config/local.json')
const publicPath = path.resolve(__dirname, '../public/chains.json')
await fs.writeFile(
_path,
JSON.stringify(updatedChains, null, 2)
);
await fs.writeFile(
publicPath,
JSON.stringify(updatedChains, null, 2)
);
const _path = path.resolve(configPath.localEvmChains);
const dirname = path.dirname(_path);
if (!existsSync(dirname)) {
await mkdirSync(dirname, { recursive: true });
}
const publicPath = path.resolve(__dirname, "../public/chains.json");
await fs.writeFile(_path, JSON.stringify(updatedChains, null, 2));
await fs.writeFile(publicPath, JSON.stringify(updatedChains, null, 2));
}

main();
6 changes: 3 additions & 3 deletions examples-web/src/config/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getDefaultProvider, providers, Wallet } from "ethers";
import testnetInfo from "@axelar-network/axelar-chains-config/info/testnet.json";
import local from "../../../chain-config/local.json";
import { configPath } from "../../../config";

if (typeof window === "undefined") {
require("dotenv").config();
Expand All @@ -15,13 +15,13 @@ function getWallet() {
export const isTestnet = process.env.NEXT_PUBLIC_ENVIRONMENT === "testnet";
export const wallet = getWallet();

export const localChains = local as any;
export const localChains = require(configPath.localEvmChains);

const testnetChains = Object.entries(testnetInfo).map(([, value]) => {
return value;
});

export const chains = isTestnet ? testnetChains : (local as any);
export const chains = isTestnet ? testnetChains : localChains;

export const srcChain = chains.find(
(chain: any) => chain.name === "Ethereum"
Expand Down
4 changes: 2 additions & 2 deletions examples/aptos/call-contract/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { AptosNetwork } = require('@axelar-network/axelar-local-dev-aptos');
const HelloWorld = rootRequire('./artifacts/examples/aptos/call-contract/contracts/HelloWorld.sol/HelloWorld.json');
const { defaultAbiCoder } = require('ethers/lib/utils');

async function preDeploy() {
async function deployOnAltChain() {
console.log(`Deploying HelloWorld for Aptos.`);
const client = new AptosNetwork(process.env.APTOS_URL);
await client.deploy('examples/aptos/call-contract/modules/build/hello_world', ['hello_world.mv']);
Expand Down Expand Up @@ -65,7 +65,7 @@ async function execute(evmChain, wallet, options) {
}

module.exports = {
preDeploy,
deployOnAltChain,
deploy,
execute,
};
4 changes: 2 additions & 2 deletions examples/aptos/token-linker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function isDeployedTokenLinker(client) {
return resources.find((resource) => resource.type === `${aptosTokenLinkerAddress}::token_linker::State`);
}

async function preDeploy() {
async function deployOnAltChain() {
const client = new AptosNetwork(process.env.APTOS_URL);
const isDeployed = await isDeployedTokenLinker(client);

Expand Down Expand Up @@ -122,7 +122,7 @@ async function execute(evmChain, wallet, options) {
}

module.exports = {
preDeploy,
deployOnAltChain,
deploy,
execute,
};
23 changes: 23 additions & 0 deletions examples/cosmos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Cosmos Examples

## Prerequisite

- Docker running on your local machine.

We will use this file to deploy to the wasm chain for this example.

## Enable Cosmos in Config

To start Axelar and Wasm chain when running `npm run start`, you've to set `cosmos: true` in [config/default.json](../../config/default.json).

## Run the EVM chains with Axelar and Wasm Chain

```
npm run start
```

This will take about 5 mins to start on the first run, since it needs to download the axelar and wasm docker images, setup axelar axelars, and creating an IBC connection between Wasm and Axelar chain.

## Basic

- [call-contract](call-contract)
Loading