-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Testing] Fix non-idempotency in (and speed up) supplier staking tests (
#815) ## Summary - Fix non-idempotency in supplier staking tests; `supplier2` was not staked at the start but was left staked at the end. - Speed up supplier staking tests by updating the shared params to minimize the unbonding period to 1 session of 2 localnet/devnet blocks. ### NOTE: This is superseded by #826 where supplier un/staking E2E tests will be removed. ## Dependents - #821 - #820 - #826 ## Issue - #799 ## Type of change Select one or more from the following: - [ ] New feature, functionality or library - [ ] Consensus breaking; add the `consensus-breaking` label if so. See #791 for details - [ ] Bug fix - [x] Code health or cleanup - [ ] Documentation - [ ] Other (specify) ## Testing - [ ] **Documentation**: `make docusaurus_start`; only needed if you make doc changes - [ ] **Unit Tests**: `make go_develop_and_test` - [ ] **LocalNet E2E Tests**: `make test_e2e` - [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR. ## Sanity Checklist - [x] I have tested my changes using the available tooling - [x] I have commented my code - [ ] I have performed a self-review of my own code; both comments & source code - [ ] I create and reference any new tickets, if applicable - [ ] I have left TODOs throughout the codebase, if applicable --------- Co-authored-by: Daniel Olshansky <[email protected]>
- Loading branch information
1 parent
6bbc940
commit 1c38f2b
Showing
19 changed files
with
331 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//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, | ||
unbondingPeriodSessions, | ||
numBlocksPerSession int64, | ||
) { | ||
require.GreaterOrEqualf(s, numBlocksPerSession, int64(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(unbondingPeriodSessions), | ||
ApplicationUnbondingPeriodSessions: uint64(unbondingPeriodSessions), | ||
ComputeUnitsToTokensMultiplier: sharedtypes.DefaultComputeUnitsToTokensMultiplier, | ||
} | ||
|
||
// 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() | ||
// TODO_IMPROVE: MsgUpdateParam currently only supports int64 and not uint64 value types. | ||
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.