suites

package
v0.0.11-rc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgUpdateParamsName = "MsgUpdateParams"
	MsgUpdateParamName  = "MsgUpdateParam"
)

Variables

View Source
var (
	ValidAddServiceFeeCoin             = cosmostypes.NewInt64Coin(volatile.DenomuPOKT, 1000000001)
	ValidProofMissingPenaltyCoin       = cosmostypes.NewInt64Coin(volatile.DenomuPOKT, 500)
	ValidProofSubmissionFeeCoin        = cosmostypes.NewInt64Coin(volatile.DenomuPOKT, 5000000)
	ValidProofRequirementThresholdCoin = cosmostypes.NewInt64Coin(volatile.DenomuPOKT, 100)
	ValidRelayDifficultyTargetHash, _  = hex.DecodeString("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
	ValidActorMinStake                 = cosmostypes.NewInt64Coin(volatile.DenomuPOKT, 100)

	SharedModuleParamConfig = ModuleParamConfig{
		ParamsMsgs: ModuleParamsMessages{
			MsgUpdateParams:         sharedtypes.MsgUpdateParams{},
			MsgUpdateParamsResponse: sharedtypes.MsgUpdateParamsResponse{},
			MsgUpdateParam:          sharedtypes.MsgUpdateParam{},
			MsgUpdateParamResponse:  sharedtypes.MsgUpdateParamResponse{},
			QueryParamsRequest:      sharedtypes.QueryParamsRequest{},
			QueryParamsResponse:     sharedtypes.QueryParamsResponse{},
		},
		ParamTypes: map[ParamType]any{
			ParamTypeUint64: sharedtypes.MsgUpdateParam_AsUint64{},
			ParamTypeString: sharedtypes.MsgUpdateParam_AsString{},
			ParamTypeBytes:  sharedtypes.MsgUpdateParam_AsBytes{},
		},
		ValidParams: sharedtypes.Params{
			NumBlocksPerSession:                12,
			GracePeriodEndOffsetBlocks:         0,
			ClaimWindowOpenOffsetBlocks:        2,
			ClaimWindowCloseOffsetBlocks:       3,
			ProofWindowOpenOffsetBlocks:        1,
			ProofWindowCloseOffsetBlocks:       3,
			SupplierUnbondingPeriodSessions:    9,
			ApplicationUnbondingPeriodSessions: 9,
			ComputeUnitsToTokensMultiplier:     420,
		},
		DefaultParams:    sharedtypes.DefaultParams(),
		NewParamClientFn: sharedtypes.NewQueryClient,
	}

	SessionModuleParamConfig = ModuleParamConfig{
		ParamsMsgs: ModuleParamsMessages{
			MsgUpdateParams:         sessiontypes.MsgUpdateParams{},
			MsgUpdateParamsResponse: sessiontypes.MsgUpdateParamsResponse{},
			MsgUpdateParam:          sessiontypes.MsgUpdateParam{},
			MsgUpdateParamResponse:  sessiontypes.MsgUpdateParamResponse{},
			QueryParamsRequest:      sessiontypes.QueryParamsRequest{},
			QueryParamsResponse:     sessiontypes.QueryParamsResponse{},
		},
		ValidParams: sessiontypes.Params{
			NumSuppliersPerSession: 420,
		},
		ParamTypes: map[ParamType]any{
			ParamTypeUint64: sessiontypes.MsgUpdateParam_AsUint64{},
		},
		DefaultParams:    sessiontypes.DefaultParams(),
		NewParamClientFn: sessiontypes.NewQueryClient,
	}

	ServiceModuleParamConfig = ModuleParamConfig{
		ParamsMsgs: ModuleParamsMessages{
			MsgUpdateParams:         servicetypes.MsgUpdateParams{},
			MsgUpdateParamsResponse: servicetypes.MsgUpdateParamsResponse{},
			MsgUpdateParam:          servicetypes.MsgUpdateParam{},
			MsgUpdateParamResponse:  servicetypes.MsgUpdateParamResponse{},
			QueryParamsRequest:      servicetypes.QueryParamsRequest{},
			QueryParamsResponse:     servicetypes.QueryParamsResponse{},
		},
		ValidParams: servicetypes.Params{
			AddServiceFee: &ValidAddServiceFeeCoin,
		},
		ParamTypes: map[ParamType]any{
			ParamTypeCoin: servicetypes.MsgUpdateParam_AsCoin{},
		},
		DefaultParams:    servicetypes.DefaultParams(),
		NewParamClientFn: servicetypes.NewQueryClient,
	}

	ApplicationModuleParamConfig = ModuleParamConfig{
		ParamsMsgs: ModuleParamsMessages{
			MsgUpdateParams:         apptypes.MsgUpdateParams{},
			MsgUpdateParamsResponse: apptypes.MsgUpdateParamsResponse{},
			MsgUpdateParam:          apptypes.MsgUpdateParam{},
			MsgUpdateParamResponse:  apptypes.MsgUpdateParamResponse{},
			QueryParamsRequest:      apptypes.QueryParamsRequest{},
			QueryParamsResponse:     apptypes.QueryParamsResponse{},
		},
		ValidParams: apptypes.Params{
			MaxDelegatedGateways: 999,
			MinStake:             &ValidActorMinStake,
		},
		ParamTypes: map[ParamType]any{
			ParamTypeUint64: apptypes.MsgUpdateParam_AsUint64{},
			ParamTypeCoin:   apptypes.MsgUpdateParam_AsCoin{},
		},
		DefaultParams:    apptypes.DefaultParams(),
		NewParamClientFn: apptypes.NewQueryClient,
	}

	GatewayModuleParamConfig = ModuleParamConfig{
		ParamsMsgs: ModuleParamsMessages{
			MsgUpdateParams:         gatewaytypes.MsgUpdateParams{},
			MsgUpdateParamsResponse: gatewaytypes.MsgUpdateParamsResponse{},
			MsgUpdateParam:          gatewaytypes.MsgUpdateParam{},
			MsgUpdateParamResponse:  gatewaytypes.MsgUpdateParamResponse{},
			QueryParamsRequest:      gatewaytypes.QueryParamsRequest{},
			QueryParamsResponse:     gatewaytypes.QueryParamsResponse{},
		},
		ValidParams: gatewaytypes.Params{
			MinStake: &ValidActorMinStake,
		},
		ParamTypes: map[ParamType]any{
			ParamTypeCoin: gatewaytypes.MsgUpdateParam_AsCoin{},
		},
		DefaultParams:    gatewaytypes.DefaultParams(),
		NewParamClientFn: gatewaytypes.NewQueryClient,
	}

	SupplierModuleParamConfig = ModuleParamConfig{
		ParamsMsgs: ModuleParamsMessages{
			MsgUpdateParams:         suppliertypes.MsgUpdateParams{},
			MsgUpdateParamsResponse: suppliertypes.MsgUpdateParamsResponse{},
			MsgUpdateParam:          suppliertypes.MsgUpdateParam{},
			MsgUpdateParamResponse:  suppliertypes.MsgUpdateParamResponse{},
			QueryParamsRequest:      suppliertypes.QueryParamsRequest{},
			QueryParamsResponse:     suppliertypes.QueryParamsResponse{},
		},
		ValidParams: suppliertypes.Params{
			MinStake: &ValidActorMinStake,
		},
		ParamTypes: map[ParamType]any{
			ParamTypeCoin: suppliertypes.MsgUpdateParam_AsCoin{},
		},
		DefaultParams:    suppliertypes.DefaultParams(),
		NewParamClientFn: suppliertypes.NewQueryClient,
	}

	ProofModuleParamConfig = ModuleParamConfig{
		ParamsMsgs: ModuleParamsMessages{
			MsgUpdateParams:         prooftypes.MsgUpdateParams{},
			MsgUpdateParamsResponse: prooftypes.MsgUpdateParamsResponse{},
			MsgUpdateParam:          prooftypes.MsgUpdateParam{},
			MsgUpdateParamResponse:  prooftypes.MsgUpdateParamResponse{},
			QueryParamsRequest:      prooftypes.QueryParamsRequest{},
			QueryParamsResponse:     prooftypes.QueryParamsResponse{},
		},
		ValidParams: prooftypes.Params{
			ProofRequestProbability:   0.1,
			ProofRequirementThreshold: &ValidProofRequirementThresholdCoin,
			ProofMissingPenalty:       &ValidProofMissingPenaltyCoin,
			ProofSubmissionFee:        &ValidProofSubmissionFeeCoin,
		},
		ParamTypes: map[ParamType]any{
			ParamTypeBytes:   prooftypes.MsgUpdateParam_AsBytes{},
			ParamTypeFloat64: prooftypes.MsgUpdateParam_AsFloat{},
			ParamTypeCoin:    prooftypes.MsgUpdateParam_AsCoin{},
		},
		DefaultParams:    prooftypes.DefaultParams(),
		NewParamClientFn: prooftypes.NewQueryClient,
	}

	TokenomicsModuleParamConfig = ModuleParamConfig{
		ParamsMsgs: ModuleParamsMessages{
			MsgUpdateParams:         tokenomicstypes.MsgUpdateParams{},
			MsgUpdateParamsResponse: tokenomicstypes.MsgUpdateParamsResponse{},
			MsgUpdateParam:          tokenomicstypes.MsgUpdateParam{},
			MsgUpdateParamResponse:  tokenomicstypes.MsgUpdateParamResponse{},
			QueryParamsRequest:      tokenomicstypes.QueryParamsRequest{},
			QueryParamsResponse:     tokenomicstypes.QueryParamsResponse{},
		},
		ValidParams: tokenomicstypes.Params{
			MintAllocationPercentages: tokenomicstypes.DefaultMintAllocationPercentages,
			DaoRewardAddress:          sample.AccAddress(),
		},
		ParamTypes: map[ParamType]any{
			ParamTypeMintAllocationPercentages: tokenomicstypes.MsgUpdateParam_AsMintAllocationPercentages{},
			ParamTypeString:                    tokenomicstypes.MsgUpdateParam_AsString{},
		},
		DefaultParams:    tokenomicstypes.DefaultParams(),
		NewParamClientFn: tokenomicstypes.NewQueryClient,
	}
)
View Source
var (
	// MsgUpdateParamEnabledModuleNames is a list of module names which support
	// individual parameter updates (i.e. MsgUpdateParam). It is initialized in
	// init().
	MsgUpdateParamEnabledModuleNames []string

	// ModuleParamConfigMap is a map of module names to their respective parameter
	// configurations. It is used by the ParamsSuite, mostly via reflection,
	// to construct and send parameter update messages and assert on their results.
	ModuleParamConfigMap = map[string]ModuleParamConfig{
		sharedtypes.ModuleName:     SharedModuleParamConfig,
		sessiontypes.ModuleName:    SessionModuleParamConfig,
		servicetypes.ModuleName:    ServiceModuleParamConfig,
		apptypes.ModuleName:        ApplicationModuleParamConfig,
		gatewaytypes.ModuleName:    GatewayModuleParamConfig,
		suppliertypes.ModuleName:   SupplierModuleParamConfig,
		prooftypes.ModuleName:      ProofModuleParamConfig,
		tokenomicstypes.ModuleName: TokenomicsModuleParamConfig,
	}
)

Functions

func NewMsgUpdateParams

func NewMsgUpdateParams(
	msgUpdateParamsType reflect.Type,
	authorityBech32 string,
	params any,
) cosmostypes.Msg

NewMsgUpdateParams constructs a new concrete pointer of msgUpdateParams type with the given param values set on it. It is returned as a cosmostypes.Msg.

Types

type AuthzIntegrationSuite

type AuthzIntegrationSuite struct {
	BaseIntegrationSuite
}

AuthzIntegrationSuite is an integration test suite that provides helper functions for running authz grant and exec messages. It is intended to be embedded in other integration test suites which are dependent on authz.

func (*AuthzIntegrationSuite) RunAuthzExecMsg

func (s *AuthzIntegrationSuite) RunAuthzExecMsg(
	t *testing.T,
	signerAddr cosmostypes.AccAddress,
	msgs ...cosmostypes.Msg,
) (msgRespsBz [][]byte, err error)

RunAuthzExecMsg executes the given messag(es) using authz. It assumes that an authorization exists for which signerAdder is the grantee.

func (*AuthzIntegrationSuite) RunAuthzGrantMsg

func (s *AuthzIntegrationSuite) RunAuthzGrantMsg(
	t *testing.T,
	granterAddr,
	granteeAddr cosmostypes.AccAddress,
	authorization authz.Authorization,
)

RunAuthzGrantMsg creates an on-chain authz grant from the given granter to the grantee addresses for the authorization object provided.

func (*AuthzIntegrationSuite) RunAuthzGrantMsgForPoktrollModules

func (s *AuthzIntegrationSuite) RunAuthzGrantMsgForPoktrollModules(
	t *testing.T,
	granterAddr, granteeAddr cosmostypes.AccAddress,
	msgName string,
	moduleNames ...string,
)

RunAuthzGrantMsgForPoktrollModules creates an on-chain authz grant for the given granter and grantee addresses for the specified message name in each of the poktroll modules present in the integration app.

type BaseIntegrationSuite

type BaseIntegrationSuite struct {
	suite.Suite
	// contains filtered or unexported fields
}

BaseIntegrationSuite is a base implementation of IntegrationSuite. It is intended to be embedded in other integration test suites.

func (*BaseIntegrationSuite) FilterEvents

func (s *BaseIntegrationSuite) FilterEvents(
	matchFn func(*cosmostypes.Event) bool,
) (matchedEvents []*cosmostypes.Event)

FilterEvents returns the events from the event manager which match the given matchFn. Events are returned in reverse order, i.e. the most recent event is first.

func (*BaseIntegrationSuite) FundAddress

func (s *BaseIntegrationSuite) FundAddress(
	t *testing.T,
	addr cosmostypes.AccAddress,
	amountUpokt int64,
)

FundAddress sends amountUpokt coins from the faucet to the given address.

func (*BaseIntegrationSuite) GetApp

func (s *BaseIntegrationSuite) GetApp() *integration.App

GetApp returns the integration app from the suite.

func (*BaseIntegrationSuite) GetBankQueryClient

func (s *BaseIntegrationSuite) GetBankQueryClient() banktypes.QueryClient

GetBankQueryClient constructs and returns a query client for the bank module of the integration app.

func (*BaseIntegrationSuite) GetCosmosModuleNames

func (s *BaseIntegrationSuite) GetCosmosModuleNames() []string

GetCosmosModuleNames returns the list of the names of all cosmos-sdk modules in the integration app.

func (*BaseIntegrationSuite) GetPoktrollModuleNames

func (s *BaseIntegrationSuite) GetPoktrollModuleNames() []string

GetPoktrollModuleNames returns the list of the names of all poktroll modules in the integration app.

func (*BaseIntegrationSuite) LatestMatchingEvent

func (s *BaseIntegrationSuite) LatestMatchingEvent(
	matchFn func(*cosmostypes.Event) bool,
) (matchedEvent *cosmostypes.Event)

LatestMatchingEvent returns the most recent event in the event manager that matches the given matchFn.

func (*BaseIntegrationSuite) NewApp

NewApp constructs a new integration app and sets it on the suite.

func (*BaseIntegrationSuite) SdkCtx

SdkCtx returns the integration app's SDK context.

func (*BaseIntegrationSuite) SetApp

func (s *BaseIntegrationSuite) SetApp(app *integration.App)

SetApp sets the integration app on the suite.

type IntegrationSuite

type IntegrationSuite interface {
	// NewApp constructs a new integration app and sets it on the suite.
	NewApp(*testing.T, ...integration.IntegrationAppOptionFn) *integration.App
	// SetApp sets the integration app on the suite.
	SetApp(*integration.App)
	// GetApp returns the integration app from the suite.
	GetApp() *integration.App
	// GetPoktrollModuleNames returns the list of the names of all poktroll modules
	// in the integration app.
	GetPoktrollModuleNames() []string
	// GetCosmosModuleNames returns the list of the names of all cosmos-sdk modules
	// in the integration app.
	GetCosmosModuleNames() []string
	// SdkCtx returns the integration app's SDK context.
	SdkCtx() *cosmostypes.Context

	// FundAddress sends amtUpokt coins from the faucet to the given address.
	FundAddress(t *testing.T, addr cosmostypes.AccAddress, amtUpokt int64)
	// GetBankQueryClient constructs and returns a query client for the bank module
	// of the integration app.
	GetBankQueryClient() banktypes.QueryClient

	// FilterEvents returns the events from the event manager which match the given
	// matchFn. Events are returned in reverse order, i.e. the most recent event is
	// first.
	FilterEvents(matchFn func(*cosmostypes.Event) bool) []*cosmostypes.Event
	// LatestMatchingEvent returns the most recent event in the event manager that
	// matches the given matchFn.
	LatestMatchingEvent(matchFn func(*cosmostypes.Event) bool) *cosmostypes.Event
}

IntegrationSuite is an interface intended to be used within test suites which exercise an integration.App.

type ModuleParamConfig

type ModuleParamConfig struct {
	ParamsMsgs ModuleParamsMessages
	// ParamTypes is a map of parameter types to their respective MsgUpdateParam_As*
	// types which satisfy the oneof for the MsgUpdateParam#AsType field. Each AsType
	// type which the module supports should be included in this map.
	ParamTypes map[ParamType]any
	// ValidParams is a set of parameters which are expected to be valid when used
	// together AND when used individually, where the renaming parameters are set
	// to their default values.
	ValidParams      any
	DefaultParams    any
	NewParamClientFn any
}

ModuleParamConfig holds type information about a module's parameters update message(s) along with default and valid non-default values and a query constructor function for the module. It is used by ParamsSuite to construct and send parameter update messages and assert on their results.

type ModuleParamsMessages

type ModuleParamsMessages struct {
	MsgUpdateParams         any
	MsgUpdateParamsResponse any
	MsgUpdateParam          any
	MsgUpdateParamResponse  any
	QueryParamsRequest      any
	QueryParamsResponse     any
}

ModuleParamsMessages holds a reference to each of the params-related message types for a given module. The values are only used for their type information which is obtained via reflection. The values are not used for their actual message contents and MAY be the zero value. If MsgUpdateParam is omitted (i.e. nil), ParamsSuite will assume that this module does not support individual parameter updates (i.e. MsgUpdateParam). In this case, MsgUpdateParamResponse SHOULD also be omitted.

type ParamType

type ParamType = string

ParamType is a type alias for a module parameter type. It is the string that is returned when calling reflect.Value#Type()#Name() on a module parameter.

const (
	ParamTypeInt64                     ParamType = "int64"
	ParamTypeUint64                    ParamType = "uint64"
	ParamTypeFloat64                   ParamType = "float64"
	ParamTypeString                    ParamType = "string"
	ParamTypeBytes                     ParamType = "uint8"
	ParamTypeCoin                      ParamType = "Coin"
	ParamTypeMintAllocationPercentages ParamType = "MintAllocationPercentages"
)

type ParamsSuite

type ParamsSuite struct {
	AuthzIntegrationSuite

	// AuthorityAddr is the cosmos account address of the authority for the integration
	// app. It is used as the **granter** of authz grants for parameter update messages.
	// In practice, is an address sourced by an on-chain string and no one has the private key.
	AuthorityAddr cosmostypes.AccAddress
	// AuthorizedAddr is the cosmos account address which is the **grantee** of authz
	// grants for parameter update messages.
	// In practice, it is the address of the foundation or the DAO.
	AuthorizedAddr cosmostypes.AccAddress
}

ParamsSuite is an integration test suite that provides helper functions for querying module parameters and running parameter update messages. It is intended to be embedded in other integration test suites which are dependent on parameter queries or updates.

func (*ParamsSuite) QueryModuleParams

func (s *ParamsSuite) QueryModuleParams(t *testing.T, moduleName string) (params any, err error)

QueryModuleParams queries the given module's parameters and returns them. It is expected to be called after s.NewApp() as it depends on the app's query helper.

func (*ParamsSuite) RequireModuleHasDefaultParams

func (s *ParamsSuite) RequireModuleHasDefaultParams(t *testing.T, moduleName string)

RequireModuleHasDefaultParams asserts that the given module's parameters are set to their default values.

func (*ParamsSuite) RunUpdateParam

func (s *ParamsSuite) RunUpdateParam(
	t *testing.T,
	moduleName string,
	paramName string,
	paramValue any,
) (msgResponseBz []byte, err error)

RunUpdateParam constructs and runs an MsgUpdateParam message via an authz exec as the AuthorizedAddr for the given module, parameter name, and value. It returns the response bytes and error. It is expected to be called after s.SetupTestAuthzGrants() as it depends on an on-chain authz grant to AuthorizedAddr for MsgUpdateParam for the given module.

func (*ParamsSuite) RunUpdateParamAsSigner

func (s *ParamsSuite) RunUpdateParamAsSigner(
	t *testing.T,
	moduleName string,
	paramName string,
	paramValue any,
	signerAddr cosmostypes.AccAddress,
) (msgResponseBz []byte, err error)

RunUpdateParamAsSigner constructs and runs an MsgUpdateParam message via an authz exec as the given signerAddr for the given module, parameter name, and value. It returns the response bytes and error. It depends on an on-chain authz grant to signerAddr for MsgUpdateParam for the given module.

func (*ParamsSuite) RunUpdateParams

func (s *ParamsSuite) RunUpdateParams(
	t *testing.T,
	msgUpdateParams cosmostypes.Msg,
) (msgResponseBz []byte, err error)

RunUpdateParams runs the given MsgUpdateParams message via an authz exec as the AuthorizedAddr and returns the response bytes and error. It is expected to be called after s.SetupTestAuthzGrants() as it depends on an on-chain authz grant to AuthorizedAddr for MsgUpdateParams for the given module.

func (*ParamsSuite) RunUpdateParamsAsSigner

func (s *ParamsSuite) RunUpdateParamsAsSigner(
	t *testing.T,
	msgUpdateParams cosmostypes.Msg,
	signerAddr cosmostypes.AccAddress,
) (msgResponseBz []byte, err error)

RunUpdateParamsAsSigner runs the given MsgUpdateParams message via an authz exec as signerAddr and returns the response bytes and error. It depends on an on-chain authz grant to signerAddr for MsgUpdateParams for the given module.

func (*ParamsSuite) SetupTestAuthzAccounts

func (s *ParamsSuite) SetupTestAuthzAccounts(t *testing.T)

SetupTestAuthzAccounts sets AuthorityAddr for the suite by getting the authority from the integration app. It also assigns a new pre-generated identity to be used as the AuthorizedAddr for the suite. It is expected to be called after s.NewApp() as it depends on the integration app and its pre-generated account iterator.

func (*ParamsSuite) SetupTestAuthzGrants

func (s *ParamsSuite) SetupTestAuthzGrants(t *testing.T)

SetupTestAuthzGrants creates on-chain authz grants for the MsgUpdateUpdateParam and MsgUpdateParams message for each module. It is expected to be called after s.NewApp() as it depends on the authority and authorized addresses having been set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL