Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@

sszgen:
sszgen --path internal/server/proto/structs.go
sszgen --path internal/genesis/structs.go

protoc:
protoc --go_out=. --go-grpc_out=. ./internal/server/proto/*.proto
4 changes: 4 additions & 0 deletions e2e/framework/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package framework

type F struct {
}
38 changes: 38 additions & 0 deletions e2e/framework/framework.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package framework

import "fmt"

var pkgSuites []*TestSuite

func AddSuites(s *TestSuite) {
pkgSuites = append(pkgSuites, s)
}

type TestSuite struct {
Cases []TestCase
}

type TestCase interface {
Run(f *F)
}

type Framework struct {
suites []*TestSuite
}

func New() *Framework {
f := &Framework{
suites: pkgSuites,
}
return f
}

func (f *Framework) Run() {
fmt.Println(f.suites, pkgSuites)
for _, s := range f.suites {
for _, c := range s.Cases {
f := &F{}
c.Run(f)
}
}
}
156 changes: 156 additions & 0 deletions e2e/single/single.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package single

import (
"context"
"fmt"
"reflect"
"time"

"github.com/hashicorp/go-hclog"
consensus "github.com/umbracle/go-eth-consensus"
"github.com/umbracle/go-eth-consensus/chaintime"
"github.com/umbracle/go-eth-consensus/http"
"github.com/umbracle/viewpoint/e2e/framework"
"github.com/umbracle/viewpoint/internal/server"
"github.com/umbracle/viewpoint/internal/server/proto"
)

func init() {
framework.AddSuites(&framework.TestSuite{
Cases: []framework.TestCase{new(SingleDeployment)},
})
}

type SingleDeployment struct {
}

func uintP(i int) *int {
return &i
}

func (s *SingleDeployment) Run(f *framework.F) {

config := server.DefaultConfig()
config.NumGenesisValidators = 10
config.NumTranches = 1
config.Spec.MinGenesisValidatorCount = 10
config.Spec.MinGenesisTime = int(time.Now().Add(10 * time.Second).Unix())
config.Spec.Altair = uintP(1)

srv, err := server.NewServer(hclog.NewNullLogger(), config)
if err != nil {
panic(err)
}

_, err = srv.NodeDeploy(context.Background(), &proto.NodeDeployRequest{
NodeClient: proto.NodeClient_Prysm,
NodeType: &proto.NodeDeployRequest_Validator_{
Validator: &proto.NodeDeployRequest_Validator{
NumTranch: 0,
WithBeacon: true,
BeaconCount: 2,
},
},
})
if err != nil {
panic(err)
}

{
_, err = srv.NodeDeploy(context.Background(), &proto.NodeDeployRequest{
NodeClient: proto.NodeClient_Lighthouse,
NodeType: &proto.NodeDeployRequest_Beacon_{
Beacon: &proto.NodeDeployRequest_Beacon{
Count: 1,
},
},
})
if err != nil {
panic(err)
}
_, err = srv.NodeDeploy(context.Background(), &proto.NodeDeployRequest{
NodeClient: proto.NodeClient_Teku,
NodeType: &proto.NodeDeployRequest_Beacon_{
Beacon: &proto.NodeDeployRequest_Beacon{
Count: 1,
},
},
})
if err != nil {
panic(err)
}
}

time.Sleep(10 * time.Second)

xx, err := srv.NodeList(context.Background(), &proto.NodeListRequest{})
if err != nil {
panic(err)
}
beacons := []*proto.Node{}
for _, i := range xx.Nodes {
if i.Type == proto.NodeType_Beacon {
beacons = append(beacons, i)
}
}

var genesisTime uint64

specs := []*consensus.Spec{}
for _, node := range beacons {
client := http.New(node.GetAddr(proto.NodePortHttp))
spec, err := client.Config().Spec()
if err != nil {
panic(err)
}
genesis, err := client.Beacon().Genesis()
if err != nil {
panic(err)
}
genesisTime = genesis.Time
specs = append(specs, spec)
}

for i := 0; i < len(specs)-1; i++ {
if !compareSpec(specs[i], specs[i+1]) {
fmt.Println(specs[i], specs[i+1])
panic("bad")
}
}

genesis := specs[0]
cTime := chaintime.New(time.Unix(int64(genesisTime), 0).UTC(), genesis.SecondsPerSlot, genesis.SlotsPerEpoch)

// wait for slot 10
fmt.Println("time", time.Now(), cTime.Epoch(3).Time)
fmt.Println(config.Spec.SecondsPerSlot, 10*config.Spec.SecondsPerSlot)

timer := cTime.Epoch(3).C()
select {
case <-timer.C:
fmt.Println("- epoch 3 -")

for _, node := range beacons {
client := http.New(node.GetAddr(proto.NodePortHttp))
syncing, err := client.Node().Syncing()
if err != nil {
panic(err)
}
fmt.Println(syncing.HeadSlot, syncing.SyncDistance)
}
}

/*
fmt.Println("- done -")
for _, node := range resp.Nodes {
if node.Type == proto.NodeType_Beacon {
client := http.New(node.GetAddr(proto.NodePortHttp))
fmt.Println(client.Node().Identity())
}
}
*/
}

func compareSpec(a, b *consensus.Spec) bool {
return reflect.DeepEqual(a, b)
}
5 changes: 5 additions & 0 deletions e2e/tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package framework

import (
_ "github.com/umbracle/viewpoint/e2e/single"
)
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/ryanuber/columnize v2.1.2+incompatible
github.com/stretchr/testify v1.8.0
github.com/umbracle/ethgo v0.1.3
github.com/umbracle/go-eth-consensus v0.1.0
github.com/umbracle/go-eth-consensus v0.1.1-0.20220806161958-5dc5ccba6075
google.golang.org/grpc v1.47.0
google.golang.org/protobuf v1.28.0
)
Expand Down Expand Up @@ -57,6 +57,7 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/posener/complete v1.1.1 // indirect
github.com/r3labs/sse v0.0.0-20210224172625-26fe804710bc // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sirupsen/logrus v1.4.2 // indirect
github.com/spf13/cast v1.3.1 // indirect
Expand All @@ -72,6 +73,7 @@ require (
golang.org/x/text v0.3.3 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.2.0 // indirect
Expand Down
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/posener/complete v1.1.1 h1:ccV59UEOTzVDnDUEFdT95ZzHVZ+5+158q8+SJb2QV5w=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/r3labs/sse v0.0.0-20210224172625-26fe804710bc h1:zAsgcP8MhzAbhMnB1QQ2O7ZhWYVGYSR2iVcjzQuPV+o=
github.com/r3labs/sse v0.0.0-20210224172625-26fe804710bc/go.mod h1:S8xSOnV3CgpNrWd0GQ/OoQfMtlg2uPRSuTzcSGrzwK8=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/ryanuber/columnize v2.1.2+incompatible h1:C89EOx/XBWwIXl8wm8OPJBd7kPF25UfsK2X7Ph/zCAk=
github.com/ryanuber/columnize v2.1.2+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
Expand All @@ -188,6 +190,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand All @@ -202,10 +205,12 @@ github.com/umbracle/ethgo v0.1.3 h1:s8D7Rmphnt71zuqrgsGTMS5gTNbueGO1zKLh7qsFzTM=
github.com/umbracle/ethgo v0.1.3/go.mod h1:g9zclCLixH8liBI27Py82klDkW7Oo33AxUOr+M9lzrU=
github.com/umbracle/fastrlp v0.0.0-20220527094140-59d5dd30e722 h1:10Nbw6cACsnQm7r34zlpJky+IzxVLRk6MKTS2d3Vp0E=
github.com/umbracle/fastrlp v0.0.0-20220527094140-59d5dd30e722/go.mod h1:c8J0h9aULj2i3umrfyestM6jCq0LK0U6ly6bWy96nd4=
github.com/umbracle/go-eth-consensus v0.0.0-20220729142744-8aee439e6678 h1:Fk8HaNRXCqTpef1AmANX9tbNaR7yWKc0K71MZ0XtAAg=
github.com/umbracle/go-eth-consensus v0.0.0-20220729142744-8aee439e6678/go.mod h1:OTPUHe4DsFq5pM9Lke1EwkhgJDXMnK+iAwTCoyrB2+Q=
github.com/umbracle/go-eth-consensus v0.1.0 h1:xm/0HCvFxrIHeiVfYoMJ9ZLbMe7IghWA52eWB2Rtfag=
github.com/umbracle/go-eth-consensus v0.1.0/go.mod h1:qEdbWIH3Ud7mRhUlOxNfScXX1JjcqHOqP355Ei14G3s=
github.com/umbracle/go-eth-consensus v0.1.1-0.20220804213956-353d32a1ea06 h1:1/OT5qmvr4nQBHMQnqpZJsc33iln/NLRjT7vO/lxI+E=
github.com/umbracle/go-eth-consensus v0.1.1-0.20220804213956-353d32a1ea06/go.mod h1:qEdbWIH3Ud7mRhUlOxNfScXX1JjcqHOqP355Ei14G3s=
github.com/umbracle/go-eth-consensus v0.1.1-0.20220806161958-5dc5ccba6075 h1:9EXK1q371lbmHYepXuOxGyP38eLxtAjhoPAvPagvOBI=
github.com/umbracle/go-eth-consensus v0.1.1-0.20220806161958-5dc5ccba6075/go.mod h1:qEdbWIH3Ud7mRhUlOxNfScXX1JjcqHOqP355Ei14G3s=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.4.0 h1:PuaTGZIw3mjYhhhbVbCQp8aciRZN9YdoB7MGX9Ko76A=
Expand Down Expand Up @@ -240,6 +245,7 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
Expand Down Expand Up @@ -317,6 +323,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/cenkalti/backoff.v1 v1.1.0 h1:Arh75ttbsvlpVA7WtVpH4u9h6Zl46xuptxqLxPiSo4Y=
gopkg.in/cenkalti/backoff.v1 v1.1.0/go.mod h1:J6Vskwqd+OMVJl8C33mmtxTBs2gyzfv7UDAkHu8BrjI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
Expand Down
6 changes: 6 additions & 0 deletions internal/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/mitchellh/cli"
"github.com/ryanuber/columnize"
_ "github.com/umbracle/viewpoint/e2e"
"github.com/umbracle/viewpoint/internal/cmd/server"
"github.com/umbracle/viewpoint/internal/server/proto"
"google.golang.org/grpc"
Expand Down Expand Up @@ -61,6 +62,11 @@ func Commands() map[string]cli.CommandFactory {
Meta: meta,
}, nil
},
"e2e run": func() (cli.Command, error) {
return &E2ERunCommand{
UI: ui,
}, nil
},
"version": func() (cli.Command, error) {
return &VersionCommand{
UI: ui,
Expand Down
38 changes: 38 additions & 0 deletions internal/cmd/e2e_run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cmd

import (
"flag"

"github.com/mitchellh/cli"
"github.com/umbracle/viewpoint/e2e/framework"
)

// E2ERunCommand is the command to deploy an e2e network
type E2ERunCommand struct {
UI cli.Ui
}

// Help implements the cli.Command interface
func (c *E2ERunCommand) Help() string {
return ""
}

// Synopsis implements the cli.Command interface
func (c *E2ERunCommand) Synopsis() string {
return ""
}

// Run implements the cli.Command interface
func (c *E2ERunCommand) Run(args []string) int {
flags := flag.NewFlagSet("e2e run", flag.ContinueOnError)

if err := flags.Parse(args); err != nil {
c.UI.Error(err.Error())
return 1
}

f := framework.New()
f.Run()

return 0
}
2 changes: 1 addition & 1 deletion internal/cmd/node_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *NodeListCommand) Run(args []string) int {
return 1
}

c.UI.Output(formatNodes(resp.Node))
c.UI.Output(formatNodes(resp.Nodes))
return 0
}

Expand Down
4 changes: 4 additions & 0 deletions internal/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ func (d *Docker) Deploy(spec *spec.Spec) (*node, error) {
return n, nil
}

func (n *node) GetPorts() map[string]uint64 {
return n.ports
}

func (n *node) Spec() *spec.Spec {
return n.opts
}
Expand Down
Loading