test(*): add integration test

This commit is contained in:
Aiden X 2020-04-16 00:37:53 +08:00
parent e3a4b447a0
commit 6331259efc
5 changed files with 104 additions and 4 deletions

View File

@ -50,10 +50,30 @@ jobs:
token: ${{secrets.CODECOV_TOKEN}}
file: ./coverage.txt
integration-test:
name: Run integration test
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Run test
run: |
export PATH=$PATH:$(go env GOPATH)/bin
make prepare
cd scripts
bash integration.sh
cd ..
make tester
build:
name: Build project
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
@ -65,3 +85,4 @@ jobs:
- name: Go build
run: go build -v ./cmd/bitxhub

View File

@ -354,7 +354,7 @@ func (x *Interchain) GetIBTPByID(id string) *boltvm.Response {
caller := x.Caller()
if caller != arr[0] || caller != arr[1] {
if caller != arr[0] && caller != arr[1] {
return boltvm.Error("The caller does not have access to this ibtp")
}

79
scripts/integration.sh Normal file
View File

@ -0,0 +1,79 @@
#!/usr/bin/env bash
set -e
CURRENT_PATH=$(pwd)
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
CONFIG_PATH=${PROJECT_PATH}/config
BUILD_PATH=${CURRENT_PATH}/build
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
N=4
function print_blue() {
printf "${BLUE}%s${NC}\n" "$1"
}
# The sed commend with system judging
# Examples:
# sed -i 's/a/b/g' bob.txt => x_replace 's/a/b/g' bob.txt
function x_replace() {
system=$(uname)
if [ "${system}" = "Linux" ]; then
sed -i "$@"
else
sed -i '' "$@"
fi
}
function prepare() {
print_blue "===> Generating $N nodes configuration"
rm -rf "${BUILD_PATH}"
mkdir "${BUILD_PATH}"
for ((i = 1; i < N + 1; i = i + 1)); do
root=${BUILD_PATH}/node${i}
mkdir -p "${root}"
cp -rf "${CURRENT_PATH}"/certs/node${i}/certs "${root}"
cp -rf "${CONFIG_PATH}"/* "${root}"
echo " #!/usr/bin/env bash" >"${root}"/start.sh
echo "./bitxhub --root \$(pwd)" start >>"${root}"/start.sh
bitxhubConfig=${root}/bitxhub.toml
networkConfig=${root}/network.toml
x_replace "s/60011/6001${i}/g" "${bitxhubConfig}"
x_replace "s/9091/909${i}/g" "${bitxhubConfig}"
x_replace "s/53121/5312${i}/g" "${bitxhubConfig}"
x_replace "s/9091/909${i}/g" "${root}"/api
x_replace "1s/1/${i}/" "${networkConfig}"
done
print_blue "===> Building plugin"
cd "${PROJECT_PATH}"/internal/plugins
make raft
for ((i = 1; i < N + 1; i = i + 1)); do
cp -rf "${PROJECT_PATH}"/internal/plugins/build "${BUILD_PATH}"/node${i}/plugins
done
}
function compile() {
print_blue "===> Compiling bitxhub"
cd "${PROJECT_PATH}"
make install
}
prepare
compile
bitxhub version
cd "${CURRENT_PATH}"
for ((i = 1; i < N + 1; i = i + 1)); do
echo "Start node${i}"
nohup bitxhub --repo="${BUILD_PATH}"/node${i} start &
done

View File

@ -160,7 +160,7 @@ func (suite *Interchain) TestGetIBTPByID() {
ib.Index = 2
ret, err := c1.InvokeBVMContract(rpcx.InterchainContractAddr, "GetIBTPByID", rpcx.String(ib.ID()))
suite.Assert().Nil(err)
suite.Assert().Equal(ret.Status.String(), "SUCCESS")
suite.Assert().Equal(true, ret.IsSuccess(), string(ret.Ret))
}
func (suite *Interchain) TestAudit() {

View File

@ -17,7 +17,7 @@ import (
func TestTester(t *testing.T) {
err := retry.Retry(func(attempt uint) error {
resp, err := http.Get(host + "chain_status")
resp, err := http.Get(host + "info?type=0")
if err != nil {
fmt.Println(err)
return err