Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit b6c8e2b

Browse files
authored
Merge pull request #14 from gyuho/e2e
[AV-1053] tests/e2e: initial commit
2 parents 917b26a + 6d58856 commit b6c8e2b

File tree

3 files changed

+211
-1
lines changed

3 files changed

+211
-1
lines changed

scripts/e2e.build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
if ! [[ "$0" =~ scripts/e2e.build.sh ]]; then
5+
echo "must be run from repository root"
6+
exit 255
7+
fi
8+
9+
# to add dependency (not needed for test build)
10+
# go get -v github.com/onsi/ginkgo/[email protected]
11+
12+
# to install the ginkgo binary (required for test build and run)
13+
go install -v github.com/onsi/ginkgo/v2/[email protected]
14+
15+
ACK_GINKGO_RC=true ginkgo build ./tests/e2e
16+
./tests/e2e/e2e.test --help

scripts/tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ if ! [[ "$0" =~ scripts/tests.sh ]]; then
66
exit 255
77
fi
88

9-
go test -race -timeout="3m" -coverprofile="coverage.out" -covermode="atomic" $(go list ./... | grep -v integration)
9+
go test -race -timeout="3m" -coverprofile="coverage.out" -covermode="atomic" $(go list ./... | grep -v tests)

tests/e2e/e2e_test.go

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
// e2e implements the e2e tests.
5+
package e2e_test
6+
7+
import (
8+
"context"
9+
"flag"
10+
"fmt"
11+
"strings"
12+
"testing"
13+
"time"
14+
15+
"github.com/ava-labs/quarkvm/chain"
16+
"github.com/ava-labs/quarkvm/client"
17+
"github.com/ava-labs/quarkvm/crypto"
18+
"github.com/ava-labs/quarkvm/parser"
19+
"github.com/fatih/color"
20+
ginkgo "github.com/onsi/ginkgo/v2"
21+
"github.com/onsi/gomega"
22+
)
23+
24+
func TestIntegration(t *testing.T) {
25+
gomega.RegisterFailHandler(ginkgo.Fail)
26+
ginkgo.RunSpecs(t, "quarkvm integration test suites")
27+
}
28+
29+
var (
30+
requestTimeout time.Duration
31+
uris []string
32+
u string
33+
endpoint string
34+
)
35+
36+
func init() {
37+
flag.DurationVar(
38+
&requestTimeout,
39+
"request-timeout",
40+
30*time.Second,
41+
"timeout for transaction issuance and confirmation",
42+
)
43+
flag.StringVar(
44+
&u,
45+
"uris",
46+
"",
47+
"comma-separated quarkvm URIs (e.g., http://127.0.0.1:9650,http://127.0.0.1:9652)",
48+
)
49+
flag.StringVar(
50+
&endpoint,
51+
"endpoint",
52+
"",
53+
"quarkvm API endpoint (e.g., /ext/bc/Bbx6eyUCSzoQLzBbM9gnLDdA9HeuiobqQS53iEthvQzeVqbwa)",
54+
)
55+
}
56+
57+
var (
58+
priv *crypto.PrivateKey
59+
60+
instances []instance
61+
)
62+
63+
type instance struct {
64+
uri string
65+
cli client.Client
66+
}
67+
68+
var _ = ginkgo.BeforeSuite(func() {
69+
gomega.Ω(endpoint).ShouldNot(gomega.BeEmpty())
70+
71+
uris = strings.Split(u, ",")
72+
n := len(uris)
73+
gomega.Ω(n).Should(gomega.BeNumerically(">", 1))
74+
75+
var err error
76+
priv, err = crypto.NewPrivateKey()
77+
gomega.Ω(err).Should(gomega.BeNil())
78+
79+
instances = make([]instance, n)
80+
for i := range instances {
81+
instances[i] = instance{
82+
uri: uris[i],
83+
cli: client.New(uris[i], endpoint, requestTimeout),
84+
}
85+
}
86+
color.Blue("created clients with %v", uris)
87+
})
88+
89+
var _ = ginkgo.AfterSuite(func() {
90+
// no-op
91+
})
92+
93+
var _ = ginkgo.Describe("[Ping]", func() {
94+
ginkgo.It("can ping", func() {
95+
for _, inst := range instances {
96+
cli := inst.cli
97+
ok, err := cli.Ping()
98+
gomega.Ω(ok).Should(gomega.BeTrue())
99+
gomega.Ω(err).Should(gomega.BeNil())
100+
}
101+
})
102+
})
103+
104+
var _ = ginkgo.Describe("[Claim/SetTx]", func() {
105+
ginkgo.It("get currently preferred block ID", func() {
106+
for _, inst := range instances {
107+
cli := inst.cli
108+
_, err := cli.Preferred()
109+
gomega.Ω(err).Should(gomega.BeNil())
110+
}
111+
})
112+
113+
pfx := []byte(fmt.Sprintf("%10d", time.Now().UnixNano()))
114+
ginkgo.It("Claim/SetTx with valid PoW in a single node", func() {
115+
ginkgo.By("mine and issue ClaimTx to the first node", func() {
116+
claimTx := &chain.ClaimTx{
117+
BaseTx: &chain.BaseTx{
118+
Sender: priv.PublicKey().Bytes(),
119+
Prefix: pfx,
120+
},
121+
}
122+
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
123+
_, err := client.MineSignIssueTx(
124+
ctx,
125+
instances[0].cli,
126+
claimTx,
127+
priv,
128+
client.WithPollTx(),
129+
client.WithPrefixInfo(pfx),
130+
)
131+
cancel()
132+
gomega.Ω(err).Should(gomega.BeNil())
133+
})
134+
135+
ginkgo.By("check prefix to check if ClaimTx has been accepted from all nodes", func() {
136+
for _, inst := range instances {
137+
color.Blue("checking prefix on %q", inst.uri)
138+
pf, err := inst.cli.PrefixInfo(pfx)
139+
gomega.Ω(err).To(gomega.BeNil())
140+
gomega.Ω(pf.Keys).To(gomega.Equal(int64(1)))
141+
gomega.Ω(pf.Owner).To(gomega.Equal(priv.PublicKey().Bytes()))
142+
}
143+
})
144+
145+
k, v := []byte("avax.kvm"), []byte("hello")
146+
ginkgo.By("mine and issue SetTx to a different node (if available)", func() {
147+
setTx := &chain.SetTx{
148+
BaseTx: &chain.BaseTx{
149+
Sender: priv.PublicKey().Bytes(),
150+
Prefix: pfx,
151+
},
152+
Key: k,
153+
Value: v,
154+
}
155+
156+
cli := instances[0].cli
157+
if len(instances) > 1 {
158+
cli = instances[1].cli
159+
}
160+
161+
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
162+
_, err := client.MineSignIssueTx(
163+
ctx,
164+
cli,
165+
setTx,
166+
priv,
167+
client.WithPollTx(),
168+
client.WithPrefixInfo(pfx),
169+
)
170+
cancel()
171+
gomega.Ω(err).Should(gomega.BeNil())
172+
})
173+
174+
ginkgo.By("check prefix to check if SetTx has been accepted from all nodes", func() {
175+
for _, inst := range instances {
176+
color.Blue("checking prefix on %q", inst.uri)
177+
pf, err := inst.cli.PrefixInfo(pfx)
178+
gomega.Ω(err).To(gomega.BeNil())
179+
gomega.Ω(pf.Keys).To(gomega.Equal(int64(2)))
180+
gomega.Ω(pf.Owner).To(gomega.Equal(priv.PublicKey().Bytes()))
181+
}
182+
})
183+
184+
ginkgo.By("send Range to all nodes", func() {
185+
for _, inst := range instances {
186+
color.Blue("checking SetTx with Range on %q", inst.uri)
187+
kvs, err := inst.cli.Range(pfx, k)
188+
gomega.Ω(err).To(gomega.BeNil())
189+
gomega.Ω(kvs[0].Key).To(gomega.Equal(append(append(pfx, parser.Delimiter), k...)))
190+
gomega.Ω(kvs[0].Value).To(gomega.Equal(v))
191+
}
192+
})
193+
})
194+
})

0 commit comments

Comments
 (0)