testmigration

package
v0.1.34 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MorseUnstakedActor = MorseAccountActorType(iota)
	MorseApplicationActor
	MorseSupplierActor

	// NumMorseAccountActorTypes is the number of MorseAccountActorTypes.
	// It takes advantage of the fact that the enum is zero-indexed.
	NumMorseAccountActorTypes
)
View Source
const (
	// MorseEOA represents a standard externally owned account (EOA)
	MorseEOA = MorseUnstakedActorType(iota)
	// MorseInvalidTooShort represents an account with an address that is too short to be valid
	MorseInvalidTooShort
	// MorseInvalidTooLong represents an account with an address that is too long to be valid
	MorseInvalidTooLong
	// MorseNonHex represents an account with an address that contains non-hexadecimal characters
	MorseNonHex
	// MorseModule represents a module account
	MorseModule
	// MorseNonCustodialOwnerAccount represents a non-custodial validator's owner account
	MorseNonCustodialOwnerAccount
)
View Source
const (
	// MorseValidator represents a standard validator with both staked and unstaked accounts
	MorseValidator = MorseValidatorActorType(iota)
	// MorseOrphanedValidator represents a validator without a corresponding unstaked account
	MorseOrphanedValidator
	// MorseUnbondingValidator represents a validator that has begun unbonding on Morse
	MorseUnbondingValidator
	// MorseUnbondedValidator represents a validator that has unbonded on Morse while waiting to be claimed
	MorseUnbondedValidator
	// MorseNonCustodialValidator represents a non-custodial validator with a separate owner account
	MorseNonCustodialValidator
)
View Source
const (
	// MorseApplication represents a standard application with both staked and unstaked accounts
	MorseApplication = MorseApplicationActorType(iota)
	// MorseOrphanedApplication represents an application without a corresponding unstaked account
	MorseOrphanedApplication
	// MorseUnbondingApplication represents an application that has begun unbonding on Morse
	MorseUnbondingApplication
	// MorseUnbondedApplication represents an application that has unbonded on Morse while waiting to be claimed
	MorseUnbondedApplication
)

Variables

View Source
var BcryptSecurityParameter = 12

BcryptSecurityParameter is a var so that it can be changed within the lcd test Making the bcrypt security parameter a var shouldn't be a security issue: One can't verify an invalid key by maliciously changing the bcrypt parameter during a runtime vulnerability. The main security threat this then exposes would be something that changes this during runtime before the user creates their key. This vulnerability must succeed to update this to that same value before every subsequent call to the keys command in future startups / or the attacker must get access to the filesystem. However, with a similar threat model (changing variables in runtime), one can cause the user to sign a different tx than what they see, which is a significantly cheaper attack then breaking a bcrypt hash. (Recall that the nonce still exists to break rainbow tables) For further notes on security parameter choice, see README.md

Functions

func EncryptAESGCM added in v0.1.2

func EncryptAESGCM(key []byte, src []byte) ([]byte, error)

func EncryptArmorPrivKey added in v0.1.2

func EncryptArmorPrivKey(privKey ed25519.PrivKey, passphrase string, hint string) (string, error)

EncryptArmorPrivKey encrypts the given private key using a random salt and the given passphrase with the AES-256-GCM algorithm. It then encapsulates the ciphertext, salt, and hint in an ArmoredJson struct and returns it as a JSON-encoded string.

func GenMorseAccount added in v0.0.14

func GenMorseAccount(index uint64) *migrationtypes.MorseAccount

GenMorseAccount returns a new MorseAccount fixture. The given index is used to deterministically generate the account's address and unstaked balance.

func GenMorseApplication added in v0.0.14

func GenMorseApplication(idx uint64) *migrationtypes.MorseApplication

GenMorseApplication returns a new MorseApplication fixture. The given index is used to deterministically generate the application's address and staked tokens.

func GenMorseApplicationStakeAmount added in v0.0.14

func GenMorseApplicationStakeAmount(index uint64) int64

GenMorseApplicationStakeAmount returns an amount by applying the given index to a pattern such that the generated amount is unique to the application stake (as opposed to the unstaked balance or supplier stake) and the given index. E.g.: - GenMorseApplicationStakeAmount(0) = 100010 - GenMorseApplicationStakeAmount(1) = 200020 - GenMorseApplicationStakeAmount(10) = 1000100

func GenMorseClaimableAccount added in v0.0.14

func GenMorseClaimableAccount(
	index uint64,
	distributionFn func(uint64) MorseAccountActorType,
) (*migrationtypes.MorseClaimableAccount, error)

GenMorseClaimableAccount returns a new MorseClaimableAccount fixture. The given index is used to deterministically generate the account's address and staked tokens. The given distribution function is used to determine the account's actor type (and stake if applicable).

func GenMorsePrivateKey added in v0.0.14

func GenMorsePrivateKey(seed uint64) cometcrypto.PrivKey

GenMorsePrivateKey creates a new ed25519 private key from the given seed.

func GenMorseSupplierStakeAmount added in v0.0.14

func GenMorseSupplierStakeAmount(index uint64) int64

GenMorseSupplierStakeAmount returns an amount by applying the given index to a pattern such that the generated amount is unique to the supplier stake (as opposed to the unstaked balance or application stake) and the given index. E.g.: - GenMorseApplicationStakeAmount(0) = 10100 - GenMorseApplicationStakeAmount(1) = 20200 - GenMorseApplicationStakeAmount(10) = 101000

func GenMorseUnstakedBalanceAmount added in v0.0.14

func GenMorseUnstakedBalanceAmount(index uint64) int64

GenMorseUnstakedBalanceAmount returns an amount by applying the given index to a pattern such that the generated amount is unique to the unstaked balance (as opposed to actor stake(s)) and the given index. E.g.: - GenMorseApplicationStakeAmount(0) = 1000001 - GenMorseApplicationStakeAmount(1) = 2000002 - GenMorseApplicationStakeAmount(10) = 10000010

func GenMorseValidator added in v0.0.14

func GenMorseValidator(idx uint64) *migrationtypes.MorseValidator

GenMorseValidator returns a new MorseValidator fixture. The given index is used to deterministically generate the validator's address and staked tokens.

func GenerateInvalidAddressMorseStateExportAndAccountState added in v0.1.11

func GenerateInvalidAddressMorseStateExportAndAccountState(t *testing.T) (*migrationtypes.MorseStateExport, *migrationtypes.MorseAccountState)

GenerateInvalidAddressMorseStateExportAndAccountState generates a MorseStateExport and MorseAccountState with invalid addresses for the following cases, and for each actor type (i.e. unstaked, app, suppler): - invalid hex - too short - too long

func GenerateModuleAddressMorseStateExportAndAccountState added in v0.1.11

func GenerateModuleAddressMorseStateExportAndAccountState(t *testing.T, moduleAccountNames []string) (*migrationtypes.MorseStateExport, *migrationtypes.MorseAccountState)

GenerateModuleAddressMorseStateExportAndAccountState generates a MorseStateExport and MorseAccountState with the following module addresses, and ONLY as a liquid account: - dao - fee_collector - application_stake_tokens_pool - staked_tokens_pool

func NewArmoredJson added in v0.1.2

func NewArmoredJson(kdf, salt, hint, ciphertext string) cmd.ArmoredJson

NewArmoredJson returns a new ArmoredJson struct with the given fields.

func NewMorseStateExportAndAccountState

func NewMorseStateExportAndAccountState(
	numAccounts int,
	distributionFn MorseAccountActorTypeDistributionFn,
) (export *migrationtypes.MorseStateExport, state *migrationtypes.MorseAccountState, err error)

NewMorseStateExportAndAccountState returns MorseStateExport and MorseAccountState structs populated with: - Random account addresses - Monotonically increasing balances/stakes - Unstaked, application, supplier accounts are distributed according to the given distribution function.

func NewMorseStateExportAndAccountStateBytes

func NewMorseStateExportAndAccountStateBytes(
	numAccounts int,
	distributionFn MorseAccountActorTypeDistributionFn,
) (morseStateExportBz []byte, morseAccountStateBz []byte, err error)

TODO_TECHDEBT: Remove once all tests use the new fixture generation. NewMorseStateExportAndAccountStateBytes returns:

  • A serialized MorseStateExport. This is the JSON output of `pocket util export-genesis-for-reset`. It is used to generate the MorseAccountState.
  • Its corresponding MorseAccountState. This is the JSON output of `pocketd tx migration collect-morse-accounts`. It is used to persist the canonical Morse migration state (snapshot) from on Shannon.

The states are populated with: - Random account addresses - Monotonically increasing balances/stakes - Unstaked, application, supplier accounts are distributed according to the given distribution function.

func NewRoundRobinClusteredAllMorseAccountActorTypes added in v0.1.11

func NewRoundRobinClusteredAllMorseAccountActorTypes(clusterSize uint64) func(index uint64) MorseAccountActorType

NewRoundRobinClusteredAllMorseAccountActorTypes returns a function which returns a MorseAccountActorType for every index, cyclically returning "clusters" of each MorseAccountActorType; i.e. continuous account types of clusterSize. E.g. if clusterSize is 2, then the resulting actor type sequence would be: - 0: MorseUnstakedActor - 1: MorseUnstakedActor - 2: MorseApplicationActor - 3: MorseApplicationActor - 4: MorseSupplierActor - 5: MorseSupplierActor

Types

type ApplicationStakesConfigFn added in v0.1.12

type ApplicationStakesConfigFn func(
	index uint64,
	actorTypeIndex uint64,
	actorType MorseApplicationActorType,
	application *migrationtypes.MorseApplication,
) (staked, unstaked *cosmostypes.Coin)

ApplicationStakesConfig is a function that returns the staked and unstaked balances for an application based on its index, actor type index, actor type, and existing application data.

type InvalidAccountsConfig added in v0.1.12

type InvalidAccountsConfig struct {
	NumAddressTooShort uint64 // Number of accounts with addresses that are too short
	NumAddressTooLong  uint64 // Number of accounts with addresses that are too long
	NumNonHexAddress   uint64 // Number of accounts with addresses containing non-hexadecimal characters
}

InvalidAccountsConfig defines the number of invalid accounts to generate with different types of address invalidity.

type ModuleAccountNameConfigFn added in v0.1.12

type ModuleAccountNameConfigFn func(index uint64, actorTypeIndex uint64) string

ModuleAccountNameConfigFn is a function that returns a module account name based on the global index and actor type index.

type MorseAccountActorType added in v0.0.14

type MorseAccountActorType int

MorseAccountActorType is an enum which represents all possible staked and unstaked actor types which are considered in the migration module.

func AllApplicationMorseAccountActorType added in v0.0.14

func AllApplicationMorseAccountActorType(index uint64) MorseAccountActorType

AllApplicationMorseAccountActorType returns MorseApplicationActor for every index.

func AllSupplierMorseAccountActorType added in v0.0.14

func AllSupplierMorseAccountActorType(index uint64) MorseAccountActorType

AllSupplierMorseAccountActorType returns MorseSupplierActor for every index.

func AllUnstakedMorseAccountActorType added in v0.0.14

func AllUnstakedMorseAccountActorType(index uint64) MorseAccountActorType

AllUnstakedMorseAccountActorType returns MorseUnstakedActor for every index.

func GetRoundRobinMorseAccountActorType added in v0.1.2

func GetRoundRobinMorseAccountActorType(idx uint64) MorseAccountActorType

GetRoundRobinMorseAccountActorType returns the actor type for the given index, given a round-robin distribution.

func RoundRobinAllMorseAccountActorTypes added in v0.0.14

func RoundRobinAllMorseAccountActorTypes(index uint64) MorseAccountActorType

RoundRobinAllMorseAccountActorTypes cyclically returns each MorseAccountActorType, one after the other, as the index increases. It is used to map a test account index to the test actor that's generated.

type MorseAccountActorTypeDistributionFn added in v0.0.14

type MorseAccountActorTypeDistributionFn func(index uint64) MorseAccountActorType

MorseAccountActorTypeDistributionFn is a function which returns a MorseAccountActorType derived from the given index. It is intended to be used in conjunction with MorseStateExport and MorseAccountState fixture generation logic.

func NewSingleMorseAccountActorTypeFn added in v0.0.14

func NewSingleMorseAccountActorTypeFn(actorType MorseAccountActorType) MorseAccountActorTypeDistributionFn

NewSingleMorseAccountActorTypeFn returns a MorseAccountActorTypeDistributionFn which returns the given actor type for every index.

type MorseApplicationActorType added in v0.1.12

type MorseApplicationActorType int

MorseApplicationActorType represents different types of application actors in Morse that can be included in test fixtures.

type MorseFixturesConfig added in v0.1.12

type MorseFixturesConfig struct {
	ValidAccountsConfig             // Configuration for valid accounts (EOAs, applications, validators)
	InvalidAccountsConfig           // Configuration for accounts with invalid addresses
	OrphanedActorsConfig            // Configuration for orphaned validators and applications
	UnbondingActorsConfig           // Configuration for unbonding validators and applications
	UnstakedAccountBalancesConfigFn // Configuration for unstaked account balances
	ValidatorStakesConfigFn         // Configuration for validator stake amounts
	ApplicationStakesConfigFn       // Configuration for application stake amounts
	ModuleAccountNameConfigFn       // Configuration for module account names
	UnstakingTimeConfig             // Configuration for unstaking times for actors which began unbonding on Morse
}

MorseFixturesConfig defines the configuration parameters for generating Morse migration test fixtures. It combines multiple sub-configurations to control the generation of different types of accounts, their balances, stakes, and other properties.

func (*MorseFixturesConfig) GetTotalAccounts added in v0.1.12

func (cfg *MorseFixturesConfig) GetTotalAccounts() uint64

GetTotalAccounts calculates the total number of accounts based on the configuration.

type MorseFixturesOptionFn added in v0.1.12

type MorseFixturesOptionFn func(config *MorseFixturesConfig)

MorseFixturesOptionFn defines a function that configures a MorseFixturesConfig. This follows the functional options pattern for configuring structs.

func WithApplicationStakesFn added in v0.1.12

func WithApplicationStakesFn(stakeFn ApplicationStakesConfigFn) MorseFixturesOptionFn

WithApplicationStakesFn sets the ApplicationStakesConfig for the fixtures. It defines how staked and unstaked balances are determined for application accounts.

func WithInvalidAccounts added in v0.1.12

func WithInvalidAccounts(cfg InvalidAccountsConfig) MorseFixturesOptionFn

WithInvalidAccounts sets the InvalidAccountsConfig for the fixtures. It determines how many invalid accounts of each type are generated.

func WithModuleAccountNameFn added in v0.1.12

func WithModuleAccountNameFn(nameFn ModuleAccountNameConfigFn) MorseFixturesOptionFn

WithModuleAccountNameFn sets the ModuleAccountNameConfig for the fixtures. It determines how module account names are generated during fixture creation.

func WithOrphanedActors added in v0.1.12

func WithOrphanedActors(cfg OrphanedActorsConfig) MorseFixturesOptionFn

WithOrphanedActors sets the OrphanedActorsConfig for the fixtures. It determines how many orphaned applications and validators are generated.

func WithUnbondingActors added in v0.1.13

func WithUnbondingActors(cfg UnbondingActorsConfig) MorseFixturesOptionFn

WithUnbondingActors sets the UnbondingActorsConfig for the fixtures.

func WithUnstakedAccountBalancesFn added in v0.1.12

func WithUnstakedAccountBalancesFn(balanceFn UnstakedAccountBalancesConfigFn) MorseFixturesOptionFn

WithUnstakedAccountBalancesFn sets the UnstakedAccountBalancesConfig for the fixtures. It defines how balances are determined for unstaked accounts.

func WithUnstakingTime added in v0.1.13

func WithUnstakingTime(cfg UnstakingTimeConfig) MorseFixturesOptionFn

WithUnstakingTime sets the UnstakingTimeConfig for the fixtures.

func WithValidAccounts added in v0.1.12

func WithValidAccounts(cfg ValidAccountsConfig) MorseFixturesOptionFn

WithValidAccounts sets the ValidAccountsConfig for the fixtures. It determines how many valid accounts of each type are generated.

func WithValidatorStakesFn added in v0.1.12

func WithValidatorStakesFn(stakeFn ValidatorStakesConfigFn) MorseFixturesOptionFn

WithValidatorStakesFn sets the ValidatorStakesConfig for the fixtures. It defines how staked and unstaked balances are determined for validator accounts.

type MorseMigrationFixtures added in v0.1.12

type MorseMigrationFixtures struct {
	// contains filtered or unexported fields
}

MorseMigrationFixtures contains the state and configuration for generating Morse migration test fixtures. It maintains internal state for tracking and indexing Morse accounts, keys, and migration state.

func NewMorseFixtures added in v0.1.12

func NewMorseFixtures(opts ...MorseFixturesOptionFn) (*MorseMigrationFixtures, error)

NewMorseFixtures creates a new MorseMigrationFixtures instance with the provided options. It initializes the necessary data structures and generates test fixtures according to the configuration provided through the options.

func (*MorseMigrationFixtures) GetApplicationFixtures added in v0.1.12

func (mf *MorseMigrationFixtures) GetApplicationFixtures(
	actorType MorseApplicationActorType,
) []*actorFixture[*migrationtypes.MorseApplication]

GetApplicationFixtures returns all application fixtures of the specified actor type. This method allows test code to access application fixtures (such as standard applications with unstaked accounts or orphaned applications) for test assertions and scenario setup.

func (*MorseMigrationFixtures) GetConfig added in v0.1.12

GetConfig returns the configuration used for generating the fixtures.

func (*MorseMigrationFixtures) GetMorseAccountState added in v0.1.12

func (mf *MorseMigrationFixtures) GetMorseAccountState() *migrationtypes.MorseAccountState

GetMorseAccountState returns the generated Morse account state for migration testing.

func (*MorseMigrationFixtures) GetMorseStateExport added in v0.1.12

func (mf *MorseMigrationFixtures) GetMorseStateExport() *migrationtypes.MorseStateExport

GetMorseStateExport returns the generated Morse state export for migration testing.

func (*MorseMigrationFixtures) GetUnstakedActorFixtures added in v0.1.12

func (mf *MorseMigrationFixtures) GetUnstakedActorFixtures(
	actorType MorseUnstakedActorType,
) []*actorFixture[*migrationtypes.MorseAccount]

GetUnstakedActorFixtures returns all unstaked actor fixtures of the specified account type. This method allows test code to access unstaked account fixtures (such as EOAs, module accounts, and accounts with invalid addresses) for test assertions and scenario setup.

func (*MorseMigrationFixtures) GetValidatorFixtures added in v0.1.12

func (mf *MorseMigrationFixtures) GetValidatorFixtures(
	actorType MorseValidatorActorType,
) []*actorFixture[*migrationtypes.MorseValidator]

GetValidatorFixtures returns all validator fixtures of the specified actor type. This method allows test code to access validator fixtures (such as standard validators with unstaked accounts or orphaned validators) for test assertions and scenario setup.

type MorseUnstakedActorType added in v0.1.12

type MorseUnstakedActorType int

MorseUnstakedActorType represents different types of unstaked Morse accounts that can be included in test fixtures.

type MorseValidatorActorType added in v0.1.12

type MorseValidatorActorType int

MorseValidatorActorType represents different types of validator actors in Morse that can be included in test fixtures.

type OrphanedActorsConfig added in v0.1.12

type OrphanedActorsConfig struct {
	NumApplicationsOrphaned uint64 // Number of orphaned application accounts
	NumValidatorsOrphaned   uint64 // Number of orphaned validator accounts
}

OrphanedActorsConfig defines the number of orphaned staked actors to generate. Orphaned actors have a staked position but no corresponding unstaked account.

type UnbondingActorsConfig added in v0.1.13

type UnbondingActorsConfig struct {
	NumApplicationsUnbondingBegan uint64 // Number of applications to generate as having begun unbonding on Morse
	NumApplicationsUnbondingEnded uint64 // Number of applications to generate as having unbonded on Morse while waiting to be claimed
	NumValidatorsUnbondingBegan   uint64 // Number of validators to generate as having begun unbonding on Morse
	NumValidatorsUnbondingEnded   uint64 // Number of validators to generate as unbonded on Morse while waiting to be claimed
}

UnbondingActorsConfig defines the number of unbonding and unbonded validators and applications to generate. DEV_NOTE: The accounts/actors are generated in the order they are defined in this struct.

type UnstakedAccountBalancesConfigFn added in v0.1.12

type UnstakedAccountBalancesConfigFn func(
	index uint64,
	actorTypeIndex uint64,
	actorType MorseUnstakedActorType,
	morseAccount *migrationtypes.MorseAccount,
) *cosmostypes.Coin

UnstakedAccountBalancesConfigFn is a function that returns the balance for an unstaked account based on its index, actor type index, actor type, and existing account data.

type UnstakingTimeConfig added in v0.1.13

type UnstakingTimeConfig struct {
	ApplicationUnstakingTimeFn UnstakingTimeConfigFn[MorseApplicationActorType, *migrationtypes.MorseApplication]
	ValidatorUnstakingTimeFn   UnstakingTimeConfigFn[MorseValidatorActorType, *migrationtypes.MorseValidator]
}

UnstakingTimeConfig holds functions that determine the unstaking time for each actor type.

type UnstakingTimeConfigFn added in v0.1.13

type UnstakingTimeConfigFn[T, A any] func(

	index uint64,

	actorTypeIndex uint64,

	actorType T,

	actor A,
) time.Time

UnstakingTimeConfigFn defines a function that configures the unstaking time for an actor. The zero time.Time value (time.Time{}) indicates that the actor type is not unbonding/unbonded.

type ValidAccountsConfig added in v0.1.12

type ValidAccountsConfig struct {
	NumAccountsValid          uint64 // Number of regular externally owned accounts
	NumApplicationsValid      uint64 // Number of application accounts
	NumValidatorsValid        uint64 // Number of validator accounts
	NumNonCustodialValidators uint64 // Number of non-custodial validator accounts
	NumModuleAccounts         uint64 // Number of module accounts
}

ValidAccountsConfig defines the number of valid accounts to generate for each account type in the test fixtures.

type ValidatorStakesConfigFn added in v0.1.12

type ValidatorStakesConfigFn func(
	index uint64,
	actorTypeIndex uint64,
	actorType MorseValidatorActorType,
	validator *migrationtypes.MorseValidator,
) (staked, unstaked *cosmostypes.Coin)

ValidatorStakesConfigFn is a function that returns the staked and unstaked balances for a validator based on its index, actor type index, actor type, and existing validator data.

Jump to

Keyboard shortcuts

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