Skip to content

Commit

Permalink
Merge branch 'update/devnet_amplifier' of github.com:axelarnetwork/ax…
Browse files Browse the repository at this point in the history
…elar-contract-deployments into update/devnet_amplifier
  • Loading branch information
João Sousa authored and João Sousa committed Sep 3, 2024
2 parents ea71555 + 0747980 commit 78e4dfe
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 456 deletions.
2 changes: 0 additions & 2 deletions .github/actions/setup-sui/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ runs:
mkdir -p sui-binaries
mv ./sui ./sui-binaries/
mv ./sui-debug ./sui-binaries/
mv ./sui-test-validator ./sui-binaries/
rm -rf sui-${{ inputs.SUI_VERSION }}-ubuntu-x86_64.tgz
- name: Save Sui binaries
Expand All @@ -53,7 +52,6 @@ runs:
run: |
sudo cp ./sui-cli/sui-binaries/sui /usr/local/bin/sui
sudo cp ./sui-cli/sui-binaries/sui-debug /usr/local/bin/sui-debug
sudo cp ./sui-cli/sui-binaries/sui-test-validator /usr/local/bin/sui-test-validator
- name: Setup Sui Wallet
shell: bash
Expand Down
39 changes: 30 additions & 9 deletions .github/workflows/test-sui.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
name: Test Sui

on:
pull_request:
paths:
- sui/**
- common/**
- .github/actions/setup-sui/**
- .github/workflows/test-sui.yaml
on: pull_request

jobs:
check-relevant-changes:
name: Check for Relevant Changes
runs-on: blacksmith-2vcpu-ubuntu-2204
outputs:
run_tests: ${{ steps.filter.outputs.sui == 'true' || steps.filter.outputs.common == 'true' || steps.filter.outputs.github == 'true' }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
sui:
- 'sui/**'
common:
- 'common/**'
github:
- '.github/actions/setup-sui/**'
- '.github/workflows/test-sui.yaml'
- name: Summarize Changes
run: |
echo "Changes in sui: ${{ steps.filter.outputs.sui }}"
echo "Changes in common: ${{ steps.filter.outputs.common }}"
echo "Changes in github: ${{ steps.filter.outputs.github }}"
test-sui:
name: Test Sui
needs: check-relevant-changes
if: ${{ needs.check-relevant-changes.outputs.run_tests == 'true' }}
runs-on: blacksmith-2vcpu-ubuntu-2204
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Node.js
- name: Setup Node.js
uses: useblacksmith/setup-node@v5
with:
node-version: 18.x
Expand All @@ -37,7 +56,9 @@ jobs:
SUI_VERSION: ${{ env.SUI_VERSION }}

- name: Spin up Sui Network
run: nohup sh -c "sui-test-validator" > nohup.out 2> nohup.err < /dev/null &
# sui-test-validator will be deprecated in the future.
# this command follows the guide in https://docs.sui.io/guides/developer/getting-started/local-network
run: nohup sh -c "RUST_LOG="off,sui_node=info" sui start --with-faucet --force-regenesis" > nohup.out 2> nohup.err < /dev/null &

- name: Wait for Sui network
uses: nev7n/wait_for_response@v1
Expand Down
88 changes: 38 additions & 50 deletions cosmwasm/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
require('dotenv').config();
const { isNil } = require('lodash');

const { instantiate2Address } = require('@cosmjs/cosmwasm-stargate');

const { isNumber, printInfo, loadConfig, saveConfig, prompt, getChainConfig } = require('../common');
const {
prepareWallet,
prepareClient,
fromHex,
getSalt,
getChains,
updateContractConfig,
fetchCodeIdFromCodeHash,
uploadContract,
instantiateContract,
Expand All @@ -17,8 +22,8 @@ const {
const { Command, Option } = require('commander');
const { addAmplifierOptions } = require('./cli-utils');

const upload = (client, wallet, chainName, config, options) => {
const { reuseCodeId, contractName, fetchCodeId } = options;
const upload = async (client, wallet, chainName, config, options) => {
const { reuseCodeId, contractName, fetchCodeId, instantiate2, salt, chainNames } = options;
const {
axelar: {
contracts: { [contractName]: contractConfig },
Expand All @@ -29,31 +34,22 @@ const upload = (client, wallet, chainName, config, options) => {
if (!fetchCodeId && (!reuseCodeId || isNil(contractConfig.codeId))) {
printInfo('Uploading contract binary');

return uploadContract(client, wallet, config, options)
.then(({ address, codeId }) => {
printInfo('Uploaded contract binary');
contractConfig.codeId = codeId;

if (!address) {
return;
}

if (chainConfig) {
contractConfig[chainConfig.axelarId] = {
...contractConfig[chainConfig.axelarId],
address,
};
} else {
contractConfig.address = address;
}

printInfo('Expected contract address', address);
})
.then(() => ({ wallet, client }));
}
const { checksum, codeId } = await uploadContract(client, wallet, config, options);

printInfo('Uploaded contract binary');
contractConfig.codeId = codeId;

if (instantiate2) {
const [account] = await wallet.getAccounts();
const address = instantiate2Address(fromHex(checksum), account.address, getSalt(salt, contractName, chainNames), 'axelar');

printInfo('Skipping upload. Reusing previously uploaded bytecode');
return Promise.resolve({ wallet, client });
updateContractConfig(contractConfig, chainConfig, 'address', address);

printInfo('Expected contract address', address);
}
} else {
printInfo('Skipping upload. Reusing previously uploaded bytecode');
}
};

const instantiate = async (client, wallet, chainName, config, options) => {
Expand All @@ -72,18 +68,11 @@ const instantiate = async (client, wallet, chainName, config, options) => {
}

const initMsg = makeInstantiateMsg(contractName, chainName, config);
return instantiateContract(client, wallet, initMsg, config, options).then((contractAddress) => {
if (chainConfig) {
contractConfig[chainConfig.axelarId] = {
...contractConfig[chainConfig.axelarId],
address: contractAddress,
};
} else {
contractConfig.address = contractAddress;
}
const contractAddress = await instantiateContract(client, wallet, initMsg, config, options);

printInfo(`Instantiated ${chainName === 'none' ? '' : chainName.concat(' ')}${contractName}. Address`, contractAddress);
});
updateContractConfig(contractConfig, chainConfig, 'address', contractAddress);

printInfo(`Instantiated ${chainName === 'none' ? '' : chainName.concat(' ')}${contractName}. Address`, contractAddress);
};

const main = async (options) => {
Expand All @@ -92,19 +81,18 @@ const main = async (options) => {

const chains = getChains(config, options);

await prepareWallet(options)
.then((wallet) => prepareClient(config, wallet))
.then(({ wallet, client }) => upload(client, wallet, chains[0], config, options))
.then(({ wallet, client }) => {
if (uploadOnly || prompt(`Proceed with deployment on axelar?`, yes)) {
return;
}

return chains.reduce((promise, chain) => {
return promise.then(() => instantiate(client, wallet, chain.toLowerCase(), config, options));
}, Promise.resolve());
})
.then(() => saveConfig(config, env));
const wallet = await prepareWallet(options);
const client = await prepareClient(config, wallet);

await upload(client, wallet, chains[0], config, options);

if (!(uploadOnly || prompt(`Proceed with deployment on axelar?`, yes))) {
for (const chain of chains) {
await instantiate(client, wallet, chain.toLowerCase(), config, options);
}
}

saveConfig(config, env);
};

const programHandler = () => {
Expand Down
Loading

0 comments on commit 78e4dfe

Please sign in to comment.