diff --git a/Makefile b/Makefile index 1f06b4f68..104950507 100644 --- a/Makefile +++ b/Makefile @@ -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 #################### @@ -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 diff --git a/config.yml b/config.yml index f21fe2be6..f6e3c1e89 100644 --- a/config.yml +++ b/config.yml @@ -100,7 +100,7 @@ genesis: - endpoints: - configs: [] rpc_type: JSON_RPC - url: http://anvil:8547 + url: http://localhost:8545 service: id: anvil name: "" diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index d82f777d7..f55a851f2 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -46480,7 +46480,7 @@ paths: service: title: >- The Service for which the application is - configured + configured for type: object properties: id: @@ -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: @@ -47176,7 +47178,7 @@ paths: service: title: >- The Service for which the application is - configured + configured for type: object properties: id: @@ -47243,7 +47245,7 @@ paths: service: title: >- The Service for which the supplier is - configured + configured for type: object properties: id: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/e2e/tests/init_test.go b/e2e/tests/init_test.go index 6bd5aeb27..454238264 100644 --- a/e2e/tests/init_test.go +++ b/e2e/tests/init_test.go @@ -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) { diff --git a/e2e/tests/node.go b/e2e/tests/node.go index ad0540942..533f347d7 100644 --- a/e2e/tests/node.go +++ b/e2e/tests/node.go @@ -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") ) @@ -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 @@ -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 @@ -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 @@ -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 +} diff --git a/e2e/tests/relay.feature b/e2e/tests/relay.feature index 4f071bfa6..484172092 100644 --- a/e2e/tests/relay.feature +++ b/e2e/tests/relay.feature @@ -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): diff --git a/pkg/appgateserver/cmd/cmd.go b/pkg/appgateserver/cmd/cmd.go index 21052e270..663562e98 100644 --- a/pkg/appgateserver/cmd/cmd.go +++ b/pkg/appgateserver/cmd/cmd.go @@ -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 } diff --git a/pkg/appgateserver/jsonrpc.go b/pkg/appgateserver/jsonrpc.go index 3be01cca7..80784fb44 100644 --- a/pkg/appgateserver/jsonrpc.go +++ b/pkg/appgateserver/jsonrpc.go @@ -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 {