Skip to content

Commit c30913c

Browse files
committed
Appliedtest diff
1 parent c9049ef commit c30913c

File tree

9 files changed

+119
-5
lines changed

9 files changed

+119
-5
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ localnet_client_debug: ## Opens a `client debug` cli to interact with blockchain
558558

559559
.PHONY: localnet_shell
560560
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).
561-
kubectl exec -it deploy/dev-cli-client --container pocket -- /bin/bash
561+
kubectl exec -it deploy/dev-cli-client --container pocket -- /bin/bash -c "export POCKET_REMOTE_CLI_URL=http://pocket-validators:50832; bash"
562562

563563
.PHONY: localnet_logs_validators
564564
localnet_logs_validators: ## Outputs logs from all validators

build/deployments/docker-compose.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ services:
141141
image: pocket/servicer:latest
142142
command: >
143143
sh -c '
144+
echo "OLSH HERE";
144145
if [ "$SERVICER1_SERVICER_ENABLED" = "true" ]; then
145146
build/scripts/watch.sh \
146147
build/config/config.servicer1.json \

e2e/tests/state_sync.feature

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Feature: State Sync Namespace
2+
3+
Scenario: Full Node Starts Block By Block Sync From Genesis In A Network At Height 4
4+
# Given there are 4 staked validators
5+
When the developer runs the command "TriggerView"
6+
Then wait for the network to reach height "4"
7+
# And a full node joins the network
8+
# Then querying the height of the full node should return 0
9+
# And querying the height of the full node should return 4
10+
11+
# Trigger a view
12+
# send a debug command -> debug helper
13+
# Wait for all the validators in the network to go to the next height
14+
# Continuously query their height -> use QUery Height
15+
# How do I guarantee I'm reaching everyone -> PeerStore
16+
# Add a full node to the network
17+
# Update the local config
18+
# Start a full node
19+
# Connect to the network
20+
# Query the height of the full node
21+
# Wait for the full node to sync
22+
# Continuously query the height of the full node
23+
# How do I know when it's done syncing -> Query the height of the network
24+
25+
26+
# Future Scenarios
27+
# Scenario: Full Node Starts Block By Block Sync From Height 2 In A Network At Height 4
28+
# Scenario: Full Node Starts Sync From Snapshot At Height 2 In A Network At Height 4
29+
# ???

e2e/tests/steps_init_test.go

+77-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//go:build e2e
2-
1+
// IN_THIS_PR: Figure out how to make this work: //go:build e2e
32
package e2e
43

54
import (
5+
"encoding/json"
66
"fmt"
77
"os"
88
"path/filepath"
@@ -34,6 +34,8 @@ const (
3434
chainId = "0001"
3535
)
3636

37+
// TODO_IN_THIS_COMMIT: Rename `validator` to something more appropriate
38+
3739
type rootSuite struct {
3840
gocuke.TestingT
3941

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

92+
// TheDeveloperRunsTheCommand is similar to TheUserRunsTheCommand but exclusive to `debug` commands
93+
func (s *rootSuite) TheDeveloperRunsTheCommand(cmd string) {
94+
cmds := strings.Split(cmd, " ")
95+
cmds = append([]string{"debug"}, cmds...)
96+
fmt.Println("OLSH", cmds)
97+
res, err := s.validator.RunCommand(cmds...)
98+
require.NoError(s, err)
99+
s.validator.result = res
100+
// IN_THIS_PR: Should we validate anything here?
101+
}
102+
103+
func (s *rootSuite) WaitForTheNetworkToReachHeight(height int64) {
104+
args := []string{
105+
"Query",
106+
"Height",
107+
}
108+
type expectedResponse struct {
109+
Height *int64 `json:"Height"`
110+
}
111+
validate := func(res *expectedResponse) bool {
112+
return res != nil && res.Height != nil
113+
}
114+
115+
resRaw, err := s.validator.RunCommand(args...)
116+
require.NoError(s, err)
117+
118+
res := getResponseFromStdout[expectedResponse](s, resRaw.Stdout, validate)
119+
require.NotNil(s, res)
120+
121+
require.Equal(s, height, *(*res).Height)
122+
}
123+
90124
func (s *rootSuite) TheUserShouldBeAbleToSeeStandardOutputContaining(arg1 string) {
91125
require.Contains(s, s.validator.result.Stdout, arg1)
92126
}
@@ -190,3 +224,44 @@ func inClusterConfig(t gocuke.TestingT) *rest.Config {
190224

191225
return config
192226
}
227+
228+
//
229+
230+
// getResponseFromStdout returns the first non-log output from stdout when running a command
231+
// For example, when running `p1 Query Height`, the output is:
232+
//
233+
// {"level":"info","module":"e2e","time":"2023-07-11T15:46:07-07:00","message":"..."}
234+
// {"height":3}
235+
//
236+
// And will return the following map so it can be used by the caller:
237+
//
238+
// map[height:3]
239+
func getResponseFromStdout[T any](t gocuke.TestingT, stdout string, validate func(res *T) bool) *T {
240+
t.Helper()
241+
242+
for _, s := range strings.Split(stdout, "\n") {
243+
fmt.Println(s)
244+
var m T
245+
if err := json.Unmarshal([]byte(s), &m); err != nil {
246+
fmt.Println("ERR", s)
247+
continue
248+
}
249+
if !validate(&m) {
250+
continue
251+
}
252+
fmt.Println("NO ERR", m)
253+
return &m
254+
}
255+
return nil
256+
}
257+
258+
// func getLogs
259+
// isLog := func(m map[string]any) bool {
260+
// keys := []string{"level", "time", "message"} //"module",
261+
// for _, key := range keys {
262+
// if _, ok := m[key]; !ok {
263+
// return false
264+
// }
265+
// }
266+
// return true
267+
// }

e2e/tests/validator.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//go:build e2e
2-
1+
// IN_THIS_PR: Figure out how to make this work: //go:build e2e
32
package e2e
43

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

2020
func init() {

p2p/background/router.go

+3
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ func (rtr *backgroundRouter) bootstrap(ctx context.Context) error {
368368
if err := rtr.connectWithRetry(ctx, libp2pAddrInfo); err != nil {
369369
return fmt.Errorf("connecting to peer: %w", err)
370370
}
371+
// if err := rtr.host.Connect(ctx, libp2pAddrInfo); err != nil {
372+
// return fmt.Errorf("connecting to peer: %w", err)
373+
// }
371374
}
372375
return nil
373376
}

p2p/module.go

+3
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,11 @@ func (m *p2pModule) Start() (err error) {
159159
}
160160
}
161161

162+
fmt.Println("OLSH3")
162163
if err := m.setupRouters(); err != nil {
163164
return fmt.Errorf("setting up routers: %w", err)
164165
}
166+
fmt.Println("OLSH4")
165167

166168
m.GetBus().
167169
GetTelemetryModule().
@@ -433,6 +435,7 @@ func (m *p2pModule) setupHost() (err error) {
433435

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

shared/modules/persistence_module.go

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type PersistenceModule interface {
3434
// Indexer operations
3535
GetTxIndexer() indexer.TxIndexer
3636
TransactionExists(transactionHash string) (bool, error)
37+
// TransactionExistsInStateTree(transactionHash string) (bool, error)
3738

3839
// Debugging / development only
3940
HandleDebugMessage(*messaging.DebugMessage) error

utility/transaction.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func (u *utilityModule) HandleTransaction(txProtoBytes []byte) error {
1919
}
2020

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

40+
3941
// Store the tx in the mempool
4042
return u.mempool.AddTx(txProtoBytes)
4143
}

0 commit comments

Comments
 (0)