Commit d756bfcc authored by QM's avatar QM

updata test

parent 0f1093a0
...@@ -17,7 +17,7 @@ go build -i ${FLAG} -v -o "${OUT_DIR}/ebcli_C" -ldflags "-X ${SRC_EBCLI}/buildfl ...@@ -17,7 +17,7 @@ go build -i ${FLAG} -v -o "${OUT_DIR}/ebcli_C" -ldflags "-X ${SRC_EBCLI}/buildfl
go build -i ${FLAG} -v -o "${OUT_DIR}/ebcli_D" -ldflags "-X ${SRC_EBCLI}/buildflags.RPCAddr=http://localhost:9904" "${SRC_EBCLI}" go build -i ${FLAG} -v -o "${OUT_DIR}/ebcli_D" -ldflags "-X ${SRC_EBCLI}/buildflags.RPCAddr=http://localhost:9904" "${SRC_EBCLI}"
cp ../ebrelayer/relayer.toml "${OUT_DIR}/relayer.toml" cp ../ebrelayer/relayer.toml "${OUT_DIR}/relayer.toml"
cp ../ebrelayer/publicTest.sh "${OUT_DIR}/publicTest.sh" cp ../testsh/publicTest.sh "${OUT_DIR}/publicTest.sh"
cp ./build/* "${OUT_DIR}" cp ./build/* "${OUT_DIR}"
OUT_TESTDIR="${1}/dapptest/$strapp" OUT_TESTDIR="${1}/dapptest/$strapp"
......
...@@ -221,9 +221,6 @@ function TestChain33ToEthAssets() { ...@@ -221,9 +221,6 @@ function TestChain33ToEthAssets() {
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr1}" -t "${tokenAddr}") result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr1}" -t "${tokenAddr}")
cli_ret "${result}" "balance" ".balance" "0" cli_ret "${result}" "balance" ".balance" "0"
kill_ebrelayerC
kill_ebrelayerD
# chain33 lock bty # chain33 lock bty
hash=$(${Chain33Cli} send x2ethereum lock -a 5 -t bty -r ${ethReceiverAddr1} -q ${tokenAddr} -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv) hash=$(${Chain33Cli} send x2ethereum lock -a 5 -t bty -r ${ethReceiverAddr1} -q ${tokenAddr} -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
block_wait "${Chain33Cli}" $((maturityDegree + 2)) block_wait "${Chain33Cli}" $((maturityDegree + 2))
...@@ -235,29 +232,176 @@ function TestChain33ToEthAssets() { ...@@ -235,29 +232,176 @@ function TestChain33ToEthAssets() {
eth_block_wait $((maturityDegree + 2)) eth_block_wait $((maturityDegree + 2))
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr1}" -t "${tokenAddr}") result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr1}" -t "${tokenAddr}")
cli_ret "${result}" "balance" ".balance" "5"
# eth burn
result=$(${CLIA} relayer ethereum burn -m 5 -k "${ethReceiverAddrKey1}" -r "${chain33SenderAddr}" -t "${tokenAddr}")
cli_ret "${result}" "burn"
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr1}" -t "${tokenAddr}")
cli_ret "${result}" "balance" ".balance" "0" cli_ret "${result}" "balance" ".balance" "0"
start_ebrelayerC # eth 等待 10 个区块
eth_block_wait $((maturityDegree + 2))
result=$(${Chain33Cli} account balance -a "${chain33SenderAddr}" -e x2ethereum)
balance_ret "${result}" "5"
echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}"
}
# eth to chain33
# 在以太坊上锁定资产,然后在 chain33 上铸币,针对 eth 资产
function TestETH2Chain33Assets() {
echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
${CLIA} relayer unlock -p 123456hzj
result=$(${CLIA} relayer ethereum bridgeBankAddr)
bridgeBankAddr=$(cli_ret "${result}" "bridgeBankAddr" ".addr")
result=$(${CLIA} relayer ethereum balance -o "${bridgeBankAddr}")
cli_ret "${result}" "balance" ".balance" "0"
# eth lock 0.1
result=$(${CLIA} relayer ethereum lock -m 0.1 -k "${ethReceiverAddrKey1}" -r 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
cli_ret "${result}" "lock"
result=$(${CLIA} relayer ethereum balance -o "${bridgeBankAddr}")
cli_ret "${result}" "balance" ".balance" "0.1"
# eth 等待 10 个区块
eth_block_wait $((maturityDegree + 2))
result=$(${Chain33Cli} x2ethereum balance -s 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -t eth | jq ".res" | jq ".[]")
balance_ret "${result}" "0.1"
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)
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 2
result=$(${CLIA} relayer ethereum balance -o "${bridgeBankAddr}")
cli_ret "${result}" "balance" ".balance" "0"
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr2}")
cli_ret "${result}" "balance" ".balance" $(echo "${balance}+0.1" | bc)
echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}"
}
function TestETH2Chain33Erc20() {
echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
${CLIA} relayer unlock -p 123456hzj
# token4erc20 在 chain33 上先有 token,同时 mint
tokenSymbol="testc"
result=$(${CLIA} relayer ethereum token4erc20 -s "${tokenSymbol}")
tokenAddr=$(cli_ret "${result}" "token4erc20" ".addr")
# 先铸币 1000
result=$(${CLIA} relayer ethereum mint -m 1000 -o "${ethReceiverAddr1}" -t "${tokenAddr}")
cli_ret "${result}" "mint"
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr1}" -t "${tokenAddr}")
cli_ret "${result}" "balance" ".balance" "1000"
result=$(${CLIA} relayer ethereum bridgeBankAddr)
bridgeBankAddr=$(cli_ret "${result}" "bridgeBankAddr" ".addr")
result=$(${CLIA} relayer ethereum balance -o "${bridgeBankAddr}" -t "${tokenAddr}")
cli_ret "${result}" "balance" ".balance" "0"
# lock 100
result=$(${CLIA} relayer ethereum lock -m 100 -k "${ethReceiverAddrKey1}" -r "${chain33Validator1}" -t "${tokenAddr}")
cli_ret "${result}" "lock"
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr1}" -t "${tokenAddr}") result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr1}" -t "${tokenAddr}")
cli_ret "${result}" "balance" ".balance" "900"
result=$(${CLIA} relayer ethereum balance -o "${bridgeBankAddr}" -t "${tokenAddr}")
cli_ret "${result}" "balance" ".balance" "100"
# eth 等待 10 个区块
eth_block_wait $((maturityDegree + 2))
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}")
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 2
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr2}" -t "${tokenAddr}")
cli_ret "${result}" "balance" ".balance" "100"
result=$(${CLIA} relayer ethereum balance -o "${bridgeBankAddr}" -t "${tokenAddr}")
cli_ret "${result}" "balance" ".balance" "0"
echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}"
}
function TestChain33ToEthAssetsKill() {
echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
tokenAddr="0x9C3D40A44a2F61Ef8D46fa8C7A731C08FB16cCEF"
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr2}" -t "${tokenAddr}")
ok=$(echo "${result}" | jq -r .isOK)
if [[ ${ok} != "true" ]]; then
# token4chain33 在 以太坊 上先有 bty
result=$(${CLIA} relayer ethereum token4chain33 -s bty)
tokenAddr=$(cli_ret "${result}" "token4chain33" ".addr")
fi
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr1}" -t "${tokenAddr}")
cli_ret "${result}" "balance" ".balance" "0"
kill_ebrelayerC
kill_ebrelayerD
# chain33 lock bty
hash=$(${Chain33Cli} send x2ethereum lock -a 5 -t bty -r ${ethReceiverAddr2} -q ${tokenAddr} -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv)
block_wait "${Chain33Cli}" $((maturityDegree + 2))
check_tx "${Chain33Cli}" "${hash}"
eth_block_wait $((maturityDegree + 2))
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr2}" -t "${tokenAddr}")
cli_ret "${result}" "balance" ".balance" "0"
start_ebrelayerC
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr2}" -t "${tokenAddr}")
cli_ret "${result}" "balance" ".balance" "5" cli_ret "${result}" "balance" ".balance" "5"
# eth burn # eth burn
result=$(${CLIA} relayer ethereum burn -m 5 -k "${ethReceiverAddrKey1}" -r "${chain33SenderAddr}" -t "${tokenAddr}") result=$(${CLIA} relayer ethereum burn -m 5 -k "${ethReceiverAddrKey2}" -r "${chain33Validator1}" -t "${tokenAddr}")
cli_ret "${result}" "burn" cli_ret "${result}" "burn"
result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr1}" -t "${tokenAddr}") result=$(${CLIA} relayer ethereum balance -o "${ethReceiverAddr2}" -t "${tokenAddr}")
cli_ret "${result}" "balance" ".balance" "0" cli_ret "${result}" "balance" ".balance" "0"
# eth 等待 10 个区块 # eth 等待 10 个区块
eth_block_wait $((maturityDegree + 2)) eth_block_wait $((maturityDegree + 2))
result=$(${Chain33Cli} account balance -a "${chain33SenderAddr}" -e x2ethereum) result=$(${Chain33Cli} account balance -a "${chain33Validator1}" -e x2ethereum)
balance_ret "${result}" "0" balance_ret "${result}" "0"
start_ebrelayerD start_ebrelayerD
result=$(${Chain33Cli} account balance -a "${chain33SenderAddr}" -e x2ethereum) result=$(${Chain33Cli} account balance -a "${chain33Validator1}" -e x2ethereum)
balance_ret "${result}" "5" balance_ret "${result}" "5"
echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}" echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}"
...@@ -265,7 +409,7 @@ function TestChain33ToEthAssets() { ...@@ -265,7 +409,7 @@ function TestChain33ToEthAssets() {
# eth to chain33 # eth to chain33
# 在以太坊上锁定资产,然后在 chain33 上铸币,针对 eth 资产 # 在以太坊上锁定资产,然后在 chain33 上铸币,针对 eth 资产
function TestETH2Chain33Assets() { function TestETH2Chain33AssetsKill() {
echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}" echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
${CLIA} relayer unlock -p 123456hzj ${CLIA} relayer unlock -p 123456hzj
...@@ -324,12 +468,12 @@ function TestETH2Chain33Assets() { ...@@ -324,12 +468,12 @@ function TestETH2Chain33Assets() {
echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}" echo -e "${GRE}=========== $FUNCNAME end ===========${NOC}"
} }
function TestETH2Chain33Erc20() { function TestETH2Chain33Erc20Kill() {
echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}" echo -e "${GRE}=========== $FUNCNAME begin ===========${NOC}"
${CLIA} relayer unlock -p 123456hzj ${CLIA} relayer unlock -p 123456hzj
# token4erc20 在 chain33 上先有 token,同时 mint # token4erc20 在 chain33 上先有 token,同时 mint
tokenSymbol="testc" tokenSymbol="testcc"
result=$(${CLIA} relayer ethereum token4erc20 -s "${tokenSymbol}") result=$(${CLIA} relayer ethereum token4erc20 -s "${tokenSymbol}")
tokenAddr=$(cli_ret "${result}" "token4erc20" ".addr") tokenAddr=$(cli_ret "${result}" "token4erc20" ".addr")
...@@ -407,12 +551,20 @@ function MainTest() { ...@@ -407,12 +551,20 @@ function MainTest() {
echo -e "${GRE}maturityDegree is ${maturityDegree} ${NOC}" echo -e "${GRE}maturityDegree is ${maturityDegree} ${NOC}"
fi fi
# init
StartRelayerAndDeploy StartRelayerAndDeploy
InitChain33Vilators InitChain33Vilators
EthImportKey EthImportKey
# test
TestChain33ToEthAssets TestChain33ToEthAssets
TestETH2Chain33Assets TestETH2Chain33Assets
TestETH2Chain33Erc20 TestETH2Chain33Erc20
# kill relayer and start relayer
TestChain33ToEthAssetsKill
TestETH2Chain33AssetsKill
TestETH2Chain33Erc20Kill
echo -e "${GRE}===========allTest $FUNCNAME end ===========${NOC}" echo -e "${GRE}===========allTest $FUNCNAME end ===========${NOC}"
} }
version: '3'
#services:
# ganachetest:
# build:
# context: .
...@@ -368,11 +368,11 @@ function updata_all_relayer_toml2() { ...@@ -368,11 +368,11 @@ function updata_all_relayer_toml2() {
function start_trufflesuite() { function start_trufflesuite() {
# 如果原来存在先删除 # 如果原来存在先删除
local ganacheName=ganachetest local ganacheName=ganachetest
local isExit=$(docker inspect ${ganacheName} | jq ".[]") #local isExit=$(docker inspect ${ganacheName} | jq ".[]" | jq ".Id")
if [[ ${isExit} != "" ]]; then #if [[ ${isExit} != "" ]]; then
docker stop ${ganacheName} docker stop ${ganacheName}
docker rm ${ganacheName} docker rm ${ganacheName}
fi #fi
# 启动 eth # 启动 eth
docker run -d --name ${ganacheName} -p 7545:8545 -l eth_test trufflesuite/ganache-cli:latest -a 10 --debug -b 5 -m "coast bar giraffe art venue decide symbol law visual crater vital fold" docker run -d --name ${ganacheName} -p 7545:8545 -l eth_test trufflesuite/ganache-cli:latest -a 10 --debug -b 5 -m "coast bar giraffe art venue decide symbol law visual crater vital fold"
......
...@@ -376,4 +376,4 @@ function main() { ...@@ -376,4 +376,4 @@ function main() {
} }
# $1 等待区块 默认10 # $1 等待区块 默认10
main "${1}" main 1
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