diff --git a/e2e/tests/init_test.go b/e2e/tests/init_test.go index 454238264..c7492903b 100644 --- a/e2e/tests/init_test.go +++ b/e2e/tests/init_test.go @@ -3,7 +3,9 @@ package e2e import ( + "flag" "fmt" + "log" "regexp" "strconv" "strings" @@ -22,6 +24,12 @@ import ( suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" ) +// TODO_TECHDEBT(@okdas): Once relayminer and appgateserver are running in tilt, +// use their respective in-tilt hostnames and run E2E tests in tilt. This +// should match the on-chain advertised endpoint for the service with the +// given serviceId. +const localnetAppGateServerUrl = "http://localhost:42069" + var ( addrRe *regexp.Regexp amountRe *regexp.Regexp @@ -31,12 +39,21 @@ var ( accNameToAppMap = make(map[string]apptypes.Application) accNameToSupplierMap = make(map[string]sharedtypes.Supplier) - keyRingFlag = "--keyring-backend=test" + flagFeaturesPath string + keyRingFlag = "--keyring-backend=test" ) func init() { addrRe = regexp.MustCompile(`address:\s+(\S+)\s+name:\s+(\S+)`) amountRe = regexp.MustCompile(`amount:\s+"(.+?)"\s+denom:\s+upokt`) + + flag.StringVar(&flagFeaturesPath, "features-path", "*.feature", "Specifies glob paths for the runner to look up .feature files") +} + +func TestMain(m *testing.M) { + flag.Parse() + log.Printf("features path: %s", flagFeaturesPath) + m.Run() } type suite struct { @@ -58,7 +75,7 @@ func (s *suite) Before() { // TestFeatures runs the e2e tests specified in any .features files in this directory // * This test suite assumes that a LocalNet is running func TestFeatures(t *testing.T) { - gocuke.NewRunner(t, &suite{}).Path("*.feature").Run() + gocuke.NewRunner(t, &suite{}).Path(flagFeaturesPath).Run() } func (s *suite) TheUserHasThePocketdBinaryInstalled() { @@ -243,16 +260,21 @@ func (s *suite) TheSessionForApplicationAndServiceContainsTheSupplier(appName st } func (s *suite) TheApplicationSendsTheSupplierARequestForServiceWithData(appName, supplierName, serviceId, requestData string) { - res, err := s.pocketd.RunCurl("", serviceId, requestData) + res, err := s.pocketd.RunCurl(localnetAppGateServerUrl, 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) + + relayKey := relayReferenceKey(appName, supplierName) + s.scenarioState[relayKey] = res.Stdout } func (s *suite) TheApplicationReceivesASuccessfulRelayResponseSignedBy(appName string, supplierName string) { - // TODO(#126, @Olshansk): Implement this step + relayKey := relayReferenceKey(appName, supplierName) + stdout, ok := s.scenarioState[relayKey] + + require.Truef(s, ok, "no relay response found for %s", relayKey) + require.Contains(s, stdout, `"result":"0x`) } func (s *suite) getStakedAmount(actorType, accName string) (bool, int) { @@ -363,3 +385,9 @@ func (s *suite) getAccBalance(accName string) int { require.NoError(s, err) return found } + +// TODO_IMPROVE: use `sessionId` and `supplierName` since those are the two values +// used to create the primary composite key on-chain to uniquely distinguish relays. +func relayReferenceKey(appName, supplierName string) string { + return fmt.Sprintf("%s/%s", appName, supplierName) +} diff --git a/e2e/tests/node.go b/e2e/tests/node.go index 533f347d7..440313431 100644 --- a/e2e/tests/node.go +++ b/e2e/tests/node.go @@ -115,7 +115,9 @@ func (p *pocketdBin) runPocketCmd(args ...string) (*commandResult, error) { // 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)} + dataStr := fmt.Sprintf("%s", data) + urlStr := fmt.Sprintf("%s/%s", rpcUrl, service) + base := []string{"-v", "POST", "-H", "Content-Type: application/json", "--data", dataStr, urlStr} args = append(base, args...) commandStr := "curl " + strings.Join(args, " ") // Create a string representation of the command cmd := exec.Command("curl", args...) diff --git a/pkg/appgateserver/errors.go b/pkg/appgateserver/errors.go index eecf99f44..c07a7843f 100644 --- a/pkg/appgateserver/errors.go +++ b/pkg/appgateserver/errors.go @@ -10,6 +10,7 @@ var ( ErrAppGateMissingAppAddress = sdkerrors.Register(codespace, 4, "missing application address") ErrAppGateMissingSigningInformation = sdkerrors.Register(codespace, 5, "missing app client signing information") ErrAppGateMissingListeningEndpoint = sdkerrors.Register(codespace, 6, "missing app client listening endpoint") - ErrAppGateEmptyRelayResponse = sdkerrors.Register(codespace, 7, "empty relay response") - ErrAppGateHandleRelay = sdkerrors.Register(codespace, 8, "internal error handling relay request") + ErrAppGateEmptyRelayResponseMeta = sdkerrors.Register(codespace, 7, "empty relay response metadata") + ErrAppGateEmptyRelayResponseSignature = sdkerrors.Register(codespace, 8, "empty relay response signature") + ErrAppGateHandleRelay = sdkerrors.Register(codespace, 9, "internal error handling relay request") ) diff --git a/pkg/appgateserver/relay_verifier.go b/pkg/appgateserver/relay_verifier.go index 4f86e1cdd..68e4cc418 100644 --- a/pkg/appgateserver/relay_verifier.go +++ b/pkg/appgateserver/relay_verifier.go @@ -26,7 +26,16 @@ func (app *appGateServer) verifyResponse( // Extract the supplier's signature if relayResponse.Meta == nil { - return ErrAppGateEmptyRelayResponse + payload := relayResponse.GetPayload() + payloadBz := make([]byte, payload.Size()) + if _, err := payload.MarshalTo(payloadBz); err != nil { + return ErrAppGateEmptyRelayResponseMeta.Wrapf( + "unable to marshal relay response payload: %s", err, + ) + } + return ErrAppGateEmptyRelayResponseSignature.Wrapf( + "response payload: %s", relayResponse.Payload, + ) } supplierSignature := relayResponse.Meta.SupplierSignature diff --git a/pkg/relayer/proxy/relay_verifier.go b/pkg/relayer/proxy/relay_verifier.go index ba8bf7e32..38da8c911 100644 --- a/pkg/relayer/proxy/relay_verifier.go +++ b/pkg/relayer/proxy/relay_verifier.go @@ -97,7 +97,7 @@ func (rp *relayerProxy) VerifyRelayRequest( // matches the relayRequest sessionId. // TODO_INVESTIGATE: Revisit the assumptions above at some point in the future, but good enough for now. if session.SessionId != relayRequest.Meta.SessionHeader.SessionId { - return ErrRelayerProxyInvalidSession + return ErrRelayerProxyInvalidSession.Wrapf("%+v", session) } // Check if the relayRequest is allowed to be served by the relayer proxy.