Skip to content

Add create-blockchain e2e test #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 8, 2022
2 changes: 1 addition & 1 deletion .github/workflows/build-test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
go-version: 1.18
- name: Run e2e tests
shell: bash
run: scripts/tests.e2e.sh 1.7.12 1.7.13
run: scripts/tests.e2e.sh 1.7.15 1.7.16 0.2.4
release:
needs: [lint_test, unit_test, e2e_test]
runs-on: ubuntu-latest
Expand Down
45 changes: 40 additions & 5 deletions scripts/tests.e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,39 @@ if ! [[ "$0" =~ scripts/tests.e2e.sh ]]; then
exit 255
fi

DEFAULT_VERSION_1=1.7.12
DEFAULT_VERSION_2=1.7.13
DEFAULT_VERSION_1=1.7.15
DEFAULT_VERSION_2=1.7.16
DEFAULT_SUBNET_EVM_VERSION=0.2.4

if [ $# == 0 ]; then
VERSION_1=$DEFAULT_VERSION_1
VERSION_2=$DEFAULT_VERSION_2
SUBNET_EVM_VERSION=$DEFAULT_SUBNET_EVM_VERSION
else
VERSION_1=$1
if [[ -z "${VERSION_1}" ]]; then
echo "Missing version argument!"
echo "Usage: ${0} [VERSION_1] [VERSION_2]" >> /dev/stderr
echo "Usage: ${0} [VERSION_1] [VERSION_2] [SUBNET_EVM_VERSION]" >> /dev/stderr
exit 255
fi
VERSION_2=$2
if [[ -z "${VERSION_2}" ]]; then
echo "Missing version argument!"
echo "Usage: ${0} [VERSION_1] [VERSION_2]" >> /dev/stderr
echo "Usage: ${0} [VERSION_1] [VERSION_2] [SUBNET_EVM_VERSION]" >> /dev/stderr
exit 255
fi
SUBNET_EVM_VERSION=$3
if [[ -z "${SUBNET_EVM_VERSION}" ]]; then
echo "Missing version argument!"
echo "Usage: ${0} [VERSION_1] [VERSION_2] [SUBNET_EVM_VERSION]" >> /dev/stderr
exit 255
fi
fi

echo "Running e2e tests with:"
echo VERSION_1: ${VERSION_1}
echo VERSION_2: ${VERSION_2}
echo SUBNET_EVM_VERSION: ${SUBNET_EVM_VERSION}

if [ ! -f /tmp/avalanchego-v${VERSION_1}/avalanchego ]
then
Expand Down Expand Up @@ -93,6 +102,31 @@ then
find /tmp/avalanchego-v${VERSION_2}
fi

if [ ! -f /tmp/subnet-evm-v${SUBNET_EVM_VERSION}/subnet-evm ]
then
############################
# download subnet-evm
# https://github.com/ava-labs/subnet-evm/releases
GOARCH=$(go env GOARCH)
DOWNLOAD_URL=https://github.com/ava-labs/subnet-evm/releases/download/v${SUBNET_EVM_VERSION}/subnet-evm_${SUBNET_EVM_VERSION}_linux_${GOARCH}.tar.gz
DOWNLOAD_PATH=/tmp/subnet-evm.tar.gz
if [[ ${GOOS} == "darwin" ]]; then
DOWNLOAD_URL=https://github.com/ava-labs/subnet-evm/releases/download/v${SUBNET_EVM_VERSION}/subnet-evm_${SUBNET_EVM_VERSION}_darwin_${GOARCH}.tar.gz
fi

rm -rf /tmp/subnet-evm-v${SUBNET_EVM_VERSION}
rm -f ${DOWNLOAD_PATH}

echo "downloading subnet-evm ${SUBNET_EVM_VERSION} at ${DOWNLOAD_URL}"
curl -L ${DOWNLOAD_URL} -o ${DOWNLOAD_PATH}

echo "extracting downloaded subnet-evm"
mkdir /tmp/subnet-evm-v${SUBNET_EVM_VERSION}
tar xzvf ${DOWNLOAD_PATH} -C /tmp/subnet-evm-v${SUBNET_EVM_VERSION}
# NOTE: We are copying the subnet-evm binary here to a plugin hardcoded as srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy which corresponds to the VM name `subnetevm` used as such in the test
cp /tmp/subnet-evm-v${SUBNET_EVM_VERSION}/subnet-evm /tmp/avalanchego-v${VERSION_2}/plugins/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy
find /tmp/subnet-evm-v${SUBNET_EVM_VERSION}/subnet-evm
fi
############################
echo "building runner"
./scripts/build.sh
Expand Down Expand Up @@ -125,7 +159,8 @@ echo "running e2e tests"
--grpc-endpoint="0.0.0.0:8080" \
--grpc-gateway-endpoint="0.0.0.0:8081" \
--avalanchego-path-1=/tmp/avalanchego-v${VERSION_1}/avalanchego \
--avalanchego-path-2=/tmp/avalanchego-v${VERSION_2}/avalanchego
--avalanchego-path-2=/tmp/avalanchego-v${VERSION_2}/avalanchego \
--subnet-evm-path=/tmp/subnet-evm-v${SUBNET_EVM_VERSION}/subnet-evm

kill -9 ${PID}
echo "ALL SUCCESS!"
177 changes: 156 additions & 21 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/ava-labs/avalanche-network-runner/rpcpb"
"github.com/ava-labs/avalanche-network-runner/server"
"github.com/ava-labs/avalanche-network-runner/utils"

"github.com/ava-labs/avalanchego/api/admin"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/message"
Expand All @@ -44,6 +43,7 @@ var (
gRPCGatewayEp string
execPath1 string
execPath2 string
subnetEvmPath string

newNodeName = "test-add-node"
customNodeConfigs = map[string]string{
Expand Down Expand Up @@ -89,6 +89,12 @@ func init() {
"",
"avalanchego executable path (to upgrade to)",
)
flag.StringVar(
&subnetEvmPath,
"subnet-evm-path",
"",
"path to subnet-evm binary",
)
}

var cli client.Client
Expand Down Expand Up @@ -116,6 +122,125 @@ var _ = ginkgo.AfterSuite(func() {
})

var _ = ginkgo.Describe("[Start/Remove/Restart/Add/Stop]", func() {
ginkgo.It("can create blockhains", func() {
existingSubnetID := ""
ginkgo.By("start with blockchain specs", func() {
color.Outf("{{green}}sending 'start' with the valid binary path:{{/}} %q\n", execPath2)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
resp, err := cli.Start(ctx, execPath2,
client.WithBlockchainSpecs([]*rpcpb.BlockchainSpec{
{
VmName: "subnetevm",
Genesis: "tests/e2e/subnet-evm-genesis.json",
},
}),
)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
color.Outf("{{green}}successfully started:{{/}} %+v\n", resp.ClusterInfo.NodeNames)
})

ginkgo.By("wait for custom chains healthy", func() {
// ignore subnet ID here
_ = waitForCustomChainsHealthy()
})

ginkgo.By("can create a blockchain with a new subnet id", func() {
color.Outf("{{blue}}can create a blockchain in a new subnet{{/}}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.CreateBlockchains(ctx,
[]*rpcpb.BlockchainSpec{
{
VmName: "subnetevm",
Genesis: "tests/e2e/subnet-evm-genesis.json",
},
},
)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

ginkgo.By("get subnet ID", func() {
existingSubnetID = waitForCustomChainsHealthy()
})

ginkgo.By("can create a blockchain with an existing subnet id", func() {
color.Outf("{{blue}}can create a blockchain in an existing subnet{{/}}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.CreateBlockchains(ctx,
[]*rpcpb.BlockchainSpec{
{
VmName: "subnetevm",
Genesis: "tests/e2e/subnet-evm-genesis.json",
SubnetId: &existingSubnetID,
},
},
)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

ginkgo.By("wait for custom chains healthy", func() {
// ignore subnet ID here
_ = waitForCustomChainsHealthy()
})

ginkgo.By("can save snapshot", func() {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.SaveSnapshot(ctx, "test")
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

ginkgo.By("can load snapshot", func() {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.LoadSnapshot(ctx, "test")
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

ginkgo.By("wait for custom chains healthy", func() {
// ignore subnet ID here
_ = waitForCustomChainsHealthy()
})

// need to remove the snapshot otherwise it fails later in the 2nd part of snapshot tests
// (testing for no snapshots)
ginkgo.By("can remove snapshot", func() {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.RemoveSnapshot(ctx, "test")
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})
ginkgo.By("can create a blockchain with an existing subnet id", func() {
color.Outf("{{blue}}can create a blockchain in an existing subnet{{/}}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.CreateBlockchains(ctx,
[]*rpcpb.BlockchainSpec{
{
VmName: "subnetevm",
Genesis: "tests/e2e/subnet-evm-genesis.json",
SubnetId: &existingSubnetID,
},
},
)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

ginkgo.By("wait for custom chains healthy", func() {
// ignore subnet ID here
_ = waitForCustomChainsHealthy()
})

ginkgo.By("stop the network", func() {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.Stop(ctx)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})
})

ginkgo.It("can start", func() {
ginkgo.By("start request with invalid exec path should fail", func() {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
Expand Down Expand Up @@ -410,26 +535,8 @@ var _ = ginkgo.Describe("[Start/Remove/Restart/Add/Stop]", func() {
gomega.Ω(err).Should(gomega.BeNil())
})
ginkgo.By("wait for network to be healthy", func() {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
var created bool
continueLoop := true
for continueLoop {
select {
case <-ctx.Done():
continueLoop = false
case <-time.After(5 * time.Second):
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
status, err := cli.Status(ctx)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
created = status.ClusterInfo.CustomChainsHealthy
if created {
continueLoop = false
}
}
}
cancel()
gomega.Ω(created).Should(gomega.Equal(true))
// ignore subnet ID here
_ = waitForCustomChainsHealthy()
})
ginkgo.By("check subnets are 1", func() {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
Expand Down Expand Up @@ -563,3 +670,31 @@ var _ = ginkgo.Describe("[Start/Remove/Restart/Add/Stop]", func() {
})
})
})

func waitForCustomChainsHealthy() string {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
var created bool
continueLoop := true
for continueLoop {
select {
case <-ctx.Done():
continueLoop = false
case <-time.After(5 * time.Second):
cctx, ccancel := context.WithTimeout(context.Background(), 15*time.Second)
status, err := cli.Status(cctx)
ccancel()
gomega.Ω(err).Should(gomega.BeNil())
created = status.ClusterInfo.CustomChainsHealthy
if created {
continueLoop = false
existingSubnetID := status.ClusterInfo.GetSubnets()[0]
gomega.Ω(existingSubnetID).Should(gomega.Not(gomega.BeNil()))
cancel()
return existingSubnetID
}
}
}
cancel()
gomega.Ω(created).Should(gomega.Equal(true))
return ""
}
47 changes: 47 additions & 0 deletions tests/e2e/subnet-evm-genesis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"config": {
"chainId": 99999,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"muirGlacierBlock": 0,
"subnetEVMTimestamp": 0,
"feeConfig": {
"gasLimit": 20000000,
"minBaseFee": 1000000000,
"targetGas": 100000000,
"baseFeeChangeDenominator": 48,
"minBlockGasCost": 0,
"maxBlockGasCost": 10000000,
"targetBlockRate": 2,
"blockGasCostStep": 500000
}
},
"alloc": {
"0x323e83bb2ce09bb19088ad11d3012b39738212bc": {
"balance": "0x52B7D2DCC80CD2E4000000"
},
"8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC": {
"balance": "0x52B7D2DCC80CD2E4000000"
},
"Ab5801a7D398351b8bE11C439e05C5B3259aeC9B": {
"balance": "0xa796504b1cb5a7c0000"
}
},
"nonce": "0x0",
"timestamp": "0x0",
"extraData": "0x00",
"gasLimit": "0x1312D00",
"difficulty": "0x0",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}