diff --git a/demo/scenarios/macos/main.jxa b/demo/scenarios/macos/main.jxa index 7f89170..82b5129 100644 --- a/demo/scenarios/macos/main.jxa +++ b/demo/scenarios/macos/main.jxa @@ -33,6 +33,18 @@ const windows = terminal.windows() const wins = [] +function saveBlockchainData () { + console.log('Saving blockchain data') + curApp.doShellScript('zip -r ./demo/ganache_home_backup.zip ./demo/ganache_home_db') + curApp.doShellScript('zip -r ./demo/ganache_side_backup.zip ./demo/ganache_side_db') +} + +function reloadBlockchainData () { + console.log('Reloading blockchain data') + curApp.doShellScript('unzip -d . ./demo/ganache_home_backup.zip') + curApp.doShellScript('unzip -d . ./demo/ganache_side_backup.zip') +} + function closeOldWindows () { for (let i in windows) { try { @@ -80,7 +92,7 @@ function openNewWindows () { } function apiRequestBackground (url) { - const response = curApp.doShellScript(`curl -X GET "${url}"`) + const response = curApp.doShellScript(`curl -s -X GET "${url}"`) try { return JSON.parse(response) } catch (e) { @@ -94,11 +106,11 @@ function exec (n, script) { function wait (n) { while (wins[n - 1].selectedTab().busy()) { - delay(0.3) + delay(0.2) } } -function execSync(n, script) { +function execSync (n, script) { exec(n, script) wait(n) } @@ -116,7 +128,7 @@ function waitLog (n, log) { if (s) { return s } - delay(0.3) + delay(0.2) } while (true) } @@ -126,7 +138,7 @@ function waitApi (n, url, check) { const checkerRes = check ? check(res) : true if (checkerRes) return checkerRes - delay(0.3) + delay(3) } while (true) } @@ -157,12 +169,12 @@ function getBncTokenBalance (address) { } function waitBncTokenBalance (address, balance) { - do { + while (true) { const newBalance = getBncTokenBalance(address) if (Math.abs(newBalance - balance) < 0.0001) return newBalance - delay(0.3) - } while (true) + delay(3) + } } function getEthTokenBalance (address) { @@ -171,12 +183,12 @@ function getEthTokenBalance (address) { } function waitEthTokenBalance (address, balance) { - do { + while (true) { const newBalance = getEthTokenBalance(address) if (Math.abs(newBalance - balance) < 0.0001) return newBalance - delay(0.3) - } while (true) + delay(3) + } } function apiRequest (n, url, suffix) { @@ -223,9 +235,10 @@ function testEthToBnc () { return true }) - userAccounts.forEach(({ privateKey }, i) => { - exec(4, `PRIVATE_KEY=${privateKey} ./src/test-services/ethereumSend/run.sh bridge ${5 + i}`) + userAccounts.forEach((account, i) => { + exec(4, `PRIVATE_KEY=${account.privateKey} ./src/test-services/ethereumSend/run.sh bridge ${5 + i}`) wait(4) + account.ethBalance -= 5 + i }) const delta = (9 + userAccounts.length) * userAccounts.length / 2 @@ -250,9 +263,10 @@ function testBncToEth () { return true }) - userAccounts.forEach(({ privateKey }, i) => { - exec(4, `PRIVATE_KEY=${privateKey} ./src/test-services/binanceSend/run.sh ${bridgeBncAddress} ${3 + i}`) + userAccounts.forEach((account , i) => { + exec(4, `PRIVATE_KEY=${account.privateKey} ./src/test-services/binanceSend/run.sh ${bridgeBncAddress} ${3 + i}`) wait(4) + account.bncBalance -= 3 + i }) const delta = (5 + userAccounts.length) * userAccounts.length / 2 @@ -339,9 +353,18 @@ function run () { clean() - execSync(4, `./demo/start-environment.sh`) + if ($.getenv('RELOAD') !== 'true') { + execSync(4, `./demo/start-environment.sh`) + + prefundEthAddresses() + + saveBlockchainData() + } else { + reloadBlockchainData() + + execSync(4, `./demo/start-environment.sh`) + } - prefundEthAddresses() prefundBncAddresses() initBalances() @@ -351,8 +374,14 @@ function run () { exec(3, `N=3 ./demo/validator-demo.sh`) // wait until binance account willl be generated - let log = waitLog(1, 'Generated multisig account in binance chain') - bridgeBncAddress = /tbnb\w+/.exec(log)[0] + waitLog(1, 'Generated multisig account in binance chain') + waitApi(1, '/info', res => { + if (res.epoch === 1) { + bridgeBncAddress = res.foreignBridgeAddress + return true + } + return false + }) // prefund binance account execSync(4, `./src/test-services/binanceSend/run.sh ${bridgeBncAddress} 100 0.1`) diff --git a/demo/scenarios/macos/run.sh b/demo/scenarios/macos/run.sh index 06f19b4..2351b7a 100755 --- a/demo/scenarios/macos/run.sh +++ b/demo/scenarios/macos/run.sh @@ -1,3 +1,5 @@ #!/bin/bash -osascript -l JavaScript ./demo/scenarios/macos/main.jxa +RELOAD=${RELOAD:=false} + +RELOAD="$RELOAD" osascript -l JavaScript ./demo/scenarios/macos/main.jxa diff --git a/demo/start-environment.sh b/demo/start-environment.sh index 8c18dbe..85ac689 100755 --- a/demo/start-environment.sh +++ b/demo/start-environment.sh @@ -21,6 +21,7 @@ start_dev_blockchain_networks() { docker kill ganache_side > /dev/null 2>&1 || true docker network create blockchain_side > /dev/null 2>&1 || true docker run -d --network blockchain_side --rm --name ganache_side -v "$SIDE_GANACHE_DB:/app/db" \ + -p "8545:8545" \ trufflesuite/ganache-cli:latest \ -m "shrug dwarf easily blade trigger lucky reopen cage lake scatter desk boat" -i 33 -q --db /app/db -b 3 --noVMErrorsOnRPCResponse diff --git a/demo/validator1/.env.development b/demo/validator1/.env.development index 80f4332..5d02252 100644 --- a/demo/validator1/.env.development +++ b/demo/validator1/.env.development @@ -3,7 +3,7 @@ HOME_BRIDGE_ADDRESS=0x44c158FE850821ae69DaF37AADF5c539e9d0025B HOME_TOKEN_ADDRESS=0xd5fE0D28e058D375b0b038fFbB446Da37E85fFdc HOME_START_BLOCK=1 -BLOCKS_RANGE_SIZE=50 +BLOCKS_RANGE_SIZE=25 SIDE_RPC_URL=http://ganache_side:8545 SIDE_SHARED_DB_ADDRESS=0xd5fE0D28e058D375b0b038fFbB446Da37E85fFdc diff --git a/demo/validator2/.env.development b/demo/validator2/.env.development index 695048e..19ea275 100644 --- a/demo/validator2/.env.development +++ b/demo/validator2/.env.development @@ -3,7 +3,7 @@ HOME_BRIDGE_ADDRESS=0x44c158FE850821ae69DaF37AADF5c539e9d0025B HOME_TOKEN_ADDRESS=0xd5fE0D28e058D375b0b038fFbB446Da37E85fFdc HOME_START_BLOCK=1 -BLOCKS_RANGE_SIZE=50 +BLOCKS_RANGE_SIZE=25 SIDE_RPC_URL=http://ganache_side:8545 SIDE_SHARED_DB_ADDRESS=0xd5fE0D28e058D375b0b038fFbB446Da37E85fFdc diff --git a/demo/validator3/.env.development b/demo/validator3/.env.development index 88e43a1..e69ef41 100644 --- a/demo/validator3/.env.development +++ b/demo/validator3/.env.development @@ -3,7 +3,7 @@ HOME_BRIDGE_ADDRESS=0x44c158FE850821ae69DaF37AADF5c539e9d0025B HOME_TOKEN_ADDRESS=0xd5fE0D28e058D375b0b038fFbB446Da37E85fFdc HOME_START_BLOCK=1 -BLOCKS_RANGE_SIZE=50 +BLOCKS_RANGE_SIZE=25 SIDE_RPC_URL=http://ganache_side:8545 SIDE_SHARED_DB_ADDRESS=0xd5fE0D28e058D375b0b038fFbB446Da37E85fFdc