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
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
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)
APPGATE_SERVER = http://localhost:42069
POCKET_ADDR_PREFIX = pokt

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

Expand Down
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ genesis:
- endpoints:
- configs: []
rpc_type: JSON_RPC
url: http://anvil:8547
url: http://localhost:8545
service:
id: anvil
name: ""
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
9 changes: 7 additions & 2 deletions e2e/tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,13 @@ 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("", serviceId, requestData)
if err != nil {
s.Fatalf("error sending relay request from app %s to supplier %s for service %s: %v", appName, supplierName, serviceId, err)
}
// TODO(#184): store & use the result of res
fmt.Println(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")
// defaultAppGateServerURL used by curl commands to send relay requests
defaultAppGateServerURL = os.Getenv("APPGATE_SERVER")
// defaultDebugOutput provides verbose output on manipulations with binaries (cli command, stdout, stderr)
defaultDebugOutput = os.Getenv("E2E_DEBUG_OUTPUT")
)
Expand All @@ -44,8 +46,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, service, data string, args ...string) (*commandResult, error)
}

// Ensure that pocketdBin struct fulfills PocketClient
Expand All @@ -58,7 +61,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 @@ -67,11 +70,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, service, data string, args ...string) (*commandResult, error) {
if rpcUrl == "" {
rpcUrl = defaultAppGateServerURL
}
return p.runCurlPostCmd(rpcUrl, service, 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 Down Expand Up @@ -101,3 +112,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, service string, data string, args ...string) (*commandResult, error) {
base := []string{"-v", "-X", "POST", "-H", "'Content-Type: application/json'", "--data", fmt.Sprintf("'%s'", data), fmt.Sprintf("%s/%s", rpcUrl, service)}
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
2 changes: 1 addition & 1 deletion pkg/appgateserver/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,6 @@ func setupAppGateServerDependencies(cmd *cobra.Command, ctx context.Context, com
return nil, fmt.Errorf("failed to create block client: %w", err)
}

// Return the dependencie config.
// Return the dependencies config.
return depinject.Supply(clientCtx, blockClient), nil
}
1 change: 0 additions & 1 deletion pkg/appgateserver/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func (app *appGateServer) handleJSONRPCRelay(
Body: relayRequestReader,
}

// Perform the HTTP request to the relayer.
log.Printf("DEBUG: Sending signed relay request to %s", supplierUrl)
relayHTTPResponse, err := http.DefaultClient.Do(relayHTTPRequest)
if err != nil {
Expand Down