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 c30913c
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ localnet_client_debug: ## Opens a `client debug` cli to interact with blockchain

.PHONY: localnet_shell
localnet_shell: ## Opens a shell in the pod that has the `client` cli available. The binary updates automatically whenever the code changes (i.e. hot reloads).
kubectl exec -it deploy/dev-cli-client --container pocket -- /bin/bash
kubectl exec -it deploy/dev-cli-client --container pocket -- /bin/bash -c "export POCKET_REMOTE_CLI_URL=http://pocket-validators:50832; bash"

.PHONY: localnet_logs_validators
localnet_logs_validators: ## Outputs logs from all validators
Expand Down
1 change: 1 addition & 0 deletions build/deployments/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ services:
image: pocket/servicer:latest
command: >
sh -c '
echo "OLSH HERE";
if [ "$SERVICER1_SERVICER_ENABLED" = "true" ]; then
build/scripts/watch.sh \
build/config/config.servicer1.json \
Expand Down
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
3 changes: 3 additions & 0 deletions p2p/background/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ func (rtr *backgroundRouter) bootstrap(ctx context.Context) error {
if err := rtr.connectWithRetry(ctx, libp2pAddrInfo); err != nil {
return fmt.Errorf("connecting to peer: %w", err)
}
// if err := rtr.host.Connect(ctx, libp2pAddrInfo); err != nil {
// return fmt.Errorf("connecting to peer: %w", err)
// }
}
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions p2p/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ func (m *p2pModule) Start() (err error) {
}
}

fmt.Println("OLSH3")
if err := m.setupRouters(); err != nil {
return fmt.Errorf("setting up routers: %w", err)
}
fmt.Println("OLSH4")

m.GetBus().
GetTelemetryModule().
Expand Down Expand Up @@ -433,6 +435,7 @@ func (m *p2pModule) setupHost() (err error) {

// isClientDebugMode returns the value of `ClientDebugMode` in the base config
func (m *p2pModule) isClientDebugMode() bool {
fmt.Println("OLSHANSKY", m.GetBus().GetRuntimeMgr().GetConfig().ClientDebugMode)
return m.GetBus().GetRuntimeMgr().GetConfig().ClientDebugMode
}

Expand Down
1 change: 1 addition & 0 deletions shared/modules/persistence_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type PersistenceModule interface {
// Indexer operations
GetTxIndexer() indexer.TxIndexer
TransactionExists(transactionHash string) (bool, error)
// TransactionExistsInStateTree(transactionHash string) (bool, error)

// Debugging / development only
HandleDebugMessage(*messaging.DebugMessage) error
Expand Down
2 changes: 2 additions & 0 deletions utility/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (u *utilityModule) HandleTransaction(txProtoBytes []byte) error {
}

// Is the tx already committed & indexed (on disk)?
// TODO? Using state tree
if txExists, err := u.GetBus().GetPersistenceModule().TransactionExists(txHash); err != nil {
return err
} else if txExists {
Expand All @@ -36,6 +37,7 @@ func (u *utilityModule) HandleTransaction(txProtoBytes []byte) error {
return err
}


// Store the tx in the mempool
return u.mempool.AddTx(txProtoBytes)
}
Expand Down

0 comments on commit c30913c

Please sign in to comment.