Skip to content

Commit

Permalink
fix: workflow besu asset exchange
Browse files Browse the repository at this point in the history
Signed-off-by: Sandeep Nishad <sandeepn.official@gmail.com>
  • Loading branch information
sandeepnRES committed Feb 8, 2023
1 parent ca494b5 commit 2153df8
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 169 deletions.
334 changes: 167 additions & 167 deletions .github/workflows/test_asset-exchange-besu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,184 +190,184 @@ jobs:
fi
working-directory: samples/besu/besu-cli

asset-exchange-besu-local:
# The type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
app_contract: ["AliceERC1155", "AliceERC20", "AliceERC721"]
asset-exchange-besu-local:
# The type of runner that the job will run on
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
app_contract: ["AliceERC1155", "AliceERC20", "AliceERC721"]

# 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/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
# 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/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'

- 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: common/protos-js
- 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: common/protos-sol
# PROTOS
- name: Build JS Protos
run: |
export PATH="$PATH:${GITHUB_WORKSPACE}/protoc/bin"
make build
working-directory: common/protos-js

# PROTOS
- name: Build Solidity Protos
run: |
export PATH="$PATH:${GITHUB_WORKSPACE}/protoc/bin"
make build
working-directory: common/protos-sol

# BESU SDK
- name: Setup BESU SDK
run: |
npm link
make build-local
working-directory: sdks/besu/interoperation-node-sdk

# 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: tests/network-setups/besu
# BESU SDK
- name: Setup BESU SDK
run: |
npm link
make build-local
working-directory: sdks/besu/interoperation-node-sdk

# Deploy contracts
- name: Deploy contracts
run: |
make deploy-contracts
working-directory: samples/besu/simpleasset
# 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: tests/network-setups/besu

# Deploy contracts
- name: Deploy contracts
run: |
make deploy-contracts
working-directory: 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: samples/besu/besu-cli
# 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: 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
- 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
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]}
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
# 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
###### 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
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."
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: samples/besu/besu-cli
if [ $COUNT == $TOTAL ]; then
exit 0
else
exit 1
fi
working-directory: samples/besu/besu-cli

2 changes: 1 addition & 1 deletion sdks/besu/interoperation-node-sdk/package-local.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hyperledger-labs/weaver-besu-interop-sdk",
"description": "Supplemental library for Web3JS based Besu client applications to enable interoperability using Weaver",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"main": "build/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion sdks/besu/interoperation-node-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hyperledger-labs/weaver-besu-interop-sdk",
"description": "Supplemental library for Web3JS based Besu client applications to enable interoperability using Weaver",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"main": "build/index.js",
"scripts": {
Expand Down

0 comments on commit 2153df8

Please sign in to comment.