Skip to content

Commit

Permalink
Appliedtest diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Olshansk committed Jul 27, 2023
1 parent c9049ef commit d353048
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 4 deletions.
29 changes: 29 additions & 0 deletions e2e/tests/state_sync.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Feature: State Sync Namespace

Scenario: Full Node Starts Block By Block Sync From Genesis In A Network At Height 4
# Given there are 4 staked validators
When the developer runs the command "TriggerView"
Then wait for the network to reach height "4"
# And a full node joins the network
# Then querying the height of the full node should return 0
# And querying the height of the full node should return 4

# Trigger a view
# send a debug command -> debug helper
# Wait for all the validators in the network to go to the next height
# Continuously query their height -> use QUery Height
# How do I guarantee I'm reaching everyone -> PeerStore
# Add a full node to the network
# Update the local config
# Start a full node
# Connect to the network
# Query the height of the full node
# Wait for the full node to sync
# Continuously query the height of the full node
# How do I know when it's done syncing -> Query the height of the network


# Future Scenarios
# Scenario: Full Node Starts Block By Block Sync From Height 2 In A Network At Height 4
# Scenario: Full Node Starts Sync From Snapshot At Height 2 In A Network At Height 4
# ???
79 changes: 77 additions & 2 deletions e2e/tests/steps_init_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//go:build e2e

// IN_THIS_PR: Figure out how to make this work: //go:build e2e
package e2e

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -34,6 +34,8 @@ const (
chainId = "0001"
)

// TODO_IN_THIS_COMMIT: Rename `validator` to something more appropriate

type rootSuite struct {
gocuke.TestingT

Expand Down Expand Up @@ -87,6 +89,38 @@ func (s *rootSuite) TheUserRunsTheCommand(cmd string) {
s.validator.result = res
}

// TheDeveloperRunsTheCommand is similar to TheUserRunsTheCommand but exclusive to `debug` commands
func (s *rootSuite) TheDeveloperRunsTheCommand(cmd string) {
cmds := strings.Split(cmd, " ")
cmds = append([]string{"debug"}, cmds...)
fmt.Println("OLSH", cmds)
res, err := s.validator.RunCommand(cmds...)
require.NoError(s, err)
s.validator.result = res
// IN_THIS_PR: Should we validate anything here?
}

func (s *rootSuite) WaitForTheNetworkToReachHeight(height int64) {
args := []string{
"Query",
"Height",
}
type expectedResponse struct {
Height *int64 `json:"Height"`
}
validate := func(res *expectedResponse) bool {
return res != nil && res.Height != nil
}

resRaw, err := s.validator.RunCommand(args...)
require.NoError(s, err)

res := getResponseFromStdout[expectedResponse](s, resRaw.Stdout, validate)
require.NotNil(s, res)

require.Equal(s, height, *(*res).Height)
}

func (s *rootSuite) TheUserShouldBeAbleToSeeStandardOutputContaining(arg1 string) {
require.Contains(s, s.validator.result.Stdout, arg1)
}
Expand Down Expand Up @@ -190,3 +224,44 @@ func inClusterConfig(t gocuke.TestingT) *rest.Config {

return config
}

//

// getResponseFromStdout returns the first non-log output from stdout when running a command
// For example, when running `p1 Query Height`, the output is:
//
// {"level":"info","module":"e2e","time":"2023-07-11T15:46:07-07:00","message":"..."}
// {"height":3}
//
// And will return the following map so it can be used by the caller:
//
// map[height:3]
func getResponseFromStdout[T any](t gocuke.TestingT, stdout string, validate func(res *T) bool) *T {
t.Helper()

for _, s := range strings.Split(stdout, "\n") {
fmt.Println(s)
var m T
if err := json.Unmarshal([]byte(s), &m); err != nil {
fmt.Println("ERR", s)
continue
}
if !validate(&m) {
continue
}
fmt.Println("NO ERR", m)
return &m
}
return nil
}

// func getLogs
// isLog := func(m map[string]any) bool {
// keys := []string{"level", "time", "message"} //"module",
// for _, key := range keys {
// if _, ok := m[key]; !ok {
// return false
// }
// }
// return true
// }
4 changes: 2 additions & 2 deletions e2e/tests/validator.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build e2e

// IN_THIS_PR: Figure out how to make this work: //go:build e2e
package e2e

import (
Expand All @@ -15,6 +14,7 @@ var (
rpcURL string
// targetPod is the kube pod that executes calls to the pocket binary under test
targetPod = "deploy/dev-cli-client"
// targetPod = "validator-001-pocket"
)

func init() {
Expand Down

0 comments on commit d353048

Please sign in to comment.