Bnc to eth tests, artifacts processing in circleci config

This commit is contained in:
Kirill Fedoseev 2019-10-28 15:47:07 +03:00
parent 13c0734691
commit 876f09f312
12 changed files with 127 additions and 55 deletions

View File

@ -67,6 +67,22 @@ orbs:
- run:
name: "Load tss image from archive"
command: docker load -i ./workspace/tss.tar.gz
save_docker_logs:
description: "A very simple command for demonstration purposes"
parameters:
validator:
type: integer
default: 1
steps:
- run: |
mkdir -p ./artifacts/logs/validator<< parameters.validator >>
docker logs validator<< parameters.validator >>_rabbitmq_1 ./artifacts/logs/validator<< parameters.validator >>/rabbitmq.log
docker logs validator<< parameters.validator >>_redis_1 ./artifacts/logs/validator<< parameters.validator >>/redis.log
docker logs validator<< parameters.validator >>_proxy_1 ./artifacts/logs/validator<< parameters.validator >>/proxy.log
docker logs validator<< parameters.validator >>_eth-watcher_1 ./artifacts/logs/validator<< parameters.validator >>/eth-watcher.log
docker logs validator<< parameters.validator >>_bnc-watcher_1 ./artifacts/logs/validator<< parameters.validator >>/bnc-watcher.log
docker logs validator<< parameters.validator >>_signer_1 ./artifacts/logs/validator<< parameters.validator >>/signer.log
docker logs validator<< parameters.validator >>_keygen_1 ./artifacts/logs/validator<< parameters.validator >>/keygen.log
jobs:
init_tss:
executor: bridge/node-dev
@ -88,7 +104,7 @@ jobs:
- run:
name: "Run dev environment, deploy contracts, prefund accounts"
command: |
./demo/start-environment.sh
BLOCK_TIME=1 ./demo/start-environment.sh
cat ./tests/config.json | jq .users[].ethAddress | xargs -I {} ./src/test-services/ethereumSend/run.sh {} 100
- run:
name: "Stop dev environment"
@ -111,7 +127,7 @@ jobs:
- run:
name: "Init tests environment"
command: |
./demo/start-environment.sh
BLOCK_TIME=3 ./demo/start-environment.sh
N=1 ./demo/validator-demo.sh -d
N=2 ./demo/validator-demo.sh -d
N=3 ./demo/validator-demo.sh -d
@ -125,7 +141,7 @@ jobs:
name: "Build and prepare tests container"
command: |
docker build -t tests ./tests
docker create --rm -e HOME_RPC_URL --name tests tests $@
docker create --rm --env-file ./tests/.env -e FOREIGN_PRIVATE_KEY --name tests tests
docker network connect blockchain_side tests
docker network connect blockchain_home tests
docker network connect validator1_test_network tests
@ -135,9 +151,23 @@ jobs:
HOME_RPC_URL: 'http://ganache_home:8545'
- run:
name: "Run tests"
command: docker start -a tests
- run:
name: "Save tests results"
command: |
docker start -a tests
docker cp "tests:/tests/results.xml" "./tests/results.xml"
mkdir -p ./artifacts/test_results/mocha
docker cp "tests:/tests/results.xml" "./artifacts/test_results/mocha/results.xml"
when: always
- store_test_results:
path: ./artifacts/test_results/mocha
- bridge/save_docker_logs:
validator: 1
- bridge/save_docker_logs:
validator: 2
- bridge/save_docker_logs:
validator: 3
- store_artifacts:
path: ./artifacts
workflows:
version: 2
main:

1
.gitignore vendored
View File

@ -18,3 +18,4 @@ src/deploy/.keys.staging
src/test-services/.keys.staging
src/test-services/.keys.development
test.js
tests/results.xml

View File

@ -7,6 +7,7 @@ cd ..
# either development or staging
TARGET_NETWORK=${TARGET_NETWORK:=development}
BLOCK_TIME=${BLOCK_TIME:=3}
DEPLOY_DIR="`pwd`/src/deploy"
TEST_SERVICES_DIR="`pwd`/src/test-services"
@ -21,7 +22,7 @@ start_dev_blockchain_networks() {
docker run -d --network blockchain_side --rm --name ganache_side -v "ganache_side_data:/app/db" \
-p "7545: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
-m "shrug dwarf easily blade trigger lucky reopen cage lake scatter desk boat" -i 33 -q --db /app/db -b "$BLOCK_TIME" --noVMErrorsOnRPCResponse
echo "Starting home test blockchain"
@ -31,7 +32,7 @@ start_dev_blockchain_networks() {
docker run -d --network blockchain_home --rm --name ganache_home -v "ganache_home_data:/app/db" \
-p "8545:8545" \
trufflesuite/ganache-cli:latest \
-m "shrug dwarf easily blade trigger lucky reopen cage lake scatter desk boat" -i 44 -q --db /app/db -b 3 --noVMErrorsOnRPCResponse
-m "shrug dwarf easily blade trigger lucky reopen cage lake scatter desk boat" -i 44 -q --db /app/db -b "$BLOCK_TIME" --noVMErrorsOnRPCResponse
sleep 4
}

7
tests/.env Normal file
View File

@ -0,0 +1,7 @@
HOME_RPC_URL=http://ganache_home:8545
HOME_BRIDGE_ADDRESS=0x44c158FE850821ae69DaF37AADF5c539e9d0025B
HOME_TOKEN_ADDRESS=0xd5fE0D28e058D375b0b038fFbB446Da37E85fFdc
FOREIGN_URL=https://testnet-dex.binance.org/
FOREIGN_CHAIN_ID=Binance-Chain-Nile
FOREIGN_ASSET=KFT-94F

View File

@ -1,3 +1,3 @@
reporter: spec
reporter: mocha-multi-reporters
reporter-option:
- mochaFile=./results.xml
- configFile=./reportersConfig.json

View File

@ -2,7 +2,7 @@ FROM node:10.16.0-alpine
WORKDIR /tests
RUN npm install -g mocha mocha-junit-reporter
RUN npm install -g mocha mocha-junit-reporter mocha-multi-reporters
RUN apk update && apk add libssl1.1 eudev-dev libressl-dev curl build-base python linux-headers libusb-dev
@ -10,7 +10,7 @@ COPY ./package.json .
RUN npm install
COPY config.json .mocharc.yml ./
COPY config.json .mocharc.yml reportersConfig.json ./
COPY test ./test
ENTRYPOINT ["mocha"]

View File

@ -0,0 +1,6 @@
{
"reporterEnabled": "spec, mocha-junit-reporter",
"mochaJunitReporterReporterOptions": {
"mochaFile": "./results.xml"
}
}

View File

@ -4,18 +4,10 @@ set -e
docker build -t tests ./tests
set -a
source ./demo/validator1/.env.development
set +a
docker rm tests || true
docker rm tests > /dev/null 2>&1 || true
docker create --name tests \
-e HOME_RPC_URL \
-e FOREIGN_URL \
-e HOME_BRIDGE_ADDRESS \
-e HOME_TOKEN_ADDRESS \
--env-file ./tests/.env \
-e FOREIGN_PRIVATE_KEY \
-e FOREIGN_ASSET \
tests $@
docker network connect blockchain_home tests
@ -25,5 +17,5 @@ docker network connect validator3_test_network tests
docker start -a tests || true
docker cp "tests:/tests/results.xml" "./tests/results.xml" || true
docker rm tests || true
docker cp "tests:/tests/results.xml" "./tests/results.xml" > /dev/null 2>&1 || true
docker rm tests > /dev/null 2>&1 || true

32
tests/test/bncToEth.js Normal file
View File

@ -0,0 +1,32 @@
const { delay } = require('./utils/wait')
module.exports = (usersFunc, foreignBridgeAddressFunc) => {
describe('exchange of tokens in bnc => eth direction', function () {
let users
let foreignBridgeAddress
let ethBalances
before(async function () {
this.timeout(60000)
users = usersFunc()
foreignBridgeAddress = foreignBridgeAddressFunc()
ethBalances = await Promise.all(users.map(user => user.getEthBalance()))
await Promise.all(users.map((user, i) => user.exchangeBnc(foreignBridgeAddress, 3 + i)))
})
it('should make coorect exchange transactions on eth side', async function () {
this.timeout(60000)
for (let i = 0; i < 3; i++) {
do {
const user = users[i]
const newEthBalance = await user.getEthBalance()
if (newEthBalance === ethBalances[i] + 3 + i) {
break
}
delay(500)
} while (true)
}
})
})
}

View File

@ -1,26 +1,27 @@
const assert = require('assert')
const createUser = require('./utils/user')
const { getSequence } = require('./utils/bncController')
const { waitPromise, delay } = require('./utils/wait')
const { waitPromise } = require('./utils/wait')
const usersConfig = require('../config').users
const { HOME_BRIDGE_ADDRESS } = process.env
module.exports = (foreignBridgeAddress) => {
describe('exchanges tokens in eth => bnc direction', function () {
module.exports = (usersFunc, foreignBridgeAddressFunc) => {
describe('exchange of tokens in eth => bnc direction', function () {
let users
let foreignBridgeAddress
let ethBalances
let bncBalances
let bncBridgeSequence
let users
before(async function () {
this.timeout(60000)
users = await usersConfig.seqMap(user => createUser(user.privateKey))
users = usersFunc()
foreignBridgeAddress = foreignBridgeAddressFunc()
ethBalances = await Promise.all(users.map(user => user.getEthBalance()))
bncBalances = await users.seqMap(user => user.getBncBalance())
bncBridgeSequence = await getSequence(foreignBridgeAddress())
bncBridgeSequence = await getSequence(foreignBridgeAddress)
await Promise.all(users.map((user, i) => user.approveEth(HOME_BRIDGE_ADDRESS, 5 + i)))
})
@ -31,12 +32,11 @@ module.exports = (foreignBridgeAddress) => {
for (let i = 0; i < 3; i++) {
assert(newEthBalances[i] === ethBalances[i] - 5 - i, `Balance of ${usersConfig[i].ethAddress} did not updated as expected`)
}
ethBalances = newEthBalances
})
it('should make exchange transaction on bnc side', async function () {
this.timeout(300000)
await waitPromise(() => getSequence(foreignBridgeAddress()), sequence => sequence === bncBridgeSequence + 1)
await waitPromise(() => getSequence(foreignBridgeAddress), sequence => sequence === bncBridgeSequence + 1)
})
it('should make correct exchange transaction', async function () {
@ -45,7 +45,6 @@ module.exports = (foreignBridgeAddress) => {
for (let i = 0; i < 3; i++) {
assert(newBncBalances[i] === bncBalances[i] + 5 + i, `Balance of ${usersConfig[i].bncAddress} did not updated as expected`)
}
bncBalances = newBncBalances
})
})
}

View File

@ -3,30 +3,41 @@ const createUser = require('./utils/user')
const { waitPromise } = require('./utils/wait')
const testEthToBnc = require('./ethToBnc')
const testBncToEth = require('./bncToEth')
const usersConfig = require('../config').users
const { FOREIGN_PRIVATE_KEY } = process.env
let user
let { getInfo } = createController(1)
let info
describe('bridge tests', function () {
let users
let foreignPrefundedUser
let info
describe('generates initial epoch keys', function () {
before(async function () {
before(async function() {
this.timeout(60000)
user = await createUser(FOREIGN_PRIVATE_KEY)
users = await usersConfig.seqMap(user => createUser(user.privateKey))
})
it('should generate keys in 2 min', async function () {
this.timeout(120000)
info = await waitPromise(getInfo, info => info.epoch === 1)
describe('generation of initial epoch keys', function () {
before(async function () {
this.timeout(60000)
foreignPrefundedUser = await createUser(FOREIGN_PRIVATE_KEY)
})
it('should generate keys', async function () {
this.timeout(120000)
info = await waitPromise(getInfo, info => info.epoch === 1)
})
after(async function () {
this.timeout(60000)
await foreignPrefundedUser.transferBnc(info.foreignBridgeAddress, 50, 0.1)
})
})
after(async function () {
this.timeout(60000)
await user.transferBnc(info.foreignBridgeAddress, 50, 0.1)
})
testEthToBnc(() => users, () => info.foreignBridgeAddress)
testBncToEth(() => users, () => info.foreignBridgeAddress)
})
testEthToBnc(() => info.foreignBridgeAddress)

View File

@ -30,19 +30,12 @@ module.exports = async function (privateKey) {
await tx.wait()
},
approveEth: async function (to, value) {
console.log('approving', to, value)
const tx = await token.approve(to, '0x' + (new BN(value).multipliedBy(10 ** 18).toString(16)), txOptions)
console.log('sent', tx)
await tx.wait()
console.log('done')
console.log(await token.allowance(ethAddress, to))
},
exchangeEth: async function (value) {
console.log(value)
const tx = await bridge.exchange('0x' + (new BN(value).multipliedBy(10 ** 18).toString(16)), txOptions)
console.log(tx)
await tx.wait()
console.log('done')
},
getBncBalance: async function () {
const balance = await getBalance(bncAddress)