set of tools extended to allow test the bridge from CLI

This commit is contained in:
Alexander Kolotov 2018-02-12 02:10:43 +03:00
parent ee3b9fe746
commit ca4f9b6370
11 changed files with 255 additions and 27 deletions

11
erc20/bridge/bridge_runner.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
#export RUST_BACKTRACE=1
#export RUST_LOG=all
#export RUST_LOG=error
#export RUST_LOG=warning
#export RUST_LOG=info
export RUST_LOG=debug
exec ./bridge --config erc20.toml --database erc20_db.toml

View File

@ -3,23 +3,30 @@
from web3 import Web3
from web3.utils.transactions import wait_for_transaction_receipt
import json
from toml import load
import sys
_contractName='ForeignBridge'
_abiFile=_contractName+".abi"
_IPC_file = '/home/koal/parity/PoA_foreign/jsonrpc.ipc'
web3 = Web3(Web3.IPCProvider(_IPC_file))
_actor = "0xf3Ee321Df87781864f46F6464e764c2827FCa73B"
_gasPrice = web3.toWei(18, 'gwei')
test_env_db = '/home/koal/parity/bridge/test_env_db.toml'
try:
test_env = load(test_env_db)
except:
sys.exit(1)
bridge_config = load('/home/koal/parity/bridge/erc20.toml')
bridge_db = load('/home/koal/parity/bridge/erc20_db.toml')
_IPC_file = bridge_config['foreign']['ipc']
web3 = Web3(Web3.IPCProvider(_IPC_file))
_actor = web3.toChecksumAddress(bridge_config['foreign']['account'])
_gasPrice = bridge_config['transactions']['foreign_deploy']['gas_price']
_txTempl={'from': _actor, 'gasPrice': _gasPrice}
if (len(sys.argv) == 3):
contractAddress = sys.argv[1]
erc20ContractAddress = sys.argv[2]
else:
sys.exit(1)
bridgeContractAddress = web3.toChecksumAddress(bridge_db['foreign_contract_address'])
tokenContractAddress = web3.toChecksumAddress(test_env['token_contract_address'])
#----------------------------------------------------------------------------
# Read ABI
@ -37,11 +44,14 @@ ContractFactory = web3.eth.contract(
# machine where validator is run.
#web3.personal.unlockAccount(actor, "11", 30)
BridgeContract = ContractFactory(contractAddress)
BridgeContract = ContractFactory(bridgeContractAddress)
print("Set contract address...")
txHash = BridgeContract.transact(transaction=_txTempl).setTokenAddress(erc20ContractAddress)
txHash = BridgeContract.transact(transaction=_txTempl).setTokenAddress(tokenContractAddress)
wait_for_transaction_receipt(web3, txHash)
print("Check that new configuration reflected in the contract...")
print("ERC20 token used by bridge:", BridgeContract.call().erc20token())
sys.exit(0)

View File

@ -0,0 +1,47 @@
#!/opt/anaconda3/bin/python
from web3 import Web3
from web3.utils.transactions import wait_for_transaction_receipt
import json
from toml import load
import sys
from random import randint
test_env_db = '/home/koal/parity/bridge/test_env_db.toml'
try:
test_env = load(test_env_db)
except:
sys.exit(1)
bridge_config = load('/home/koal/parity/bridge/erc20.toml')
bridge_db = load('/home/koal/parity/bridge/erc20_db.toml')
_IPC_file = bridge_config['home']['ipc']
#web3 = Web3(Web3.IPCProvider(_IPC_file))
web3 = Web3(Web3.HTTPProvider("http://127.0.0.1:38545"))
_gasPrice = bridge_config['transactions']['withdraw_relay']['gas_price']
bridgeContractAddress = web3.toChecksumAddress(bridge_db['home_contract_address'])
if 'actor_address' in test_env:
actor = web3.toChecksumAddress(test_env['actor_address'])
else:
sys.exit("actor is not set in testenv DB")
################################################################################
# Sending ether to the bridge contract
################################################################################
value = web3.toWei(randint(700, 5000), 'szabo')
tx = {'from': actor, 'to': bridgeContractAddress, 'value': value ,'gasPrice': _gasPrice}
print("Sending", value, "to Home bridge")
web3.personal.unlockAccount(actor, "11", "0x5")
txHash = web3.eth.sendTransaction(tx)
wait_for_transaction_receipt(web3, txHash)
print("TX:", txHash.hex())
sys.exit(0)

View File

@ -1,3 +1,9 @@
#!/bin/bash
exec ./bridge --config erc20.toml --database erc20_db.toml
PARITY_BASE="/home/koal/parity/bridge"
RUNNER="bridge_runner.sh"
TASK="PoA_bridge"
cd ${PARITY_BASE}
exec screen -d -m -U -t "${TASK}" -S "${TASK}.screen" -h 5000 -L -s ${PARITY_BASE}/${RUNNER}

View File

@ -0,0 +1,52 @@
#!/opt/anaconda3/bin/python
from web3 import Web3
import json
from toml import load
import sys
#_tokenName='MintableToken'
_tokenName = 'BridgeableToken'
_abiFile = _tokenName+".abi"
test_env_db = '/home/koal/parity/bridge/test_env_db.toml'
try:
test_env = load(test_env_db)
except:
sys.exit(1)
bridge_config = load('/home/koal/parity/bridge/erc20.toml')
bridge_db = load('/home/koal/parity/bridge/erc20_db.toml')
_IPC_file = bridge_config['foreign']['ipc']
web3 = Web3(Web3.IPCProvider(_IPC_file))
tokenContractAddress = web3.toChecksumAddress(test_env['token_contract_address'])
addresses = [web3.toChecksumAddress(bridge_db['foreign_contract_address'])]
if 'actor_address' in test_env:
addresses.append(web3.toChecksumAddress(test_env['actor_address']))
#----------------------------------------------------------------------------
# Read ABI
#----------------------------------------------------------------------------
with open(_abiFile) as f:
_contractABI=json.load(f)
f.close()
#print(_contractABI[0])
ContractFactory = web3.eth.contract(
abi = _contractABI,
)
#############################################################################
# MAIN PART STARTED HERE
#############################################################################
TokenContract = ContractFactory(tokenContractAddress)
for i in addresses:
balance = TokenContract.call().balanceOf(i)
print(i, ":", balance)
sys.exit(0)

View File

@ -3,25 +3,32 @@
from web3 import Web3
from web3.utils.transactions import wait_for_transaction_receipt
import json
from toml import load, dump
import sys
#_tokenName='MintableToken'
_tokenName='BridgeableToken'
_abiFile=_tokenName+".abi"
_binFile=_tokenName+".bin"
_tokenName = 'BridgeableToken'
_abiFile = _tokenName+".abi"
_binFile = _tokenName+".bin"
_IPC_file = '/home/koal/parity/PoA_foreign/jsonrpc.ipc'
test_env_db = '/home/koal/parity/bridge/test_env_db.toml'
try:
test_env = load(test_env_db)
except:
test_env = {}
bridge_config = load('/home/koal/parity/bridge/erc20.toml')
bridge_db = load('/home/koal/parity/bridge/erc20_db.toml')
_IPC_file = bridge_config['foreign']['ipc']
web3 = Web3(Web3.IPCProvider(_IPC_file))
_actor = "0xf3Ee321Df87781864f46F6464e764c2827FCa73B"
_gasPrice = web3.toWei(18, 'gwei')
_tokenAmount = 100000
_actor = web3.toChecksumAddress(bridge_config['foreign']['account'])
_gasPrice = bridge_config['transactions']['foreign_deploy']['gas_price']
_tokenAmount = 100000
_txTempl={'from': _actor, 'gasPrice': _gasPrice}
if (len(sys.argv) == 2):
bridgeContractAddress = sys.argv[1]
else:
sys.exit(1)
bridgeContractAddress = web3.toChecksumAddress(bridge_db['foreign_contract_address'])
#----------------------------------------------------------------------------
# Read ABI
@ -41,9 +48,13 @@ f.close()
ContractFactory = web3.eth.contract(
abi = _contractABI,
bytecode = _contractBIN,
bytecode = _contractBIN
)
#############################################################################
# MAIN PART STARTED HERE
#############################################################################
# Assuminng that the account is unlocked and script is run on the same
# machine where validator is run.
#web3.personal.unlockAccount(actor, "11", 30)
@ -60,14 +71,22 @@ print("Contract address:", contractAddress)
TokenContract = ContractFactory(contractAddress)
# delegate rights to mint tokens
print("Set minting permissions...")
txHash = TokenContract.transact(transaction=_txTempl).setMintAgent(_actor, True)
wait_for_transaction_receipt(web3, txHash)
# mint few tokens
print("Mint tokens and transfer to the bridge contract " + bridgeContractAddress)
txHash = TokenContract.transact(transaction=_txTempl).mint(bridgeContractAddress, _tokenAmount)
wait_for_transaction_receipt(web3, txHash)
# Store test environment configuration only in case of successful setup
test_env['token_contract_address'] = contractAddress
with open(test_env_db, 'w') as f:
dump(test_env, f)
f.close()
sys.exit(0)

View File

@ -0,0 +1,67 @@
#!/opt/anaconda3/bin/python
from web3 import Web3
from web3.utils.transactions import wait_for_transaction_receipt
import json
from toml import load
import sys
from random import randint
_tokenName = 'BridgeableToken'
_abiFile = _tokenName+".abi"
test_env_db = '/home/koal/parity/bridge/test_env_db.toml'
try:
test_env = load(test_env_db)
except:
sys.exit(1)
bridge_config = load('/home/koal/parity/bridge/erc20.toml')
bridge_db = load('/home/koal/parity/bridge/erc20_db.toml')
#_IPC_file = bridge_config['home']['ipc']
#web3 = Web3(Web3.IPCProvider(_IPC_file))
web3 = Web3(Web3.HTTPProvider("http://127.0.0.1:48545"))
_gasPrice = bridge_config['transactions']['withdraw_confirm']['gas_price']
tokenContractAddress = web3.toChecksumAddress(test_env['token_contract_address'])
bridgeContractAddress = web3.toChecksumAddress(bridge_db['foreign_contract_address'])
if 'actor_address' in test_env:
actor = web3.toChecksumAddress(test_env['actor_address'])
else:
sys.exit("actor is not set in testenv DB")
#----------------------------------------------------------------------------
# Read ABI
#----------------------------------------------------------------------------
with open(_abiFile) as f:
_contractABI=json.load(f)
f.close()
#print(_contractABI[0])
ContractFactory = web3.eth.contract(
abi = _contractABI,
)
#############################################################################
# MAIN PART STARTED HERE
#############################################################################
TokenContract = ContractFactory(tokenContractAddress)
balance = TokenContract.call().balanceOf(actor)
value = randint(balance // 4, balance // 2)
print("Sending", value, "to Home bridge")
web3.personal.unlockAccount(actor, "11", "0x5")
txHash = TokenContract.transact({'from': actor, 'gasPrice': _gasPrice}).approveAndCall(bridgeContractAddress, value, b'')
wait_for_transaction_receipt(web3, txHash)
print("TX:", txHash.hex())
sys.exit(0)

View File

@ -0,0 +1,14 @@
#!/opt/anaconda3/bin/python
from web3 import Web3
#from web3.utils.transactions import wait_for_transaction_receipt
web3 = Web3(Web3.IPCProvider('/home/koal/parity/PoA_foreign/jsonrpc.ipc'))
signer = web3.toChecksumAddress("0xf3ee321df87781864f46f6464e764c2827fca73b")
sender = web3.toChecksumAddress("0x37a30534da3d53aa1867adde26e114a3161b2b12")
#sender = "0x08c7e1b446520914ba7126325d69fe2863f62413"
for i in [signer, sender]:
balance=web3.eth.getBalance(i)
print(i, ":", web3.fromWei(balance, 'ether'))

View File

@ -3,11 +3,11 @@
from web3 import Web3
#from web3.utils.transactions import wait_for_transaction_receipt
signer = "0x842eb2142c5aa1260954f07aae39ddee1640c3a7"
sender = "0x37a30534da3d53aa1867adde26e114a3161b2b12"
web3 = Web3(Web3.IPCProvider('/home/koal/parity/PoA_home/jsonrpc.ipc'))
signer = web3.toChecksumAddress("0x842eb2142c5aa1260954f07aae39ddee1640c3a7")
sender = web3.toChecksumAddress("0x37a30534da3d53aa1867adde26e114a3161b2b12")
for i in [signer, sender]:
balance=web3.eth.getBalance(i)
print(i, ":", web3.fromWei(balance, 'ether'))