keeper

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 57 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TestServiceId1  = "svc1"  // staked for by app1 & supplier1
	TestServiceId11 = "svc11" // staked for by app1

	TestServiceId2  = "svc2"  // staked for by app2 & supplier1
	TestServiceId22 = "svc22" // staked for by app2

	TestServiceId12 = "svc12" // staked for by app1, app2 & supplier1

	TestApp1Address = "pokt1mdccn4u38eyjdxkk4h0jaddw4n3c72u82m5m9e" // Generated via sample.AccAddress()
	TestApp1        = apptypes.Application{
		Address: TestApp1Address,
		Stake:   &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)},
		ServiceConfigs: []*sharedtypes.ApplicationServiceConfig{
			{
				ServiceId: TestServiceId1,
			},
			{
				ServiceId: TestServiceId11,
			},
			{
				ServiceId: TestServiceId12,
			},
		},
	}

	TestApp2Address = "pokt133amv5suh75zwkxxcq896azvmmwszg99grvk9f" // Generated via sample.AccAddress()
	TestApp2        = apptypes.Application{
		Address: TestApp1Address,
		Stake:   &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)},
		ServiceConfigs: []*sharedtypes.ApplicationServiceConfig{
			{
				ServiceId: TestServiceId2,
			},
			{
				ServiceId: TestServiceId22,
			},
			{
				ServiceId: TestServiceId12,
			},
		},
	}

	TestSupplierUrl             = "http://olshansky.info"
	TestSupplierOperatorAddress = sample.AccAddress()
	TestSupplier                = sharedtypes.Supplier{
		OperatorAddress: TestSupplierOperatorAddress,
		Stake:           &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)},
		Services: []*sharedtypes.SupplierServiceConfig{
			{
				ServiceId: TestServiceId1,
				Endpoints: []*sharedtypes.SupplierEndpoint{
					{
						Url:     TestSupplierUrl,
						RpcType: sharedtypes.RPCType_JSON_RPC,
						Configs: make([]*sharedtypes.ConfigOption, 0),
					},
				},
			},
			{
				ServiceId: TestServiceId2,
				Endpoints: []*sharedtypes.SupplierEndpoint{
					{
						Url:     TestSupplierUrl,
						RpcType: sharedtypes.RPCType_GRPC,
						Configs: make([]*sharedtypes.ConfigOption, 0),
					},
				},
			},
			{
				ServiceId: TestServiceId12,
				Endpoints: []*sharedtypes.SupplierEndpoint{
					{
						Url:     TestSupplierUrl,
						RpcType: sharedtypes.RPCType_GRPC,
						Configs: make([]*sharedtypes.ConfigOption, 0),
					},
				},
			},
		},
	}
)

Functions

func AddAccToAccMapCoins

func AddAccToAccMapCoins(t *testing.T, addr, denom string, amount uint64)

AddAccToAccMapCoins adds to the mapAccAddrCoins map the coins specified as parameters, to the function under the address specified. When it cleans up it deletes the entry in the map for the provided address.

func AddGatewayToStakedGatewayMap

func AddGatewayToStakedGatewayMap(t *testing.T, gatewayAddr string)

AddGatewayToStakedGatewayMap adds the given gateway address to the staked gateway map for use in the application's mocked gateway keeper and ensures that it is removed from the map when the test is complete

func ApplicationKeeper

func ApplicationKeeper(t testing.TB) (keeper.Keeper, context.Context)

ApplicationKeeper creates a new application keeper for testing and returns the keeper and context.

func AssertDefaultParamsEqualExceptFields added in v0.0.3

func AssertDefaultParamsEqualExceptFields[P any](
	t *testing.T,
	expectedParams P,
	actualParams P,
	exceptFields ...string,
)

AssertDefaultParamsEqualExceptFields asserts that the expectedParams and actualParams are equal except for the fields specified in exceptFields. expectedParams and actualParams MUST be reference types (e.g. pionters).

func GatewayKeeper

func GatewayKeeper(t testing.TB) (keeper.Keeper, context.Context)

func ProofKeeper

func ProofKeeper(t testing.TB) (keeper.Keeper, context.Context)

ProofKeeper is a helper function to create a proof keeper and a context. It uses mocked dependencies only.

func RemoveGatewayFromStakedGatewayMap

func RemoveGatewayFromStakedGatewayMap(t *testing.T, gatewayAddr string)

RemoveGatewayFromStakedGatewayMap removes the given gateway address from the staked gateway map for use in the application's mocked gateway keeper

func ServiceKeeper

func ServiceKeeper(t testing.TB) (keeper.Keeper, context.Context)

func SessionKeeper

func SessionKeeper(t testing.TB, opts ...KeeperOptionFn) (keeper.Keeper, context.Context)

func SetBlockHash

func SetBlockHash(ctx context.Context, hash []byte) context.Context

SetBlockHash updates the block hash for the given context and returns the updated context.

func SetBlockHeight

func SetBlockHeight(ctx context.Context, height int64) context.Context

SetBlockHeight updates the block height for the given context and returns the updated context.

func SharedKeeper added in v0.0.3

func SharedKeeper(t testing.TB) (keeper.Keeper, sdk.Context)

func TokenomicsKeeper

func TokenomicsKeeper(t testing.TB) (tokenomicsKeeper tokenomicskeeper.Keeper, ctx context.Context)

func TokenomicsKeeperWithActorAddrs added in v0.0.3

func TokenomicsKeeperWithActorAddrs(t testing.TB) (
	tokenomicsKeeper tokenomicskeeper.Keeper,
	ctx context.Context,
	appAddr string,
	supplierOperatorAddr string,
	service *sharedtypes.Service,
)

TODO_TECHDEBT: Remove this and force everyone to use NewTokenomicsModuleKeepers. There is a difference in the method signatures and mocking, which was simply a result of the evolution of the testutil package. TODO_REFACTOR(@Olshansk): Rather than making `service`, `appAddr` and `supplierOperatorAddr` explicit params, make them passable by the caller as options.

func WithDefaultModuleBalances added in v0.0.11

func WithDefaultModuleBalances() func(cfg *tokenomicsModuleKeepersConfig)

WithDefaultModuleBalances mints an arbitrary amount of uPOKT to the respective modules.

func WithModuleAccountBalances added in v0.0.11

func WithModuleAccountBalances(moduleAccountBalances map[string]int64) func(cfg *tokenomicsModuleKeepersConfig)

WithModuleAccountBalances mints the given amount of uPOKT to the respective modules.

Types

type ApplicationModuleKeepers added in v0.0.7

type ApplicationModuleKeepers struct {
	*keeper.Keeper
	types.SharedKeeper
}

ApplicationModuleKeepers is a struct that contains the keepers needed for testing the application module.

func NewApplicationModuleKeepers added in v0.0.7

func NewApplicationModuleKeepers(t testing.TB) (ApplicationModuleKeepers, context.Context)

NewApplicationModuleKeepers creates a new application keeper for testing along with its dependencies then returns the application module keepers and context.

type KeeperOptionFn added in v0.0.10

type KeeperOptionFn func(*keeperConfig)

KeeperOptionFn is a function type that sets/updates fields on the keeperConfig.

func WithSharedModuleParams added in v0.0.11

func WithSharedModuleParams(sharedParams *sharedtypes.Params) KeeperOptionFn

WithSharedModuleParams returns a KeeperOptionFn that sets the moduleParams field on the keeperConfig.

type ProofKeepersOpt

type ProofKeepersOpt func(context.Context, *ProofModuleKeepers) context.Context

ProofKeepersOpt is a function which receives and potentially modifies the context and proof keepers during construction of the aggregation.

func WithBlockHash

func WithBlockHash(hash []byte) ProofKeepersOpt

WithBlockHash sets the initial block hash for the context and returns the updated context.

func WithBlockHeight

func WithBlockHeight(height int64) ProofKeepersOpt

WithBlockHeight sets the initial block height for the context and returns the updated context.

type ProofModuleKeepers

ProofModuleKeepers is an aggregation of the proof keeper and all its dependency keepers, and the codec that they share. Each keeper is embedded such that the ProofModuleKeepers implements all the interfaces of the keepers. To call a method which is common to multiple keepers (e.g. `#SetParams()`), the field corresponding to the desired keeper on which to call the method MUST be specified (e.g. `keepers.AccountKeeper#SetParams()`).

func NewProofModuleKeepers

func NewProofModuleKeepers(t testing.TB, opts ...ProofKeepersOpt) (_ *ProofModuleKeepers, ctx context.Context)

NewProofModuleKeepers is a helper function to create a proof keeper and a context. It uses real dependencies for all keepers except the bank keeper, which is mocked as it's not used directly by the proof keeper or its dependencies.

func (*ProofModuleKeepers) AddServiceActors

func (keepers *ProofModuleKeepers) AddServiceActors(
	ctx context.Context,
	t *testing.T,
	service *sharedtypes.Service,
	supplierOperatorAddr string,
	appAddr string,
)

AddServiceActors adds a supplier and an application for a specific service so a successful session can be generated for testing purposes.

func (*ProofModuleKeepers) GetSessionHeader

func (keepers *ProofModuleKeepers) GetSessionHeader(
	ctx context.Context,
	t *testing.T,
	appAddr string,
	service *sharedtypes.Service,
	blockHeight int64,
) *sessiontypes.SessionHeader

GetSessionHeader is a helper to retrieve the session header for a specific (app, service, height).

type SupplierModuleKeepers added in v0.0.6

type SupplierModuleKeepers struct {
	*keeper.Keeper
	types.SharedKeeper
	// Tracks the amount of funds returned to the supplier owner when the supplier is unbonded.
	SupplierBalanceMap map[string]int64
}

SupplierModuleKeepers is a struct that contains the keepers needed for testing the supplier module.

type TokenomicsModuleKeepers

TokenomicsModuleKeepers is an aggregation of the tokenomics keeper, all its dependency keepers, and the codec that they share. Each keeper is embedded such that the TokenomicsModuleKeepers implements all the interfaces of the keepers. To call a method which is common to multiple keepers (e.g. `#SetParams()`), the field corresponding to the desired keeper on which to call the method MUST be specified (e.g. `keepers.AccountKeeper#SetParams()`).

func NewTokenomicsModuleKeepers

func NewTokenomicsModuleKeepers(
	t testing.TB,
	logger log.Logger,
	opts ...TokenomicsModuleKeepersOptFn,
) (_ TokenomicsModuleKeepers, ctx context.Context)

NewTokenomicsModuleKeepers is a helper function to create a tokenomics keeper and a context. It uses real dependencies for all upstream keepers.

type TokenomicsModuleKeepersOptFn added in v0.0.11

type TokenomicsModuleKeepersOptFn func(cfg *tokenomicsModuleKeepersConfig)

TokenomicsModuleKeepersOptFn is a function which receives and potentially modifies the context and tokenomics keepers during construction of the aggregation.

func WithApplication added in v0.0.10

func WithApplication(applicaion apptypes.Application) TokenomicsModuleKeepersOptFn

WithApplication is an option to set the application in the tokenomics module keepers.

func WithModuleParams added in v0.0.10

func WithModuleParams(moduleParams map[string]cosmostypes.Msg) TokenomicsModuleKeepersOptFn

WithModuleParams returns a KeeperOptionFn that sets the moduleParams field on the keeperConfig.

func WithProofRequirement added in v0.0.10

func WithProofRequirement(proofRequired bool) TokenomicsModuleKeepersOptFn

WithProofRequirement is an option to enable or disable the proof requirement in the tokenomics module keepers by setting the proof request probability to 1 or 0, respectively whie setting the proof requirement threshold to 0 or MaxInt64, respectively.

func WithProposerAddr added in v0.0.8

func WithProposerAddr(addr string) TokenomicsModuleKeepersOptFn

WithProposerAddr is an option to set the proposer address in the context used by the tokenomics module keepers.

func WithService added in v0.0.6

WithService is an option to set the service in the tokenomics module keepers.

func WithSupplier added in v0.0.10

func WithSupplier(supplier sharedtypes.Supplier) TokenomicsModuleKeepersOptFn

WithSupplier is an option to set the supplier in the tokenomics module keepers.

func WithTokenLogicModules added in v0.0.11

func WithTokenLogicModules(processors []tlm.TokenLogicModule) TokenomicsModuleKeepersOptFn

WithTokenLogicModules returns a TokenomicsModuleKeepersOptFn that sets the given TLM processors on the tokenomicsModuleKeepersConfig.

Jump to

Keyboard shortcuts

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