Skip to content

Commit

Permalink
chore: review feedback improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite committed Nov 15, 2023
1 parent 122bec0 commit 8c1f5b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
35 changes: 19 additions & 16 deletions e2e/tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ import (
suppliertypes "github.com/pokt-network/poktroll/x/supplier/types"
)

// TODO_TECHDEBT(#179): 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
Expand All @@ -33,20 +39,20 @@ var (
accNameToAppMap = make(map[string]apptypes.Application)
accNameToSupplierMap = make(map[string]sharedtypes.Supplier)

featuresPathFlag string
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(&featuresPathFlag, "features-path", "*.feature", "Specifies glob paths for the runner to look up .feature files")
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", featuresPathFlag)
log.Printf("features path: %s", flagFeaturesPath)
m.Run()
}

Expand All @@ -69,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(featuresPathFlag).Run()
gocuke.NewRunner(t, &suite{}).Path(flagFeaturesPath).Run()
}

func (s *suite) TheUserHasThePocketdBinaryInstalled() {
Expand Down Expand Up @@ -254,26 +260,17 @@ func (s *suite) TheSessionForApplicationAndServiceContainsTheSupplier(appName st
}

func (s *suite) TheApplicationSendsTheSupplierARequestForServiceWithData(appName, supplierName, serviceId, requestData string) {
// TODO_TECHDEBT(#179): 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.
res, err := s.pocketd.RunCurl("http://localhost:42069", 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)
}

relayKey := getRelayKey(appName, supplierName)
relayKey := relayReferenceKey(appName, supplierName)
s.scenarioState[relayKey] = res.Stdout
}

// TODO_IN_THIS_COMMIT: move
func getRelayKey(appName, supplierName string) string {
return fmt.Sprintf("%s/%s", appName, supplierName)
}

func (s *suite) TheApplicationReceivesASuccessfulRelayResponseSignedBy(appName string, supplierName string) {
relayKey := getRelayKey(appName, supplierName)
relayKey := relayReferenceKey(appName, supplierName)
stdout, ok := s.scenarioState[relayKey]

require.Truef(s, ok, "no relay response found for %s", relayKey)
Expand Down Expand Up @@ -388,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)
}
5 changes: 3 additions & 2 deletions pkg/appgateserver/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
ErrAppGateEmptyRelayResponseSignature = sdkerrors.Register(codespace, 7, "empty relay response signature")
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")
)
4 changes: 2 additions & 2 deletions pkg/appgateserver/relay_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func (app *appGateServer) verifyResponse(
payload := relayResponse.GetPayload()
payloadBz := make([]byte, payload.Size())
if _, err := payload.MarshalTo(payloadBz); err != nil {
return ErrAppGateEmptyRelayResponseSignature.Wrapf(
"unable to unmarshal relay response payload: %s", err,
return ErrAppGateEmptyRelayResponseMeta.Wrapf(
"unable to marshal relay response payload: %s", err,
)
}
return ErrAppGateEmptyRelayResponseSignature.Wrapf(
Expand Down

0 comments on commit 8c1f5b9

Please sign in to comment.