Skip to content

Commit bcb3da5

Browse files
Integration tests. (#325)
* Integration tests. * Integration tests: merged master. * Integration tests: small fixes. * Min peers mining check. * Fix comment: Validate -> Valid. Co-authored-by: Alexey Kiselev <[email protected]>
1 parent f6d905c commit bcb3da5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1404
-476
lines changed

.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.github
2+
blocks_storage
3+
build
4+
key_value
5+
vendor

Dockerfile

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
FROM golang:1.12
1+
FROM golang:1.14 as parent
2+
3+
WORKDIR /app
4+
5+
COPY go.mod .
6+
COPY go.sum .
7+
8+
RUN go mod download
9+
10+
FROM parent
211

3-
WORKDIR /go/src/github.com/wavesplatform/gowaves
412

5-
COPY cmd cmd
613
COPY pkg pkg
7-
COPY Makefile Makefile
8-
COPY vendor vendor
14+
COPY cmd cmd
15+
COPY Makefile .
916

1017
RUN make build-node-linux
18+
RUN make build-integration-linux
1119

1220
EXPOSE 6863
1321
EXPOSE 6869
22+
EXPOSE 6870
1423

15-
CMD build/bin/linux-amd64/node run --waves-network=wavesW -d 0.0.0.0:6863 -w 0.0.0.0:6869
24+
CMD ./build/bin/linux-amd64/integration -log-level DEBUG -node ./build/bin/linux-amd64/node

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,6 @@ mock:
167167
proto:
168168
@protoc --proto_path=pkg/grpc/protobuf-schemas/proto/ --go_out=plugins=grpc:$(GOPATH)/src pkg/grpc/protobuf-schemas/proto/waves/*.proto
169169
@protoc --proto_path=pkg/grpc/protobuf-schemas/proto/ --go_out=plugins=grpc:$(GOPATH)/src pkg/grpc/protobuf-schemas/proto/waves/node/grpc/*.proto
170+
171+
build-integration-linux:
172+
@GOOS=linux GOARCH=amd64 go build -o build/bin/linux-amd64/integration ./cmd/integration

cmd/integration/main.go

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"flag"
6+
"fmt"
7+
"os"
8+
"os/exec"
9+
"strings"
10+
"time"
11+
12+
"github.com/wavesplatform/gowaves/pkg/util/common"
13+
"github.com/wavesplatform/gowaves/pkg/util/java_opts"
14+
"go.uber.org/zap"
15+
)
16+
17+
var (
18+
logLevel = flag.String("log-level", "DEBUG", "Logging level. Supported levels: DEBUG, INFO, WARN, ERROR, FATAL. Default logging level INFO.")
19+
node = flag.String("node", "", "Path to node executable.")
20+
)
21+
22+
type Argument struct {
23+
Name string
24+
Value string
25+
ProdiveEmpty bool
26+
}
27+
28+
type Arguments []Argument
29+
30+
func (a Arguments) String() string {
31+
s := strings.Builder{}
32+
for _, row := range a {
33+
s.WriteString(" -")
34+
s.WriteString(row.Name)
35+
s.WriteString(" ")
36+
s.WriteString(row.Value)
37+
}
38+
return s.String()
39+
}
40+
41+
func (a Arguments) Strings() []string {
42+
var out []string
43+
for _, row := range a {
44+
out = append(out, "-"+row.Name)
45+
if row.Value != "" {
46+
out = append(out, row.Value)
47+
}
48+
}
49+
return out
50+
}
51+
52+
func (a Arguments) SkipEmpty(name, value string) Arguments {
53+
if value == "" {
54+
return a
55+
}
56+
return append(a, Argument{
57+
Name: name,
58+
Value: value,
59+
})
60+
}
61+
62+
func (a Arguments) NonEmpty(name, value string) Arguments {
63+
if value == "" {
64+
panic("empty value provided for name: " + name)
65+
}
66+
return append(a, Argument{
67+
Name: name,
68+
Value: value,
69+
})
70+
}
71+
72+
func (a Arguments) Empty(name string) Arguments {
73+
return append(a, Argument{
74+
Name: name,
75+
})
76+
}
77+
78+
func main() {
79+
flag.Parse()
80+
// difference between scala System.currentTimeMillis() and time.Now()
81+
<-time.After(2 * time.Second)
82+
common.SetupLogger(*logLevel)
83+
84+
zap.S().Debug(os.Getenv("WAVES_OPTS"))
85+
zap.S().Debug(os.Environ())
86+
87+
cfg := java_opts.ParseEnvString(os.Getenv("WAVES_OPTS"))
88+
89+
arguments := Arguments(nil).
90+
NonEmpty("log-level", "DEBUG").
91+
NonEmpty("state-path", cfg.String("waves.directory", "/tmp/waves")).
92+
SkipEmpty("peers", cfg.String("waves.network.known-peers")).
93+
SkipEmpty("min-peers-mining", cfg.String("waves.miner.quorum", "1")).
94+
NonEmpty("declared-address", cfg.String("waves.network.declared-address")).
95+
SkipEmpty("name", cfg.String("waves.network.node-name", "gowaves")).
96+
SkipEmpty("peers", strings.Join(cfg.Array("waves.network.known-peers"), ",")).
97+
Empty("build-extended-api").
98+
NonEmpty("grpc-address", "0.0.0.0:6870").
99+
NonEmpty("api-address", "0.0.0.0:6869").
100+
NonEmpty("blockchain-type", "integration").
101+
NonEmpty("integration.genesis.signature", cfg.String("waves.blockchain.custom.genesis.signature")).
102+
NonEmpty("integration.genesis.timestamp", cfg.String("waves.blockchain.custom.genesis.timestamp")).
103+
NonEmpty("integration.genesis.block-timestamp", cfg.String("waves.blockchain.custom.genesis.block-timestamp")).
104+
NonEmpty("integration.account-seed", cfg.String("account-seed")).
105+
NonEmpty("integration.address-scheme-character", cfg.String("waves.blockchain.custom.address-scheme-character", "I")) //
106+
107+
if cfg.String("waves.miner.enable") == "no" {
108+
arguments = arguments.Empty("disable-miner")
109+
}
110+
111+
cmd := exec.Command(*node, arguments.Strings()...)
112+
113+
stdout, err := cmd.StdoutPipe()
114+
if err != nil {
115+
zap.S().Errorf("stdout err: %+v", err)
116+
return
117+
}
118+
119+
go func() {
120+
stderr, err := cmd.StderrPipe()
121+
if err != nil {
122+
zap.S().Error(err)
123+
return
124+
}
125+
scanner := bufio.NewScanner(stderr)
126+
scanner.Split(bufio.ScanLines)
127+
for scanner.Scan() {
128+
m := scanner.Text()
129+
fmt.Println("err: ", m)
130+
}
131+
}()
132+
<-time.After(100 * time.Millisecond)
133+
134+
err = cmd.Start()
135+
if err != nil {
136+
zap.S().Error(err)
137+
return
138+
}
139+
140+
go func() {
141+
b := make([]byte, 1024*8)
142+
for {
143+
n, err := stdout.Read(b)
144+
if err != nil {
145+
fmt.Println("stdout.Read(b) err: ", err)
146+
break
147+
}
148+
fmt.Print(string(b[:n]))
149+
}
150+
}()
151+
152+
err = cmd.Wait()
153+
if err != nil {
154+
zap.S().Errorf("%+T", err)
155+
if e, ok := err.(*exec.ExitError); ok {
156+
zap.S().Errorf("%s", e.Stderr)
157+
}
158+
zap.S().Errorf("err: %+v", err)
159+
return
160+
}
161+
}

0 commit comments

Comments
 (0)