forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
415 lines (354 loc) · 18.6 KB
/
test_weaver-asset-exchange-besu.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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# This is a basic workflow to help you get started with Actions
name: Test Asset Exchange Besu
env:
NODEJS_VERSION: v18.18.2
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
check_code_changed:
outputs:
status: ${{ steps.changes.outputs.weaver_code_changed }}
runs-on: ubuntu-22.04
steps:
- uses: actions/[email protected]
- uses: dorny/[email protected]
id: changes
with:
filters: |
weaver_code_changed:
- './weaver/**'
- '.github/workflows/test_weaver-asset-exchange-besu.yaml'
asset-exchange-besu:
needs: check_code_changed
if: ${{ false }}
# The type of runner that the job will run on
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
app_contract: ["AliceERC1155", "AliceERC20", "AliceERC721"]
exclude:
- app_contract: ${{ needs.check_code_changed.outputs.status != 'true' }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/[email protected]
- name: Set up JDK 11
uses: actions/[email protected]
with:
java-version: '11'
distribution: 'adopt'
- name: Use Node.js ${{ env.NODEJS_VERSION }}
uses: actions/[email protected]
with:
node-version: ${{ env.NODEJS_VERSION }}
- name: Use Protoc 3.15
run: |
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v3.15.6/protoc-3.15.6-linux-x86_64.zip
unzip protoc-3.15.6-linux-x86_64.zip -d protoc
# PROTOS
- name: Build Solidity Protos
run: |
export PATH="$PATH:${GITHUB_WORKSPACE}/protoc/bin"
make build
working-directory: weaver/common/protos-sol
# BESU NETWORK
- name: Start Besu Network
run: |
sudo apt install -y tmux jq
wget https://hyperledger.jfrog.io/artifactory/besu-binaries/besu/22.7.0/besu-22.7.0.zip
unzip besu-22.7.0.zip
export PATH="${PWD}/besu-22.7.0/bin:$PATH"
wget https://artifacts.consensys.net/public/ethsigner/raw/names/ethsigner.zip/versions/22.1.3/ethsigner-22.1.3.zip
unzip ethsigner-22.1.3.zip
export PATH="${PWD}/ethsigner-22.1.3/bin:$PATH"
make start
sleep 100
working-directory: weaver/tests/network-setups/besu
# Deploy contracts
- name: Deploy contracts
run: |
make deploy-contracts
working-directory: weaver/samples/besu/simpleasset
# BESU CLI
- name: Setup BESU CLI .npmrc
run: |
cp .npmrc.template .npmrc
sed -i "s/<personal-access-token>/${{ secrets.GITHUB_TOKEN }}/g" .npmrc
cat .npmrc
working-directory: weaver/samples/besu/besu-cli
- name: Setup BESU CLI init
run: |
make build
cp config.template.json tmp.json
cp config.template.json tmp.json
jq -r '.network1.tokenContract |= "../simpleasset/build/contracts/${{ matrix.app_contract }}.json"' tmp.json > config.json
cp config.json tmp.json
jq -r '.network2.tokenContract |= "../simpleasset/build/contracts/BobERC20.json"' tmp.json > config.json
rm tmp.json
working-directory: weaver/samples/besu/besu-cli
- name: Asset Exchange Besu CLI Tests
run: |
export PATH="${PWD}/bin:$PATH"
COUNT=0
TOTAL=10
# HTLC Params
timeout=1000
hashBase64="ivHErp1x4bJDKuRo6L5bApO/DdoyD/dG0mAZrzLZEIs="
preimage="secrettext"
# issue tokens to account 1
initAmount=10
transferAmount=5
tokenId=0
# & lock 5 token for account 2 in network 1
if [ ${{ matrix.app_contract }} == "AliceERC20" ]; then
besu-cli asset issue --network=network1 --account=1 --amount=${initAmount} --asset_type=ERC20
besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --amount=${transferAmount} --timeout=${timeout} --hash_base64=${hashBase64} 1> tmp.out
elif [ ${{ matrix.app_contract }} == "AliceERC1155" ]; then
besu-cli asset issue --network=network1 --account=1 --amount=${initAmount} --token_id=${tokenId} --token_data="" --asset_type=ERC1155
besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --amount=${transferAmount} --token_id=${tokenId} --timeout=${timeout} --asset_type=ERC1155 --hash_base64=${hashBase64} 1> tmp.out
else
initAmount=1
transferAmount=1
besu-cli asset issue --network=network1 --account=1 --token_id=${tokenId} --asset_type=ERC721 1> tmp.out
tokenId=$(cat tmp.out | grep "New ERC721 token minted with id " | sed -e 's/New ERC721 token minted with id //')
cat tmp.out
echo $tokenId
besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --token_id=${tokenId} --asset_type=ERC721 --timeout=${timeout} --hash_base64=${hashBase64} 1> tmp.out
fi
balanceRem=$((initAmount-transferAmount))
cat tmp.out | grep "Account balance of the sender in Network network1: ${initAmount} " && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out | grep "Account balance of the sender in Network network1: ${balanceRem}" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out | grep "Account balance of the recipient in Network network1: 0" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out
tmp_string=$(cat tmp.out | grep "Lock contract ID:")
arrIN=(${tmp_string//:/ })
LOCK_ID=${arrIN[3]}
# Is Asset locked
besu-cli asset is-locked --network=network1 --lock_contract_id=$LOCK_ID 1> tmp.out
cat tmp.out | grep "in Network network1: true" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out
# Claim asset
besu-cli asset claim --network=network1 --recipient_account=2 --preimage=${preimage} --token_id=${tokenId} --lock_contract_id=$LOCK_ID 1> tmp.out
cat tmp.out | grep "Account balance of the recipient in Network network1 before claiming: 0" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out | grep "Account balance of the recipient in Network network1 after claiming: ${transferAmount}" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out
###### test unlock #######
timeout=20
initAmount=5
recipientAmt=0
transferAmount=2
tokenId=1
if [ ${{ matrix.app_contract }} == "AliceERC20" ]; then
recipientAmt=5
besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --amount=${transferAmount} --timeout=${timeout} --hash_base64=${hashBase64} 1> tmp.out
elif [ ${{ matrix.app_contract }} == "AliceERC1155" ]; then
besu-cli asset issue --network=network1 --account=1 --amount=${initAmount} --token_id=${tokenId} --token_data="" --asset_type=ERC1155
besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --amount=${transferAmount} --token_id=${tokenId} --timeout=${timeout} --asset_type=ERC1155 --hash_base64=${hashBase64} 1> tmp.out
else
initAmount=1
transferAmount=1
recipientAmt=1
besu-cli asset issue --network=network1 --account=1 --token_id=${tokenId} --asset_type=ERC721 1> tmp.out
tokenId=$(cat tmp.out | grep "New ERC721 token minted with id " | sed -e 's/New ERC721 token minted with id //')
cat tmp.out
echo $tokenId
besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --token_id=${tokenId} --asset_type=ERC721 --timeout=${timeout} --hash_base64=${hashBase64} 1> tmp.out
fi
balanceRem=$((initAmount-transferAmount))
cat tmp.out | grep "Account balance of the sender in Network network1: ${initAmount}" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out | grep "Account balance of the sender in Network network1: ${balanceRem}" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out | grep "Account balance of the recipient in Network network1: ${recipientAmt}" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out
tmp_string=$(cat tmp.out | grep "Lock contract ID:")
arrIN=(${tmp_string//:/ })
LOCK_ID=${arrIN[3]}
sleep $timeout
besu-cli asset unlock --network=network1 --lock_contract_id=$LOCK_ID --sender_account=1 --token_id=${tokenId} 1> tmp.out
cat tmp.out | grep "before unlocking: ${balanceRem}" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out | grep "after unlocking: ${initAmount}" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out
# RESULT
echo "Passed $COUNT/$TOTAL Tests."
if [ $COUNT == $TOTAL ]; then
exit 0
else
exit 1
fi
working-directory: weaver/samples/besu/besu-cli
asset-exchange-besu-local:
needs: check_code_changed
# The type of runner that the job will run on
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
app_contract: ["AliceERC1155", "AliceERC20", "AliceERC721"]
exclude:
- app_contract: ${{ needs.check_code_changed.outputs.status != 'true' }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Print needs.check_code_changed.outputs.status
run: echo needs.check_code_changed.outputs.status => ${{ needs.check_code_changed.outputs.status }}
- name: Print needs.check_code_changed.outputs.status != true
run: echo needs.check_code_changed.outputs.status != true => ${{ needs.check_code_changed.outputs.status != 'true' }}
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/[email protected]
- name: Set up JDK 11
uses: actions/[email protected]
with:
java-version: '11'
distribution: 'adopt'
- name: Use Node.js ${{ env.NODEJS_VERSION }}
uses: actions/[email protected]
with:
node-version: ${{ env.NODEJS_VERSION }}
- name: Use Protoc 3.15
run: |
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v3.15.6/protoc-3.15.6-linux-x86_64.zip
unzip protoc-3.15.6-linux-x86_64.zip -d protoc
# PROTOS
- name: Build JS Protos
run: |
export PATH="$PATH:${GITHUB_WORKSPACE}/protoc/bin"
make build
working-directory: weaver/common/protos-js
# PROTOS
- name: Build Solidity Protos
run: |
export PATH="$PATH:${GITHUB_WORKSPACE}/protoc/bin"
make build
working-directory: weaver/common/protos-sol
# BESU SDK
- name: Setup BESU SDK
run: make build-local
working-directory: weaver/sdks/besu/node
# BESU NETWORK
- name: Start Besu Network
run: |
sudo apt install -y tmux jq
wget https://hyperledger.jfrog.io/artifactory/besu-binaries/besu/22.7.0/besu-22.7.0.zip
unzip besu-22.7.0.zip
export PATH="${PWD}/besu-22.7.0/bin:$PATH"
wget https://artifacts.consensys.net/public/ethsigner/raw/names/ethsigner.zip/versions/22.1.3/ethsigner-22.1.3.zip
unzip ethsigner-22.1.3.zip
export PATH="${PWD}/ethsigner-22.1.3/bin:$PATH"
make start
sleep 100
working-directory: weaver/tests/network-setups/besu
# Deploy contracts
- name: Deploy contracts
run: |
make deploy-contracts
working-directory: weaver/samples/besu/simpleasset
# BESU CLI
- name: Setup BESU CLI init
run: |
make build-local
cp config.template.json tmp.json
cp config.template.json tmp.json
jq -r '.network1.tokenContract |= "../simpleasset/build/contracts/${{ matrix.app_contract }}.json"' tmp.json > config.json
cp config.json tmp.json
jq -r '.network2.tokenContract |= "../simpleasset/build/contracts/BobERC20.json"' tmp.json > config.json
rm tmp.json
working-directory: weaver/samples/besu/besu-cli
- name: Asset Exchange Besu CLI Tests
run: |
export PATH="${PWD}/bin:$PATH"
COUNT=0
TOTAL=10
# HTLC Params
timeout=1000
hashBase64="ivHErp1x4bJDKuRo6L5bApO/DdoyD/dG0mAZrzLZEIs="
preimage="secrettext"
# issue tokens to account 1
initAmount=10
transferAmount=5
tokenId=0
# & lock 5 token for account 2 in network 1
if [ ${{ matrix.app_contract }} == "AliceERC20" ]; then
besu-cli asset issue --network=network1 --account=1 --amount=${initAmount} --asset_type=ERC20
besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --amount=${transferAmount} --timeout=${timeout} --hash_base64=${hashBase64} 1> tmp.out
elif [ ${{ matrix.app_contract }} == "AliceERC1155" ]; then
besu-cli asset issue --network=network1 --account=1 --amount=${initAmount} --token_id=${tokenId} --token_data="" --asset_type=ERC1155
besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --amount=${transferAmount} --token_id=${tokenId} --timeout=${timeout} --asset_type=ERC1155 --hash_base64=${hashBase64} 1> tmp.out
else
initAmount=1
transferAmount=1
besu-cli asset issue --network=network1 --account=1 --token_id=${tokenId} --asset_type=ERC721 1> tmp.out
tokenId=$(cat tmp.out | grep "New ERC721 token minted with id " | sed -e 's/New ERC721 token minted with id //')
cat tmp.out
echo $tokenId
besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --token_id=${tokenId} --asset_type=ERC721 --timeout=${timeout} --hash_base64=${hashBase64} 1> tmp.out
fi
balanceRem=$((initAmount-transferAmount))
cat tmp.out | grep "Account balance of the sender in Network network1: ${initAmount} " && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out | grep "Account balance of the sender in Network network1: ${balanceRem}" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out | grep "Account balance of the recipient in Network network1: 0" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out
tmp_string=$(cat tmp.out | grep "Lock contract ID:")
arrIN=(${tmp_string//:/ })
LOCK_ID=${arrIN[3]}
# Is Asset locked
besu-cli asset is-locked --network=network1 --lock_contract_id=$LOCK_ID 1> tmp.out
cat tmp.out | grep "in Network network1: true" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out
# Claim asset
besu-cli asset claim --network=network1 --recipient_account=2 --preimage=${preimage} --token_id=${tokenId} --lock_contract_id=$LOCK_ID 1> tmp.out
cat tmp.out | grep "Account balance of the recipient in Network network1 before claiming: 0" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out | grep "Account balance of the recipient in Network network1 after claiming: ${transferAmount}" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out
###### test unlock #######
timeout=20
initAmount=5
recipientAmt=0
transferAmount=2
tokenId=1
if [ ${{ matrix.app_contract }} == "AliceERC20" ]; then
recipientAmt=5
besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --amount=${transferAmount} --timeout=${timeout} --hash_base64=${hashBase64} 1> tmp.out
elif [ ${{ matrix.app_contract }} == "AliceERC1155" ]; then
besu-cli asset issue --network=network1 --account=1 --amount=${initAmount} --token_id=${tokenId} --token_data="" --asset_type=ERC1155
besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --amount=${transferAmount} --token_id=${tokenId} --timeout=${timeout} --asset_type=ERC1155 --hash_base64=${hashBase64} 1> tmp.out
else
initAmount=1
transferAmount=1
recipientAmt=1
besu-cli asset issue --network=network1 --account=1 --token_id=${tokenId} --asset_type=ERC721 1> tmp.out
tokenId=$(cat tmp.out | grep "New ERC721 token minted with id " | sed -e 's/New ERC721 token minted with id //')
cat tmp.out
echo $tokenId
besu-cli asset lock --network=network1 --sender_account=1 --recipient_account=2 --token_id=${tokenId} --asset_type=ERC721 --timeout=${timeout} --hash_base64=${hashBase64} 1> tmp.out
fi
balanceRem=$((initAmount-transferAmount))
cat tmp.out | grep "Account balance of the sender in Network network1: ${initAmount}" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out | grep "Account balance of the sender in Network network1: ${balanceRem}" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out | grep "Account balance of the recipient in Network network1: ${recipientAmt}" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out
tmp_string=$(cat tmp.out | grep "Lock contract ID:")
arrIN=(${tmp_string//:/ })
LOCK_ID=${arrIN[3]}
sleep $timeout
besu-cli asset unlock --network=network1 --lock_contract_id=$LOCK_ID --sender_account=1 --token_id=${tokenId} 1> tmp.out
cat tmp.out | grep "before unlocking: ${balanceRem}" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out | grep "after unlocking: ${initAmount}" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out
# RESULT
echo "Passed $COUNT/$TOTAL Tests."
if [ $COUNT == $TOTAL ]; then
exit 0
else
exit 1
fi
working-directory: weaver/samples/besu/besu-cli