From 3a7315cf184c77fe81257954260f632600ca8061 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 11 Sep 2024 10:57:42 +0200 Subject: [PATCH 01/14] test: make stake_supplier.feature idempotent --- e2e/tests/stake_supplier.feature | 3 +++ 1 file changed, 3 insertions(+) diff --git a/e2e/tests/stake_supplier.feature b/e2e/tests/stake_supplier.feature index 8a9aff15d..0cb143140 100644 --- a/e2e/tests/stake_supplier.feature +++ b/e2e/tests/stake_supplier.feature @@ -34,3 +34,6 @@ Feature: Stake Supplier Namespace But the session for application "app1" and service "anvil" does not contain "supplier2" When the user waits for supplier "supplier2" to become active for service "anvil" Then the session for application "app1" and service "anvil" contains the supplier "supplier2" + # Cleanup to make this feature idempotent. + And the user unstakes a "supplier" from the account "supplier2" + And the user waits for the supplier for account "supplier2" unbonding period to finish From 97068770ce22e2383a7179307fe1af765e98bac8 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 11 Sep 2024 10:57:52 +0200 Subject: [PATCH 02/14] test: speed up stake_supplier.feature --- e2e/tests/stake_supplier.feature | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/e2e/tests/stake_supplier.feature b/e2e/tests/stake_supplier.feature index 0cb143140..8fbb97ac2 100644 --- a/e2e/tests/stake_supplier.feature +++ b/e2e/tests/stake_supplier.feature @@ -14,6 +14,21 @@ Feature: Stake Supplier Namespace Scenario: User can unstake a Supplier Given the user has the pocketd binary installed + # Reduce the application unbonding period to avoid timeouts and speed up scenarios. + And an authz grant from the "gov" "module" account to the "pnf" "user" account for each module MsgUpdateParam message exists + # NB: If new parameters are added to the shared module, they + # MUST be included here; otherwise, this step will fail. + And the "pnf" account sends an authz exec message to update all "shared" module params + | name | value | type | + | num_blocks_per_session | 2 | int64 | + | grace_period_end_offset_blocks | 0 | int64 | + | claim_window_open_offset_blocks | 0 | int64 | + | claim_window_close_offset_blocks | 1 | int64 | + | proof_window_open_offset_blocks | 0 | int64 | + | proof_window_close_offset_blocks | 1 | int64 | + | supplier_unbonding_period_sessions | 1 | int64 | + | application_unbonding_period_sessions | 1 | int64 | + And all "shared" module params should be updated And the "supplier" for account "supplier2" is staked with "1000070" uPOKT And an account exists for "supplier2" When the user unstakes a "supplier" from the account "supplier2" @@ -27,6 +42,21 @@ Feature: Stake Supplier Namespace Scenario: User can restake a Supplier waiting for it to become active again Given the user has the pocketd binary installed + # Reduce the application unbonding period to avoid timeouts and speed up scenarios. + And an authz grant from the "gov" "module" account to the "pnf" "user" account for each module MsgUpdateParam message exists + # NB: If new parameters are added to the shared module, they + # MUST be included here; otherwise, this step will fail. + And the "pnf" account sends an authz exec message to update all "shared" module params + | name | value | type | + | num_blocks_per_session | 2 | int64 | + | grace_period_end_offset_blocks | 0 | int64 | + | claim_window_open_offset_blocks | 0 | int64 | + | claim_window_close_offset_blocks | 1 | int64 | + | proof_window_open_offset_blocks | 0 | int64 | + | proof_window_close_offset_blocks | 1 | int64 | + | supplier_unbonding_period_sessions | 1 | int64 | + | application_unbonding_period_sessions | 1 | int64 | + And all "shared" module params should be updated And the user verifies the "supplier" for account "supplier2" is not staked Then the user stakes a "supplier" with "1000070" uPOKT for "anvil" service from the account "supplier2" And the user should wait for the "supplier" module "StakeSupplier" message to be submitted From f2ec505cd10c4258107780c52dd78e50ff251eca Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 11 Sep 2024 11:00:14 +0200 Subject: [PATCH 03/14] chore: simplification --- e2e/tests/init_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/tests/init_test.go b/e2e/tests/init_test.go index afc4a72ba..8aee69e2e 100644 --- a/e2e/tests/init_test.go +++ b/e2e/tests/init_test.go @@ -38,7 +38,7 @@ import ( prooftypes "github.com/pokt-network/poktroll/x/proof/types" servicetypes "github.com/pokt-network/poktroll/x/service/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" - shared "github.com/pokt-network/poktroll/x/shared" + "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" ) @@ -740,8 +740,8 @@ func (s *suite) getSupplierUnbondingHeight(accName string) int64 { var resp sharedtypes.QueryParamsResponse responseBz := []byte(strings.TrimSpace(res.Stdout)) s.cdc.MustUnmarshalJSON(responseBz, &resp) - unbondingHeight := shared.GetSupplierUnbondingHeight(&resp.Params, supplier) - return unbondingHeight + + return shared.GetSupplierUnbondingHeight(&resp.Params, supplier) } // getApplicationInfo returns the application information for a given application address. From e5672c14dadd3b47f3bd6c1105b79964912571d0 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 11 Sep 2024 11:00:25 +0200 Subject: [PATCH 04/14] chore: fix typos --- e2e/tests/stake_supplier.feature | 2 +- x/shared/supplier.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/tests/stake_supplier.feature b/e2e/tests/stake_supplier.feature index 8fbb97ac2..94f45a731 100644 --- a/e2e/tests/stake_supplier.feature +++ b/e2e/tests/stake_supplier.feature @@ -1,6 +1,6 @@ Feature: Stake Supplier Namespace - Scenario: User can stake and unstake a Supplier waiting for it to unbound + Scenario: User can stake a Supplier Given the user has the pocketd binary installed And the user verifies the "supplier" for account "supplier2" is not staked And the account "supplier2" has a balance greater than "1000070" uPOKT diff --git a/x/shared/supplier.go b/x/shared/supplier.go index fc92d872f..f81b7aaff 100644 --- a/x/shared/supplier.go +++ b/x/shared/supplier.go @@ -10,7 +10,7 @@ func GetSupplierUnbondingHeight( sharedParams *sharedtypes.Params, supplier *sharedtypes.Supplier, ) int64 { - supplierUnbondingPeriodSessions := sharedParams.SupplierUnbondingPeriodSessions * sharedParams.NumBlocksPerSession + supplierUnbondingPeriodBlocks := sharedParams.SupplierUnbondingPeriodSessions * sharedParams.NumBlocksPerSession - return int64(supplier.UnstakeSessionEndHeight + supplierUnbondingPeriodSessions) + return int64(supplier.UnstakeSessionEndHeight + supplierUnbondingPeriodBlocks) } From 597f75f1e5842789c6bd1107c210dc5689fa1a01 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 12 Sep 2024 09:45:53 +0200 Subject: [PATCH 05/14] refactor: supplier feature steps --- e2e/tests/stake_supplier.feature | 30 +------- e2e/tests/stake_supplier_steps_test.go | 98 ++++++++++++++++++++++++++ e2e/tests/update_params_test.go | 26 ++++--- 3 files changed, 117 insertions(+), 37 deletions(-) create mode 100644 e2e/tests/stake_supplier_steps_test.go diff --git a/e2e/tests/stake_supplier.feature b/e2e/tests/stake_supplier.feature index 94f45a731..f3062ea8c 100644 --- a/e2e/tests/stake_supplier.feature +++ b/e2e/tests/stake_supplier.feature @@ -15,20 +15,7 @@ Feature: Stake Supplier Namespace Scenario: User can unstake a Supplier Given the user has the pocketd binary installed # Reduce the application unbonding period to avoid timeouts and speed up scenarios. - And an authz grant from the "gov" "module" account to the "pnf" "user" account for each module MsgUpdateParam message exists - # NB: If new parameters are added to the shared module, they - # MUST be included here; otherwise, this step will fail. - And the "pnf" account sends an authz exec message to update all "shared" module params - | name | value | type | - | num_blocks_per_session | 2 | int64 | - | grace_period_end_offset_blocks | 0 | int64 | - | claim_window_open_offset_blocks | 0 | int64 | - | claim_window_close_offset_blocks | 1 | int64 | - | proof_window_open_offset_blocks | 0 | int64 | - | proof_window_close_offset_blocks | 1 | int64 | - | supplier_unbonding_period_sessions | 1 | int64 | - | application_unbonding_period_sessions | 1 | int64 | - And all "shared" module params should be updated + And the "supplier" unbonding period param is successfully set to "1" sessions of "2" blocks And the "supplier" for account "supplier2" is staked with "1000070" uPOKT And an account exists for "supplier2" When the user unstakes a "supplier" from the account "supplier2" @@ -43,20 +30,7 @@ Feature: Stake Supplier Namespace Scenario: User can restake a Supplier waiting for it to become active again Given the user has the pocketd binary installed # Reduce the application unbonding period to avoid timeouts and speed up scenarios. - And an authz grant from the "gov" "module" account to the "pnf" "user" account for each module MsgUpdateParam message exists - # NB: If new parameters are added to the shared module, they - # MUST be included here; otherwise, this step will fail. - And the "pnf" account sends an authz exec message to update all "shared" module params - | name | value | type | - | num_blocks_per_session | 2 | int64 | - | grace_period_end_offset_blocks | 0 | int64 | - | claim_window_open_offset_blocks | 0 | int64 | - | claim_window_close_offset_blocks | 1 | int64 | - | proof_window_open_offset_blocks | 0 | int64 | - | proof_window_close_offset_blocks | 1 | int64 | - | supplier_unbonding_period_sessions | 1 | int64 | - | application_unbonding_period_sessions | 1 | int64 | - And all "shared" module params should be updated + And the "supplier" unbonding period param is successfully set to "1" sessions of "2" blocks And the user verifies the "supplier" for account "supplier2" is not staked Then the user stakes a "supplier" with "1000070" uPOKT for "anvil" service from the account "supplier2" And the user should wait for the "supplier" module "StakeSupplier" message to be submitted diff --git a/e2e/tests/stake_supplier_steps_test.go b/e2e/tests/stake_supplier_steps_test.go new file mode 100644 index 000000000..15197a25e --- /dev/null +++ b/e2e/tests/stake_supplier_steps_test.go @@ -0,0 +1,98 @@ +//go:build e2e + +package e2e + +import ( + "reflect" + "strings" + "unicode" + + "github.com/stretchr/testify/require" + + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" +) + +func (s *suite) TheUnbondingPeriodParamIsSuccessfullySetToSessionsOfBlocks( + _ string, + supplierUnbondingPeriodSessions, + numBlocksPerSession int64, +) { + require.GreaterOrEqualf(s, numBlocksPerSession, 2, + "num_blocks_per_session MUST be at least 2 to satisfy parameter validation requirements") + + paramModuleName := "shared" + granter := "gov" + grantee := "pnf" + + // Ensure an authz grant is present such that this step may update parameters. + s.AnAuthzGrantFromTheAccountToTheAccountForEachModuleMsgupdateparamMessageExists( + granter, "module", + grantee, "user", + ) + + // NB: If new parameters are added to the shared module, they + // MUST be included here; otherwise, this step will fail. + sharedParams := sharedtypes.Params{ + NumBlocksPerSession: uint64(numBlocksPerSession), + GracePeriodEndOffsetBlocks: 0, + ClaimWindowOpenOffsetBlocks: 0, + ClaimWindowCloseOffsetBlocks: 1, + ProofWindowOpenOffsetBlocks: 0, + ProofWindowCloseOffsetBlocks: 1, + SupplierUnbondingPeriodSessions: uint64(supplierUnbondingPeriodSessions), + ApplicationUnbondingPeriodSessions: 1, + } + + // Convert params struct to the map type expected by + // s.sendAuthzExecToUpdateAllModuleParams(). + paramsMap := paramsAnyMapFromParamsStruct(sharedParams) + s.sendAuthzExecToUpdateAllModuleParams(grantee, paramModuleName, paramsMap) + + // Assert that the parameter values were updated. + s.AllModuleParamsShouldBeUpdated(paramModuleName) +} + +// paramsAnyMapFromParamStruct construct a paramsAnyMap from any +// protobuf Param message type (tx.proto) using reflection. +func paramsAnyMapFromParamsStruct(paramStruct any) paramsAnyMap { + paramsMap := make(paramsAnyMap) + paramsReflectValue := reflect.ValueOf(paramStruct) + for i := 0; i < paramsReflectValue.NumField(); i++ { + fieldValue := paramsReflectValue.Field(i) + fieldStruct := paramsReflectValue.Type().Field(i) + paramName := toSnakeCase(fieldStruct.Name) + + fieldTypeName := fieldStruct.Type.Name() + if fieldTypeName == "uint64" { + fieldTypeName = "int64" + fieldValue = reflect.ValueOf(int64(fieldValue.Interface().(uint64))) + } + + paramsMap[paramName] = paramAny{ + name: paramName, + typeStr: fieldTypeName, + value: fieldValue.Interface(), + } + } + return paramsMap +} + +func toSnakeCase(str string) string { + var result strings.Builder + + for i, runeValue := range str { + if unicode.IsUpper(runeValue) { + // If it's not the first letter, add an underscore + if i > 0 { + result.WriteRune('_') + } + // Convert to lowercase + result.WriteRune(unicode.ToLower(runeValue)) + } else { + // Otherwise, just append the rune as-is + result.WriteRune(runeValue) + } + } + + return result.String() +} diff --git a/e2e/tests/update_params_test.go b/e2e/tests/update_params_test.go index c13b1dfc6..74d98168c 100644 --- a/e2e/tests/update_params_test.go +++ b/e2e/tests/update_params_test.go @@ -217,16 +217,9 @@ func (s *suite) AllModuleParamsShouldBeSetToTheirDefaultValues(moduleName string // TheAccountSendsAnAuthzExecMessageToUpdateAllModuleParams sends an authz exec // message to update all module params for the given module. func (s *suite) TheAccountSendsAnAuthzExecMessageToUpdateAllModuleParams(accountName, moduleName string, table gocuke.DataTable) { - // NB: set s#moduleParamsMap for later assertion. - s.expectedModuleParams = moduleParamsMap{ - moduleName: s.parseParamsTable(table), - } - - // Use the map of params to populate a tx JSON template & write it to a file. - txJSONFile := s.newTempUpdateParamsTxJSONFile(s.expectedModuleParams) + paramsTableMap := s.parseParamsTable(table) - // Send the authz exec tx to update all module params. - s.sendAuthzExecTx(accountName, txJSONFile.Name()) + s.sendAuthzExecToUpdateAllModuleParams(accountName, moduleName, paramsTableMap) } // AllModuleParamsShouldBeUpdated asserts that all module params have been updated as expected. @@ -479,6 +472,21 @@ func (s *suite) assertExpectedModuleParamsUpdated(moduleName string) { } } +// sendAuthzExecToUpdateAllModuleParams constructs and sends an authz exec +// tx to update all params for moduleName the given params. +func (s *suite) sendAuthzExecToUpdateAllModuleParams(accountName, moduleName string, params paramsAnyMap) { + // NB: set s#moduleParamsMap for later assertion. + s.expectedModuleParams = moduleParamsMap{ + moduleName: params, + } + + // Use the map of params to populate a tx JSON template & write it to a file. + txJSONFile := s.newTempUpdateParamsTxJSONFile(s.expectedModuleParams) + + // Send the authz exec tx to update all module params. + s.sendAuthzExecTx(accountName, txJSONFile.Name()) +} + // assertUpdatedParams deserializes the param query response JSON into a // MsgUpdateParams of type P & asserts that it matches the expected params. func assertUpdatedParams[P cosmostypes.Msg]( From d5be66d571e89ba0c924ea9da00ec04aea31b840 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 16 Sep 2024 11:42:05 +0200 Subject: [PATCH 06/14] chore: rename paramsAnyMap type to mitigate variable name shadowing --- e2e/tests/params_tx_test.go | 4 ++-- e2e/tests/params_types_test.go | 6 +++--- e2e/tests/parse_params_test.go | 20 ++++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/e2e/tests/params_tx_test.go b/e2e/tests/params_tx_test.go index 87e4e2463..926f856e2 100644 --- a/e2e/tests/params_tx_test.go +++ b/e2e/tests/params_tx_test.go @@ -51,7 +51,7 @@ func (s *suite) sendAuthzExecTx(signingKeyName, txJSONFilePath string) { } // newTempUpdateParamsTxJSONFile creates & returns a new temp file with the JSON representation of a tx -// which contains a MsgUpdateParams to update **all module params** for each module & paramsMap +// which contains a MsgUpdateParams to update **all module params** for each module & paramsAnyMap // in the given moduleParamsMap. The returned file is intended for use with the `authz exec` CLI // subcommand: `poktrolld tx authz exec `. func (s *suite) newTempUpdateParamsTxJSONFile(moduleParams moduleParamsMap) *os.File { @@ -76,7 +76,7 @@ func (s *suite) newTempUpdateParamsTxJSONFile(moduleParams moduleParamsMap) *os. } // newTempUpdateParamTxJSONFile creates & returns a new temp file with the JSON representation of a tx -// which contains a MsgUpdateParam to update params **individually** for each module & paramsMap in the +// which contains a MsgUpdateParam to update params **individually** for each module & paramsAnyMap in the // given moduleParamsMap. The returned file is intended for use with the `authz exec` CLI subcommand: // `poktrolld tx authz exec `. func (s *suite) newTempUpdateParamTxJSONFile(moduleParams moduleParamsMap) *os.File { diff --git a/e2e/tests/params_types_test.go b/e2e/tests/params_types_test.go index facd7abca..8da752793 100644 --- a/e2e/tests/params_types_test.go +++ b/e2e/tests/params_types_test.go @@ -9,11 +9,11 @@ type ( paramNameKey = string ) -// paramsMap is a map of param names to param values. -type paramsMap map[paramNameKey]paramAny +// paramsAnyMap is a map of param names to param values. +type paramsAnyMap map[paramNameKey]paramAny // moduleParamsMap is a map of module names to params maps. -type moduleParamsMap map[moduleNameKey]paramsMap +type moduleParamsMap map[moduleNameKey]paramsAnyMap // paramAny is a struct that holds a param type and a param value. type paramAny struct { diff --git a/e2e/tests/parse_params_test.go b/e2e/tests/parse_params_test.go index e33e1e423..508332741 100644 --- a/e2e/tests/parse_params_test.go +++ b/e2e/tests/parse_params_test.go @@ -28,11 +28,11 @@ const ( paramTypeColIdx ) -// parseParamsTable parses a gocuke.DataTable into a paramsMap. -func (s *suite) parseParamsTable(table gocuke.DataTable) paramsMap { +// parseParamsTable parses a gocuke.DataTable into a paramsAnyMap. +func (s *suite) parseParamsTable(table gocuke.DataTable) paramsAnyMap { s.Helper() - paramsMap := make(paramsMap) + paramsMap := make(paramsAnyMap) // NB: skip the header row. for rowIdx := 1; rowIdx < table.NumRows(); rowIdx++ { @@ -78,9 +78,9 @@ func (s *suite) parseParam(table gocuke.DataTable, rowIdx int) paramAny { } } -// paramsMapToMsgUpdateParams converts a paramsMap into a MsgUpdateParams, which +// paramsMapToMsgUpdateParams converts a paramsAnyMap into a MsgUpdateParams, which // it returns as a proto.Message/cosmostypes.Msg interface type. -func (s *suite) paramsMapToMsgUpdateParams(moduleName string, paramsMap paramsMap) (msgUpdateParams cosmostypes.Msg) { +func (s *suite) paramsMapToMsgUpdateParams(moduleName string, paramsMap paramsAnyMap) (msgUpdateParams cosmostypes.Msg) { s.Helper() switch moduleName { @@ -104,7 +104,7 @@ func (s *suite) paramsMapToMsgUpdateParams(moduleName string, paramsMap paramsMa return msgUpdateParams } -func (s *suite) newTokenomicsMsgUpdateParams(params paramsMap) cosmostypes.Msg { +func (s *suite) newTokenomicsMsgUpdateParams(params paramsAnyMap) cosmostypes.Msg { authority := authtypes.NewModuleAddress(s.granterName).String() msgUpdateParams := &tokenomicstypes.MsgUpdateParams{ @@ -123,7 +123,7 @@ func (s *suite) newTokenomicsMsgUpdateParams(params paramsMap) cosmostypes.Msg { return proto.Message(msgUpdateParams) } -func (s *suite) newProofMsgUpdateParams(params paramsMap) cosmostypes.Msg { +func (s *suite) newProofMsgUpdateParams(params paramsAnyMap) cosmostypes.Msg { authority := authtypes.NewModuleAddress(s.granterName).String() msgUpdateParams := &prooftypes.MsgUpdateParams{ @@ -150,7 +150,7 @@ func (s *suite) newProofMsgUpdateParams(params paramsMap) cosmostypes.Msg { return proto.Message(msgUpdateParams) } -func (s *suite) newSharedMsgUpdateParams(params paramsMap) cosmostypes.Msg { +func (s *suite) newSharedMsgUpdateParams(params paramsAnyMap) cosmostypes.Msg { authority := authtypes.NewModuleAddress(s.granterName).String() msgUpdateParams := &sharedtypes.MsgUpdateParams{ @@ -183,7 +183,7 @@ func (s *suite) newSharedMsgUpdateParams(params paramsMap) cosmostypes.Msg { return proto.Message(msgUpdateParams) } -func (s *suite) newAppMsgUpdateParams(params paramsMap) cosmostypes.Msg { +func (s *suite) newAppMsgUpdateParams(params paramsAnyMap) cosmostypes.Msg { authority := authtypes.NewModuleAddress(s.granterName).String() msgUpdateParams := &apptypes.MsgUpdateParams{ @@ -203,7 +203,7 @@ func (s *suite) newAppMsgUpdateParams(params paramsMap) cosmostypes.Msg { return proto.Message(msgUpdateParams) } -func (s *suite) newServiceMsgUpdateParams(params paramsMap) cosmostypes.Msg { +func (s *suite) newServiceMsgUpdateParams(params paramsAnyMap) cosmostypes.Msg { authority := authtypes.NewModuleAddress(s.granterName).String() msgUpdateParams := &servicetypes.MsgUpdateParams{ From 7e71c388cdc0b7111a01339d1655f034ad5fcced Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 19 Sep 2024 19:33:04 +0200 Subject: [PATCH 07/14] fix: failing E2E test --- e2e/tests/stake_supplier_steps_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/e2e/tests/stake_supplier_steps_test.go b/e2e/tests/stake_supplier_steps_test.go index 15197a25e..d0d8f99e9 100644 --- a/e2e/tests/stake_supplier_steps_test.go +++ b/e2e/tests/stake_supplier_steps_test.go @@ -14,10 +14,10 @@ import ( func (s *suite) TheUnbondingPeriodParamIsSuccessfullySetToSessionsOfBlocks( _ string, - supplierUnbondingPeriodSessions, + unbondingPeriodSessions, numBlocksPerSession int64, ) { - require.GreaterOrEqualf(s, numBlocksPerSession, 2, + require.GreaterOrEqualf(s, numBlocksPerSession, int64(2), "num_blocks_per_session MUST be at least 2 to satisfy parameter validation requirements") paramModuleName := "shared" @@ -39,8 +39,9 @@ func (s *suite) TheUnbondingPeriodParamIsSuccessfullySetToSessionsOfBlocks( ClaimWindowCloseOffsetBlocks: 1, ProofWindowOpenOffsetBlocks: 0, ProofWindowCloseOffsetBlocks: 1, - SupplierUnbondingPeriodSessions: uint64(supplierUnbondingPeriodSessions), - ApplicationUnbondingPeriodSessions: 1, + SupplierUnbondingPeriodSessions: uint64(unbondingPeriodSessions), + ApplicationUnbondingPeriodSessions: uint64(unbondingPeriodSessions), + ComputeUnitsToTokensMultiplier: sharedtypes.DefaultComputeUnitsToTokensMultiplier, } // Convert params struct to the map type expected by From ba7aaa7eb6e7f2686831e11928664d80a25451dc Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 19 Sep 2024 19:33:23 +0200 Subject: [PATCH 08/14] chore: sync shared module default params --- config.yml | 3 +++ tools/scripts/params/shared_all.json | 7 +++++-- x/shared/types/params.go | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/config.yml b/config.yml index 7921b0573..4c5215779 100644 --- a/config.yml +++ b/config.yml @@ -268,3 +268,6 @@ genesis: claim_window_close_offset_blocks: 4 proof_window_open_offset_blocks: 0 proof_window_close_offset_blocks: 4 + supplier_unbonding_period_sessions: 1 + application_unbonding_period_sessions: 1 + compute_units_to_tokens_multiplier: 42 diff --git a/tools/scripts/params/shared_all.json b/tools/scripts/params/shared_all.json index fa5e04f78..2a489f27c 100644 --- a/tools/scripts/params/shared_all.json +++ b/tools/scripts/params/shared_all.json @@ -5,12 +5,15 @@ "@type": "/poktroll.shared.MsgUpdateParams", "authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t", "params": { - "num_blocks_per_session": "4", + "num_blocks_per_session": "10", "grace_period_end_offset_blocks": "1", "claim_window_open_offset_blocks": "1", "claim_window_close_offset_blocks": "4", "proof_window_open_offset_blocks": "0", - "proof_window_close_offset_blocks": "4" + "proof_window_close_offset_blocks": "4", + "supplier_unbonding_period_sessions": "1", + "application_unbonding_period_sessions": "1", + "compute_units_to_tokens_multiplier": "42" } } ] diff --git a/x/shared/types/params.go b/x/shared/types/params.go index 3a5afd62d..d5921f62d 100644 --- a/x/shared/types/params.go +++ b/x/shared/types/params.go @@ -5,11 +5,11 @@ import ( ) const ( - DefaultNumBlocksPerSession = 4 + DefaultNumBlocksPerSession = 10 ParamNumBlocksPerSession = "num_blocks_per_session" DefaultGracePeriodEndOffsetBlocks = 1 ParamGracePeriodEndOffsetBlocks = "grace_period_end_offset_blocks" - DefaultClaimWindowOpenOffsetBlocks = 2 + DefaultClaimWindowOpenOffsetBlocks = 1 ParamClaimWindowOpenOffsetBlocks = "claim_window_open_offset_blocks" DefaultClaimWindowCloseOffsetBlocks = 4 ParamClaimWindowCloseOffsetBlocks = "claim_window_close_offset_blocks" @@ -17,9 +17,9 @@ const ( ParamProofWindowOpenOffsetBlocks = "proof_window_open_offset_blocks" DefaultProofWindowCloseOffsetBlocks = 4 ParamProofWindowCloseOffsetBlocks = "proof_window_close_offset_blocks" - DefaultSupplierUnbondingPeriodSessions = 4 // 4 sessions + DefaultSupplierUnbondingPeriodSessions = 1 // 1 session ParamSupplierUnbondingPeriodSessions = "supplier_unbonding_period_sessions" - DefaultApplicationUnbondingPeriodSessions = 4 // 4 sessions + DefaultApplicationUnbondingPeriodSessions = 1 // 1 session ParamApplicationUnbondingPeriodSessions = "application_unbonding_period_sessions" DefaultComputeUnitsToTokensMultiplier = 42 // TODO_MAINNET: Determine the default value. ParamComputeUnitsToTokensMultiplier = "compute_units_to_tokens_multiplier" From 5c46e3dfb1a99551637c33d3845c1db06ffead7c Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 19 Sep 2024 19:37:06 +0200 Subject: [PATCH 09/14] chore: add comment --- e2e/tests/stake_supplier_steps_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e/tests/stake_supplier_steps_test.go b/e2e/tests/stake_supplier_steps_test.go index d0d8f99e9..2b1e9e28e 100644 --- a/e2e/tests/stake_supplier_steps_test.go +++ b/e2e/tests/stake_supplier_steps_test.go @@ -64,6 +64,7 @@ func paramsAnyMapFromParamsStruct(paramStruct any) paramsAnyMap { paramName := toSnakeCase(fieldStruct.Name) fieldTypeName := fieldStruct.Type.Name() + // TODO_IMPROVE: MsgUpdateParam currently only supports int64 and not uint64 value types. if fieldTypeName == "uint64" { fieldTypeName = "int64" fieldValue = reflect.ValueOf(int64(fieldValue.Interface().(uint64))) From 4c1c962b99887a9d4583163d607f17576fa29299 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 19 Sep 2024 21:06:10 +0200 Subject: [PATCH 10/14] fix: update_param e2e test --- e2e/tests/update_params.feature | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/e2e/tests/update_params.feature b/e2e/tests/update_params.feature index c1a9b77f9..a84cad537 100644 --- a/e2e/tests/update_params.feature +++ b/e2e/tests/update_params.feature @@ -68,22 +68,22 @@ Feature: Params Namespace Then the "" module param "" should be updated Examples: - | module | message_type | param_name | param_value | param_type | - | proof | /poktroll.proof.MsgUpdateParam | min_relay_difficulty_bits | 12 | int64 | - | proof | /poktroll.proof.MsgUpdateParam | proof_request_probability | 0.1 | float | - | proof | /poktroll.proof.MsgUpdateParam | proof_requirement_threshold | 100 | coin | - | proof | /poktroll.proof.MsgUpdateParam | proof_missing_penalty | 500 | coin | - | proof | /poktroll.proof.MsgUpdateParam | proof_submission_fee | 5000000 | coin | - | shared | /poktroll.shared.MsgUpdateParam | num_blocks_per_session | 5 | int64 | - | shared | /poktroll.shared.MsgUpdateParam | grace_period_end_offset_blocks | 2 | int64 | - | shared | /poktroll.shared.MsgUpdateParam | claim_window_open_offset_blocks | 2 | int64 | - | shared | /poktroll.shared.MsgUpdateParam | claim_window_close_offset_blocks | 3 | int64 | - | shared | /poktroll.shared.MsgUpdateParam | proof_window_open_offset_blocks | 1 | int64 | - | shared | /poktroll.shared.MsgUpdateParam | proof_window_close_offset_blocks | 5 | int64 | - | shared | /poktroll.shared.MsgUpdateParam | supplier_unbonding_period_sessions | 5 | int64 | - | shared | /poktroll.shared.MsgUpdateParam | application_unbonding_period_sessions | 5 | int64 | - | shared | /poktroll.shared.MsgUpdateParam | compute_units_to_tokens_multiplier | 68 | int64 | - | service | /poktroll.service.MsgUpdateParam | add_service_fee | 1000000001 | coin | + | module | message_type | param_name | param_value | param_type | + | proof | /poktroll.proof.MsgUpdateParam | min_relay_difficulty_bits | 12 | int64 | + | proof | /poktroll.proof.MsgUpdateParam | proof_request_probability | 0.1 | float | + | proof | /poktroll.proof.MsgUpdateParam | proof_requirement_threshold | 100 | coin | + | proof | /poktroll.proof.MsgUpdateParam | proof_missing_penalty | 500 | coin | + | proof | /poktroll.proof.MsgUpdateParam | proof_submission_fee | 5000000 | coin | + | shared | /poktroll.shared.MsgUpdateParam | num_blocks_per_session | 9 | int64 | + | shared | /poktroll.shared.MsgUpdateParam | grace_period_end_offset_blocks | 0 | int64 | + | shared | /poktroll.shared.MsgUpdateParam | claim_window_open_offset_blocks | 2 | int64 | + | shared | /poktroll.shared.MsgUpdateParam | claim_window_close_offset_blocks | 3 | int64 | + | shared | /poktroll.shared.MsgUpdateParam | proof_window_open_offset_blocks | 1 | int64 | + | shared | /poktroll.shared.MsgUpdateParam | proof_window_close_offset_blocks | 5 | int64 | + | shared | /poktroll.shared.MsgUpdateParam | supplier_unbonding_period_sessions | 5 | int64 | + | shared | /poktroll.shared.MsgUpdateParam | application_unbonding_period_sessions | 5 | int64 | + | shared | /poktroll.shared.MsgUpdateParam | compute_units_to_tokens_multiplier | 68 | int64 | + | service | /poktroll.service.MsgUpdateParam | add_service_fee | 1000000001 | coin | Scenario: An unauthorized user cannot update individual module params Given the user has the pocketd binary installed From 8b98715b09f2356a2d6d14d376e77d7a3d30a6df Mon Sep 17 00:00:00 2001 From: Bryan White Date: Fri, 20 Sep 2024 09:41:26 +0200 Subject: [PATCH 11/14] fix: failing tests --- testutil/keeper/session.go | 55 ++++++++++++++++------- x/proof/module/helpers_test.go | 5 +-- x/proof/module/query_claim_test.go | 24 +++++++--- x/session/keeper/session_hydrator_test.go | 29 +++++++++--- x/supplier/keeper/unbond_suppliers.go | 1 + 5 files changed, 85 insertions(+), 29 deletions(-) diff --git a/testutil/keeper/session.go b/testutil/keeper/session.go index 74ff98a07..8f84999f0 100644 --- a/testutil/keeper/session.go +++ b/testutil/keeper/session.go @@ -113,8 +113,33 @@ var ( } ) -func SessionKeeper(t testing.TB) (keeper.Keeper, context.Context) { +// keeperConfig is a configuration struct to be used during keeper construction +// to modify its behavior. +type keeperConfig struct { + // moduleParams is a map of module names to their respective module parameters. + // This is used to set the initial module parameters in the keeper. + moduleParams map[string]sdk.Msg +} + +// KeeperOptionFn is a function type that sets/updates fields on the keeperConfig. +type KeeperOptionFn func(*keeperConfig) + +// WithModuleParams returns a KeeperOptionFn that sets the moduleParams field +// on the keeperConfig. +func WithModuleParams(moduleParams map[string]sdk.Msg) KeeperOptionFn { + return func(c *keeperConfig) { + c.moduleParams = moduleParams + } +} + +func SessionKeeper(t testing.TB, opts ...KeeperOptionFn) (keeper.Keeper, context.Context) { t.Helper() + + cfg := &keeperConfig{} + for _, opt := range opts { + opt(cfg) + } + storeKey := storetypes.NewKVStoreKey(types.StoreKey) db := dbm.NewMemDB() @@ -134,7 +159,12 @@ func SessionKeeper(t testing.TB) (keeper.Keeper, context.Context) { mockAppKeeper := defaultAppKeeperMock(t) mockSupplierKeeper := defaultSupplierKeeperMock(t) - mockSharedKeeper := defaultSharedKeeperMock(t) + + sharedParams := new(sharedtypes.Params) + if params, ok := cfg.moduleParams[sharedtypes.ModuleName]; ok { + sharedParams = params.(*sharedtypes.Params) + } + mockSharedKeeper := defaultSharedKeeperMock(t, sharedParams) k := keeper.NewKeeper( cdc, @@ -218,25 +248,18 @@ func defaultSupplierKeeperMock(t testing.TB) types.SupplierKeeper { return mockSupplierKeeper } -func defaultSharedKeeperMock(t testing.TB) types.SharedKeeper { +func defaultSharedKeeperMock(t testing.TB, params *sharedtypes.Params) types.SharedKeeper { t.Helper() ctrl := gomock.NewController(t) + if params == nil { + params = new(sharedtypes.Params) + *params = sharedtypes.DefaultParams() + } + mockSharedKeeper := mocks.NewMockSharedKeeper(ctrl) mockSharedKeeper.EXPECT().GetParams(gomock.Any()). - Return(sharedtypes.DefaultParams()). + Return(*params). AnyTimes() return mockSharedKeeper } - -// TODO_TECHDEBT: Figure out how to vary the supplierKeep on a per test basis with exposing `SupplierKeeper publically` - -// type option[V any] func(k *keeper.Keeper) - -// WithPublisher returns an option function which sets the given publishCh of the -// resulting observable when passed to NewObservable(). -// func WithSupplierKeeperMock(supplierKeeper types.SupplierKeeper) option[any] { -// return func(k *keeper.Keeper) { -// k.supplierKeeper = supplierKeeper -// } -// } diff --git a/x/proof/module/helpers_test.go b/x/proof/module/helpers_test.go index 7f983a1fc..59948a505 100644 --- a/x/proof/module/helpers_test.go +++ b/x/proof/module/helpers_test.go @@ -37,6 +37,7 @@ func networkWithClaimObjects( numSessions int, numSuppliers int, numApps int, + sharedParams *sharedtypes.Params, ) (net *network.Network, claims []types.Claim, clientCtx cosmosclient.Context) { t.Helper() @@ -84,14 +85,12 @@ func networkWithClaimObjects( appGenesisBuffer, err := cfg.Codec.MarshalJSON(appGenesisState) require.NoError(t, err) - sharedParams := sharedtypes.DefaultParams() - // Create numSessions * numApps * numSuppliers claims. for sessionIdx := 0; sessionIdx < numSessions; sessionIdx++ { for _, appAcct := range appAccts { for _, supplierOperatorAcct := range supplierOperatorAccts { claim := newTestClaim( - t, &sharedParams, + t, sharedParams, supplierOperatorAcct.Address.String(), testsession.GetSessionStartHeightWithDefaultParams(1), appAcct.Address.String(), diff --git a/x/proof/module/query_claim_test.go b/x/proof/module/query_claim_test.go index 70cf9e48c..818adad8c 100644 --- a/x/proof/module/query_claim_test.go +++ b/x/proof/module/query_claim_test.go @@ -24,7 +24,8 @@ func TestClaim_Show(t *testing.T) { numSuppliers := 3 numApps := 3 - net, claims, clientCtx := networkWithClaimObjects(t, numSessions, numApps, numSuppliers) + sharedParams := sharedtypes.DefaultParams() + net, claims, clientCtx := networkWithClaimObjects(t, numSessions, numApps, numSuppliers, &sharedParams) commonArgs := []string{ fmt.Sprintf("--%s=json", cometcli.OutputFlag), @@ -122,17 +123,30 @@ func TestClaim_Show(t *testing.T) { func TestClaim_List(t *testing.T) { numSuppliers := 4 numApps := 1 + numBlocksPerSession := 4 + sharedParams := &sharedtypes.Params{ + NumBlocksPerSession: uint64(numBlocksPerSession), + GracePeriodEndOffsetBlocks: 1, + ClaimWindowOpenOffsetBlocks: 1, + ClaimWindowCloseOffsetBlocks: 4, + ProofWindowOpenOffsetBlocks: 0, + ProofWindowCloseOffsetBlocks: 4, + SupplierUnbondingPeriodSessions: 1, + ApplicationUnbondingPeriodSessions: 1, + ComputeUnitsToTokensMultiplier: 42, + } + // TODO_HACK(@Olshansk): Due to the bug found in `networkWithClaimObjects`, this // is a temporary workaround instead of setting numSessions to its own // independent constant, which requires us to temporarily align the // with the num blocks per session. See the `forloop` in `networkWithClaimObjects` // that has a TODO_HACK as well. - require.Equal(t, 0, numSuppliers*numApps%sharedtypes.DefaultNumBlocksPerSession) + require.Equal(t, 0, numSuppliers*numApps%numBlocksPerSession) - numSessions := numSuppliers * numApps / sharedtypes.DefaultNumBlocksPerSession + numSessions := numSuppliers * numApps / numBlocksPerSession // Submitting one claim per block for simplicity - numClaimsPerSession := sharedtypes.DefaultNumBlocksPerSession + numClaimsPerSession := numBlocksPerSession totalClaims := numSessions * numClaimsPerSession // TODO_FLAKY(@bryanchriswhite): The `networkWithClaimObjects is flaky because @@ -145,7 +159,7 @@ func TestClaim_List(t *testing.T) { t.Errorf("Test panicked: %s", r) } }() - net, claims, clientCtx := networkWithClaimObjects(t, numSessions, numSuppliers, numApps) + net, claims, clientCtx := networkWithClaimObjects(t, numSessions, numSuppliers, numApps, sharedParams) prepareArgs := func(next []byte, offset, limit uint64, total bool) []string { args := []string{ diff --git a/x/session/keeper/session_hydrator_test.go b/x/session/keeper/session_hydrator_test.go index 6f0994da3..df1f0682c 100644 --- a/x/session/keeper/session_hydrator_test.go +++ b/x/session/keeper/session_hydrator_test.go @@ -10,10 +10,29 @@ import ( "github.com/pokt-network/poktroll/testutil/sample" "github.com/pokt-network/poktroll/x/session/keeper" "github.com/pokt-network/poktroll/x/session/types" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" +) + +var ( + testSharedParams = sharedtypes.Params{ + NumBlocksPerSession: 4, + GracePeriodEndOffsetBlocks: 1, + ClaimWindowOpenOffsetBlocks: 1, + ClaimWindowCloseOffsetBlocks: 0, + ProofWindowOpenOffsetBlocks: 4, + ProofWindowCloseOffsetBlocks: 4, + SupplierUnbondingPeriodSessions: 1, + ApplicationUnbondingPeriodSessions: 1, + ComputeUnitsToTokensMultiplier: 42, + } + + sharedParamsOpt = keepertest.WithModuleParams(map[string]sdk.Msg{ + sharedtypes.ModuleName: &testSharedParams, + }) ) func TestSession_HydrateSession_Success_BaseCase(t *testing.T) { - sessionKeeper, ctx := keepertest.SessionKeeper(t) + sessionKeeper, ctx := keepertest.SessionKeeper(t, sharedParamsOpt) ctx = sdk.UnwrapSDKContext(ctx).WithBlockHeight(100) // provide a sufficiently large block height to avoid errors blockHeight := int64(10) @@ -112,7 +131,7 @@ func TestSession_HydrateSession_Metadata(t *testing.T) { appAddr := keepertest.TestApp1Address serviceId := keepertest.TestServiceId1 - sessionKeeper, ctx := keepertest.SessionKeeper(t) + sessionKeeper, ctx := keepertest.SessionKeeper(t, sharedParamsOpt) ctx = sdk.UnwrapSDKContext(ctx).WithBlockHeight(100) // provide a sufficiently large block height to avoid errors for _, test := range tests { @@ -199,7 +218,7 @@ func TestSession_HydrateSession_SessionId(t *testing.T) { }, } - sessionKeeper, ctx := keepertest.SessionKeeper(t) + sessionKeeper, ctx := keepertest.SessionKeeper(t, sharedParamsOpt) ctx = sdk.UnwrapSDKContext(ctx).WithBlockHeight(100) // provide a sufficiently large block height to avoid errors for _, test := range tests { @@ -270,7 +289,7 @@ func TestSession_HydrateSession_Application(t *testing.T) { } blockHeight := int64(10) - sessionKeeper, ctx := keepertest.SessionKeeper(t) + sessionKeeper, ctx := keepertest.SessionKeeper(t, sharedParamsOpt) ctx = sdk.UnwrapSDKContext(ctx).WithBlockHeight(100) // provide a sufficiently large block height to avoid errors for _, test := range tests { @@ -331,7 +350,7 @@ func TestSession_HydrateSession_Suppliers(t *testing.T) { } blockHeight := int64(10) - sessionKeeper, ctx := keepertest.SessionKeeper(t) + sessionKeeper, ctx := keepertest.SessionKeeper(t, sharedParamsOpt) ctx = sdk.UnwrapSDKContext(ctx).WithBlockHeight(100) // provide a sufficiently large block height to avoid errors for _, test := range tests { diff --git a/x/supplier/keeper/unbond_suppliers.go b/x/supplier/keeper/unbond_suppliers.go index ba8242e88..16a491c64 100644 --- a/x/supplier/keeper/unbond_suppliers.go +++ b/x/supplier/keeper/unbond_suppliers.go @@ -5,6 +5,7 @@ import ( "fmt" cosmostypes "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/poktroll/x/shared" "github.com/pokt-network/poktroll/x/supplier/types" ) From bedc05c5d8d44671782eb15de86f4aef09fc4cda Mon Sep 17 00:00:00 2001 From: Bryan White Date: Fri, 20 Sep 2024 10:08:47 +0200 Subject: [PATCH 12/14] fix: failing tests --- .../keeper/msg_server_update_param_test.go | 134 ++++++++++-------- 1 file changed, 71 insertions(+), 63 deletions(-) diff --git a/x/shared/keeper/msg_server_update_param_test.go b/x/shared/keeper/msg_server_update_param_test.go index 9554c7019..da4a2ca03 100644 --- a/x/shared/keeper/msg_server_update_param_test.go +++ b/x/shared/keeper/msg_server_update_param_test.go @@ -14,18 +14,29 @@ import ( sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) +var testSharedParams = sharedtypes.Params{ + NumBlocksPerSession: 4, + GracePeriodEndOffsetBlocks: 1, + ClaimWindowOpenOffsetBlocks: 2, + ClaimWindowCloseOffsetBlocks: 4, + ProofWindowOpenOffsetBlocks: 0, + ProofWindowCloseOffsetBlocks: 4, + SupplierUnbondingPeriodSessions: 4, + ApplicationUnbondingPeriodSessions: 4, + ComputeUnitsToTokensMultiplier: 42, +} + func TestMsgUpdateParam_UpdateNumBlocksPerSession(t *testing.T) { - var expectedNumBlocksPerSession int64 = 8 + var expectedNumBlocksPerSession int64 = 13 k, ctx := testkeeper.SharedKeeper(t) msgSrv := keeper.NewMsgServerImpl(k) - // Set the parameters to their default values - defaultParams := sharedtypes.DefaultParams() - require.NoError(t, k.SetParams(ctx, defaultParams)) + // Set the parameters. + require.NoError(t, k.SetParams(ctx, testSharedParams)) // Ensure the default values are different from the new values we want to set - require.NotEqual(t, uint64(expectedNumBlocksPerSession), defaultParams.NumBlocksPerSession) + require.NotEqual(t, uint64(expectedNumBlocksPerSession), testSharedParams.NumBlocksPerSession) // Update the number of blocks per session updateParamMsg := &sharedtypes.MsgUpdateParam{ @@ -39,7 +50,7 @@ func TestMsgUpdateParam_UpdateNumBlocksPerSession(t *testing.T) { require.Equal(t, uint64(expectedNumBlocksPerSession), res.Params.NumBlocksPerSession) // Ensure the other parameters are unchanged - testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, "NumBlocksPerSession") + testkeeper.AssertDefaultParamsEqualExceptFields(t, &testSharedParams, res.Params, "NumBlocksPerSession") } func TestMsgUpdateParam_UpdateClaimWindowOpenOffsetBlocks(t *testing.T) { @@ -47,30 +58,30 @@ func TestMsgUpdateParam_UpdateClaimWindowOpenOffsetBlocks(t *testing.T) { k, ctx := testkeeper.SharedKeeper(t) msgSrv := keeper.NewMsgServerImpl(k) - - defaultParams := sharedtypes.DefaultParams() + // Copy test params to avoid modifying them. + sharedParams := testSharedParams // Calculate the minimum unbonding period sessions required by the staking actors // to pass UpdateParam validation. minUnbodningPeriodSessions := getMinActorUnbondingPeriodSessions( - &defaultParams, - defaultParams.ClaimWindowOpenOffsetBlocks, + &sharedParams, + sharedParams.ClaimWindowOpenOffsetBlocks, uint64(expectedClaimWindowOpenOffestBlocks), ) // Update the SupplierUnbondingPeriodSessions such that it is greater than the // cumulative proof window close blocks to pass UpdateParam validation. - defaultParams.SupplierUnbondingPeriodSessions = minUnbodningPeriodSessions + sharedParams.SupplierUnbondingPeriodSessions = minUnbodningPeriodSessions // Update the ApplicationUnbondingPeriodSessions such that it is greater than the // cumulative proof window close blocks to pass UpdateParam validation. - defaultParams.ApplicationUnbondingPeriodSessions = minUnbodningPeriodSessions + sharedParams.ApplicationUnbondingPeriodSessions = minUnbodningPeriodSessions // Set the parameters to their default values - require.NoError(t, k.SetParams(ctx, defaultParams)) + require.NoError(t, k.SetParams(ctx, sharedParams)) // Ensure the default values are different from the new values we want to set - require.NotEqual(t, uint64(expectedClaimWindowOpenOffestBlocks), defaultParams.ClaimWindowOpenOffsetBlocks) + require.NotEqual(t, uint64(expectedClaimWindowOpenOffestBlocks), sharedParams.ClaimWindowOpenOffsetBlocks) // Update the claim window open offset blocks param updateParamMsg := &sharedtypes.MsgUpdateParam{ @@ -84,7 +95,7 @@ func TestMsgUpdateParam_UpdateClaimWindowOpenOffsetBlocks(t *testing.T) { require.Equal(t, uint64(expectedClaimWindowOpenOffestBlocks), res.Params.ClaimWindowOpenOffsetBlocks) // Ensure the other parameters are unchanged - testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, "ClaimWindowOpenOffsetBlocks") + testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, "ClaimWindowOpenOffsetBlocks") } func TestMsgUpdateParam_UpdateClaimWindowCloseOffsetBlocks(t *testing.T) { @@ -92,30 +103,30 @@ func TestMsgUpdateParam_UpdateClaimWindowCloseOffsetBlocks(t *testing.T) { k, ctx := testkeeper.SharedKeeper(t) msgSrv := keeper.NewMsgServerImpl(k) - - defaultParams := sharedtypes.DefaultParams() + // Copy test params to avoid modifying them. + sharedParams := testSharedParams // Calculate the minimum unbonding period sessions required by the staking actors // to pass UpdateParam validation. minUnbodningPeriodSessions := getMinActorUnbondingPeriodSessions( - &defaultParams, - defaultParams.ClaimWindowOpenOffsetBlocks, + &sharedParams, + sharedParams.ClaimWindowOpenOffsetBlocks, uint64(expectedClaimWindowCloseOffestBlocks), ) // Update the SupplierUnbondingPeriodSessions such that it is greater than the // cumulative proof window close blocks to pass UpdateParam validation. - defaultParams.SupplierUnbondingPeriodSessions = minUnbodningPeriodSessions + sharedParams.SupplierUnbondingPeriodSessions = minUnbodningPeriodSessions // Update the ApplicationUnbondingPeriodSessions such that it is greater than the // cumulative proof window close blocks to pass UpdateParam validation. - defaultParams.ApplicationUnbondingPeriodSessions = minUnbodningPeriodSessions + sharedParams.ApplicationUnbondingPeriodSessions = minUnbodningPeriodSessions // Set the parameters to their default values - require.NoError(t, k.SetParams(ctx, defaultParams)) + require.NoError(t, k.SetParams(ctx, sharedParams)) // Ensure the default values are different from the new values we want to set - require.NotEqual(t, uint64(expectedClaimWindowCloseOffestBlocks), defaultParams.ClaimWindowCloseOffsetBlocks) + require.NotEqual(t, uint64(expectedClaimWindowCloseOffestBlocks), sharedParams.ClaimWindowCloseOffsetBlocks) // Update the claim window close offset blocks param updateParamMsg := &sharedtypes.MsgUpdateParam{ @@ -129,7 +140,7 @@ func TestMsgUpdateParam_UpdateClaimWindowCloseOffsetBlocks(t *testing.T) { require.Equal(t, uint64(expectedClaimWindowCloseOffestBlocks), res.Params.ClaimWindowCloseOffsetBlocks) // Ensure the other parameters are unchanged - testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, "ClaimWindowCloseOffsetBlocks") + testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, "ClaimWindowCloseOffsetBlocks") } func TestMsgUpdateParam_UpdateProofWindowOpenOffsetBlocks(t *testing.T) { @@ -137,30 +148,30 @@ func TestMsgUpdateParam_UpdateProofWindowOpenOffsetBlocks(t *testing.T) { k, ctx := testkeeper.SharedKeeper(t) msgSrv := keeper.NewMsgServerImpl(k) - - defaultParams := sharedtypes.DefaultParams() + // Copy test params to avoid modifying them. + sharedParams := testSharedParams // Calculate the minimum unbonding period sessions required by the staking actors // to pass UpdateParam validation. minUnbodningPeriodSessions := getMinActorUnbondingPeriodSessions( - &defaultParams, - defaultParams.ClaimWindowOpenOffsetBlocks, + &sharedParams, + sharedParams.ClaimWindowOpenOffsetBlocks, uint64(expectedProofWindowOpenOffestBlocks), ) // Update the SupplierUnbondingPeriodSessions such that it is greater than the // cumulative proof window close blocks to pass UpdateParam validation. - defaultParams.SupplierUnbondingPeriodSessions = minUnbodningPeriodSessions + sharedParams.SupplierUnbondingPeriodSessions = minUnbodningPeriodSessions // Update the ApplicationUnbondingPeriodSessions such that it is greater than the // cumulative proof window close blocks to pass UpdateParam validation. - defaultParams.ApplicationUnbondingPeriodSessions = minUnbodningPeriodSessions + sharedParams.ApplicationUnbondingPeriodSessions = minUnbodningPeriodSessions // Set the parameters to their default values - require.NoError(t, k.SetParams(ctx, defaultParams)) + require.NoError(t, k.SetParams(ctx, sharedParams)) // Ensure the default values are different from the new values we want to set - require.NotEqual(t, uint64(expectedProofWindowOpenOffestBlocks), defaultParams.ProofWindowOpenOffsetBlocks) + require.NotEqual(t, uint64(expectedProofWindowOpenOffestBlocks), sharedParams.ProofWindowOpenOffsetBlocks) // Update the proof window open offset blocks param updateParamMsg := &sharedtypes.MsgUpdateParam{ @@ -174,7 +185,7 @@ func TestMsgUpdateParam_UpdateProofWindowOpenOffsetBlocks(t *testing.T) { require.Equal(t, uint64(expectedProofWindowOpenOffestBlocks), res.Params.ProofWindowOpenOffsetBlocks) // Ensure the other parameters are unchanged - testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, "ProofWindowOpenOffsetBlocks") + testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, "ProofWindowOpenOffsetBlocks") } func TestMsgUpdateParam_UpdateProofWindowCloseOffsetBlocks(t *testing.T) { @@ -182,30 +193,30 @@ func TestMsgUpdateParam_UpdateProofWindowCloseOffsetBlocks(t *testing.T) { k, ctx := testkeeper.SharedKeeper(t) msgSrv := keeper.NewMsgServerImpl(k) - - defaultParams := sharedtypes.DefaultParams() + // Copy test params to avoid modifying them. + sharedParams := testSharedParams // Calculate the minimum unbonding period sessions required by the staking actors // to pass UpdateParam validation. minUnbodningPeriodSessions := getMinActorUnbondingPeriodSessions( - &defaultParams, - defaultParams.ClaimWindowOpenOffsetBlocks, + &sharedParams, + sharedParams.ClaimWindowOpenOffsetBlocks, uint64(expectedProofWindowCloseOffestBlocks), ) // Update the SupplierUnbondingPeriodSessions such that it is greater than the // cumulative proof window close blocks to pass UpdateParam validation. - defaultParams.SupplierUnbondingPeriodSessions = minUnbodningPeriodSessions + sharedParams.SupplierUnbondingPeriodSessions = minUnbodningPeriodSessions // Update the ApplicationUnbondingPeriodSessions such that it is greater than the // cumulative proof window close blocks to pass UpdateParam validation. - defaultParams.ApplicationUnbondingPeriodSessions = minUnbodningPeriodSessions + sharedParams.ApplicationUnbondingPeriodSessions = minUnbodningPeriodSessions // Set the parameters to their default values - require.NoError(t, k.SetParams(ctx, defaultParams)) + require.NoError(t, k.SetParams(ctx, sharedParams)) // Ensure the default values are different from the new values we want to set - require.NotEqual(t, uint64(expectedProofWindowCloseOffestBlocks), defaultParams.ProofWindowCloseOffsetBlocks) + require.NotEqual(t, uint64(expectedProofWindowCloseOffestBlocks), sharedParams.ProofWindowCloseOffsetBlocks) // Update the proof window close offset blocks param updateParamMsg := &sharedtypes.MsgUpdateParam{ @@ -219,7 +230,7 @@ func TestMsgUpdateParam_UpdateProofWindowCloseOffsetBlocks(t *testing.T) { require.Equal(t, uint64(expectedProofWindowCloseOffestBlocks), res.Params.ProofWindowCloseOffsetBlocks) // Ensure the other parameters are unchanged - testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, "ProofWindowCloseOffsetBlocks") + testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, "ProofWindowCloseOffsetBlocks") } func TestMsgUpdateParam_UpdateGracePeriodEndOffsetBlocks(t *testing.T) { @@ -227,18 +238,18 @@ func TestMsgUpdateParam_UpdateGracePeriodEndOffsetBlocks(t *testing.T) { k, ctx := testkeeper.SharedKeeper(t) msgSrv := keeper.NewMsgServerImpl(k) - - defaultParams := sharedtypes.DefaultParams() + // Copy test params to avoid modifying them. + sharedParams := testSharedParams // Update the claim window open offset blocks which has to be at least equal to // GracePeriodEndOffsetBlocks to pass UpdateParam validation. - defaultParams.ClaimWindowOpenOffsetBlocks = uint64(expectedGracePeriodEndOffestBlocks) + sharedParams.ClaimWindowOpenOffsetBlocks = uint64(expectedGracePeriodEndOffestBlocks) // Set the parameters to their default values - require.NoError(t, k.SetParams(ctx, defaultParams)) + require.NoError(t, k.SetParams(ctx, sharedParams)) // Ensure the default values are different from the new values we want to set - require.NotEqual(t, uint64(expectedGracePeriodEndOffestBlocks), defaultParams.GetGracePeriodEndOffsetBlocks()) + require.NotEqual(t, uint64(expectedGracePeriodEndOffestBlocks), sharedParams.GetGracePeriodEndOffsetBlocks()) // Update the proof window close offset blocks param updateParamMsg := &sharedtypes.MsgUpdateParam{ @@ -252,7 +263,7 @@ func TestMsgUpdateParam_UpdateGracePeriodEndOffsetBlocks(t *testing.T) { require.Equal(t, uint64(expectedGracePeriodEndOffestBlocks), res.Params.GetGracePeriodEndOffsetBlocks()) // Ensure the other parameters are unchanged - testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, "GracePeriodEndOffsetBlocks") + testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, "GracePeriodEndOffsetBlocks") } func TestMsgUpdateParam_UpdateSupplierUnbondingPeriodSessions(t *testing.T) { @@ -261,12 +272,11 @@ func TestMsgUpdateParam_UpdateSupplierUnbondingPeriodSessions(t *testing.T) { k, ctx := testkeeper.SharedKeeper(t) msgSrv := keeper.NewMsgServerImpl(k) - defaultParams := sharedtypes.DefaultParams() - // Set the parameters to their default values - require.NoError(t, k.SetParams(ctx, defaultParams)) + // Set the parameters. + require.NoError(t, k.SetParams(ctx, testSharedParams)) // Ensure the default values are different from the new values we want to set - require.NotEqual(t, uint64(expectedSupplierUnbondingPerid), defaultParams.GetSupplierUnbondingPeriodSessions()) + require.NotEqual(t, uint64(expectedSupplierUnbondingPerid), testSharedParams.GetSupplierUnbondingPeriodSessions()) // Update the supplier unbonding period param updateParamMsg := &sharedtypes.MsgUpdateParam{ @@ -280,7 +290,7 @@ func TestMsgUpdateParam_UpdateSupplierUnbondingPeriodSessions(t *testing.T) { require.Equal(t, uint64(expectedSupplierUnbondingPerid), res.Params.GetSupplierUnbondingPeriodSessions()) // Ensure the other parameters are unchanged - testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, "SupplierUnbondingPeriodSessions") + testkeeper.AssertDefaultParamsEqualExceptFields(t, &testSharedParams, res.Params, "SupplierUnbondingPeriodSessions") // Ensure that a supplier unbonding period that is less than the cumulative // proof window close blocks is not allowed. @@ -299,12 +309,11 @@ func TestMsgUpdateParam_UpdateApplicationUnbondingPeriodSessions(t *testing.T) { k, ctx := testkeeper.SharedKeeper(t) msgSrv := keeper.NewMsgServerImpl(k) - defaultParams := sharedtypes.DefaultParams() - // Set the parameters to their default values - require.NoError(t, k.SetParams(ctx, defaultParams)) + // Set the parameters. + require.NoError(t, k.SetParams(ctx, testSharedParams)) // Ensure the default values are different from the new values we want to set - require.NotEqual(t, uint64(expectedApplicationUnbondingPerid), defaultParams.GetApplicationUnbondingPeriodSessions()) + require.NotEqual(t, uint64(expectedApplicationUnbondingPerid), testSharedParams.GetApplicationUnbondingPeriodSessions()) // Update the application unbonding period param updateParamMsg := &sharedtypes.MsgUpdateParam{ @@ -318,7 +327,7 @@ func TestMsgUpdateParam_UpdateApplicationUnbondingPeriodSessions(t *testing.T) { require.Equal(t, uint64(expectedApplicationUnbondingPerid), res.Params.GetApplicationUnbondingPeriodSessions()) // Ensure the other parameters are unchanged - testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, "ApplicationUnbondingPeriodSessions") + testkeeper.AssertDefaultParamsEqualExceptFields(t, &testSharedParams, res.Params, "ApplicationUnbondingPeriodSessions") // Ensure that a application unbonding period that is less than the cumulative // proof window close blocks is not allowed. @@ -337,12 +346,11 @@ func TestMsgUpdateParam_ComputeUnitsToTokenMultiplier(t *testing.T) { k, ctx := testkeeper.SharedKeeper(t) msgSrv := keeper.NewMsgServerImpl(k) - defaultParams := sharedtypes.DefaultParams() - // Set the parameters to their default values - require.NoError(t, k.SetParams(ctx, defaultParams)) + // Set the parameters. + require.NoError(t, k.SetParams(ctx, testSharedParams)) // Ensure the default values are different from the new values we want to set - require.NotEqual(t, uint64(expectedComputeUnitsToTokenMultiplier), defaultParams.GetComputeUnitsToTokensMultiplier()) + require.NotEqual(t, uint64(expectedComputeUnitsToTokenMultiplier), testSharedParams.GetComputeUnitsToTokensMultiplier()) // Update the compute units to token multiplier param updateParamMsg := &sharedtypes.MsgUpdateParam{ @@ -356,7 +364,7 @@ func TestMsgUpdateParam_ComputeUnitsToTokenMultiplier(t *testing.T) { require.Equal(t, uint64(expectedComputeUnitsToTokenMultiplier), res.Params.GetComputeUnitsToTokensMultiplier()) // Ensure the other parameters are unchanged - testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, "ComputeUnitsToTokensMultiplier") + testkeeper.AssertDefaultParamsEqualExceptFields(t, &testSharedParams, res.Params, "ComputeUnitsToTokensMultiplier") // Ensure that compute units to token multiplier that is less than 1 is not allowed. updateParamMsg = &sharedtypes.MsgUpdateParam{ From 287761458b7ec10dadee3c92cb56b44f99a72aa2 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Fri, 20 Sep 2024 10:33:53 +0200 Subject: [PATCH 13/14] fix: failing tests --- x/session/keeper/query_get_session_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/session/keeper/query_get_session_test.go b/x/session/keeper/query_get_session_test.go index b683aed19..cff54f93a 100644 --- a/x/session/keeper/query_get_session_test.go +++ b/x/session/keeper/query_get_session_test.go @@ -21,7 +21,7 @@ func init() { // the Cosmos SDK context aware wrapper around it. func TestSession_GetSession_Success(t *testing.T) { - keeper, ctx := keepertest.SessionKeeper(t) + keeper, ctx := keepertest.SessionKeeper(t, sharedParamsOpt) ctx = sdk.UnwrapSDKContext(ctx).WithBlockHeight(100) // provide a sufficiently large block height to avoid errors tests := []struct { @@ -69,7 +69,7 @@ func TestSession_GetSession_Success(t *testing.T) { } func TestSession_GetSession_Failure(t *testing.T) { - keeper, ctx := keepertest.SessionKeeper(t) + keeper, ctx := keepertest.SessionKeeper(t, sharedParamsOpt) ctx = sdk.UnwrapSDKContext(ctx).WithBlockHeight(100) // provide a sufficiently large block height to avoid errors tests := []struct { From 24e72348a4fb60019871cdc5dc398534fbc722a8 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 23 Sep 2024 10:45:49 +0200 Subject: [PATCH 14/14] Empty commit