-
Notifications
You must be signed in to change notification settings - Fork 19
278 lines (252 loc) · 9.74 KB
/
reusable-integration-test-v1.yml
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
name: Integration Test v1
on:
push:
workflow_call:
inputs:
# If `extra_github_env` is set, it will be put into GITHUB_ENV at the beginning of each job
#
# ```
# - name: Update GITHUB_ENV if inputs.extra_github_env set
# if: "${{ inputs.extra_github_env != '' }}"
# run: echo ${{ inputs.extra_github_env }} >> $GITHUB_ENV
# ```
#
# ## Examples
#
# * Specify the kicker version
#
# ```yaml
# extra_github_env: |
# GODWOKEN_TESTS_REPO=keroro520/godwoken-tests # default is godwokenrises/godwoken-tests
# GODWOKEN_TESTS_REF=helloworld # default is develop
# GODWOKEN_KICKER_REPO=godwokenrises/godwoken-kicker # default is godwokenrises/godwoken-kicker
# GODWOKEN_KICKER_REF=develop # default is develop
#
# GODWOKEN_PREBUILD_IMAGE_NAME=ghcr.io/keroro520/godwoken-prebuilds:v1-godwoken-d3eb41a-202205310512 # (deprecated)
# GODWOKEN_IMAGE=ghcr.io/godwokenrises/godwoken:develop
#
# # DEBUG_MODE: if we need more debug logs, we could enable log levels per Godwoken module
# # See https://rust-lang-nursery.github.io/rust-cookbook/development_tools/debugging/config_log.html#enable-log-levels-per-module
# RUST_LOG=info,ckb_script::verify=debug ...
# ```
extra_github_env:
type: string
description: 'Append write into GITHUB_ENV at the begining of every job'
required: false
jobs:
# Run integration-tests on devnet_v1 deployed by Godowoken-Kicker
test-on-devnet-v1:
runs-on: ubuntu-latest
steps:
- name: Update GITHUB_ENV if inputs.extra_github_env set
if: "${{ inputs.extra_github_env != '' }}"
run: |
echo "${{ inputs.extra_github_env }}" >> $GITHUB_ENV
- name: Checkout godwoken-tests
uses: actions/checkout@v4
with:
repository: ${{ env.GODWOKEN_TESTS_REPO || 'godwokenrises/godwoken-tests' }}
ref: ${{ env.GODWOKEN_TESTS_REF || 'develop' }}
submodules: 'recursive'
- name: Checkout godwoken-kicker
uses: actions/checkout@v4
with:
repository: ${{ env.GODWOKEN_KICKER_REPO || 'godwokenrises/godwoken-kicker' }}
ref: ${{ env.GODWOKEN_KICKER_REF || 'develop' }}
path: kicker
submodules: 'recursive'
- name: Rust Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry
~/.cargo/git
target
kicker/cache/build
key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
- name: Install moleculec
run: |
test "$(moleculec --version)" = "Moleculec 0.7.2" \
|| CARGO_TARGET_DIR=target/ cargo install moleculec --version 0.7.2 --force
- name: Install Capsule
env:
CAPSULE_VERSION: v0.7.3
run: |
capsule -V \
|| (curl -OL https://github.com/nervosnetwork/capsule/releases/download/${CAPSULE_VERSION}/capsule_${CAPSULE_VERSION}_x86_64-linux.tar.gz \
&& tar xf capsule_${CAPSULE_VERSION}_x86_64-linux.tar.gz \
&& mv capsule_${CAPSULE_VERSION}_x86_64-linux/capsule ~/.cargo/bin/)
- name: Modify Godwoken image if GODWOKEN_IMAGE is set
if: ${{ env.GODWOKEN_IMAGE }}
uses: mikefarah/yq@v4
with:
cmd: |
echo "Update the image of Godwoken fullnode"
yq -i '.services.godwoken.image = "${{ env.GODWOKEN_IMAGE }}"' kicker/docker/docker-compose.yml
echo "Update the image of Godwoken readonly-node"
yq -i '.services.godwoken-readonly.image = "${{ env.GODWOKEN_IMAGE }}"' kicker/docker/docker-compose.yml
echo "====== kicker/docker/docker-compose.yml ======"
cat kicker/docker/docker-compose.yml
# set up buildx/BuildKit runner in the context,
# make the Docker cache exportable and thus properly cacheable
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Ensure clean state
- name: Run Godwoken-Kicker clean
working-directory: kicker
run: |
./kicker clean
- name: Init Godwoken-Kicker services
working-directory: kicker
run: |
docker system df -v
docker-compose --version
./kicker init
- name: Start Godwoken-Kicker services
timeout-minutes: 45
working-directory: kicker
env:
START_GODWOKEN_V0: true
run: |
# Temporary workaround unreliable web3 health check
(echo " == kicker start attempt: 1 == " && ./kicker start) || \
(echo " == kicker start attempt: 2 == " && ./kicker stop && ./kicker start) || \
(echo " == kicker start failed == " && exit 1)
./kicker logs --tail 6
# - name: Enable offchain validator of Godwoken
# working-directory: kicker
# if: ${{ false }}
# run: |
# sudo chown -R `whoami` workspace/config.toml
# grep -q "\[offchain_validator\]" workspace/config.toml \
# || cat >> workspace/config.toml << __EOF__
# [offchain_validator]
# verify_withdrawal_signature = true
# verify_tx_signature = true
# verify_tx_execution = true
# verify_max_cycles = 140000000
# dump_tx_on_failure = true
# __EOF__
# docker restart docker_godwoken_1
# docker-compose --file docker/docker-compose.yml logs --tail 6
- uses: actions/setup-node@v4
with:
node-version: '18'
- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: |
npm --version
echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- name: Get yarn cache directory
id: yarn-cache-dir
run: |
yarn --version
echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- name: Node Cache
uses: actions/cache@v3
id: npm-and-yarn-cache
with:
path: |
${{ steps.npm-cache-dir.outputs.dir }}
${{ steps.yarn-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('contracts/package-lock.json', 'light-godwoken/yarn.lock', 'scripts/light-godwoken-cli/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Setup Light-Godwoken-CLI
working-directory: scripts/light-godwoken-cli
run: ./init.sh
- name: Deposit for 2 dev accounts
working-directory: kicker
run: |
# Deposit for the test accounts defined in `contracts/hardhat.config.js`.
# The corresponding private keys are
# 1390c30e5d5867ee7246619173b5922d3b04009cab9e9d91e14506231281a997
# 2dc6374a2238e414e51874f514b0fa871f8ce0eb1e7ecaa0aed229312ffc91b0
./kicker deposit 0x966B30e576A4d6731996748B48Dd67C94eF29067 10000
./kicker deposit 0x4fef21f1d42e0d23d72100aefe84d555781c31bb 10000
- name: init tools
working-directory: tools
run: |
yarn install && yarn build-all
- name: Wait 1 layer2 blocks passed
uses: actions/github-script@v7
with:
script: |
const { waitXl2BlocksPassed } = require("./scripts/helper");
await waitXl2BlocksPassed(1);
- name: Withdraw for 2 dev accounts
working-directory: scripts/light-godwoken-cli
run: |
lgc withdraw -p 1390c30e5d5867ee7246619173b5922d3b04009cab9e9d91e14506231281a997 -c 400 -n devnet_v1
lgc withdraw -p 2dc6374a2238e414e51874f514b0fa871f8ce0eb1e7ecaa0aed229312ffc91b0 -c 400 -n devnet_v1
- name: Deposit for withdraw from v0 to v1 test
working-directory: kicker
run: |
./kicker deposit 0x966B30e576A4d6731996748B48Dd67C94eF29999 1000
./kicker deposit-v0 10000 # Use ckb-miner key
- name: Wait 1 layer2 blocks passed
uses: actions/github-script@v7
with:
script: |
const { waitXl2BlocksPassed } = require("./scripts/helper");
await waitXl2BlocksPassed(1);
- name: Withdraw from v0 to v1
working-directory: kicker
run: |
./kicker withdraw-v0-to-v1 0x966B30e576A4d6731996748B48Dd67C94eF29999 1000
counter=1
while [ $counter -le 60 ]
do
balance=$(./kicker get-balance 0x966B30e576A4d6731996748B48Dd67C94eF29999 | grep -oE "Balance:\s*[[:digit:]]+" | awk '{print $2}')
echo "current balance: ==${balance}=="
# deposit 1000 + withdraw from v0 1000 (NOTE: CKB decimal is 18, aka 2000 * 10^18)
if [ "$balance" = "2000000000000000000000" ]; then
echo "withdraw from v0 to v1 success"
exit 0
fi
((counter++))
sleep 20s
done
echo "withdraw from v0 to v1 fail"
exit 1
- name: Wait 1 layer2 blocks passed
uses: actions/github-script@v7
with:
script: |
const { waitXl2BlocksPassed } = require("./scripts/helper");
await waitXl2BlocksPassed(1);
- name: Run hardhat test --network gw_devnet_v1
working-directory: contracts
run: npm install && npm run test
# Only enable tmate while debugging
# - name: Setup tmate session
# if: ${{ failure() }}
# uses: mxschmitt/action-tmate@v3
# timeout-minutes: 30
- name: Save logs
if: always()
working-directory: kicker
run: |
./kicker ps
./kicker logs --tail 66
./kicker logs > /tmp/kicker.log
- name: Archive logs
if: always()
uses: actions/upload-artifact@v4
with:
name: kicker-logs
path: |
/tmp/kicker.log
- name: Archive the dumped transactions in kicker/workspace/debug-tx-dump
if: always()
uses: actions/upload-artifact@v4
with:
name: debug-tx-dump
path: |
kicker/workspace/debug-tx-dump
- name: Stop containers of Kicker
if: always()
working-directory: kicker
run: ./kicker stop