Skip to content

Commit

Permalink
[Test Utils] Minor developer experience test improvements (#574)
Browse files Browse the repository at this point in the history
Minor testing development environment improvements while going through the code:
- More comments
- Added `.env.dev` for sourcing
- Added an E2E test so `make test_e2e_params` is idempotent
- Added additional warning messages when running a local stress test
- Added a makefile catch all

Co-authored-by: Redouane Lakrache <[email protected]>
  • Loading branch information
Olshansk and red-0ne authored Jun 6, 2024
1 parent c6c5e6f commit ef972d5
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 38 deletions.
28 changes: 28 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file contains environment variables that are used in the development environment.
# It is a copy of what's in the Makefile but makes local development easier through
# a simple `source .env.dev` command.

POKTROLLD_HOME=./localnet/poktrolld
# The pocket node (validator in the localnet context)
POCKET_NODE=tcp://127.0.0.1:36657
# TestNet RPC endpoint for validator maintained by Grove. Needs to be updated if there's another "primary" testnet.
TESTNET_RPC=https://testnet-validated-validator-rpc.poktroll.com/
APPGATE_SERVER=http://localhost:42069
GATEWAY_URL=http://localhost:42079
POCKET_ADDR_PREFIX=pokt
CHAIN_ID=poktroll

# The domain ending in ".town" is staging, ".city" is production
GROVE_GATEWAY_STAGING_ETH_MAINNET=https://eth-mainnet.rpc.grove.town
# The "protocol" field here instructs the Grove gateway which network to use
JSON_RPC_DATA_ETH_BLOCK_HEIGHT='{"protocol": "shannon-testnet","jsonrpc":"2.0","id":"0","method":"eth_blockNumber", "params": []}'

# On-chain module account addresses. Search for `func TestModuleAddress` in the
# codebase to get an understanding of how we got these values.
APPLICATION_MODULE_ADDRESS=pokt1rl3gjgzexmplmds3tq3r3yk84zlwdl6djzgsvm
SUPPLIER_MODULE_ADDRESS=pokt1j40dzzmn6cn9kxku7a5tjnud6hv37vesr5ccaa
GATEWAY_MODULE_ADDRESS=pokt1f6j7u6875p2cvyrgjr0d2uecyzah0kget9vlpl
SERVICE_MODULE_ADDRESS=pokt1nhmtqf4gcmpxu0p6e53hpgtwj0llmsqpxtumcf
GOV_ADDRESS=pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t
# PNF acts on behalf of the DAO and who AUTHZ must delegate to
PNF_ADDRESS=pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
run: make go_lint

- name: Test
run: make go_test
run: make test_all
82 changes: 58 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
.SILENT:

SHELL = /bin/sh

# TODO_IMPROVE: Look into how we can we source `.env.dev` and have everything
# here work.

# ifneq (,$(wildcard .env))
# include .env
# export $(shell sed 's/=.*//' .env)
# endif

POKTROLLD_HOME ?= ./localnet/poktrolld
POCKET_NODE ?= tcp://127.0.0.1:36657 # The pocket node (validator in the localnet context)
TESTNET_RPC ?= https://testnet-validated-validator-rpc.poktroll.com/ # TestNet RPC endpoint for validator maintained by Grove. Needs to be update if there's another "primary" testnet.
Expand Down Expand Up @@ -107,6 +116,10 @@ help: ## Prints all the targets in all the Makefiles
### Checks ###
##############

# TODO_DOCUMENT: All of the `check_` helpers can be installed differently depending
# on the user's OS and environment.
# NB: For mac users, you may need to install with the proper linkers: https://github.com/golang/go/issues/65940

.PHONY: check_go_version
# Internal helper target - check go version
check_go_version:
Expand Down Expand Up @@ -303,7 +316,7 @@ localnet_down: ## Delete resources created by localnet
tilt down

.PHONY: localnet_regenesis
localnet_regenesis: check_yq acc_initialize_pubkeys_warn_message ## Regenerate the localnet genesis file
localnet_regenesis: check_yq warn_message_acc_initialize_pubkeys ## Regenerate the localnet genesis file
# NOTE: intentionally not using --home <dir> flag to avoid overwriting the test keyring
@echo "Initializing chain..."
@set -e
Expand Down Expand Up @@ -348,7 +361,7 @@ go_imports: check_go_version ## Run goimports on all go files
#############

.PHONY: test_e2e_env
test_e2e_env: acc_initialize_pubkeys_warn_message ## Setup the default env vars for E2E tests
test_e2e_env: warn_message_acc_initialize_pubkeys ## Setup the default env vars for E2E tests
export POCKET_NODE=$(POCKET_NODE) && \
export APPGATE_SERVER=$(APPGATE_SERVER) && \
export POKTROLLD_HOME=../../$(POKTROLLD_HOME)
Expand Down Expand Up @@ -382,36 +395,32 @@ test_e2e_params: test_e2e_env ## Run only the E2E suite that exercises parameter
go test -v ./e2e/tests/... -tags=e2e,test --features-path=update_params.feature

.PHONY: test_load_relays_stress
test_load_relays_stress: ## Run the stress test for E2E relays on non-ephemeral chains
test_load_relays_stress: ## Run the stress test for E2E relays on a persistent (non-ephemeral) remote chains
go test -v -count=1 ./load-testing/tests/... \
-tags=load,test -run LoadRelays --log-level=debug --timeout=30m \
--manifest ./load-testing/loadtest_manifest.yaml

.PHONY: test_load_relays_stress_localnet
test_load_relays_stress_localnet: test_e2e_env ## Run the stress test for E2E relays.
test_load_relays_stress_localnet: warn_message_local_stress_test test_e2e_env ## Run the stress test for E2E relays on LocalNet.
go test -v -count=1 ./load-testing/tests/... \
-tags=load,test -run LoadRelays --log-level=debug --timeout=30m \
--manifest ./load-testing/localnet_loadtest_manifest.yaml

.PHONY: go_test_verbose
go_test_verbose: check_go_version ## Run all go tests verbosely
.PHONY: test_verbose
test_verbose: check_go_version ## Run all go tests verbosely
go test -count=1 -v -race -tags test ./...

.PHONY: go_test
go_test: check_go_version ## Run all go tests showing detailed output only on failures
.PHONY: test_all
test_all: check_go_version ## Run all go tests showing detailed output only on failures
go test -count=1 -race -tags test ./...

.PHONY: go_test_integration
go_test_integration: check_go_version ## Run all go tests, including integration
.PHONY: test_integration
test_integration: check_go_version ## Run all go tests, including integration
go test -count=1 -v -race -tags test,integration ./...

.PHONY: itest
itest: check_go_version ## Run tests iteratively (see usage for more)
./tools/scripts/itest.sh $(filter-out $@,$(MAKECMDGOALS))
# catch-all target for itest
%:
# no-op
@:

.PHONY: go_mockgen
go_mockgen: ## Use `mockgen` to generate mocks used for testing purposes of all the modules.
Expand All @@ -437,7 +446,7 @@ go_testgen_accounts: ## Generate test accounts for usage in test environments
go_develop: check_ignite_version proto_regen go_mockgen ## Generate protos and mocks

.PHONY: go_develop_and_test
go_develop_and_test: go_develop go_test ## Generate protos, mocks and run all tests
go_develop_and_test: go_develop test_all ## Generate protos, mocks and run all tests

#############
### TODOS ###
Expand Down Expand Up @@ -759,16 +768,33 @@ acc_initialize_pubkeys: ## Make sure the account keeper has public keys for all
--node $(POCKET_NODE) \
--chain-id $(CHAIN_ID);)

.PHONY: acc_initialize_pubkeys_warn_message
acc_initialize_pubkeys_warn_message: ## Print a warning message about the need to run `make acc_initialize_pubkeys`
########################
### Warning Messages ###
########################

.PHONY: warn_message_acc_initialize_pubkeys
warn_message_acc_initialize_pubkeys: ## Print a warning message about the need to run `make acc_initialize_pubkeys`
@echo "+----------------------------------------------------------------------------------+"
@echo "| |"
@echo "| IMPORTANT: Please run the following command once to initialize E2E tests |"
@echo "| after the network has started: |"
@echo "| make acc_initialize_pubkeys |"
@echo "| IMPORTANT: Please run the following command once to initialize |"
@echo "| E2E tests after the network has started: |"
@echo "| |"
@echo "| make acc_initialize_pubkeys |"
@echo "| |"
@echo "+----------------------------------------------------------------------------------+"

.PHONY: warn_message_local_stress_test
warn_message_local_stress_test: ## Print a warning message when kicking off a local E2E relay stress test
@echo "+-----------------------------------------------------------------------------------------------+"
@echo "| |"
@echo "| IMPORTANT: Please read the following before continuing with the stress test. |"
@echo "| |"
@echo "| 1. Review the # of suppliers & gateways in 'load-testing/localnet_loadtest_manifest.yaml' |"
@echo "| 2. Update 'localnet_config.yaml' to reflect what you found in (1) |"
@echo "| |"
@echo "| TODO_DOCUMENT(@olshansk): Move this into proper documentation w/ clearer explanations |"
@echo "| |"
@echo "+-----------------------------------------------------------------------------------------------+"

##############
### Claims ###
Expand Down Expand Up @@ -875,6 +901,10 @@ ignite_acc_list: ## List all the accounts in LocalNet
ignite_poktrolld_build: check_go_version check_ignite_version ## Build the poktrolld binary using Ignite
ignite chain build --skip-proto --debug -v -o $(shell go env GOPATH)/bin

.PHONY: ignite_openapi_gen
ignite_openapi_gen: ## Generate the OpenAPI spec for the Ignite API
ignite generate openapi --yes

##################
### CI Helpers ###
##################
Expand Down Expand Up @@ -929,10 +959,6 @@ go_docs: check_godoc ## Generate documentation for the project
echo "Visit http://localhost:6060/pkg/github.com/pokt-network/poktroll/"
godoc -http=:6060

.PHONY: openapi_gen
openapi_gen: ## Generate the OpenAPI spec for the Ignite API
ignite generate openapi --yes

.PHONY: docusaurus_start
docusaurus_start: check_npm check_node ## Start the Docusaurus server
(cd docusaurus && npm i && npm run start)
Expand Down Expand Up @@ -984,3 +1010,11 @@ grove_staging_eth_block_height: ## Sends a relay through the staging grove gatew
-H 'Content-Type: application/json' \
-H 'Protocol: shannon-testnet' \
--data $(JSON_RPC_DATA_ETH_BLOCK_HEIGHT)

#################
### Catch all ###
#################

%:
@echo "Error: target '$@' not found."
@exit 1
2 changes: 1 addition & 1 deletion docusaurus/docs/develop/developer_guide/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ There are some flaky tests, so you can re-run with the following command without
needing to regenerate the mocks and types:

```bash
make go_test
make test_all
```

### 1.4 Create a `k8s` cluster
Expand Down
5 changes: 5 additions & 0 deletions e2e/tests/update_params.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Feature: Params Namespace

Scenario: All params are reset to their default values
Given the user has the pocketd binary installed
And an authz grant from the "gov" "module" account to the "pnf" "user" account for the "/poktroll.tokenomics.MsgUpdateParams" message exists
Then all module params are reset to their default values

Scenario: An unauthorized user cannot update a module params
Given the user has the pocketd binary installed
And all "tokenomics" module params are set to their default values
Expand Down
43 changes: 41 additions & 2 deletions e2e/tests/update_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
"time"

cometcli "github.com/cometbft/cometbft/libs/cli"
"github.com/cosmos/cosmos-sdk/codec/types"
cosmostypes "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/gogoproto/proto"
"github.com/regen-network/gocuke"
"github.com/stretchr/testify/require"

Expand All @@ -31,6 +33,9 @@ const (
// txFeesCoinStr is the string representation of the amount & denom of tokens
// which are sufficient to pay for tx fees in the test.
txFeesCoinStr = "1000000upokt"
// PNF is the account that acts on behalf of the DAO and is therefore the only
// one authorized to perform certain actions such as updating params.
pnfKeyName = "pnf"
)

// AllModuleParamsAreSetToTheirDefaultValues asserts that all module params are set to their default values.
Expand Down Expand Up @@ -219,9 +224,43 @@ func (s *suite) TheModuleParamShouldBeUpdated(moduleName, paramName string) {
s.assertExpectedModuleParamsUpdated(moduleName)
}

// AllModuleParamsShouldBeSetToTheirDefaultValues ensures that all module params are set to their default values.
func (s *suite) AllModuleParamsAreResetToTheirDefaultValues() {
var anyMsgs []*types.Any

// List of all module MsgUpdateParams types and their respective default param functions
modules := []struct {
msgUpdateParamsType reflect.Type
defaultParams any
}{
{reflect.TypeOf(&apptypes.MsgUpdateParams{}), apptypes.DefaultParams()},
{reflect.TypeOf(&gatewaytypes.MsgUpdateParams{}), gatewaytypes.DefaultParams()},
{reflect.TypeOf(&prooftypes.MsgUpdateParams{}), prooftypes.DefaultParams()},
{reflect.TypeOf(&servicetypes.MsgUpdateParams{}), servicetypes.DefaultParams()},
{reflect.TypeOf(&sessiontypes.MsgUpdateParams{}), sessiontypes.DefaultParams()},
{reflect.TypeOf(&sharedtypes.MsgUpdateParams{}), sharedtypes.DefaultParams()},
{reflect.TypeOf(&suppliertypes.MsgUpdateParams{}), suppliertypes.DefaultParams()},
{reflect.TypeOf(&tokenomicstypes.MsgUpdateParams{}), tokenomicstypes.DefaultParams()},
}

for _, module := range modules {
msgUpdateParams := reflect.New(module.msgUpdateParamsType.Elem()).Interface().(proto.Message)
msgUpdateParamsValue := reflect.ValueOf(msgUpdateParams).Elem()
msgUpdateParamsValue.FieldByName("Authority").SetString(s.granteeName)
msgUpdateParamsValue.FieldByName("Params").Set(reflect.ValueOf(module.defaultParams))

anyMsg, err := types.NewAnyWithValue(msgUpdateParams)
require.NoError(s, err)
anyMsgs = append(anyMsgs, anyMsg)
}

file := s.newTempTxJSONFile(anyMsgs)
s.sendAuthzExecTx(s.granteeName, file.Name())
}

// TheModuleParamShouldBeSetToItsDefaultValue asserts that the given param for the
// given module has been set to its default value.
func (s *suite) TheModuleParamShouldBeSetToItsDefaultValue(moduleName string, paramName string) {
func (s *suite) TheModuleParamShouldBeSetToItsDefaultValue(moduleName, paramName string) {
// TODO_HACK: So long as no other modules are expected to have been changed by this scenario,
// it is more than sufficient (and less code) to re-use the existing step which asserts that
// all modules have their params set to their respective defaults.
Expand Down Expand Up @@ -251,7 +290,7 @@ func (s *suite) fundAddress(addr string, coin cosmostypes.Coin) {
"tx",
"bank",
"send",
"pnf",
pnfKeyName,
addr,
coin.String(),
"--yes",
Expand Down
10 changes: 8 additions & 2 deletions load-testing/loadtest_manifest.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# This file is used to configure the load test for non-ephemeral chains.
# The load test uses the provided gateways and the staked suppliers to send relays.

# This file is used to configure the load test for non-ephemeral chains.
# It is intended to target a remote environment, such as a devnet or testnet.
is_ephemeral_chain: false

# testnet_node is the URL of the node that the load test will use to query the
# chain and submit transactions.
testnet_node: https://testnet-validated-validator-rpc.poktroll.com

# The service ID to request relays from.
service_id: "0021"

# The address of the account that will be used to fund the the application accounts
# so that they can stake on the network.
funding_account_address: pokt14eh973xt99s7edugnyvd5d5u50d6j0hysw2vsm # address for pnf account

# In non-ephemeral chains, the gateways are identified by their address.
gateways:
# address is the bech32 pokt address of the gateway.
- address: pokt16sty9mjdh4u2fwgj8ptufg42cysvh6gsyx6wfp
# The url used to send relays to the gateway on.
exposed_url: http://localhost:84
exposed_url: http://localhost:84
29 changes: 21 additions & 8 deletions load-testing/localnet_loadtest_manifest.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
# List of pre-provisioned suppliers used for load testing
# The number of pre-provisioned **LocalNet** actors are managed in
# localnet_config.yaml by the respective actors `count` property.
# NB: The number of pre-provisioned **LocalNet** actors are managed in
# 'localnet_config.yaml' by the respective actors `count` property.
is_ephemeral_chain: true

# The service ID to use for the load test.
service_id: anvil

# The address of the account that will be used to fund the the application,
# gateway and supplier accounts so that they can stake on the network.
funding_account_address: pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw # address for pnf account

# List of pre-provisioned suppliers used for load testing.
# Thse suppliers will be progressively staked during the load test, according
# These suppliers will be progressively staked during the load test, according
# to the test plan that is being executed.
suppliers:
# The supplier address that is available in the load test's environment keyring,
# used to identify the supplier and sign relays and transactions with.
# It must be the address corresponding to the provided signing_key_name in the
# `relay_miner_config.yaml` file.

# RelayMiner 1; http://localhost:10350/r/relayminer1/overview
- address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj
# The advertised URL used by the supplier when it submits a stake message on-chain.
# The advertised URL used by the supplier when it submits a stake message on-chain.
exposed_url: http://relayminer1:8545

# RelayMiner 2; http://localhost:10350/r/relayminer2/overview
- address: pokt1re27pw4llwnatx4sq7rlggqzcm6j3f39epq2wa
exposed_url: http://relayminer2:8545

# RelayMiner 3; http://localhost:10350/r/relayminer3/overview
- address: pokt1j6dun0x8eyq5mmsmq83zs3c2utt85q8478c89u
exposed_url: http://relayminer3:8545

# List of pre-provisioned gateways used for load testing.
# These gateways will be progressively staked and delegated to during the load test.
gateways:
# The gateway address that is available in the load test's environment keyring,
# used to identify the gateway and sign relays and transactions with.
# It must be the address corresponding to the provided signing_key_name in the
# `appgate_server_config.yaml` file.

# Gateway 1; http://localhost:10350/r/gateway1/overview
- address: pokt15vzxjqklzjtlz7lahe8z2dfe9nm5vxwwmscne4
# The url used to send relays to the gateway on.
exposed_url: http://localhost:42079
exposed_url: http://localhost:42079 # The url used to send relays to the gateway on.

# Gateway 2; http://localhost:10350/r/gateway2/overview
- address: pokt15w3fhfyc0lttv7r585e2ncpf6t2kl9uh8rsnyz
exposed_url: http://localhost:42080

# Gateway 3; http://localhost:10350/r/gateway3/overview
- address: pokt1zhmkkd0rh788mc9prfq0m2h88t9ge0j83gnxya
exposed_url: http://localhost:42081
exposed_url: http://localhost:42081
Loading

0 comments on commit ef972d5

Please sign in to comment.