Commit 3faf2dca authored by harrylee's avatar harrylee Committed by vipwzw

update code for autotest

parent a7821a40
......@@ -26,12 +26,7 @@ build/para.sh
build/system-test-rpc.sh
build/ci
build/autotest/*
!build/autotest/copy-autotest.sh
!build/autotest/build.sh
!build/autotest/local/local-autotest.sh
!build/autotest/jerkinsci/*.yml
!build/autotest/jerkinsci/*.sh
!build/autotest/jerkinsci/Dockerfile-autotest
.DS_Store
logs/
build/wallet
......@@ -52,4 +47,3 @@ build/sendstock
build/sendstock.toml
build/*.csv
......@@ -46,20 +46,23 @@ vet:
autotest: ## build autotest binary
@cd build/autotest && bash ./build.sh ${CHAIN33_PATH} && cd ../../
@if [ -n "$(dapp)" ]; then \
# && rm -rf build/autotest/local \
# && cp -r $(CHAIN33_PATH)/build/autotest/local $(CHAIN33_PATH)/build/autotest/*.sh build/autotest \
cd build/autotest && chmod 755 local && bash ./copy-autotest.sh local \
&& cd local && chmod 640 *.toml && bash ./local-autotest.sh $(dapp) \
chmod -R 755 build/autotest/local \
&& rm -rf build/autotest/local \
&& cp -r $(CHAIN33_PATH)/build/autotest/local $(CHAIN33_PATH)/build/autotest/*.sh build/autotest \
&& cd build/autotest && chmod -R 755 local && chmod 755 *.sh && bash ./copy-autotest.sh local \
&& cd local && bash ./local-autotest.sh $(dapp) \
&& cd ../../../; fi
autotest_ci: autotest ## autotest ci
# @rm -rf build/autotest/jerkinsci \
# && cp -r $(CHAIN33_PATH)/build/autotest/jerkinsci $(CHAIN33_PATH)/build/autotest/*.sh build/autotest/ \
cd build/autotest && bash ./copy-autotest.sh jerkinsci/temp$(proj) \
@chmod -R 755 build/autotest/jerkinsci \
&& rm -rf build/autotest/jerkinsci \
&& cp -r $(CHAIN33_PATH)/build/autotest/jerkinsci $(CHAIN33_PATH)/build/autotest/*.sh build/autotest/ \
cd build/autotest &&chmod -R 755 jerkinsci && chmod 755 *.sh && bash ./copy-autotest.sh jerkinsci/temp$(proj) \
&& cd jerkinsci && bash ./jerkins-ci-autotest.sh $(proj) && cd ../../../
autotest_tick: autotest ## run with ticket mining
@rm -rf build/autotest/gitlabci \
@chmod -R 755 build/autotest/gitlabci \
&& rm -rf build/autotest/gitlabci \
&& cp -r $(CHAIN33_PATH)/build/autotest/gitlabci $(CHAIN33_PATH)/build/autotest/*.sh build/autotest/ \
&& cd build/autotest && bash ./copy-autotest.sh gitlabci \
&& cd build/autotest &&chmod -R 755 gitlabci && chmod 755 *.sh && bash ./copy-autotest.sh gitlabci \
&& cd gitlabci && bash ./gitlab-ci-autotest.sh build && cd ../../../
updatemod:
......
......@@ -20,14 +20,20 @@ https://camo.githubusercontent.com/915b7be44ada53c290eb157634330494ebe3e30a/6874
#### 支持make file的平台
```
// 开启mod功能
export GO111MODULE=on
//国内用户需要导入阿里云代理,用于下载依赖包
export GOPROXY=https://mirrors.aliyun.com/goproxy
make
```
就可以完成编译安装
```
注意:国内用户需要导入一下代理,才能获取依赖包,mod功能在Makefile中默认开启
```
## 运行
```
......
#!/usr/bin/env bash
set -e
set -o pipefail
#set -o verbose
#set -o xtrace
# os: ubuntu16.04 x64
#chain33 dapp autotest root directory
declare -a Chain33AutoTestDirs=("system" "plugin" "vendor/github.com/33cn/chain33/system" "vendor/github.com/33cn/plugin/plugin")
#copy auto test to specific directory
# check args
if [ "$#" -lt 1 ]; then
echo "Usage: $0 directory list"
exit 1
fi
function copyAutoTestConfig() {
echo "#copy auto test config to path \"$1\""
local AutoTestConfigFile="$1/autotest.toml"
#pre config auto test
{
echo 'cliCmd="./chain33-cli"'
echo "checkTimeout=60"
} >"${AutoTestConfigFile}"
#copy all the dapp test case config file
for rootDir in "${Chain33AutoTestDirs[@]}"; do
if [ ! -d ../../"${rootDir}" ]; then
continue
fi
testDirArr=$(find ../../"${rootDir}" -type d -name autotest)
for autotest in ${testDirArr}; do
dapp=$(basename "$(dirname "${autotest}")")
dappConfig=${autotest}/${dapp}.toml
#make sure dapp have auto test config
if [ -e "${dappConfig}" ]; then
cp "${dappConfig}" "$1"/
#add dapp test case config
{
echo "[[TestCaseFile]]"
echo "dapp=\"$dapp\""
echo "filename=\"$dapp.toml\""
} >>"${AutoTestConfigFile}"
fi
done
done
}
function copyChain33() {
echo "# copy chain33 bin to path \"$1\", make sure build chain33"
cp ../chain33 ../chain33-cli ../chain33.toml "$1"
cp "${CHAIN33_PATH}"/cmd/chain33/chain33.test.toml "$1"
}
echo "=======CHAIN33_PATH:${CHAIN33_PATH}===="
for dir in "$@"; do
#check dir exist
if [ ! -d "${dir}" ]; then
mkdir "${dir}"
fi
cp autotest "${dir}"
copyAutoTestConfig "${dir}"
copyChain33 "${dir}"
echo "# all copy have done!"
done
......@@ -33,6 +33,7 @@ function down() {
# shellchk not recommend the first way
# remains=( $(docker-compose ps -q | awk '{print $1}') )
mapfile -t remains < <(docker-compose ps -q | awk '{print $1}')
# shellcheck disable=SC2154
num=${#remains[@]}
echo "container num=$num"
if [ "$num" -gt 0 ]; then
......
......@@ -3,7 +3,7 @@ module github.com/33cn/plugin
go 1.12
require (
github.com/33cn/chain33 v0.0.0-20190818024326-42774b0804be
github.com/33cn/chain33 v0.0.0-20190823042135-d05c4b3b53e3
github.com/BurntSushi/toml v0.3.1
github.com/NebulousLabs/Sia v1.3.7
github.com/btcsuite/btcd v0.0.0-20181013004428-67e573d211ac
......
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/33cn/chain33 v0.0.0-20190818024326-42774b0804be h1:CAwVuwS6AuKpws0EcughQYmwiplFcSF4WvAGSwtijQI=
github.com/33cn/chain33 v0.0.0-20190818024326-42774b0804be/go.mod h1:4I8n+Zyf3t0UKM5jjpqJY627Tub62oXkLsdzIv4r6rQ=
github.com/33cn/chain33 v0.0.0-20190823042135-d05c4b3b53e3 h1:MU2A1//oeTZPYXdn0kvwMDevQpboK469+xre8t5VYH4=
github.com/33cn/chain33 v0.0.0-20190823042135-d05c4b3b53e3/go.mod h1:4I8n+Zyf3t0UKM5jjpqJY627Tub62oXkLsdzIv4r6rQ=
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7 h1:PqzgE6kAMi81xWQA2QIVxjWkFHptGgC547vchpUbtFo=
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
......
......@@ -27,7 +27,7 @@ InitLog() {
Log() {
if [ -e ${log_file} ]; then
$(touch ${log_file})
touch ${log_file}
fi
# get current time
local curtime
......@@ -46,35 +46,37 @@ GetInputFile() {
PackageFiles() {
Log "Begin to package the files: ${file}"
$(tar zcf ${package} $file)
tar zcf "${package}" "$file"
}
GetUserNamePasswdAndPath() {
echo "Which way to get environment? 1) Input 2) Config file"
read choice
if [ ${choice} -eq 1 ]; then
if [ "${choice}" -eq 1 ]; then
echo 'Please input the username, password and path of the destination: (such as "ubuntu 123456 /home/ubuntu/chain33")'
read destInfo
username=$(echo ${destInfo} | awk -F ' ' '{print $1}')
password=$(echo ${destInfo} | awk -F ' ' '{print $2}')
remote_dir=$(echo ${destInfo} | awk -F ' ' '{print $3}')
username=$(echo "${destInfo}" | awk -F ' ' '{print $1}')
password=$(echo "${destInfo}" | awk -F ' ' '{print $2}')
remote_dir=$(echo "${destInfo}" | awk -F ' ' '{print $3}')
echo 'Please input ip list of your destination: (such as "192.168.3.143 192.168.3.144 192.168.3.145 192.168.3.146")'
read iplist
index=0
CreateNewConfigFile
for ip in $(echo ${iplist}); do
index=$(expr $index + 1)
echo "[servers.${index}]" >>${config_file}
echo "userName:${username}" >>${config_file}
echo "password:${password}" >>${config_file}
echo "hostIp:${ip}" >>${config_file}
echo "path:${remote_dir}" >>${config_file}
for ip in "${iplist}"; do
index=$((index + 1))
{
echo "[servers.${index}]"
echo "userName:${username}"
echo "password:${password}"
echo "hostIp:${ip}"
echo "path:${remote_dir}"
} >>${config_file}
done
Log "The dest ip is ${ip} and path is ${remote_dir}"
elif [ ${choice} -eq 2 ]; then
elif [ "${choice}" -eq 2 ]; then
ShowConfigInfo
echo "Does the config of destination right?(yes/no)"
......@@ -83,7 +85,7 @@ GetUserNamePasswdAndPath() {
echo "The config file is wrong. You can config it manually."
return 1
fi
elif [ ${choice} -eq 3 ]; then
elif [ "${choice}" -eq 3 ]; then
echo "Wrong input..."
return 2
fi
......@@ -96,14 +98,14 @@ SendFileAndDecompressFile() {
for line in $sections; do
if [[ $line =~ $serverStr ]]; then
index=$(echo $line | awk -F '.' '{print $2}' | awk -F ']' '{print$1}')
getInfoByIndexAndKey $index "userName"
index=$(echo "$line" | awk -F '.' '{print $2}' | awk -F ']' '{print$1}')
getInfoByIndexAndKey "$index" "userName"
username=${info}
getInfoByIndexAndKey $index "password"
getInfoByIndexAndKey "$index" "password"
password=${info}
getInfoByIndexAndKey $index "hostIp"
getInfoByIndexAndKey "$index" "hostIp"
ip=${info}
getInfoByIndexAndKey $index "path"
getInfoByIndexAndKey "$index" "path"
remote_dir=${info}
ExpectCmd "scp ${package} ${username}@${ip}:${remote_dir}"
......@@ -125,8 +127,8 @@ ExpectCmd() {
expect -c "
spawn ${cmd}
expect {
"yes" { send "yes\\r"; exp_continue }
"password" { send "$password\\r" }
\"yes\" { send \"yes\\r\"; exp_continue }
\"password\" { send \"${password}\\r\"}
}
expect eof"
}
......@@ -149,14 +151,14 @@ ShowConfigInfo() {
for line in $sections; do
if [[ $line =~ $serverStr ]]; then
index=$(echo $line | awk -F '.' '{print $2}' | awk -F ']' '{print$1}')
getInfoByIndexAndKey $index "userName"
index=$(echo "$line" | awk -F '.' '{print $2}' | awk -F ']' '{print$1}')
getInfoByIndexAndKey "$index" "userName"
echo "servers.$index: userName->$info"
getInfoByIndexAndKey $index "password"
getInfoByIndexAndKey "$index" "password"
echo "servers.$index: password->$info"
getInfoByIndexAndKey $index "hostIp"
getInfoByIndexAndKey "$index" "hostIp"
echo "servers.$index: hostIp->$info"
getInfoByIndexAndKey $index "path"
getInfoByIndexAndKey "$index" "path"
echo "servers.$index: path->$info"
fi
done
......@@ -168,15 +170,15 @@ getSections() {
getInfoByIndex() {
index=$1
nextIndex=$(expr ${index} + 1)
info=$(cat ${config_file} | sed -n "/^[# ]*\[servers.${index}/,/^[# ]*\[servers.${nextIndex}/p")
nextIndex=$((index + 1))
info=$(sed <${config_file} -n "/^[# ]*\[servers.${index}/,/^[# ]*\[servers.${nextIndex}/p")
}
getInfoByIndexAndKey() {
index=$1
nextIndex=$(expr ${index} + 1)
nextIndex=$((index + 1))
key=$2
info=$(cat ${config_file} | sed -n "/^[# ]*\[servers.${index}/,/^[# ]*\[servers.${nextIndex}/p" | grep -i $key | awk -F ':' '{print $2}')
info=$(sed <${config_file} -n "/^[# ]*\[servers.${index}/,/^[# ]*\[servers.${nextIndex}/p" | grep -i "$key" | awk -F ':' '{print $2}')
}
help() {
......
......@@ -515,7 +515,7 @@ func TestListProposalComment(t *testing.T) {
}
for _, tcase := range testcase {
key := calcCommentHeight(tcase.propID,
dapp.HeightIndexStr(tcase.height, int64(tcase.index)))
dapp.HeightIndexStr(tcase.height, tcase.index))
cur.Height = tcase.height
cur.Index = int32(tcase.index)
value := types.Encode(cur)
......
......@@ -565,7 +565,7 @@ func TestDelMavlData(t *testing.T) {
db := store.GetDB()
db.Set([]byte(mvccPrefix), []byte("value1"))
db.Set(mvccPrefix, []byte("value1"))
db.Set([]byte(fmt.Sprintf("%s123", mvccPrefix)), []byte("value2"))
db.Set([]byte(fmt.Sprintf("%s546", mvccPrefix)), []byte("value3"))
db.Set([]byte(fmt.Sprintf("123%s", mvccPrefix)), []byte("value4"))
......@@ -582,7 +582,7 @@ func TestDelMavlData(t *testing.T) {
}
}
v, err := db.Get([]byte(mvccPrefix))
v, err := db.Get(mvccPrefix)
require.NoError(t, err)
require.Equal(t, []byte("value1"), v)
v, err = db.Get([]byte(fmt.Sprintf("%s123", mvccPrefix)))
......@@ -760,7 +760,7 @@ func TestDeletePrunedMavl(t *testing.T) {
v1, err = store.GetDB().Get([]byte(fmt.Sprintln(hashNodePrefix, "456")))
require.Error(t, err)
require.Equal(t, v1, []uint8([]byte(nil)))
require.Equal(t, v1, []byte(nil))
v2, err := store.GetDB().Get([]byte(fmt.Sprintln(hashNodePrefix, "123")))
require.NoError(t, err)
require.Equal(t, v2, []byte("v1"))
......
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