pokt-network / poktroll

The official Shannon upgrade implementation of the Pocket Network Protocol implemented using the Cosmos SDK
MIT License
15 stars 8 forks source link

[Testing] Fix non-idempotency in (and speed up) supplier staking tests #815

Closed bryanchriswhite closed 1 month ago

bryanchriswhite commented 1 month ago

Summary

NOTE: This is superseded by #826 where supplier un/staking E2E tests will be removed.

Dependents

Issue

Type of change

Select one or more from the following:

Testing

Sanity Checklist

github-actions[bot] commented 1 month ago

The CI will now also run the e2e tests on devnet, which increases the time it takes to complete all CI checks.

You may need to run make trigger_ci to submit an empty commit that'll trigger the tests.

GCP workloads (requires changing the namespace to 815)) Grafana network dashboard for devnet-issue-815

bryanchriswhite commented 1 month ago

@reviewer, here's the diff between 2f1af15..bedc05c:

image

git diff 2f1af15..bedc05c ```diff diff --git a/config.yml b/config.yml index 7921b057..4c521577 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/e2e/tests/stake_supplier_steps_test.go b/e2e/tests/stake_supplier_steps_test.go index 15197a25..2b1e9e28 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 @@ -63,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))) diff --git a/e2e/tests/update_params.feature b/e2e/tests/update_params.feature index c1a9b77f..a84cad53 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 diff --git a/testutil/keeper/session.go b/testutil/keeper/session.go index 74ff98a0..8f84999f 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/tools/scripts/params/shared_all.json b/tools/scripts/params/shared_all.json index fa5e04f7..2a489f27 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/proof/module/helpers_test.go b/x/proof/module/helpers_test.go index 7f983a1f..59948a50 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 70cf9e48..818adad8 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 6f0994da..df1f0682 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/shared/keeper/msg_server_update_param_test.go b/x/shared/keeper/msg_server_update_param_test.go index 9554c701..da4a2ca0 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{ diff --git a/x/shared/types/params.go b/x/shared/types/params.go index 3a5afd62..d5921f62 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" diff --git a/x/supplier/keeper/unbond_suppliers.go b/x/supplier/keeper/unbond_suppliers.go index ba8242e8..16a491c6 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" ) ```