-
Notifications
You must be signed in to change notification settings - Fork 17
321 lines (254 loc) · 14 KB
/
test-sui.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
name: Test Sui
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: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18' # Hardcoded to ensure consistency.
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
shell: bash
run: npm ci
- name: Get Sui Version
shell: bash
run: |
SUI_VERSION=$(jq -r '.SUI_VERSION' "node_modules/@axelar-network/axelar-cgp-sui/version.json")
echo "SUI_VERSION=$SUI_VERSION" >> $GITHUB_ENV
- name: Setup Sui CLI
uses: axelarnetwork/axelar-cgp-sui/.github/actions/setup-sui@main
with:
sui-version: ${{ env.SUI_VERSION }}
- 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
- name: Spin up Sui Network
# 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
with:
url: 'http://localhost:9123'
responseCode: 200
timeout: 60000
interval: 1000
- 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 '{
"chains": {
"sui": {
"name": "Sui",
"axelarId": "sui",
"networkType": "localnet",
"chainType": "sui",
"tokenSymbol": "SUI",
"rpc": "http://127.0.0.1:9000",
"faucetUrl": "http://127.0.0.1:9123",
"contracts": {
"AxelarGateway": {}
}
}
}
}' > ./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 Utils
run: node sui/deploy-contract deploy Utils
- name: Deploy VersionControl
run: node sui/deploy-contract deploy VersionControl
- name: Deploy AxelarGateway
run: node sui/deploy-contract deploy AxelarGateway --signers wallet
- name: Deploy Relayer Discovery
run: node sui/deploy-contract deploy RelayerDiscovery
- name: Deploy GasService
run: node sui/deploy-contract deploy GasService
- name: Deploy Operators
run: node sui/deploy-contract deploy Operators
- name: Deploy ABI
run: node sui/deploy-contract deploy Abi
- name: Deploy ITS
run: node sui/deploy-contract deploy ITS
- 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 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 Example ######
- 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 '.chains.sui.contracts.Example.objects.GmpChannelId' | 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: ITS Example ######
- name: Prepare ITS Example Parameters
run: |
echo "sourceChain=Ethereum" >> $GITHUB_ENV
echo "transferMessageId=0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-01" >> $GITHUB_ENV
echo "deployMessageId=0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-02" >> $GITHUB_ENV
echo "sourceAddress=0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5" >> $GITHUB_ENV
echo "amount=1" >> $GITHUB_ENV
echo "symbol=IMD" >> $GITHUB_ENV
echo "decimals=9" >> $GITHUB_ENV
echo "name=interchain-moo-deng" >> $GITHUB_ENV
echo "emptyTokenSymbol=ETY" >> $GITHUB_ENV
echo "emptyTokenName=Empty" >> $GITHUB_ENV
echo "emptyTokenDecimals=6" >> $GITHUB_ENV
config=$(cat axelar-chains-config/info/local.json)
echo "channelId=$(echo $config | jq -r '.chains.sui.contracts.ITS.objects.ChannelId')" >> $GITHUB_ENV
echo "destinationContractAddress=$(echo $config | jq -r '.chains.sui.contracts.Example.objects.ItsChannelId')" >> $GITHUB_ENV
- name: Deploy Test Tokens
run: |
node sui/its-example deploy-token --origin ${{ env.symbol }} ${{ env.name }} ${{ env.decimals }}
node sui/its-example deploy-token ${{ env.emptyTokenSymbol }} ${{ env.emptyTokenName }} ${{ env.emptyTokenDecimals }}
# Prepare additional parameters for the example:
transferInfo=$(node sui/its-example.js print-receive-transfer ${{ env.symbol }} ${{ env.sourceAddress }} ${{ env.amount }})
deploymentInfo=$(node sui/its-example.js print-receive-deployment ${{ env.emptyTokenName }} ${{ env.emptyTokenSymbol }} ${{ env.emptyTokenDecimals }})
echo "transferPayloadHash=$(echo $transferInfo | jq -r .payloadHash)" >> $GITHUB_ENV
echo "transferPayload=$(echo $transferInfo | jq -r .payload)" >> $GITHUB_ENV
echo "deployPayload=$(echo $deploymentInfo | jq -r .payload)" >> $GITHUB_ENV
echo "deployPayloadHash=$(echo $deploymentInfo | jq -r .payloadHash)" >> $GITHUB_ENV
- name: Setup Trusted Addresses
run: |
node sui/its.js setup-trusted-address $sourceChain $sourceAddress
- name: Send Token to another chain
run: |
node sui/its-example send-token $symbol $sourceChain $sourceAddress 0.1 10
- name: Receive Token from another chain
run: |
node sui/gateway.js approve --proof wallet $sourceChain $transferMessageId $sourceAddress $channelId $transferPayloadHash
node sui/its-example receive-token $sourceChain $transferMessageId $sourceAddress $symbol $transferPayload
- name: Send Token Deployment to another chain
run: |
node sui/its-example send-deployment $symbol $sourceChain 0.1 10
- name: Receive Token Deployment from another chain
run: |
node sui/gateway.js approve --proof wallet $sourceChain $deployMessageId $sourceAddress $channelId $deployPayloadHash
node sui/its-example receive-deployment $sourceChain $deployMessageId $sourceAddress $emptyTokenSymbol $deployPayload
###### 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 ######
- name: Init Multisig
run: |
# Create new addresses
sui client new-address secp256k1 multisig1
sui client new-address secp256k1 multisig2
# Export keys and addresses
KEY_1=$(sui keytool export --key-identity multisig1 --json | jq -r .key.publicBase64Key)
KEY_2=$(sui keytool export --key-identity multisig2 --json | jq -r .key.publicBase64Key)
# Get multisig address
MULTISIG_ADDRESS=$(sui keytool multi-sig-address --pks $KEY_1 $KEY_2 --weights 1 1 --threshold 1 --json | jq -r .multisigAddress)
# Initialize multisig
node sui/multisig.js init --threshold 1 --base64PublicKeys $KEY_1 $KEY_2 --schemeTypes secp256k1 secp256k1
# Faucet operations
node sui/faucet.js --recipient $MULTISIG_ADDRESS
# Set environment variables
echo "MULTISIG_ADDRESS=$MULTISIG_ADDRESS" >> $GITHUB_ENV
- name: Transfer Upgrade Cap to Multisig Address
run: |
upgrade_cap=$(cat axelar-chains-config/info/local.json | jq -r '.chains.sui.contracts.AxelarGateway.objects.UpgradeCap')
node sui/transfer-object.js --objectId $upgrade_cap --recipient $MULTISIG_ADDRESS
- name: Generate Unsigned Tx File
run: |
node sui/deploy-contract.js upgrade AxelarGateway any_upgrade --offline --txFilePath ./tx-upgrade.json --sender $MULTISIG_ADDRESS
- name: Sign Tx File with Multisig Signer
run: |
pk_1=$(sui keytool export --key-identity multisig1 --json | jq .exportedPrivateKey | sed 's/"//g')
pk_2=$(sui keytool export --key-identity multisig2 --json | jq .exportedPrivateKey | sed 's/"//g')
node sui/multisig.js sign --txBlockPath ./tx-upgrade.json --signatureFilePath signature-1.json --offline --privateKey $pk_1
node sui/multisig.js sign --txBlockPath ./tx-upgrade.json --signatureFilePath signature-2.json --offline --privateKey $pk_2
- name: Submit Signed Tx File
run: |
# Define output file for the executed transaction
output_file="./output.json"
# Execute the upgrade transaction
node sui/multisig.js combine --txBlockPath ./tx-upgrade.json --signatureFilePath ./combined.json --signatures signature-1.json signature-2.json --executeResultPath ${output_file}
# Store the new package id in a variable
new_package_id=$(jq '.objectChanges[] | select(.type == "published") | .packageId' $output_file | sed 's/"//g')
# Update the local.json file with the new package id
jq --arg pkg "$new_package_id" '.chains.sui.contracts.AxelarGateway.address = $pkg' axelar-chains-config/info/local.json > temp.json \
&& mv temp.json axelar-chains-config/info/local.json
- name: Post Upgrade Gateway Approval With New Package ID
run: node sui/gateway.js approve --proof wallet ethereum 0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-10 0x4F4495243837681061C4743b74B3eEdf548D56A5 0x6ce0d81b412abca2770eddb1549c9fcff721889c3aab1203dc93866db22ecc4b 0x56570de287d73cd1cb6092bb8fdee6173974955fdef345ae579ee9f475ea7432
###### 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