Updated tests env file and scripts.
This commit is contained in:
parent
17690e7ac2
commit
1b91c790f1
|
@ -5,6 +5,7 @@ HOME_PRIVATE_KEY=e2aeb24eaa63102d0c0821717c3b6384abdabd7af2ad4ec8e650dce300798b2
|
|||
|
||||
SIDE_RPC_URL=http://ganache_side:8545
|
||||
|
||||
FOREIGN_URL=https://testnet-dex.binance.org/
|
||||
FOREIGN_CHAIN_ID=Binance-Chain-Nile
|
||||
FOREIGN_ASSET=KFT-94F
|
||||
FOREIGN_URL=http://http-api:8000
|
||||
FOREIGN_CHAIN_ID=Binance-Dev
|
||||
FOREIGN_ASSET=DEV-BA8
|
||||
FOREIGN_PRIVATE_KEY=dd5ec5a7abe9d1fff21170ae591085f000fc6fd9ca0107fe047593f44e328e40
|
||||
|
|
|
@ -6,6 +6,7 @@ set -v
|
|||
docker build -t tss ./src/tss
|
||||
|
||||
./demo/start-environment.sh
|
||||
./src/binance-testnet/run.sh
|
||||
|
||||
cat ./tests/config.json | jq .users[].ethAddress | xargs -I {} ./src/test-services/ethereumSend/run.sh {} 300
|
||||
cat ./tests/config.json | jq .users[].bncAddress | xargs -I {} ./src/test-services/binanceSend/run.sh {} 300 0.1
|
||||
|
|
|
@ -7,9 +7,9 @@ docker build -t tests ./tests
|
|||
docker rm tests > /dev/null 2>&1 || true
|
||||
docker create --name tests \
|
||||
--env-file ./tests/.env \
|
||||
-e FOREIGN_PRIVATE_KEY \
|
||||
tests $@
|
||||
|
||||
docker network connect binance_net tests
|
||||
docker network connect blockchain_home tests
|
||||
docker network connect blockchain_side tests
|
||||
docker network connect validator1_test_network tests
|
||||
|
|
|
@ -32,8 +32,8 @@ describe('bridge tests', function () {
|
|||
let bncPrefundedUser
|
||||
|
||||
before(async function () {
|
||||
ethPrefundedUser = await createUser(HOME_PRIVATE_KEY)
|
||||
bncPrefundedUser = await createUser(FOREIGN_PRIVATE_KEY)
|
||||
ethPrefundedUser = await createUser(HOME_PRIVATE_KEY, 'eth')
|
||||
bncPrefundedUser = await createUser(FOREIGN_PRIVATE_KEY, 'bnc')
|
||||
|
||||
const bnbBalance = await bncPrefundedUser.getBnbBalance()
|
||||
assert.ok(bnbBalance >= 1, `Insufficient BNB balance on ${bncPrefundedUser.ethAddress} in Binance network, expected 1 BNB, got ${bnbBalance}`)
|
||||
|
|
|
@ -13,34 +13,38 @@ const txOptions = {
|
|||
|
||||
const { SIDE_RPC_URL } = process.env
|
||||
|
||||
async function createUser(privateKey) {
|
||||
const providerSide = new ethers.providers.JsonRpcProvider(SIDE_RPC_URL)
|
||||
const walletSide = new ethers.Wallet(privateKey, providerSide)
|
||||
const wallet = new ethers.Wallet(privateKey, provider)
|
||||
const ethAddress = wallet.address
|
||||
const bncAddress = getAddressFromPrivateKey(privateKey)
|
||||
const token = tokenContract.connect(wallet)
|
||||
const bridge = bridgeContract.connect(wallet)
|
||||
|
||||
const bncClient = await createBncClient(privateKey)
|
||||
async function createUser(privateKey, network) {
|
||||
const opts = {}
|
||||
if (network !== 'bnc') {
|
||||
opts.providerSide = new ethers.providers.JsonRpcProvider(SIDE_RPC_URL)
|
||||
opts.walletSide = new ethers.Wallet(privateKey, opts.providerSide)
|
||||
opts.wallet = new ethers.Wallet(privateKey, provider)
|
||||
opts.ethAddress = opts.wallet.address
|
||||
opts.token = tokenContract.connect(opts.wallet)
|
||||
opts.bridge = bridgeContract.connect(opts.wallet)
|
||||
}
|
||||
if (network !== 'eth') {
|
||||
opts.bncAddress = getAddressFromPrivateKey(privateKey)
|
||||
opts.bncClient = await createBncClient(privateKey)
|
||||
}
|
||||
|
||||
return {
|
||||
ethAddress,
|
||||
bncAddress,
|
||||
ethAddress: opts.ethAddress,
|
||||
bncAddress: opts.bncAddress,
|
||||
async getEthBalance() {
|
||||
const balance = await wallet.getBalance()
|
||||
const balance = await opts.wallet.getBalance()
|
||||
return parseFloat(new BN(balance).dividedBy(10 ** 18).toFixed(8, 3))
|
||||
},
|
||||
async getSideEthBalance() {
|
||||
const balance = await walletSide.getBalance()
|
||||
const balance = await opts.walletSide.getBalance()
|
||||
return parseFloat(new BN(balance).dividedBy(10 ** 18).toFixed(8, 3))
|
||||
},
|
||||
async getErcBalance() {
|
||||
const balance = await token.balanceOf(ethAddress)
|
||||
const balance = await opts.token.balanceOf(opts.ethAddress)
|
||||
return parseFloat(new BN(balance).dividedBy(10 ** 18).toFixed(8, 3))
|
||||
},
|
||||
async transferEth(to, value) {
|
||||
const tx = await wallet.sendTransaction(
|
||||
const tx = await opts.wallet.sendTransaction(
|
||||
{
|
||||
to,
|
||||
value: `0x${new BN(value).multipliedBy(10 ** 18).toString(16)}`
|
||||
|
@ -50,7 +54,7 @@ async function createUser(privateKey) {
|
|||
await tx.wait()
|
||||
},
|
||||
async transferEthSide(to, value) {
|
||||
const tx = await walletSide.sendTransaction(
|
||||
const tx = await opts.walletSide.sendTransaction(
|
||||
{
|
||||
to,
|
||||
value: `0x${new BN(value).multipliedBy(10 ** 18).toString(16)}`
|
||||
|
@ -60,7 +64,7 @@ async function createUser(privateKey) {
|
|||
await tx.wait()
|
||||
},
|
||||
async transferErc(to, value) {
|
||||
const tx = await token.transfer(
|
||||
const tx = await opts.token.transfer(
|
||||
to,
|
||||
`0x${new BN(value).multipliedBy(10 ** 18).toString(16)}`,
|
||||
txOptions
|
||||
|
@ -68,7 +72,7 @@ async function createUser(privateKey) {
|
|||
await tx.wait()
|
||||
},
|
||||
async approveErc(to, value) {
|
||||
const tx = await token.approve(
|
||||
const tx = await opts.token.approve(
|
||||
to,
|
||||
`0x${new BN(value).multipliedBy(10 ** 18).toString(16)}`,
|
||||
txOptions
|
||||
|
@ -76,27 +80,27 @@ async function createUser(privateKey) {
|
|||
await tx.wait()
|
||||
},
|
||||
async exchangeErc(value) {
|
||||
const tx = await bridge.exchange(
|
||||
const tx = await opts.bridge.exchange(
|
||||
`0x${new BN(value).multipliedBy(10 ** 18).toString(16)}`,
|
||||
txOptions
|
||||
)
|
||||
await tx.wait()
|
||||
},
|
||||
async getBnbBalance() {
|
||||
const balance = await getBnbBalance(bncAddress)
|
||||
const balance = await getBnbBalance(opts.bncAddress)
|
||||
await delay(1000)
|
||||
return balance
|
||||
},
|
||||
async getBepBalance() {
|
||||
const balance = await getBepBalance(bncAddress)
|
||||
const balance = await getBepBalance(opts.bncAddress)
|
||||
await delay(1000)
|
||||
return balance
|
||||
},
|
||||
async transferBepBnb(to, tokens, bnbs) {
|
||||
return await bncClient.transfer(to, tokens, bnbs)
|
||||
return await opts.bncClient.transfer(to, tokens, bnbs)
|
||||
},
|
||||
async exchangeBep(bridgeAddress, value) {
|
||||
return await bncClient.exchange(bridgeAddress, value)
|
||||
return await opts.bncClient.exchange(bridgeAddress, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue