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

chore(sui): gh workflow for testing sui commands #339

Merged
merged 53 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ea3d3bd
chore: init test file
npty Aug 19, 2024
985e66d
chore: rename evm test
npty Aug 19, 2024
1d53c76
chore: add sui cli setup script
npty Aug 19, 2024
68a48fe
feat: init sui test scripts
npty Aug 19, 2024
9c11a86
chore: fix unclosed }
npty Aug 19, 2024
981a6b0
chore: fix path for sui cli
npty Aug 19, 2024
66b20a3
chore: fix cache key
npty Aug 19, 2024
9e65554
chore: add gmp sendCall command
npty Aug 20, 2024
d598965
Merge branch 'main' into chore/gh-workflow-for-sui-scripts
npty Aug 20, 2024
9732ac8
chore: fix gmp command
npty Aug 20, 2024
8814e7c
feat: add Gateway and Operators tests
npty Aug 20, 2024
7cb0727
chore: comment out error tests
npty Aug 20, 2024
a44db6d
chore: remove log
npty Aug 20, 2024
76725b6
feat: add keypair and transfer-object test
npty Aug 20, 2024
1786acf
chore: add todo
npty Aug 20, 2024
ca34fb0
chore: prettier
npty Aug 20, 2024
ab3f4b0
chore: add `continue-on-error: true` for the command that might failed
npty Aug 20, 2024
4e06bb5
chore: add if: always to mark that step as failed when error
npty Aug 21, 2024
e175b08
chore: fix using wrong script when collecting and refunding gas
npty Aug 21, 2024
e968ff1
chore: remove always()
npty Aug 21, 2024
8ca6c1f
chore: setup sui localnet
npty Aug 21, 2024
0f1c5e2
chore: setup random address for sui
npty Aug 21, 2024
a3043b6
chore: add command to init sui config file
npty Aug 21, 2024
843aacf
fix: setup sui client file
npty Aug 21, 2024
d64849b
chore: fix sui setup error
npty Aug 21, 2024
2d824f5
chore: fix var not resolved correctly
npty Aug 21, 2024
fa85ea6
chore: fix log
npty Aug 21, 2024
a7f9613
chore: rename test to example
npty Aug 23, 2024
40c5b7c
chore: rename test to example in gmp.js
npty Aug 23, 2024
0b2791d
chore: fix deploy test step
npty Aug 23, 2024
d5806e4
Merge branch 'main' into chore/gh-workflow-for-sui-scripts
npty Aug 23, 2024
a9cc229
Merge branch 'main' into chore/gh-workflow-for-sui-scripts
npty Aug 26, 2024
8d0dd03
chore: try adding newNonce for rotate signers
npty Aug 27, 2024
97727da
Merge branch 'main' into chore/gh-workflow-for-sui-scripts
npty Aug 27, 2024
1827313
chore: update arg for gas refund
npty Aug 27, 2024
9039562
chore: rename
npty Aug 27, 2024
8149a89
chore: edit local.json
npty Aug 27, 2024
74300b3
chore: test gateway before gmp
npty Aug 27, 2024
ffba33a
chore: update readme for example contract deployment
npty Aug 27, 2024
c8b5560
chore: bump axelar-cgp-sui to 0.4.1
npty Aug 27, 2024
6f4e6ad
chore: fix executing incoming call contract step
npty Aug 27, 2024
8f577a5
chore: log channel id
npty Aug 27, 2024
58f496c
chore: update log index in approve and execute
npty Aug 27, 2024
d0e244d
chore: remove extra line
npty Aug 27, 2024
0f49900
chore: add version.json
npty Aug 27, 2024
4efc586
chore: print version mismatch message when deploy a contract
npty Aug 27, 2024
e513875
feat(sui): add init multisig command (#349)
npty Aug 29, 2024
e3626d0
Merge branch 'main' into chore/gh-workflow-for-sui-scripts
npty Aug 29, 2024
0ad655d
chore: check if sui test are needed
npty Aug 29, 2024
4a0a32f
chore: check for gh workflows as well
npty Aug 29, 2024
193770d
chore: remove redundant job
npty Aug 29, 2024
f0a1f8f
chore: remove unneeded checks
npty Aug 29, 2024
d75c9dd
chore: prettier
npty Aug 29, 2024
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
67 changes: 67 additions & 0 deletions .github/actions/setup-sui/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Setup Sui CLI
description: 'Setup Sui CLI and install dependencies'

inputs:
SUI_VERSION:
description: 'The version of Sui CLI to install'
required: true

runs:
using: 'composite'

steps:
- name: Debug Action Input
shell: bash
run: echo "SUI_VERSION=${{ inputs.SUI_VERSION }}"

- name: Install Dependencies
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y libpq-dev

- name: Cache Sui binaries
id: cache-sui
uses: actions/cache@v4
with:
path: sui-cli/sui-binaries/
key: sui-${{ inputs.SUI_VERSION }}

- name: Download and Install Sui
npty marked this conversation as resolved.
Show resolved Hide resolved
shell: bash
if: steps.cache-sui.outputs.cache-hit != 'true'
run: |
mkdir -p sui-cli && cd sui-cli
curl -L -o sui-${{ inputs.SUI_VERSION }}-ubuntu-x86_64.tgz https://github.com/MystenLabs/sui/releases/download/${{ inputs.SUI_VERSION }}/sui-${{ inputs.SUI_VERSION }}-ubuntu-x86_64.tgz
tar -xvf sui-${{ inputs.SUI_VERSION }}-ubuntu-x86_64.tgz
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
if: steps.cache-sui.outputs.cache-hit != 'true'
id: cache-sui-save
uses: actions/cache@v4
with:
path: sui-cli/sui-binaries/
key: sui-${{ inputs.SUI_VERSION }}

- name: Add Sui binaries to PATH
shell: bash
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
run: |
echo -e "y\n\n1" | sui client envs
sui client new-address secp256k1 wallet
sui client switch --address wallet
SUI_PRIVATE_KEY=$(sui keytool export --key-identity wallet --json | jq .exportedPrivateKey | sed 's/"//g')
SUI_ADDRESS=$(sui keytool export --key-identity wallet --json | jq .key.suiAddress | sed 's/"//g')
echo "SUI_PRIVATE_KEY=${SUI_PRIVATE_KEY}" >> $GITHUB_ENV
echo "SUI_ADDRESS=${SUI_ADDRESS}" >> $GITHUB_ENV
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Test
name: Test Evm

on: pull_request

jobs:
test:
test-evm:
runs-on: blacksmith-2vcpu-ubuntu-2204

steps:
Expand Down
148 changes: 148 additions & 0 deletions .github/workflows/test-sui.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: Test Sui

on: pull_request

jobs:
test-sui:
runs-on: blacksmith-2vcpu-ubuntu-2204

steps:
npty marked this conversation as resolved.
Show resolved Hide resolved
- name: Checkout code
uses: actions/checkout@v4

- name: Install Node.js
uses: useblacksmith/setup-node@v5
with:
node-version: 18.x
cache: 'npm'

- name: Install
run: npm ci

- name: Read SUI_VERSION from JSON
id: read-json
run: |
SUI_VERSION=$(jq -r '.SUI_VERSION' sui/version.json)
echo "SUI_VERSION=${SUI_VERSION}" >> $GITHUB_ENV

- name: Setup Sui CLI and install dependencies
uses: ./.github/actions/setup-sui
with:
SUI_VERSION: ${{ env.SUI_VERSION }}

- name: Spin up Sui Network
run: nohup sh -c "sui-test-validator" > nohup.out 2> nohup.err < /dev/null &

- name: Sleep for 30 seconds
run: sleep 30s
shell: bash

- name: Setup Sui Local Network
run: |
sui client new-env --alias local --rpc http://127.0.0.1:9000
sui client switch --env local

- name: Prepare local.json
run: |
echo '{
"sui": {
"name": "Sui",
"axelarId": "sui",
"networkType": "localnet",
"tokenSymbol": "SUI",
"rpc": "http://127.0.0.1:9000",
"faucetUrl": "http://127.0.0.1:9123",
"contracts": {}
}
}' > ./axelar-chains-config/info/local.json

# Create .env file with default hardhat private key that's prefunded
- name: Prepare .env
run: |
echo "PRIVATE_KEY=$SUI_PRIVATE_KEY" >> .env
echo 'ENV=local' >> .env
echo 'SKIP_EXISTING = true' >> .env

- name: Display local.json
run: cat ./axelar-chains-config/info/local.json

- name: Request SUI from faucet
run: node sui/faucet.js

###### Command: Deploy Contract ######

- name: Deploy AxelarGateway
run: node sui/deploy-contract deploy AxelarGateway --signers wallet

- name: Deploy GasService
run: node sui/deploy-contract deploy GasService

- name: Deploy Operators
run: node sui/deploy-contract deploy Operators

- name: Deploy Example
run: node sui/deploy-contract deploy Example

###### Command: Gas Service ######

- name: Pay Gas
run: node sui/gas-service.js payGas --amount 100 ethereum 0x6f24A47Fc8AE5441Eb47EFfC3665e70e69Ac3F05 0xba76c6980428A0b10CFC5d8ccb61949677A61233 0x1234

- name: Refund Gas
run: node sui/gas-service.js refund 0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-2 --amount 1

- name: Collect Gas
run: node sui/gas-service.js collectGas --amount 0.1

###### Command: Gateway ######
- name: Gateway Approve
run: node sui/gateway.js approve --proof wallet ethereum 0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-2 0x4F4495243837681061C4743b74B3eEdf548D56A5 0x6ce0d81b412abca2770eddb1549c9fcff721889c3aab1203dc93866db22ecc4b 0x56570de287d73cd1cb6092bb8fdee6173974955fdef345ae579ee9f475ea7432

- name: Gateway Call Contract
run: node sui/gateway.js call-contract ethereum 0x4F4495243837681061C4743b74B3eEdf548D56A5 0x1234

- name: Gateway Rotate Signers
run: node sui/gateway.js rotate --signers wallet --proof wallet --newNonce test2

###### Command: GMP ######

- name: Execute Outgoing Call Contract
run: node sui/gmp.js sendCall ethereum 0x6f24A47Fc8AE5441Eb47EFfC3665e70e69Ac3F05 0.1 0x1234

- name: Execute Incoming Call Contract
run: |
channel_id=$(cat axelar-chains-config/info/local.json | jq '.sui.contracts.Example.objects.ChannelId' | sed 's/"//g')
echo "Channel ID: $channel_id"
node sui/gateway.js approve --proof wallet ethereum 0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-3 0x4F4495243837681061C4743b74B3eEdf548D56A5 $channel_id 0x56570de287d73cd1cb6092bb8fdee6173974955fdef345ae579ee9f475ea7432
node sui/gmp.js execute ethereum 0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-3 0x4F4495243837681061C4743b74B3eEdf548D56A5 0x1234

###### Command: Operators ######

- name: Store Capability Object in Operators
run: node sui/operators.js storeCap

- name: Add Operator
run: node sui/operators.js add $SUI_ADDRESS

- name: Collect Gas with Operator
run: node sui/operators.js collectGas --amount 1

- name: Refund Gas with Operator
run: node sui/operators.js refund 0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-2 --amount 1

- name: Remove Operator
run: node sui/operators.js remove $SUI_ADDRESS

###### Command: Generate Keypair ######
- name: Generate Keypair
run: node sui/generate-keypair.js

###### Command: Multisig ######

# TODO: Add multisig tests

blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved
###### Command: Transfer Object ######
- name: Transfer Object
run: |
object_id=$(sui client objects --json | jq -r '.[-1].data.objectId')
node sui/transfer-object.js --objectId $object_id --recipient 0xdd7c964ff032273889eb6029a29314413b461629c45c0442c6f9cf8342450c12
17 changes: 4 additions & 13 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"lint": "eslint --fix '**/*.js'",
"prettier": "prettier --write '**/*.js' 'axelar-chains-config/info/*.json' 'package.json' 'evm/**/*.json' '.github/**/*.yaml'"
"prettier": "prettier --write '**/*.js' 'axelar-chains-config/info/*.json' 'package.json' 'evm/**/*.json' '.github/**/*.yaml'",
"test:sui": "mocha sui"
},
"repository": {
"type": "git",
Expand All @@ -23,7 +24,7 @@
"homepage": "https://github.com/axelarnetwork/axelar-contract-deployments#readme",
"dependencies": {
"@axelar-network/axelar-cgp-solidity": "6.3.1",
"@axelar-network/axelar-cgp-sui": "0.0.0-snapshot.218635e",
"@axelar-network/axelar-cgp-sui": "^0.4.1",
"@axelar-network/axelar-gmp-sdk-solidity": "5.10.0",
"@axelar-network/interchain-token-service": "1.2.4",
"@cosmjs/cosmwasm-stargate": "^0.32.1",
Expand Down
2 changes: 1 addition & 1 deletion sui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ node sui/deploy-contract.js deploy GasService
Deploy the test GMP package:

```bash
node sui/deploy-contract.js deploy Test
node sui/deploy-contract.js deploy Example
```

Deploy the Operators package:
Expand Down
20 changes: 12 additions & 8 deletions sui/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
getSingletonChannelId,
getItsChannelId,
getSquidChannelId,
checkSuiVersionMatch,
} = require('./utils');

/**
Expand All @@ -42,7 +43,7 @@ const {
* 2. Ensure the corresponding folder exists in the specified path
*
*/
const PACKAGE_DIRS = ['gas_service', 'test', 'axelar_gateway', 'operators', 'abi', 'governance', 'its', 'squid'];
const PACKAGE_DIRS = ['gas_service', 'example', 'axelar_gateway', 'operators', 'abi', 'governance', 'its', 'squid'];

/**
* Package Mapping Object for Command Options and Post-Deployment Functions
Expand All @@ -51,7 +52,7 @@ const PACKAGE_CONFIGS = {
cmdOptions: {
AxelarGateway: () => GATEWAY_CMD_OPTIONS,
GasService: () => [],
Test: () => [],
Example: () => [],
Operators: () => [],
Abi: () => [],
Governance: () => [],
Expand All @@ -61,7 +62,7 @@ const PACKAGE_CONFIGS = {
postDeployFunctions: {
AxelarGateway: postDeployAxelarGateway,
GasService: postDeployGasService,
Test: postDeployTest,
Example: postDeployExample,
Operators: postDeployOperators,
Abi: {},
Governance: {},
Expand Down Expand Up @@ -105,16 +106,16 @@ async function postDeployGasService(published, keypair, client, config, chain, o
};
}

async function postDeployTest(published, keypair, client, config, chain, options) {
async function postDeployExample(published, keypair, client, config, chain, options) {
const relayerDiscovery = config.sui.contracts.AxelarGateway?.objects?.RelayerDiscovery;

const [singletonObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [`${published.packageId}::test::Singleton`]);
const [singletonObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [`${published.packageId}::gmp::Singleton`]);
const channelId = await getSingletonChannelId(client, singletonObjectId);
chain.contracts.Test.objects = { Singleton: singletonObjectId, ChannelId: channelId };
chain.contracts.Example.objects = { Singleton: singletonObjectId, ChannelId: channelId };

const tx = new Transaction();
tx.moveCall({
target: `${published.packageId}::test::register_transaction`,
target: `${published.packageId}::gmp::register_transaction`,
arguments: [tx.object(relayerDiscovery), tx.object(singletonObjectId)],
});

Expand Down Expand Up @@ -195,7 +196,7 @@ async function postDeployAxelarGateway(published, keypair, client, config, chain

// Update chain configuration
chain.contracts.AxelarGateway = {
address: packageId,
...chain.contracts.AxelarGateway,
objects: {
Gateway: gateway,
RelayerDiscovery: relayerDiscovery,
Expand Down Expand Up @@ -246,6 +247,9 @@ async function postDeploySquid(published, keypair, client, config, chain, option
async function deploy(keypair, client, supportedContract, config, chain, options) {
const { packageDir, packageName } = supportedContract;

// Print warning if version mismatch from defined version in version.json
checkSuiVersionMatch();

// Deploy package
const published = await deployPackage(packageDir, client, keypair, options);

Expand Down
1 change: 0 additions & 1 deletion sui/docs/gmp.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ This command will execute the message to the contract that associated with the g
node sui/gmp.js execute ethereum 0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-2 0x4F4495243837681061C4743b74B3eEdf548D56A5 0x1234 --channelId 0xcd5d203ea2cf1139af83939e3f74114a31fe682cc90f73a0d2647956bc3e5acf
```


Note:
- `source`, `sourceAddress` and `messageId` needed to be matched with the approve command.
- `payload` must be associated with the `payloadHash` in the approve command.
Loading
Loading