Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] Updating relay.feature to run curl command to enable E2E Relay Test #178

Merged
merged 9 commits into from
Nov 15, 2023
Merged
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

POKTROLLD_HOME := ./localnet/poktrolld
POCKET_NODE = tcp://127.0.0.1:36657 # The pocket rollup node (full node and sequencer in the localnet context)
RELAYER_NODE = http://anvil:8547 # TODO_IN_THIS_COMMIT: UPDATE THIS URL
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
POCKET_ADDR_PREFIX = pokt

####################
Expand Down Expand Up @@ -137,6 +138,7 @@ go_imports: check_go_version ## Run goimports on all go files
test_e2e: ## Run all E2E tests
export POCKET_NODE=$(POCKET_NODE) && \
POKTROLLD_HOME=../../$(POKTROLLD_HOME) && \
RELAYER_NODE=$(RELAYER_NODE) && \
go test -v ./e2e/tests/... -tags=e2e

.PHONY: go_test
Expand Down
30 changes: 16 additions & 14 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46480,7 +46480,7 @@ paths:
service:
title: >-
The Service for which the application is
configured
configured for
type: object
properties:
id:
Expand Down Expand Up @@ -46660,7 +46660,9 @@ paths:
type: object
properties:
service:
title: The Service for which the application is configured
title: >-
The Service for which the application is configured
for
type: object
properties:
id:
Expand Down Expand Up @@ -47176,7 +47178,7 @@ paths:
service:
title: >-
The Service for which the application is
configured
configured for
type: object
properties:
id:
Expand Down Expand Up @@ -47243,7 +47245,7 @@ paths:
service:
title: >-
The Service for which the supplier is
configured
configured for
type: object
properties:
id:
Expand Down Expand Up @@ -76787,7 +76789,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the application is configured
title: The Service for which the application is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -76871,7 +76873,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the application is configured
title: The Service for which the application is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -76965,7 +76967,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the application is configured
title: The Service for which the application is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77016,7 +77018,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the application is configured
title: The Service for which the application is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77284,7 +77286,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the application is configured
title: The Service for which the application is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77348,7 +77350,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the supplier is configured
title: The Service for which the supplier is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77538,7 +77540,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the application is configured
title: The Service for which the application is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77600,7 +77602,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the supplier is configured
title: The Service for which the supplier is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77814,7 +77816,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the supplier is configured
title: The Service for which the supplier is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77943,7 +77945,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the supplier is configured
title: The Service for which the supplier is configured for
type: object
properties:
id:
Expand Down
8 changes: 6 additions & 2 deletions e2e/tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,12 @@ func (s *suite) TheSessionForApplicationAndServiceContainsTheSupplier(appName st
s.Fatalf("session for app %s and service %s does not contain supplier %s", appName, serviceId, supplierName)
}

func (s *suite) TheApplicationSendsTheSupplierARelayRequestForService(appName string, supplierName string, requestName string, serviceId string) {
// TODO(#126, @Olshansk): Implement this step
func (s *suite) TheApplicationSendsTheSupplierARequestForServiceWithData(appName, supplierName, serviceId, requestData string) {
res, err := s.pocketd.RunCurl("", requestData)
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
s.Fatalf("error sending relay request from app %s to supplier %s for service %s: %v", appName, supplierName, serviceId, err)
}
fmt.Println("OLSH", res)
}

func (s *suite) TheApplicationReceivesASuccessfulRelayResponseSignedBy(appName string, supplierName string) {
Expand Down
51 changes: 45 additions & 6 deletions e2e/tests/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var (
defaultRPCHost = "127.0.0.1"
// defaultHome is the default home directory for pocketd
defaultHome = os.Getenv("POKTROLLD_HOME")
// defaultRelayerURL used by curl commands to send relay requests
defaultRelayerURL = os.Getenv("RELAYER_NODE")
)

func init() {
Expand All @@ -42,8 +44,9 @@ type commandResult struct {

// PocketClient is a single function interface for interacting with a node
type PocketClient interface {
RunCommand(...string) (*commandResult, error)
RunCommandOnHost(string, ...string) (*commandResult, error)
RunCommand(args ...string) (*commandResult, error)
RunCommandOnHost(rpcUrl string, args ...string) (*commandResult, error)
RunCurl(rpcUrl string, data string, args ...string) (*commandResult, error)
}

// Ensure that pocketdBin struct fulfills PocketClient
Expand All @@ -56,7 +59,7 @@ type pocketdBin struct {

// RunCommand runs a command on the local machine using the pocketd binary
func (p *pocketdBin) RunCommand(args ...string) (*commandResult, error) {
return p.runCmd(args...)
return p.runPocketCmd(args...)
}

// RunCommandOnHost runs a command on specified host with the given args
Expand All @@ -65,11 +68,19 @@ func (p *pocketdBin) RunCommandOnHost(rpcUrl string, args ...string) (*commandRe
rpcUrl = defaultRPCURL
}
args = append(args, "--node", rpcUrl)
return p.runCmd(args...)
return p.runPocketCmd(args...)
}

// runCmd is a helper to run a command using the local pocketd binary with the flags provided
func (p *pocketdBin) runCmd(args ...string) (*commandResult, error) {
// RunCurl runs a curl command on the local machine
func (p *pocketdBin) RunCurl(rpcUrl string, data string, args ...string) (*commandResult, error) {
if rpcUrl == "" {
rpcUrl = defaultRelayerURL
}
return p.runCurlPostCmd(rpcUrl, data, args...)
}

// runPocketCmd is a helper to run a command using the local pocketd binary with the flags provided
func (p *pocketdBin) runPocketCmd(args ...string) (*commandResult, error) {
base := []string{"--home", defaultHome}
args = append(base, args...)
commandStr := "poktrolld " + strings.Join(args, " ") // Create a string representation of the command
Expand All @@ -95,3 +106,31 @@ func (p *pocketdBin) runCmd(args ...string) (*commandResult, error) {

return r, err
}

// runCurlPostCmd is a helper to run a command using the local pocketd binary with the flags provided
func (p *pocketdBin) runCurlPostCmd(rpcUrl string, data string, args ...string) (*commandResult, error) {
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
base := []string{"-X", "POST", "-H", "Content-Type: application/json", "--data", data, rpcUrl}
args = append(base, args...)
commandStr := "curl " + strings.Join(args, " ") // Create a string representation of the command
cmd := exec.Command("curl", args...)

var stdoutBuf, stderrBuf bytes.Buffer
cmd.Stdout = &stdoutBuf
cmd.Stderr = &stderrBuf

err := cmd.Run()
r := &commandResult{
Command: commandStr, // Set the command string
Stdout: stdoutBuf.String(),
Stderr: stderrBuf.String(),
Err: err,
}
p.result = r

if err != nil {
// Include the command executed in the error message for context
err = fmt.Errorf("error running command [%s]: %v, stderr: %s", commandStr, err, stderrBuf.String())
}

return r, err
}
2 changes: 1 addition & 1 deletion e2e/tests/relay.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Relay Namespace
And the application "app1" is staked for service "anvil"
And the supplier "supplier1" is staked for service "anvil"
And the session for application "app1" and service "anvil" contains the supplier "supplier1"
When the application "app1" sends the supplier "supplier1" a "getBlock" relay request for service "anvil"
When the application "app1" sends the supplier "supplier1" a request for service "anvil" with data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
Then the application "app1" receives a successful relay response signed by "supplier1"

# TODO_TEST(@Olshansk):
Expand Down