Skip to content

Commit

Permalink
[TEST] Helpers for E2E testing to alleviate issues related to public …
Browse files Browse the repository at this point in the history
…keys on genesis (#357)

Some helpers and workarounds to improve the E2E testing experience.

- #180
---

Co-authored-by: Redouane Lakrache <[email protected]>
  • Loading branch information
Olshansk and red-0ne authored Feb 2, 2024
1 parent 1b4a8d5 commit d78256b
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 35 deletions.
3 changes: 1 addition & 2 deletions .github/workflows-helpers/run-e2e-test-job-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ spec:
poktrolld q gateway list-gateway --node=$POCKET_NODE && \
poktrolld q application list-application --node=$POCKET_NODE && \
poktrolld q supplier list-supplier --node=$POCKET_NODE && \
poktrolld tx supplier stake-supplier --config=/poktroll/localnet/poktrolld/config/supplier1_stake_config.yaml --keyring-backend=test --from=supplier1 --node=$POCKET_NODE --yes && \
poktrolld tx application stake-application --config=/poktroll/localnet/poktrolld/config/application1_stake_config.yaml --keyring-backend=test --from=app1 --node=$POCKET_NODE --yes && \
make acc_initialize_pubkeys && \
go test -v ./e2e/tests/... -tags=e2e
env:
- name: AUTH_TOKEN
Expand Down
38 changes: 32 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
.SILENT:

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
SHELL = /bin/sh
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 @@ -166,7 +167,7 @@ localnet_down: ## Delete resources created by localnet
kubectl delete secret celestia-secret || exit 1

.PHONY: localnet_regenesis
localnet_regenesis: ## Regenerate the localnet genesis file
localnet_regenesis: acc_initialize_pubkeys_warn_message ## Regenerate the localnet genesis file
# NOTE: intentionally not using --home <dir> flag to avoid overwriting the test keyring
ignite chain init
mkdir -p $(POKTROLLD_HOME)/config/
Expand Down Expand Up @@ -195,7 +196,7 @@ go_imports: check_go_version ## Run goimports on all go files
#############

.PHONY: test_e2e
test_e2e: ## Run all E2E tests
test_e2e: acc_initialize_pubkeys_warn_message ## Run all E2E tests
export POCKET_NODE=$(POCKET_NODE) && \
export APPGATE_SERVER=$(APPGATE_SERVER) && \
POKTROLLD_HOME=../../$(POKTROLLD_HOME) && \
Expand Down Expand Up @@ -357,7 +358,6 @@ app_list: ## List all the staked applications
app_stake: ## Stake tokens for the application specified (must specify the APP and SERVICES env vars)
poktrolld --home=$(POKTROLLD_HOME) tx application stake-application --config $(POKTROLLD_HOME)/config/$(SERVICES) --keyring-backend test --from $(APP) --node $(POCKET_NODE)

# TODO_IMPROVE(#180): Make sure genesis-staked actors are available via AccountKeeper
.PHONY: app1_stake
app1_stake: ## Stake app1 (also staked in genesis)
APP=app1 SERVICES=application1_stake_config.yaml make app_stake
Expand Down Expand Up @@ -517,6 +517,32 @@ acc_balance_query_app1: ## Query the balance of app1
acc_balance_total_supply: ## Query the total supply of the network
poktrolld --home=$(POKTROLLD_HOME) q bank total --node $(POCKET_NODE)

# NB: Ignite does not populate `pub_key` in `accounts` within `genesis.json` leading
# to queries like this to fail: `poktrolld query account pokt1<addr> --node $(POCKET_NODE).
# We attempted using a `tx multi-send` from the `faucet` to all accounts, but
# that also did not solve this problem because the account itself must sign the
# transaction for its public key to be populated in the account keeper. As such,
# the solution is to send funds from every account in genesis to some address
# (PNF was selected ambigously) to make sure their public keys are populated.

.PHONY: acc_initialize_pubkeys
acc_initialize_pubkeys: ## Make sure the account keeper has public keys for all available accounts
$(eval ADDRESSES=$(shell make -s ignite_acc_list | grep pokt | awk '{printf "%s ", $$2}' | sed 's/.$$//'))
$(eval PNF_ADDR=pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw)
# @printf "Addresses: ${ADDRESSES}"
$(foreach addr, $(ADDRESSES),\
echo $(addr);\
poktrolld tx bank send \
$(addr) $(PNF_ADDR) 1000upokt \
--yes \
--home=$(POKTROLLD_HOME) \
--node $(POCKET_NODE);)

.PHONY: acc_initialize_pubkeys_warn_message
acc_initialize_pubkeys_warn_message: ## Print a warning message about the need to run `make acc_initialize_pubkeys`
@printf "!!! YOU MUST RUN THE FOLLOWING COMMAND ONCE FOR E2E TESTS TO WORK AFTER THE NETWORK HAS STARTED!!!\n"\
"\t\tmake acc_initialize_pubkeys\n"

##############
### Claims ###
##############
Expand Down
26 changes: 8 additions & 18 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47184,7 +47184,7 @@ paths:
service:
title: >-
The Service for which the application is
configured
configured for
type: object
properties:
id:
Expand Down Expand Up @@ -47251,7 +47251,7 @@ paths:
service:
title: >-
The Service for which the supplier is
configured
configured for
type: object
properties:
id:
Expand Down Expand Up @@ -47287,14 +47287,12 @@ paths:
- GRPC
- WEBSOCKET
- JSON_RPC
- REST
default: UNKNOWN_RPC
description: |-
- UNKNOWN_RPC: Undefined RPC type
- GRPC: gRPC
- WEBSOCKET: WebSocket
- JSON_RPC: JSON-RPC
- REST: REST
configs:
type: array
items:
Expand Down Expand Up @@ -77918,7 +77916,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 @@ -77982,7 +77980,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 @@ -78017,14 +78015,12 @@ definitions:
- GRPC
- WEBSOCKET
- JSON_RPC
- REST
default: UNKNOWN_RPC
description: |-
- UNKNOWN_RPC: Undefined RPC type
- GRPC: gRPC
- WEBSOCKET: WebSocket
- JSON_RPC: JSON-RPC
- REST: REST
configs:
type: array
items:
Expand Down Expand Up @@ -78174,7 +78170,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 @@ -78236,7 +78232,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 @@ -78271,14 +78267,12 @@ definitions:
- GRPC
- WEBSOCKET
- JSON_RPC
- REST
default: UNKNOWN_RPC
description: |-
- UNKNOWN_RPC: Undefined RPC type
- GRPC: gRPC
- WEBSOCKET: WebSocket
- JSON_RPC: JSON-RPC
- REST: REST
configs:
type: array
items:
Expand Down Expand Up @@ -78425,7 +78419,6 @@ definitions:
- GRPC: gRPC
- WEBSOCKET: WebSocket
- JSON_RPC: JSON-RPC
- REST: REST
title: Enum to define RPC types
pocket.shared.Supplier:
type: object
Expand Down Expand Up @@ -78454,7 +78447,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 @@ -78494,7 +78487,6 @@ definitions:
- GRPC: gRPC
- WEBSOCKET: WebSocket
- JSON_RPC: JSON-RPC
- REST: REST
configs:
type: array
items:
Expand Down Expand Up @@ -78553,7 +78545,6 @@ definitions:
- GRPC: gRPC
- WEBSOCKET: WebSocket
- JSON_RPC: JSON-RPC
- REST: REST
configs:
type: array
items:
Expand Down Expand Up @@ -78587,7 +78578,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 @@ -78626,7 +78617,6 @@ definitions:
- GRPC: gRPC
- WEBSOCKET: WebSocket
- JSON_RPC: JSON-RPC
- REST: REST
configs:
type: array
items:
Expand Down
6 changes: 3 additions & 3 deletions docusaurus/docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ If you re-run, `make app_list` you should see that `SHANNON_ADDRESS` is now stak

### Send a relay

:::danger
Please run `make supplier1_stake && make app1_stake` before sending a relay.
This is related to some techdebt(#180) that will be fixed soon.
:::warning
You must run `make acc_initialize_pubkeys` before sending a relay in order for
the public keys to be initialized correctly.
:::

If you look in `localnet/poktrolld/config/appgate_server_config.yaml`, you'll find
Expand Down
3 changes: 1 addition & 2 deletions e2e/tests/relay.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Feature: Relay Namespace

# TODO_TECHDEBT(@Olshansk, #180): This test requires you to run `make supplier1_stake && make app1_stake` first
# As a shorter workaround, we can also add steps that stake the application and supplier as part of the scenario.
# NB: `make acc_initialize_pubkeys` must have been executed before this test is run
Scenario: App can send relay to Supplier
Given the user has the pocketd binary installed
And the application "app1" is staked for service "anvil"
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/athanorlabs/go-dleq v0.1.0
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/ibc-go/v7 v7.3.1
Expand All @@ -50,6 +51,7 @@ require (
golang.org/x/crypto v0.15.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/sync v0.5.0
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb
google.golang.org/grpc v1.59.0
gopkg.in/yaml.v2 v2.4.0
)
Expand Down Expand Up @@ -96,7 +98,6 @@ require (
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v0.20.0 // indirect
Expand Down Expand Up @@ -293,7 +294,6 @@ require (
google.golang.org/api v0.143.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
1 change: 0 additions & 1 deletion localnet/poktrolld/config/supplier1_stake_config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# TODO(@Olshansk, @okdas): Add more services (in addition to anvil) for apps and suppliers to stake for.
# TODO_TECHDEBT: svc1 below are only in place to make GetSession testable
# TODO_IMPROVE(#180): Make sure genesis-staked actors are available via AccountKeeper
stake_amount: 1000upokt
services:
- service_id: anvil
Expand Down
5 changes: 4 additions & 1 deletion pkg/sdk/errors.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package sdk

import sdkerrors "cosmossdk.io/errors"
import (
sdkerrors "cosmossdk.io/errors"
)

var (
codespace = "poktrollsdk"
ErrSDKHandleRelay = sdkerrors.Register(codespace, 1, "internal error handling relay request")
ErrSDKInvalidRelayResponseSignature = sdkerrors.Register(codespace, 2, "invalid relay response signature")
ErrSDKEmptyRelayResponseSignature = sdkerrors.Register(codespace, 3, "empty relay response signature")
ErrSDKVerifyResponseSignature = sdkerrors.Register(codespace, 4, "error verifying relay response signature")
ErrSDKEmptySupplierPubKey = sdkerrors.Register(codespace, 5, "empty supplier public key")
)
14 changes: 14 additions & 0 deletions pkg/sdk/relay_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"

"github.com/pokt-network/poktroll/pkg/polylog"
"github.com/pokt-network/poktroll/x/service/types"
)

Expand All @@ -14,6 +15,8 @@ func (sdk *poktrollSDK) verifyResponse(
supplierAddress string,
relayResponse *types.RelayResponse,
) error {
logger := polylog.Ctx(context.Background())

// Get the supplier's public key.
supplierPubKey, err := sdk.getSupplierPubKeyFromAddress(ctx, supplierAddress)
if err != nil {
Expand All @@ -34,6 +37,13 @@ func (sdk *poktrollSDK) verifyResponse(
return err
}

logger.Debug().
Str("supplier", supplierAddress).
Str("application", relayResponse.Meta.SessionHeader.ApplicationAddress).
Str("service", relayResponse.Meta.SessionHeader.Service.Id).
Int64("end_height", relayResponse.Meta.SessionHeader.SessionEndBlockHeight).
Msg("About to verify relay response signature.")

// Verify the relay response signature.
if !supplierPubKey.VerifySignature(responseSignableBz[:], supplierSignature) {
return ErrSDKInvalidRelayResponseSignature
Expand Down Expand Up @@ -61,6 +71,10 @@ func (sdk *poktrollSDK) getSupplierPubKeyFromAddress(
}

fetchedPubKey := acc.GetPubKey()
if fetchedPubKey == nil {
return nil, ErrSDKEmptySupplierPubKey
}

// Cache the retrieved public key.
sdk.supplierAccountCache[supplierAddress] = fetchedPubKey

Expand Down

0 comments on commit d78256b

Please sign in to comment.