Commit 36d9fce4 authored by QM's avatar QM

finish rpc test

parent 2e954ca3
......@@ -67,7 +67,6 @@ function run_dapp() {
fi
cd ..
echo "============ run dapp=$app end ================="
}
function run_single_app() {
......@@ -145,7 +144,6 @@ function main() {
elif [ "${OP}" == "modify" ]; then
sed -i $sedfix '/^useGithub=.*/a version=1' chain33.toml
fi
}
# run script
......
......@@ -461,31 +461,29 @@ function dapp_test_address() {
}
function base_config() {
# sync
transfer "${CLI}"
# transfer "${CLI4}"
}
function rpc_test() {
if [ "$DAPP" == "" ]; then
system_test_rpc "http://${1}:8801"
dapp_test_address "${CLI}"
dapp_test_rpc "http://${1}:8801" "${NODE3}"
dapp_test_rpc "http://${1}:8801" "${dockerNamePrefix}"
fi
if [ "$DAPP" == "paracross" ]; then
system_test_rpc "http://${1}:8901"
dapp_test_address "${CLI}"
dapp_test_rpc "http://${1}:8901"
fi
}
function dapp_run() {
if [ -e "$DAPP_TEST_FILE" ]; then
${DAPP} "${CLI}" "${1}" "${2}"
fi
}
function main() {
echo "==============================DAPP=$DAPP main begin========================================================"
### init para ####
......
FROM ubuntu:16.04
FROM ubuntu:16.04.02
WORKDIR /root
COPY relayer.toml relayer.toml
......
......@@ -29,26 +29,29 @@ ethReceiverAddrKey2="9dc6df3a8ab139a54d8a984f54958ae0661f880229bf3bdbb886b87d58b
maturityDegree=10
tokenAddrBty=""
tokenAddr=""
ethUrl=""
portRelayer=20000
function kill_ebrelayerC() {
kill_ebrelayer "./C/ebrelayer"
#shellcheck disable=SC2154
docker stop "${dockerNamePrefix}_ebrelayerc_1"
}
function kill_ebrelayerD() {
kill_ebrelayer "./D/ebrelayer"
docker stop "${dockerNamePrefix}_ebrelayerd_1"
}
function start_ebrelayerC() {
start_ebrelayer "./C/ebrelayer" "./C/ebrelayer.log"
docker start "${dockerNamePrefix}_ebrelayerc_1"
${CLIC} relayer unlock -p 123456hzj
sleep 5
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
sleep 10
}
function start_ebrelayerD() {
start_ebrelayer "./D/ebrelayer" "./D/ebrelayer.log"
docker start "${dockerNamePrefix}_ebrelayerd_1"
${CLID} relayer unlock -p 123456hzj
sleep 5
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
sleep 10
}
......@@ -75,16 +78,27 @@ function StartRelayerAndDeploy() {
done
# change EthProvider url
{
inetAddr=$(get_inet_addr)
dockerAddr=$(get_docker_addr "${dockerNamePrefix}_ganachetest_1")
ethUrl="http://${dockerAddr}:8545"
# shellcheck disable=SC2155
local line=$(delete_line_show "./relayer.toml" "EthProvider=\"ws:")
sed -i ''"${line}"' a EthProvider="ws://'"${inetAddr}"':7545/"' "./relayer.toml"
sed -i ''"${line}"' a EthProvider="ws://'"${dockerAddr}"':8545/"' "./relayer.toml"
line=$(delete_line_show "./relayer.toml" "EthProviderCli=\"http:")
sed -i ''"${line}"' a EthProviderCli="http://'"${inetAddr}"':7545"' "./relayer.toml"
}
sed -i ''"${line}"' a EthProviderCli="http://'"${dockerAddr}"':8545"' "./relayer.toml"
grep_port=$(netstat -tlpn | grep "\b${portRelayer}\b")
while [ -n "$grep_port" ]; do
echo "port $portRelayer is in use"
portRelayer=$((portRelayer - 4))
grep_port=$(netstat -tlpn | grep "\b${portRelayer}\b")
done
if [ "${portRelayer}" != "20000" ]; then
line=$(delete_line_show "./docker-compose-ebrelayer.yml" "20000:20000")
sed -i ''"${line}"' a \ \ \ \ \ \ -\ "'${portRelayer}':'${portRelayer}'"' "./docker-compose-ebrelayer.yml"
fi
docker-compose -f docker-compose-ebrelayer.yml up --build -d
sleep 1
......@@ -101,7 +115,7 @@ function StartRelayerAndDeploy() {
updata_relayer_toml "${BridgeRegistry}" ${maturityDegree} "./relayer.toml"
docker-compose -f docker-compose-ebrelayer.yml up --build -d
updata_docker_relayer_toml
updata_docker_relayer_toml "${portRelayer}"
for name in b c d; do
docker-compose -f "docker-compose-ebrelayer$name.yml" up --build -d
done
......@@ -217,14 +231,14 @@ function TestChain33ToEthAssets() {
cli_ret "${result}" "balance" ".balance" "0"
# chain33 lock bty
hash=$(${Chain33Cli} send x2ethereum lock -a 5 -t coins.bty -r ${ethReceiverAddr1} -q "${tokenAddrBty}" -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
hash=$(${Chain33Cli} send x2ethereum lock -a 5 -t coins.bty -r ${ethReceiverAddr1} -q "${tokenAddrBty}" --node_addr "${ethUrl}" -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
block_wait "${Chain33Cli}" $((maturityDegree + 2))
check_tx "${Chain33Cli}" "${hash}"
result=$(${Chain33Cli} account balance -a 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -e x2ethereum)
balance_ret "${result}" "195.0000"
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr1}" -t "${tokenAddrBty}")
cli_ret "${result}" "balance" ".balance" "5"
......@@ -237,7 +251,7 @@ function TestChain33ToEthAssets() {
cli_ret "${result}" "balance" ".balance" "0"
# eth 等待 10 个区块
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
result=$(${Chain33Cli} account balance -a "${chain33SenderAddr}" -e x2ethereum)
balance_ret "${result}" "5"
......@@ -265,7 +279,7 @@ function TestETH2Chain33Assets() {
cli_ret "${result}" "balance" ".balance" "0.1"
# eth 等待 10 个区块
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
result=$(${Chain33Cli} x2ethereum balance -s 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -t eth | jq ".res" | jq ".[]")
balance_ret "${result}" "0.1"
......@@ -273,14 +287,14 @@ function TestETH2Chain33Assets() {
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr2}")
balance=$(cli_ret "${result}" "balance" ".balance")
hash=$(${Chain33Cli} send x2ethereum burn -a 0.1 -t eth -r ${ethReceiverAddr2} -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
hash=$(${Chain33Cli} send x2ethereum burn -a 0.1 -t eth -r ${ethReceiverAddr2} --node_addr "${ethUrl}" -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
block_wait "${Chain33Cli}" $((maturityDegree + 2))
check_tx "${Chain33Cli}" "${hash}"
result=$(${Chain33Cli} x2ethereum balance -s 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -t eth | jq ".res" | jq ".[]")
balance_ret "${result}" "0"
eth_block_wait $((maturityDegree + 3))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
result=$(${CLIA} relayer ethereum balance -o "${bridgeBankAddr}")
cli_ret "${result}" "balance" ".balance" "0"
......@@ -324,20 +338,20 @@ function TestETH2Chain33Erc20() {
cli_ret "${result}" "balance" ".balance" "100"
# eth 等待 10 个区块
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
result=$(${Chain33Cli} x2ethereum balance -s "${chain33Validator1}" -t "${tokenSymbol}" -a "${tokenAddr}" | jq ".res" | jq ".[]")
balance_ret "${result}" "100"
# chain33 burn 100
hash=$(${Chain33Cli} send x2ethereum burn -a 100 -t "${tokenSymbol}" -r ${ethReceiverAddr2} -q "${tokenAddr}" -k "${chain33Validator1}")
hash=$(${Chain33Cli} send x2ethereum burn -a 100 -t "${tokenSymbol}" -r ${ethReceiverAddr2} -q "${tokenAddr}" --node_addr "${ethUrl}" -k "${chain33Validator1}")
block_wait "${Chain33Cli}" $((maturityDegree + 2))
check_tx "${Chain33Cli}" "${hash}"
result=$(${Chain33Cli} x2ethereum balance -s "${chain33Validator1}" -t "${tokenSymbol}" -a "${tokenAddr}" | jq ".res" | jq ".[]")
balance_ret "${result}" "0"
eth_block_wait $((maturityDegree + 3))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr2}" -t "${tokenAddr}")
cli_ret "${result}" "balance" ".balance" "100"
......@@ -364,11 +378,11 @@ function TestChain33ToEthAssetsKill() {
kill_ebrelayerD
# chain33 lock bty
hash=$(${Chain33Cli} send x2ethereum lock -a 5 -t coins.bty -r ${ethReceiverAddr2} -q "${tokenAddrBty}" -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
hash=$(${Chain33Cli} send x2ethereum lock -a 5 -t coins.bty -r ${ethReceiverAddr2} -q "${tokenAddrBty}" --node_addr "${ethUrl}" -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
block_wait "${Chain33Cli}" $((maturityDegree + 2))
check_tx "${Chain33Cli}" "${hash}"
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr2}" -t "${tokenAddrBty}")
cli_ret "${result}" "balance" ".balance" "0"
......@@ -386,7 +400,7 @@ function TestChain33ToEthAssetsKill() {
cli_ret "${result}" "balance" ".balance" "0"
# eth 等待 10 个区块
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
result=$(${Chain33Cli} account balance -a "${chain33Validator1}" -e x2ethereum)
balance_ret "${result}" "0"
......@@ -422,7 +436,7 @@ function TestETH2Chain33AssetsKill() {
cli_ret "${result}" "balance" ".balance" "0.1"
# eth 等待 10 个区块
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
result=$(${Chain33Cli} x2ethereum balance -s 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -t eth | jq ".res" | jq ".[]")
balance_ret "${result}" "0"
......@@ -439,14 +453,14 @@ function TestETH2Chain33AssetsKill() {
kill_ebrelayerC
kill_ebrelayerD
hash=$(${Chain33Cli} send x2ethereum burn -a 0.1 -t eth -r ${ethReceiverAddr2} -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
hash=$(${Chain33Cli} send x2ethereum burn -a 0.1 -t eth -r ${ethReceiverAddr2} --node_addr "${ethUrl}" -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
block_wait "${Chain33Cli}" $((maturityDegree + 2))
check_tx "${Chain33Cli}" "${hash}"
result=$(${Chain33Cli} x2ethereum balance -s 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -t eth | jq ".res" | jq ".[]")
balance_ret "${result}" "0"
eth_block_wait $((maturityDegree + 3))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
result=$(${CLIA} relayer ethereum balance -o "${bridgeBankAddr}")
cli_ret "${result}" "balance" ".balance" "0.1"
......@@ -496,7 +510,7 @@ function TestETH2Chain33Erc20Kill() {
cli_ret "${result}" "balance" ".balance" "100"
# eth 等待 10 个区块
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
result=$(${Chain33Cli} x2ethereum balance -s "${chain33Validator1}" -t "${tokenSymbol}" -a "${tokenAddr2}" | jq ".res" | jq ".[]")
balance_ret "${result}" "0"
......@@ -511,14 +525,14 @@ function TestETH2Chain33Erc20Kill() {
kill_ebrelayerD
# chain33 burn 100
hash=$(${Chain33Cli} send x2ethereum burn -a 100 -t "${tokenSymbol}" -r ${ethReceiverAddr2} -q "${tokenAddr2}" -k "${chain33Validator1}")
hash=$(${Chain33Cli} send x2ethereum burn -a 100 -t "${tokenSymbol}" -r ${ethReceiverAddr2} -q "${tokenAddr2}" --node_addr "${ethUrl}" -k "${chain33Validator1}")
block_wait "${Chain33Cli}" $((maturityDegree + 2))
check_tx "${Chain33Cli}" "${hash}"
result=$(${Chain33Cli} x2ethereum balance -s "${chain33Validator1}" -t "${tokenSymbol}" -a "${tokenAddr2}" | jq ".res" | jq ".[]")
balance_ret "${result}" "0"
eth_block_wait $((maturityDegree + 3))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
start_ebrelayerC
start_ebrelayerD
......@@ -534,7 +548,7 @@ function TestETH2Chain33Erc20Kill() {
function AllRelayerMainTest() {
set +e
docker_chain33_ip=$(docker inspect "${NODE3}" | jq ".[].NetworkSettings.Networks" | grep "IPAddress" | awk '{ print $2}' | sed 's/\"//g' | sed 's/,//g')
docker_chain33_ip=$(get_docker_addr "${dockerNamePrefix}_chain33_1")
Chain33Cli="./chain33-cli --rpc_laddr http://${docker_chain33_ip}:8801"
CLIA="docker exec ${dockerNamePrefix}_ebrelayera_1 /root/ebcli_A"
......@@ -559,11 +573,11 @@ function AllRelayerMainTest() {
TestChain33ToEthAssets
TestETH2Chain33Assets
TestETH2Chain33Erc20
#
# # kill relayer and start relayer
# TestChain33ToEthAssetsKill
# TestETH2Chain33AssetsKill
# TestETH2Chain33Erc20Kill
# kill relayer and start relayer
TestChain33ToEthAssetsKill
TestETH2Chain33AssetsKill
TestETH2Chain33Erc20Kill
echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}"
}
......
......@@ -4,8 +4,6 @@ services:
ganachetest:
entrypoint: ["node", "/app/ganache-core.docker.cli.js", "-a", "10", "-b", "2", "--debug", "-m", "coast bar giraffe art venue decide symbol law visual crater vital fold"]
image: trufflesuite/ganache-cli:latest
ports:
- "7545:8545"
ebrelayera:
build:
......
......@@ -6,10 +6,6 @@ set -x
source "./publicTest.sh"
source "./allRelayerTest.sh"
CLIA="./ebcli_A"
Chain33_CLI=""
Ethsender="0xa4ea64a583f6e51c3799335b28a8f0529570a635"
privateKeys[0]="8656d2bc732a8a816a461ba5e2d8aac7c7f85c26a813df30d5327210465eb230"
privateKeys[1]="3fa21584ae2e4fd74db9b58e2386f5481607dfa4d7ba0617aaa7858e5025dc1e"
......@@ -29,10 +25,14 @@ ethAddress[6]="0x0C05bA5c230fDaA503b53702aF1962e08D0C60BF"
maturityDegree=10
tokenAddr=""
tokenAddrBty=""
Chain33_CLI=""
CLIA=""
ethUrl=""
loop_send_lock_eth() {
# while 遍历数组
echo -e "${GRE}=========== Ethereum Lock begin ===========${NOC}"
#shellcheck disable=SC2154
preChain33Balance=$(${Chain33_CLI} x2ethereum balance -s 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -t eth | jq ".res" | jq ".[]" | jq ".balance" | sed 's/\"//g')
i=0
......@@ -44,7 +44,8 @@ loop_send_lock_eth() {
let i++
done
eth_block_wait $((maturityDegree + 2))
#shellcheck disable=SC2154
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
i=0
while [[ i -lt ${#privateKeys[@]} ]]; do
......@@ -71,13 +72,13 @@ loop_send_burn_eth() {
i=0
while [[ i -lt ${#privateKeys[@]} ]]; do
preEthBalance[$i]=$(curl -ksd '{"jsonrpc":"2.0","method":"eth_getBalance","params":["'${ethAddress[i]}'", "latest"],"id":1}' http://localhost:7545 | jq -r ".result")
ethTxHash=$(${Chain33_CLI} send x2ethereum burn -a 1 -r ${ethAddress[i]} -t eth -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
ethTxHash=$(${Chain33_CLI} send x2ethereum burn -a 1 -r ${ethAddress[i]} -t eth --node_addr "${ethUrl}" -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
echo ${i} "burn chain33 tx hash:" "${ethTxHash}"
# shellcheck disable=SC2219
let i++
done
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
i=0
while [[ i -lt ${#privateKeys[@]} ]]; do
......@@ -104,13 +105,13 @@ loop_send_lock_bty() {
i=0
while [[ i -lt ${#privateKeys[@]} ]]; do
preEthBalance[$i]=$(${CLIA} relayer ethereum balance -o "${ethAddress[i]}" -t "${tokenAddrBty}" | jq -r ".balance")
ethTxHash=$(${Chain33_CLI} send x2ethereum lock -q "${tokenAddrBty}" -a 1 -r ${ethAddress[i]} -t coins.bty -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
ethTxHash=$(${Chain33_CLI} send x2ethereum lock -q "${tokenAddrBty}" -a 1 -r ${ethAddress[i]} -t coins.bty --node_addr "${ethUrl}" -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
echo ${i} "lock chain33 tx hash:" "${ethTxHash}"
# shellcheck disable=SC2219
let i++
done
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
i=0
while [[ i -lt ${#privateKeys[@]} ]]; do
......@@ -141,7 +142,7 @@ loop_send_burn_bty() {
let i++
done
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
i=0
while [[ i -lt ${#privateKeys[@]} ]]; do
......@@ -171,7 +172,7 @@ loop_send_lock_erc20() {
# shellcheck disable=SC2219
let i++
done
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
nowEthBalance=$(${CLIA} relayer ethereum balance -o "${Ethsender}" -t "${tokenAddr}" | jq -r ".balance")
res=$((preEthBalance - nowEthBalance))
......@@ -190,13 +191,13 @@ loop_send_burn_erc20() {
i=0
while [[ i -lt ${#privateKeys[@]} ]]; do
preEthBalance[i]=$(${CLIA} relayer ethereum balance -o "${ethAddress[i]}" -t "${tokenAddr}" | jq -r ".balance")
ethTxHash=$(${Chain33_CLI} send x2ethereum burn -a 1 -r ${ethAddress[i]} -t testc -q "${tokenAddr}" -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
ethTxHash=$(${Chain33_CLI} send x2ethereum burn -a 1 -r ${ethAddress[i]} -t testc -q "${tokenAddr}" --node_addr "${ethUrl}" -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
echo ${i} "burn chain33 tx hash:" "${ethTxHash}"
# shellcheck disable=SC2219
let i++
done
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
i=0
while [[ i -lt ${#privateKeys[@]} ]]; do
......@@ -215,8 +216,10 @@ loop_send_burn_erc20() {
perf_test_main() {
echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
docker_chain33_ip=$(docker inspect "${NODE3}" | jq ".[].NetworkSettings.Networks" | grep "IPAddress" | awk '{ print $2}' | sed 's/\"//g' | sed 's/,//g')
Chain33_CLI="./chain33-cli --rpc_laddr http://${docker_chain33_ip}:8801"
#shellcheck disable=SC2154
docker_chain33_ip=$(get_docker_addr "${dockerNamePrefix}_chain33_1")
#shellcheck disable=SC2034
Chain33Cli="./chain33-cli --rpc_laddr http://${docker_chain33_ip}:8801"
if [[ ${1} != "" ]]; then
maturityDegree=${1}
......
......@@ -27,11 +27,31 @@ function exit_cp_file() {
# shellcheck disable=SC2154
docker cp "${dockerNamePrefix}_ebrelayer${name}_1":/root/logs/x2Ethereum_relayer.log "$dirName/ebrelayer$name.log"
done
docker cp "${NODE3}":/root/logs/chain33.log "$dirName/chain33.log"
docker cp "${dockerNamePrefix}_chain33_1":/root/logs/chain33.log "$dirName/chain33.log"
exit 1
}
function copyErrLogs() {
if [ -n "$CASE_ERR" ]; then
# /var/lib/jenkins
# shellcheck disable=SC2116
dirNameFa=$(echo ~)
dirName="$dirNameFa/x2ethereumlogs"
if [ ! -d "${dirName}" ]; then
# shellcheck disable=SC2086
mkdir -p ${dirName}
fi
for name in a b c d; do
# shellcheck disable=SC2154
docker cp "${dockerNamePrefix}_ebrelayer${name}_rpc_1":/root/logs/x2Ethereum_relayer.log "$dirName/ebrelayer$name_rpc.log"
done
docker cp "${dockerNamePrefix}_chain33_1":/root/logs/chain33.log "$dirName/chain33_rpc.log"
fi
}
function kill_all_ebrelayer() {
for name in A B C D; do
local ebrelayer="./../build/$name/ebrelayer"
......@@ -348,14 +368,19 @@ function get_inet_addr() {
echo "${inetAddr}"
}
# $1 dockerName
function get_docker_addr() {
local dockerAddr=$(docker inspect "${1}" | jq ".[].NetworkSettings.Networks" | grep "IPAddress" | awk '{ print $2}' | sed 's/\"//g' | sed 's/,//g')
echo "${dockerAddr}"
}
# 更新配置文件 $1 为 BridgeRegistry 合约地址; $2 等待区块 默认10; $3 relayer.toml 地址
function updata_relayer_toml() {
local BridgeRegistry=${1}
local maturityDegree=${2}
local file=${3}
# local chain33Host=$(docker inspect "${NODE3}" | jq ".[].NetworkSettings.Networks.${PROJ}_default.IPAddress" | sed 's/\"//g')
local chain33Host=$(docker inspect "${NODE3}" | jq ".[].NetworkSettings.Networks" | grep "IPAddress" | awk '{ print $2}' | sed 's/\"//g' | sed 's/,//g')
local chain33Host=$(get_docker_addr "${dockerNamePrefix}_chain33_1")
if [[ ${chain33Host} == "" ]]; then
echo -e "${RED}chain33Host is empty${NOC}"
exit_cp_file
......@@ -410,8 +435,15 @@ function updata_relayer_toml_ropston() {
sed -i 's/maturityDegree=10/'maturityDegree="${maturityDegree}"'/g' "${file}"
}
# $1 portRelayer
function updata_docker_relayer_toml() {
local port=20000
local port=$1
local portRelayer=$1
if [ "${portRelayer}" != "20000" ]; then
sed -i 's/20000/'"${portRelayer}"'/g' "./relayer.toml"
sed -i 's/20000/'"${portRelayer}"'/g' "./Dockerfile-x2ethrelay"
fi
for name in b c d; do
local file="./relayer$name.toml"
......@@ -423,7 +455,7 @@ function updata_docker_relayer_toml() {
done
port=$((port + 1))
sed -i 's/20000/'${port}'/g' "${file}"
sed -i 's/'"${portRelayer}"'/'${port}'/g' "${file}"
sed -i 's/x2ethereum/x2ethereum'${name}'/g' "${file}"
......@@ -434,8 +466,7 @@ function updata_docker_relayer_toml() {
local line=$(delete_line_show "${dockerfile}" "COPY relayer.toml relayer.toml")
sed -i ''"${line}"' a COPY relayer'$name'.toml relayer.toml' "${dockerfile}"
line=$(delete_line_show "${dockerfile}" "EXPOSE 20000")
sed -i ''"${line}"' a EXPOSE '$port'' "${dockerfile}"
sed -i 's/'"${portRelayer}"'/'"${port}"'/g' "${dockerfile}"
local dockeryml="./docker-compose-ebrelayer$name.yml"
cp "./docker-compose-ebrelayer.yml" "${dockeryml}"
......@@ -446,8 +477,77 @@ function updata_docker_relayer_toml() {
line=$(delete_line_show "${dockeryml}" "dockerfile: Dockerfile-x2ethrelay")
sed -i ''"${line}"' a \ \ \ \ \ \ dockerfile: Dockerfile-x2ethrelay'$name'' "${dockeryml}"
line=$(delete_line_show "${dockeryml}" "20000:20000")
sed -i ''"${line}"' a \ \ \ \ \ \ -\ "'${port}':'${port}'"' "${dockeryml}"
sed -i 's/'"${portRelayer}"'/'${port}'/g' "${dockeryml}"
done
}
# 更新配置文件 $1 为 BridgeRegistry 合约地址; $2 等待区块 默认10; $3 MAIN_HTTP; $4 relayer.toml 地址
function updata_relayer_toml_rpc() {
local BridgeRegistry=${1}
local maturityDegree=${2}
local MAIN_HTTP=${3}
local file=${4}
# shellcheck disable=SC2155
local pushHost=$(get_inet_addr)
if [[ ${pushHost} == "" ]]; then
echo -e "${RED}pushHost is empty${NOC}"
copyErrLogs
fi
# shellcheck disable=SC2155
local line=$(delete_line_show "${file}" "chain33Host")
# 在第 line 行后面 新增合约地址
sed -i ''"${line}"' a chain33Host="'"${MAIN_HTTP}"'"' "${file}"
line=$(delete_line_show "${file}" "pushHost")
sed -i ''"${line}"' a pushHost="http://'"${pushHost}"':20000"' "${file}"
line=$(delete_line_show "${file}" "BridgeRegistry")
sed -i ''"${line}"' a BridgeRegistry="'"${BridgeRegistry}"'"' "${file}"
sed -i 's/EthMaturityDegree=10/'EthMaturityDegree="${maturityDegree}"'/g' "${file}"
sed -i 's/maturityDegree=10/'maturityDegree="${maturityDegree}"'/g' "${file}"
sed -i 's/^EthBlockFetchPeriod=.*/EthBlockFetchPeriod=500/g' "${file}"
sed -i 's/^fetchHeightPeriodMs=.*/fetchHeightPeriodMs=500/g' "${file}"
}
# $1 portRelayer
function updata_docker_relayer_toml_rpc() {
local portRelayer=$1
local port=$1
sed -i 's/20000/'"${portRelayer}"'/g' "./x2ethereum/relayer.toml"
sed -i 's/20000/'"${portRelayer}"'/g' "./x2ethereum/Dockerfile-x2ethrelay"
for name in b c d; do
local file="./x2ethereum/relayer$name.toml"
cp './x2ethereum/relayer.toml' "${file}"
# 删除配置文件中不需要的字段
for deleteName in "deployerPrivateKey" "operatorAddr" "validatorsAddr" "initPowers" "deployerPrivateKey" "deploy"; do
delete_line "${file}" "${deleteName}"
done
port=$((port - 1))
sed -i 's/'"${portRelayer}"'/'${port}'/g' "${file}"
sed -i 's/x2ethereum/x2ethereum'${name}'/g' "${file}"
local dockerfile="./x2ethereum/Dockerfile-x2ethrelay$name"
cp "./x2ethereum/Dockerfile-x2ethrelay" "${dockerfile}"
# shellcheck disable=SC2155
local line=$(delete_line_show "${dockerfile}" "COPY relayer.toml relayer.toml")
sed -i ''"${line}"' a COPY relayer'$name'.toml relayer.toml' "${dockerfile}"
sed -i 's/'"${portRelayer}"'/'"${port}"'/g' "${dockerfile}"
local dockeryml="./x2ethereum/docker-compose-ebrelayer$name.yml"
cp "./x2ethereum/docker-compose-ebrelayer.yml" "${dockeryml}"
sed -i 's/ebrelayera/ebrelayer'${name}'/g' "${dockeryml}"
sed -i 's/Dockerfile-x2ethrelay/Dockerfile-x2ethrelay'${name}'/g' "${dockeryml}"
sed -i 's/'"${portRelayer}"'/'${port}'/g' "${dockeryml}"
done
}
......@@ -515,6 +615,7 @@ function wait_prophecy_finish() {
fi
count=$((count + 1))
if [[ ${count} == 30 ]]; then
set -x
echo -e "${RED}failed to get balance${NOC}"
exit_cp_file
fi
......
......@@ -3,7 +3,6 @@
# shellcheck source=/dev/null
source "./allRelayerTest.sh"
#source "./relayerTest.sh"
source "./perf_test.sh"
function x2ethereum() {
......@@ -15,8 +14,8 @@ function x2ethereum() {
echo "========================== x2ethereum test =========================="
set +e
set -x
AllRelayerMainTest 5
# perf_test_main 10
AllRelayerMainTest 1
perf_test_main 10
echo "========================== x2ethereum test end =========================="
fi
}
#!/usr/bin/env bash
#shellcheck disable=SC2128
#shellcheck source=/dev/null
set -x
source ../dapp-test-common.sh
source "../x2ethereum/publicTest.sh"
sendAddress="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
sendPriKey="0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01"
MAIN_HTTP=""
NODE3=""
chain33SenderAddr="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
# validatorsAddr=["0x92c8b16afd6d423652559c6e266cbe1c29bfd84f", "0x0df9a824699bc5878232c9e612fe1a5346a5a368", "0xcb074cb21cdddf3ce9c3c0a7ac4497d633c9d9f1", "0xd9dab021e74ecf475788ed7b61356056b2095830"]
ethValidatorAddrKeyA="3fa21584ae2e4fd74db9b58e2386f5481607dfa4d7ba0617aaa7858e5025dc1e"
......@@ -29,116 +28,14 @@ ethReceiverAddrKey1="355b876d7cbcb930d5dfab767f66336ce327e082cbaa1877210c1bae89b
ethReceiverAddr2="0x0c05ba5c230fdaa503b53702af1962e08d0c60bf"
#ethReceiverAddrKey2="9dc6df3a8ab139a54d8a984f54958ae0661f880229bf3bdbb886b87d58b56a08"
maturityDegree=5
portRelayer=19999
ethUrl=""
CLIA_HTTP="http://127.0.0.1:9901"
CLIB_HTTP="http://127.0.0.1:9902"
CLIC_HTTP="http://127.0.0.1:9903"
CLID_HTTP="http://127.0.0.1:9904"
# 更新 B C D 的配置文件
function updata_all_relayer_toml_rpc() {
local port=9901
local port2=20000
for name in B C D; do
local file="./x2ethereum/$name/relayer.toml"
cp './x2ethereum/A/relayer.toml' "${file}"
cp './x2ethereum/A/ebrelayer' "./x2ethereum/$name/ebrelayer"
# 删除配置文件中不需要的字段
for deleteName in "deployerPrivateKey" "operatorAddr" "validatorsAddr" "initPowers" "deployerPrivateKey" "deploy"; do
delete_line "${file}" "${deleteName}"
done
# 替换端口
port=$((port + 1))
sed -i 's/localhost:9901/localhost:'${port}'/g' "${file}"
port2=$((port2 + 1))
sed -i 's/20000/'${port2}'/g' "${file}"
sed -i 's/x2ethereum/x2ethereum'${name}'/g' "${file}"
done
}
# 更新配置文件 $1 为 BridgeRegistry 合约地址; $2 等待区块 默认10; $3 relayer.toml 地址
function updata_relayer_toml_rpc() {
local BridgeRegistry=${1}
local maturityDegree=${2}
local file=${3}
# shellcheck disable=SC2155
local pushHost=$(ifconfig wlp2s0 | grep "inet " | awk '{ print $2}' | awk -F: '{print $2}')
if [[ ${pushHost} == "" ]]; then
pushHost=$(ifconfig wlp2s0 | grep "inet " | awk '{ print $2}')
if [[ ${pushHost} == "" ]]; then
pushHost=$(ifconfig eth0 | grep "inet " | awk '{ print $2}' | awk -F: '{print $2}')
if [[ ${pushHost} == "" ]]; then
pushHost=$(ifconfig eth0 | grep "inet " | awk '{ print $2}')
if [[ ${pushHost} == "" ]]; then
ip addr show eth0
pushHost=$(ip addr show eth0 | grep "inet " | awk '{ print $2}' | head -c-4)
fi
fi
fi
fi
if [[ ${pushHost} == "" ]]; then
echo -e "${RED}pushHost is empty${NOC}"
exit 1
fi
# shellcheck disable=SC2155
local line=$(delete_line_show "${file}" "chain33Host")
# 在第 line 行后面 新增合约地址
sed -i ''"${line}"' a chain33Host="'"${MAIN_HTTP}"'"' "${file}"
line=$(delete_line_show "${file}" "pushHost")
sed -i ''"${line}"' a pushHost="http://'"${pushHost}"':20000"' "${file}"
line=$(delete_line_show "${file}" "BridgeRegistry")
sed -i ''"${line}"' a BridgeRegistry="'"${BridgeRegistry}"'"' "${file}"
sed -i 's/EthMaturityDegree=10/'EthMaturityDegree="${maturityDegree}"'/g' "${file}"
sed -i 's/maturityDegree=10/'maturityDegree="${maturityDegree}"'/g' "${file}"
sed -i 's/^EthBlockFetchPeriod=.*/EthBlockFetchPeriod=500/g' "${file}"
sed -i 's/^fetchHeightPeriodMs=.*/fetchHeightPeriodMs=500/g' "${file}"
}
function copyErrLogs() {
if [ -n "$CASE_ERR" ]; then
# /var/lib/jenkins
# shellcheck disable=SC2116
dirNameFa=$(echo ~)
dirName="$dirNameFa/x2ethereumlogs"
if [ ! -d "${dirName}" ]; then
# shellcheck disable=SC2086
mkdir -p ${dirName}
fi
for name in A B C D; do
cp "./x2ethereum/$name/ebrelayer.log" "$dirName/rpc_ebrelayer$name.log"
done
pwd
docker cp "${NODE3}":/root/logs/chain33.log "$dirName/rpc_chain33.log"
# oldIFS=$IFS
# IFS=//
# # shellcheck disable=SC2207
# arrpwd=($(pwd))
# if [ ${#arrpwd[@]} -ge 3 ]; then
# i=$((${#arrpwd[@]} - 3))
# # shellcheck disable=SC2116
# # shellcheck disable=SC2086
# dockerName=$(echo ${arrpwd[$i]})
# docker cp "${dockerName}_chain33_1":/root/logs/chain33.log "$dirName/rpc_chain33.log"
# fi
# IFS=$oldIFS
fi
}
# $1 sendAddress, $2 balance
function queryExecBalance() {
local resp=""
......@@ -165,7 +62,7 @@ function queryChain33Balance() {
# $1 req , $2 balance
function queryRelayerBalance() {
chain33_Http "${1}" ${CLIA_HTTP} '(.error|not) and (.result != null)' "GetBalance" ".result.balance"
chain33_Http "${1}" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "GetBalance" ".result.balance"
if [ "${RETURN_RESP}" != "${2}" ]; then
echo_rst "queryRelayerBalance" "1" "${RETURN_RESP} != ${2}"
copyErrLogs
......@@ -186,32 +83,81 @@ function queryChain33X2ethBalance() {
function StartRelayerAndDeploy() {
echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
for name in A B C D; do
local ebrelayer="./x2ethereum/$name/ebrelayer"
kill_ebrelayer "${ebrelayer}"
cp ../x2ethereum/* ./x2ethereum/
for dockerName in ganachetest ebrelayera ebrelayerb ebrelayerc ebrelayerd; do
line=$(delete_line_show "./x2ethereum/docker-compose-x2ethereum.yml" "${dockerName}:")
sed -i ''"${line}"' a \ \ '${dockerName}'_rpc:' "./x2ethereum/docker-compose-x2ethereum.yml"
done
sleep 1
rm -rf './x2ethereum/A' './x2ethereum/B' './x2ethereum/C' './x2ethereum/D'
mkdir './x2ethereum/A' './x2ethereum/B' './x2ethereum/C' './x2ethereum/D'
cp '../x2ethereum/relayer.toml' './x2ethereum/A/relayer.toml'
cp '../x2ethereum/ebrelayer' './x2ethereum/A/ebrelayer'
docker-compose -f ./x2ethereum/docker-compose-x2ethereum.yml up --build -d
sleep 5
# change EthProvider url
dockerAddr=$(get_docker_addr "${dockerNamePrefix}_ganachetest_rpc_1")
ethUrl="http://${dockerAddr}:8545"
# shellcheck disable=SC2155
local line=$(delete_line_show "./x2ethereum/relayer.toml" "EthProvider=\"ws:")
sed -i ''"${line}"' a EthProvider="ws://'"${dockerAddr}"':8545/"' "./x2ethereum/relayer.toml"
line=$(delete_line_show "./x2ethereum/relayer.toml" "EthProviderCli=\"http:")
sed -i ''"${line}"' a EthProviderCli="http://'"${dockerAddr}"':8545"' "./x2ethereum/relayer.toml"
start_trufflesuite
start_ebrelayer "./x2ethereum/A/ebrelayer" "./x2ethereum/A/ebrelayer.log"
grep_port=$(netstat -tlpn | grep "\b${portRelayer}\b")
while [ -n "$grep_port" ]; do
echo "port $portRelayer is in use"
portRelayer=$((portRelayer - 4))
grep_port=$(netstat -tlpn | grep "\b${portRelayer}\b")
done
line=$(delete_line_show "./x2ethereum/docker-compose-ebrelayer.yml" "20000:20000")
sed -i ''"${line}"' a \ \ \ \ \ \ -\ "'${portRelayer}':'${portRelayer}'"' "./x2ethereum/docker-compose-ebrelayer.yml"
line=$(delete_line_show "./x2ethereum/docker-compose-ebrelayer.yml" "ebrelayera:")
sed -i ''"${line}"' a \ \ ebrelayera_rpc:' "./x2ethereum/docker-compose-ebrelayer.yml"
line=$(delete_line_show "./x2ethereum/relayer.toml" "localhost:9901")
sed -i ''"${line}"' a JrpcBindAddr=":9901"' "./x2ethereum/relayer.toml"
docker-compose -f ./x2ethereum/docker-compose-ebrelayer.yml up --build -d
sleep 1
ebrelayeraRpcHost=$(get_docker_addr "${dockerNamePrefix}_ebrelayera_rpc_1")
if [[ ${ebrelayeraRpcHost} == "" ]]; then
echo -e "${RED}ebrelayeraRpcHost a is empty${NOC}"
copyErrLogs
fi
CLIA_HTTP="http://${ebrelayeraRpcHost}:9901"
# 部署合约
InitAndDeploy
# 获取 BridgeRegistry 地址
local req='{"method":"Manager.ShowBridgeRegistryAddr","params":[{}]}'
chain33_Http "$req" ${CLIA_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result.addr"
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "$FUNCNAME" ".result.addr"
local BridgeRegistry="$RETURN_RESP"
kill_ebrelayer "./x2ethereum/A/ebrelayer"
docker-compose -f ./x2ethereum/docker-compose-ebrelayer.yml down
# 修改 relayer.toml 配置文件
updata_relayer_toml_rpc "${BridgeRegistry}" "${maturityDegree}" "./x2ethereum/A/relayer.toml"
updata_all_relayer_toml_rpc
updata_relayer_toml_rpc "${BridgeRegistry}" "${maturityDegree}" "${MAIN_HTTP}" "./x2ethereum/relayer.toml"
updata_docker_relayer_toml_rpc ${portRelayer}
docker-compose -f "./x2ethereum/docker-compose-ebrelayer.yml" up --build -d
for name in b c d; do
docker-compose -f "./x2ethereum/docker-compose-ebrelayer$name.yml" down
docker-compose -f "./x2ethereum/docker-compose-ebrelayer$name.yml" up --build -d
done
sleep 1
ebrelayeraRpcHost=$(get_docker_addr "${dockerNamePrefix}_ebrelayera_rpc_1")
CLIA_HTTP="http://${ebrelayeraRpcHost}:9901"
ebrelayeraRpcHost=$(get_docker_addr "${dockerNamePrefix}_ebrelayerb_rpc_1")
CLIB_HTTP="http://${ebrelayeraRpcHost}:9901"
ebrelayeraRpcHost=$(get_docker_addr "${dockerNamePrefix}_ebrelayerc_rpc_1")
CLIC_HTTP="http://${ebrelayeraRpcHost}:9901"
ebrelayeraRpcHost=$(get_docker_addr "${dockerNamePrefix}_ebrelayerd_rpc_1")
CLID_HTTP="http://${ebrelayeraRpcHost}:9901"
echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}"
}
......@@ -219,13 +165,13 @@ function StartRelayerAndDeploy() {
function InitAndDeploy() {
echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
local req='{"method":"Manager.SetPassphase","params":[{"Passphase":"123456hzj"}]}'
chain33_Http "$req" ${CLIA_HTTP} '(.error|not) and (.result != null)' "SetPassphase" ".result"
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "SetPassphase" ".result"
local req='{"method":"Manager.Unlock","params":["123456hzj"]}'
chain33_Http "$req" ${CLIA_HTTP} '(.error|not) and (.result != null)' "Unlock" ".result"
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "Unlock" ".result"
local req='{"method":"Manager.DeployContrcts","params":[{}]}'
chain33_Http "$req" ${CLIA_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}"
}
......@@ -278,41 +224,35 @@ function InitChain33Vilators() {
function EthImportKey() {
echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
local port=9901
# 重启 ebrelayer 并解锁
for name in A B C D; do
start_ebrelayer "./x2ethereum/$name/ebrelayer" "./x2ethereum/$name/ebrelayer.log"
local CLI_HTTP="http://127.0.0.1:${port}"
if [ "${name}" != "A" ]; then
# 解锁
local req='{"method":"Manager.SetPassphase","params":[{"Passphase":"123456hzj"}]}'
chain33_Http "$req" ${CLI_HTTP} '(.error|not) and (.result != null)' "SetPassphase" ".result"
fi
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "SetPassphase" ".result"
chain33_Http "$req" "${CLIB_HTTP}" '(.error|not) and (.result != null)' "SetPassphase" ".result"
chain33_Http "$req" "${CLIC_HTTP}" '(.error|not) and (.result != null)' "SetPassphase" ".result"
chain33_Http "$req" "${CLID_HTTP}" '(.error|not) and (.result != null)' "SetPassphase" ".result"
req='{"method":"Manager.Unlock","params":["123456hzj"]}'
chain33_Http "$req" ${CLI_HTTP} '(.error|not) and (.result != null)' "Unlock" ".result"
port=$((port + 1))
done
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "Unlock" ".result"
chain33_Http "$req" "${CLIB_HTTP}" '(.error|not) and (.result != null)' "Unlock" ".result"
chain33_Http "$req" "${CLIC_HTTP}" '(.error|not) and (.result != null)' "Unlock" ".result"
chain33_Http "$req" "${CLID_HTTP}" '(.error|not) and (.result != null)' "Unlock" ".result"
local req='{"method":"Manager.ImportChain33PrivateKey4EthRelayer","params":["'${chain33ValidatorKey1}'"]}'
chain33_Http "$req" ${CLIA_HTTP} '(.error|not) and (.result != null)' "ImportChain33PrivateKey4EthRelayer" ".result"
req='{"method":"Manager.ImportChain33PrivateKey4EthRelayer","params":["'${chain33ValidatorKey1}'"]}'
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "ImportChain33PrivateKey4EthRelayer" ".result"
req='{"method":"Manager.ImportChain33PrivateKey4EthRelayer","params":["'${chain33ValidatorKey2}'"]}'
chain33_Http "$req" ${CLIB_HTTP} '(.error|not) and (.result != null)' "ImportChain33PrivateKey4EthRelayer" ".result"
chain33_Http "$req" "${CLIB_HTTP}" '(.error|not) and (.result != null)' "ImportChain33PrivateKey4EthRelayer" ".result"
req='{"method":"Manager.ImportChain33PrivateKey4EthRelayer","params":["'${chain33ValidatorKey3}'"]}'
chain33_Http "$req" ${CLIC_HTTP} '(.error|not) and (.result != null)' "ImportChain33PrivateKey4EthRelayer" ".result"
chain33_Http "$req" "${CLIC_HTTP}" '(.error|not) and (.result != null)' "ImportChain33PrivateKey4EthRelayer" ".result"
req='{"method":"Manager.ImportChain33PrivateKey4EthRelayer","params":["'${chain33ValidatorKey4}'"]}'
chain33_Http "$req" ${CLID_HTTP} '(.error|not) and (.result != null)' "ImportChain33PrivateKey4EthRelayer" ".result"
chain33_Http "$req" "${CLID_HTTP}" '(.error|not) and (.result != null)' "ImportChain33PrivateKey4EthRelayer" ".result"
req='{"method":"Manager.ImportChain33RelayerPrivateKey","params":[{"privateKey":"'${ethValidatorAddrKeyA}'"}]}'
chain33_Http "$req" ${CLIA_HTTP} '(.error|not) and (.result != null)' "ImportChain33RelayerPrivateKey" ".result"
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "ImportChain33RelayerPrivateKey" ".result"
req='{"method":"Manager.ImportChain33RelayerPrivateKey","params":[{"privateKey":"'${ethValidatorAddrKeyB}'"}]}'
chain33_Http "$req" ${CLIB_HTTP} '(.error|not) and (.result != null)' "ImportChain33RelayerPrivateKey" ".result"
chain33_Http "$req" "${CLIB_HTTP}" '(.error|not) and (.result != null)' "ImportChain33RelayerPrivateKey" ".result"
req='{"method":"Manager.ImportChain33RelayerPrivateKey","params":[{"privateKey":"'${ethValidatorAddrKeyC}'"}]}'
chain33_Http "$req" ${CLIC_HTTP} '(.error|not) and (.result != null)' "ImportChain33RelayerPrivateKey" ".result"
chain33_Http "$req" "${CLIC_HTTP}" '(.error|not) and (.result != null)' "ImportChain33RelayerPrivateKey" ".result"
req='{"method":"Manager.ImportChain33RelayerPrivateKey","params":[{"privateKey":"'${ethValidatorAddrKeyD}'"}]}'
chain33_Http "$req" ${CLID_HTTP} '(.error|not) and (.result != null)' "ImportChain33RelayerPrivateKey" ".result"
chain33_Http "$req" "${CLID_HTTP}" '(.error|not) and (.result != null)' "ImportChain33RelayerPrivateKey" ".result"
echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}"
}
......@@ -321,9 +261,8 @@ function TestChain33ToEthAssets() {
echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
# token4chain33 在 以太坊 上先有 bty
local req='{"method":"Manager.CreateBridgeToken","params":["coins.bty"]}'
chain33_Http "$req" ${CLIA_HTTP} '(.error|not) and (.result != null)' "CreateBridgeToken" ".result.addr"
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "CreateBridgeToken" ".result.addr"
tokenAddrBty=${RETURN_RESP}
# tokenAddrBty="0x9C3D40A44a2F61Ef8D46fa8C7A731C08FB16cCEF"
req='{"method":"Manager.GetBalance","params":[{"owner":"'${ethReceiverAddr1}'","tokenAddr":"'${tokenAddrBty}'"}]}'
queryRelayerBalance "$req" "0"
......@@ -335,20 +274,20 @@ function TestChain33ToEthAssets() {
queryExecBalance "${sendAddress}" "19500000000"
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
req='{"method":"Manager.GetBalance","params":[{"owner":"'${ethReceiverAddr1}'","tokenAddr":"'${tokenAddrBty}'"}]}'
queryRelayerBalance "$req" "5"
# eth burn
req='{"method":"Manager.Burn","params":[{"ownerKey":"'${ethReceiverAddrKey1}'","tokenAddr":"'${tokenAddrBty}'","chain33Receiver":"'${chain33SenderAddr}'","amount":"500000000"}]}'
chain33_Http "$req" ${CLIA_HTTP} '(.error|not) and (.result != null)' "Burn" ".result"
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "Burn" ".result"
req='{"method":"Manager.GetBalance","params":[{"owner":"'${ethReceiverAddr1}'","tokenAddr":"'${tokenAddrBty}'"}]}'
queryRelayerBalance "$req" "0"
# eth 等待 10 个区块
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
queryExecBalance "${chain33SenderAddr}" "500000000"
......@@ -360,7 +299,7 @@ function TestChain33ToEthAssets() {
function TestETH2Chain33Assets() {
echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
local req='{"method":"Manager.ShowBridgeBankAddr","params":[{}]}'
chain33_Http "$req" ${CLIA_HTTP} '(.error|not) and (.result != null)' "ShowBridgeBankAddr" ".result.addr"
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "ShowBridgeBankAddr" ".result.addr"
bridgeBankAddr="${RETURN_RESP}"
req='{"method":"Manager.GetBalance","params":[{"owner":"'${bridgeBankAddr}'","tokenAddr":""}]}'
......@@ -368,19 +307,19 @@ function TestETH2Chain33Assets() {
# eth lock 0.1
req='{"method":"Manager.LockEthErc20Asset","params":[{"ownerKey":"'${ethReceiverAddrKey1}'","tokenAddr":"","amount":"100000000000000000","chain33Receiver":"'${sendAddress}'"}]}'
chain33_Http "$req" ${CLIA_HTTP} '(.error|not) and (.result != null)' "LockEthErc20Asset" ".result"
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "LockEthErc20Asset" ".result"
req='{"method":"Manager.GetBalance","params":[{"owner":"'${bridgeBankAddr}'","tokenAddr":""}]}'
queryRelayerBalance "$req" "0.1"
# eth 等待 10 个区块
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
req='{"method":"Chain33.Query","params":[{"execer":"x2ethereum","funcName":"GetRelayerBalance","payload":{"tokenSymbol":"eth","address":"'${sendAddress}'","tokenAddr":"0x0000000000000000000000000000000000000000"}}]}'
queryChain33X2ethBalance "${req}" "0.1"
req='{"method":"Manager.GetBalance","params":[{"owner":"'${ethReceiverAddr2}'","tokenAddr":""}]}'
chain33_Http "${req}" ${CLIA_HTTP} '(.error|not) and (.result != null)' "GetBalance" ".result.balance"
chain33_Http "${req}" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "GetBalance" ".result.balance"
local balance=${RETURN_RESP}
# burn 0.1
......@@ -390,7 +329,7 @@ function TestETH2Chain33Assets() {
req='{"method":"Chain33.Query","params":[{"execer":"x2ethereum","funcName":"GetRelayerBalance","payload":{"tokenSymbol":"eth","address":"'${sendAddress}'","tokenAddr":"0x0000000000000000000000000000000000000000"}}]}'
queryChain33X2ethBalance "${req}" "0"
eth_block_wait $((maturityDegree + 3))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
req='{"method":"Manager.GetBalance","params":[{"owner":"'${bridgeBankAddr}'","tokenAddr":""}]}'
queryRelayerBalance "$req" "0"
......@@ -406,18 +345,18 @@ function TestETH2Chain33Erc20() {
echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
# token4erc20 在 chain33 上先有 token,同时 mint
local req='{"method":"Manager.CreateERC20Token","params":["testc"]}'
chain33_Http "$req" ${CLIA_HTTP} '(.error|not) and (.result != null)' "CreateERC20Token" ".result.addr"
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "CreateERC20Token" ".result.addr"
tokenAddr="${RETURN_RESP}"
# 先铸币 1000
req='{"method":"Manager.MintErc20","params":[{"owner":"'${ethReceiverAddr1}'","tokenAddr":"'${tokenAddr}'","amount":"100000000000"}]}'
chain33_Http "$req" ${CLIA_HTTP} '(.error|not) and (.result != null)' "MintErc20" ".result.addr"
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "MintErc20" ".result.addr"
req='{"method":"Manager.GetBalance","params":[{"owner":"'${ethReceiverAddr1}'","tokenAddr":"'${tokenAddr}'"}]}'
queryRelayerBalance "$req" "1000"
local req='{"method":"Manager.ShowBridgeBankAddr","params":[{}]}'
chain33_Http "$req" ${CLIA_HTTP} '(.error|not) and (.result != null)' "ShowBridgeBankAddr" ".result.addr"
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "ShowBridgeBankAddr" ".result.addr"
bridgeBankAddr="${RETURN_RESP}"
req='{"method":"Manager.GetBalance","params":[{"owner":"'${bridgeBankAddr}'","tokenAddr":"'${tokenAddr}'"}]}'
......@@ -425,7 +364,7 @@ function TestETH2Chain33Erc20() {
# lock 100
req='{"method":"Manager.LockEthErc20Asset","params":[{"ownerKey":"'${ethReceiverAddrKey1}'","tokenAddr":"'${tokenAddr}'","amount":"10000000000","chain33Receiver":"'${chain33Validator1}'"}]}'
chain33_Http "$req" ${CLIA_HTTP} '(.error|not) and (.result != null)' "LockEthErc20Asset" ".result"
chain33_Http "$req" "${CLIA_HTTP}" '(.error|not) and (.result != null)' "LockEthErc20Asset" ".result"
req='{"method":"Manager.GetBalance","params":[{"owner":"'${ethReceiverAddr1}'","tokenAddr":"'${tokenAddr}'"}]}'
queryRelayerBalance "$req" "900"
......@@ -434,7 +373,7 @@ function TestETH2Chain33Erc20() {
queryRelayerBalance "$req" "100"
# eth 等待 10 个区块
eth_block_wait $((maturityDegree + 2))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
req='{"method":"Chain33.Query","params":[{"execer":"x2ethereum","funcName":"GetRelayerBalance","payload":{"tokenSymbol":"testc","address":"'${chain33Validator1}'","tokenAddr":"'${tokenAddr}'"}}]}'
queryChain33X2ethBalance "${req}" "100"
......@@ -447,7 +386,7 @@ function TestETH2Chain33Erc20() {
req='{"method":"Chain33.Query","params":[{"execer":"x2ethereum","funcName":"GetRelayerBalance","payload":{"tokenSymbol":"testc","address":"'${chain33Validator1}'","tokenAddr":"'${tokenAddr}'"}}]}'
queryChain33X2ethBalance "${req}" "0"
eth_block_wait $((maturityDegree + 3))
eth_block_wait $((maturityDegree + 2)) "${ethUrl}"
req='{"method":"Manager.GetBalance","params":[{"owner":"'${ethReceiverAddr2}'","tokenAddr":"'${tokenAddr}'"}]}'
queryRelayerBalance "$req" "100"
......@@ -459,11 +398,11 @@ function TestETH2Chain33Erc20() {
}
function rpc_test() {
set -x
set +e
set -x
chain33_RpcTestBegin x2ethereum
MAIN_HTTP="$1"
NODE3="$2"
dockerNamePrefix="$2"
echo "main_ip=$MAIN_HTTP"
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
......@@ -477,6 +416,8 @@ function rpc_test() {
TestChain33ToEthAssets
TestETH2Chain33Assets
TestETH2Chain33Erc20
docker-compose -f ./x2ethereum/docker-compose-x2ethereum.yml down
fi
chain33_RpcTestRst x2ethereum "$CASE_ERR"
}
......
......@@ -72,7 +72,6 @@ func addChain33ToEthFlags(cmd *cobra.Command) {
cmd.Flags().Float64P("amount", "a", float64(0), "the amount of this contract want to lock")
_ = cmd.MarkFlagRequired("amount")
}
func burn(cmd *cobra.Command, args []string) {
......
......@@ -65,7 +65,7 @@ func main() {
ctx, cancel := context.WithCancel(context.Background())
var wg sync.WaitGroup
log.Info("db info:", " Dbdriver = ", cfg.SyncTxConfig.Dbdriver, ", DbPath = ", cfg.SyncTxConfig.DbPath, ", DbCache = ", cfg.SyncTxConfig.DbCache)
log.Info("db info:", " Dbdriver = ", cfg.SyncTxConfig.Dbdriver, ", DbPath = ", cfg.SyncTxConfig.DbPath, ", DbCache = ", cfg.SyncTxConfig.DbCache, ", EthProvider = ", cfg.EthProvider)
log.Info("deploy info:", "BridgeRegistry", cfg.BridgeRegistry)
mainlog.Info("db info:", " Dbdriver = ", cfg.SyncTxConfig.Dbdriver, ", DbPath = ", cfg.SyncTxConfig.DbPath, ", DbCache = ", cfg.SyncTxConfig.DbCache)
db := dbm.NewDB("relayer_db_service", cfg.SyncTxConfig.Dbdriver, cfg.SyncTxConfig.DbPath, cfg.SyncTxConfig.DbCache)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment