Skip to content

Commit

Permalink
[WIP] Updating relay.feature to run curl command
Browse files Browse the repository at this point in the history
  • Loading branch information
Olshansk committed Nov 10, 2023
1 parent 5af2ae9 commit 0c4e353
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 21 deletions.
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
4 changes: 2 additions & 2 deletions e2e/tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ 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) {
s.pocketd.RunCurl(requestData)
}

func (s *suite) TheApplicationReceivesASuccessfulRelayResponseSignedBy(appName string, supplierName string) {
Expand Down
42 changes: 38 additions & 4 deletions e2e/tests/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type commandResult struct {
type PocketClient interface {
RunCommand(...string) (*commandResult, error)
RunCommandOnHost(string, ...string) (*commandResult, error)
RunCurl(string, ...string) (*commandResult, error)
}

// Ensure that pocketdBin struct fulfills PocketClient
Expand All @@ -56,7 +57,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 +66,16 @@ 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(data string, args ...string) (*commandResult, error) {
return p.runCurlPostCmd(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 +101,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(data string, args ...string) (*commandResult, error) {
base := []string{"-X", "POST", "-H", "Content-Type: application/json", "--data", data}
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

0 comments on commit 0c4e353

Please sign in to comment.