Skip to content

Commit

Permalink
fix: update ts version; besu-cli sdk imports; added packages test for…
Browse files Browse the repository at this point in the history
… besu asset exchange in workflow

Signed-off-by: Sandeep Nishad <sandeepn.official@gmail.com>
  • Loading branch information
sandeepnRES committed Feb 8, 2023
1 parent 122c203 commit ca494b5
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 43 deletions.
206 changes: 190 additions & 16 deletions .github/workflows/test_asset-exchange-besu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,13 @@ jobs:
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
# 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
Expand All @@ -83,16 +69,23 @@ jobs:
working-directory: 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: samples/besu/besu-cli

- name: Setup BESU CLI init
run: |
make build-local
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: samples/besu/besu-cli
working-directory: samples/besu/besu-cli

- name: Asset Exchange Besu CLI Tests
run: |
Expand Down Expand Up @@ -196,4 +189,185 @@ jobs:
exit 1
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"]

# 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

# 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

# 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

- 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: samples/besu/besu-cli

1 change: 1 addition & 0 deletions samples/besu/besu-cli/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.npmrc
package-lock.json
config.json
node_modules
2 changes: 2 additions & 0 deletions samples/besu/besu-cli/.npmrc.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@hyperledger-labs:registry=https://npm.pkg.github.com/hyperledger-labs
//npm.pkg.github.com/:_authToken=<personal-access-token>
11 changes: 5 additions & 6 deletions samples/besu/besu-cli/package-local.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,19 @@
"@hyperledger-labs/weaver-protos-js": "file:../../../common/protos-js",
"@truffle/contract": "^4.2.14",
"gluegun": "latest",
"winston": "^3.3.3",
"logform": "~2.4.2"
"winston": "^3.3.3"
},
"devDependencies": {
"@types/jest": "^24.0.18",
"@types/node": "^12.7.11",
"jest": "^24.1.0",
"jest": "^29.4.2",
"prettier": "^1.12.1",
"ts-jest": "^24.1.0",
"ts-node": "^8.4.1",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0",
"tslint-config-standard": "^8.0.1",
"typescript": "^3.6.3"
"typescript": "^4.9.5"
},
"jest": {
"preset": "ts-jest",
Expand Down
11 changes: 5 additions & 6 deletions samples/besu/besu-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,19 @@
"@hyperledger-labs/weaver-protos-js": "~1.5.0",
"@truffle/contract": "^4.2.14",
"gluegun": "latest",
"winston": "^3.3.3",
"logform": "~2.4.2"
"winston": "^3.3.3"
},
"devDependencies": {
"@types/jest": "^24.0.18",
"@types/node": "^12.7.11",
"jest": "^24.1.0",
"jest": "^29.4.2",
"prettier": "^1.12.1",
"ts-jest": "^24.1.0",
"ts-node": "^8.4.1",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0",
"tslint-config-standard": "^8.0.1",
"typescript": "^3.6.3"
"typescript": "^4.9.5"
},
"jest": {
"preset": "ts-jest",
Expand Down
8 changes: 4 additions & 4 deletions samples/besu/besu-cli/src/commands/asset/claim.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GluegunCommand } from 'gluegun'
import { getNetworkConfig, commandHelp } from '../../helper/helper'
import { getContractInstance } from '../../helper/besu-functions'
import * as assetManager from '@hyperledger-labs/weaver-besu-interop-sdk/src/AssetManager'
import { SHA256 } from "@hyperledger-labs/weaver-besu-interop-sdk/src/HashFunctions";
import { AssetManager } from '@hyperledger-labs/weaver-besu-interop-sdk'
import { HashFunctions } from "@hyperledger-labs/weaver-besu-interop-sdk";

const Web3 = require('web3')

Expand Down Expand Up @@ -157,9 +157,9 @@ const command: GluegunCommand = {
} before claiming: ${recipientBalance.toString()}`
)

const hash = new SHA256()
const hash = new HashFunctions.SHA256()
hash.setPreimage(options.preimage)
await assetManager
await AssetManager
.claimAssetInHTLC(
interopContract,
lockContractId,
Expand Down
4 changes: 2 additions & 2 deletions samples/besu/besu-cli/src/commands/asset/is-locked.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GluegunCommand } from 'gluegun'
import { getNetworkConfig, commandHelp } from '../../helper/helper'
import { getContractInstance } from '../../helper/besu-functions'
import * as assetManager from '@hyperledger-labs/weaver-besu-interop-sdk/src/AssetManager'
import { AssetManager } from '@hyperledger-labs/weaver-besu-interop-sdk'
const Web3 = require('web3')

const command: GluegunCommand = {
Expand Down Expand Up @@ -81,7 +81,7 @@ const command: GluegunCommand = {
// const accounts = await web3N.eth.getAccounts()
// var sender = accounts[networkConfig.senderAccountIndex]

var isLocked = await assetManager
var isLocked = await AssetManager
.isAssetLockedInHTLC(interopContract, lockContractId)
.catch(function() {
console.log('isAssetLocked threw an error')
Expand Down
12 changes: 6 additions & 6 deletions samples/besu/besu-cli/src/commands/asset/lock.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GluegunCommand } from 'gluegun'
import { getNetworkConfig, commandHelp } from '../../helper/helper'
import { getContractInstance } from '../../helper/besu-functions'
import * as assetManager from '@hyperledger-labs/weaver-besu-interop-sdk/src/AssetManager'
import { SHA256 } from '@hyperledger-labs/weaver-besu-interop-sdk/src/HashFunctions'
import { AssetManager } from '@hyperledger-labs/weaver-besu-interop-sdk'
import { HashFunctions } from "@hyperledger-labs/weaver-besu-interop-sdk";

const Web3 = require('web3')
const crypto = require('crypto')
Expand Down Expand Up @@ -210,7 +210,7 @@ const command: GluegunCommand = {
console.log('Hash (base64): ', hash_base64)
console.log('Preimage: ', preimage)

const hash = new SHA256();
const hash = new HashFunctions.SHA256();
hash.setSerializedHashBase64(hash_base64)

// Balances of sender and receiver before locking
Expand Down Expand Up @@ -242,7 +242,7 @@ const command: GluegunCommand = {
await tokenContract
.approve(tokenContract.address, options.token_id, { from: sender })
try {
lockTx = await assetManager.createHTLC(
lockTx = await AssetManager.createHTLC(
interopContract,
tokenContract,
options.asset_type,
Expand All @@ -261,7 +261,7 @@ const command: GluegunCommand = {
await tokenContract
.setApprovalForAll(tokenContract.address, true, { from: sender })
try {
lockTx = await assetManager.createHybridHTLC(
lockTx = await AssetManager.createHybridHTLC(
interopContract,
tokenContract,
options.asset_type,
Expand All @@ -282,7 +282,7 @@ const command: GluegunCommand = {
await tokenContract
.approve(tokenContract.address, amount, { from: sender })
try {
lockTx = await assetManager.createFungibleHTLC(
lockTx = await AssetManager.createFungibleHTLC(
interopContract,
tokenContract,
options.asset_type,
Expand Down
Loading

0 comments on commit ca494b5

Please sign in to comment.