icsim

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Failure = 0
	Success = 1
)

Variables

This section is empty.

Functions

func CheckDoubleSignReportedEvent added in v1.4.0

func CheckDoubleSignReportedEvent(
	event *txresult.TestEventLog, signer module.Address, dsBlockHeight int64, dsType string) bool

func CheckElectablePRep added in v1.4.0

func CheckElectablePRep(prep *icstate.PRep, expGrade icstate.Grade) bool

func CheckICXBurnedV2Event added in v1.4.0

func CheckICXBurnedV2Event(
	event *txresult.TestEventLog, from module.Address, amount, totalSupply *big.Int) bool

func CheckPRepCountConfigSetEvent added in v1.4.0

func CheckPRepCountConfigSetEvent(event *txresult.TestEventLog, main, sub, extra int64) bool

func CheckPenalizedPRep added in v1.4.0

func CheckPenalizedPRep(prep *icstate.PRep) bool

func CheckPenaltyImposedEvent added in v1.4.0

func CheckPenaltyImposedEvent(
	event *txresult.TestEventLog, owner module.Address, status icstate.Status, pt icmodule.PenaltyType) bool

func CheckReceiptSuccess added in v1.4.0

func CheckReceiptSuccess(receipts ...Receipt) bool

func CheckSlashedEvent added in v1.4.0

func CheckSlashedEvent(
	event *txresult.TestEventLog, owner, bonder module.Address, slashed *big.Int) bool

func CheckSlashingRateSetEvent added in v1.4.0

func CheckSlashingRateSetEvent(
	event *txresult.TestEventLog, pt icmodule.PenaltyType, rate icmodule.Rate) bool

func CheckUnjailingPRep added in v1.4.0

func CheckUnjailingPRep(prep *icstate.PRep) bool

func NewCallContext

func NewCallContext(wc WorldContext, from module.Address) *callContext

func NewConsensusInfo added in v1.4.0

func NewConsensusInfo(dbase db.Database, vl []module.Validator, voted []bool) module.ConsensusInfo

func NewConsensusInfoBySim added in v1.4.0

func NewConsensusInfoBySim(sim Simulator, nilVoteIndices ...int) module.ConsensusInfo

func ValidatorIndexOf added in v1.4.0

func ValidatorIndexOf(vl []module.Validator, address module.Address) int

Types

type Block

type Block interface {
	Txs() []Transaction
	AddTransaction(tx Transaction)
}

func NewBlock

func NewBlock() Block

type Env

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

func NewEnv

func NewEnv(c *SimConfig, revision module.Revision) (*Env, error)

NewEnv initializes environment for extension simulation test Default configuration: 100 preps with 2000 ICX 100 bonders with 10000 ICX 100 users with 10000 ICX

func (*Env) Governance added in v1.4.0

func (env *Env) Governance() module.Address

func (*Env) RegisterPReps

func (env *Env) RegisterPReps() ([]Receipt, error)

RegisterPReps register all preps in Env

func (*Env) SetBonderLists

func (env *Env) SetBonderLists() ([]Receipt, error)

func (*Env) SetBonds

func (env *Env) SetBonds(amount *big.Int) ([]Receipt, error)

SetBonds makes all env.bonders[i] bond a given amount to env.preps[i]

func (*Env) SetDelegations

func (env *Env) SetDelegations(addrs []module.Address, amount *big.Int) ([]Receipt, error)

func (*Env) SetDelegationsAll

func (env *Env) SetDelegationsAll() error

func (*Env) SetRevision added in v1.4.0

func (env *Env) SetRevision(revision module.Revision) ([]Receipt, error)

func (*Env) SetStakes

func (env *Env) SetStakes(addrs []module.Address, amount *big.Int) ([]Receipt, error)

func (*Env) SetStakesAll

func (env *Env) SetStakesAll(amount *big.Int) ([]Receipt, error)

SetStakesAll stakes a given amount of ICX for bonders and users

func (*Env) Simulator added in v1.4.0

func (env *Env) Simulator() Simulator

type Event added in v1.4.0

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

func NewEvent added in v1.4.0

func NewEvent(from module.Address, indexed, data [][]byte) *Event

func (*Event) Data added in v1.4.0

func (e *Event) Data() [][]byte

func (*Event) From added in v1.4.0

func (e *Event) From() module.Address

func (*Event) Indexed added in v1.4.0

func (e *Event) Indexed() [][]byte

func (*Event) Signature added in v1.4.0

func (e *Event) Signature() string

type Receipt

type Receipt interface {
	BlockHeight() int64
	Status() int
	Error() error
	Events() []*txresult.TestEventLog
}

func NewReceipt

func NewReceipt(blockHeight int64, err error, events []*txresult.TestEventLog) Receipt

type RewardFund

type RewardFund struct {
	Iglobal int64
	Iprep   int64
	Icps    int64
	Irelay  int64
	Ivoter  int64
}

type SimConfig added in v1.4.0

type SimConfig struct {
	TermPeriod                           int64
	MainPRepCount                        int64
	SubPRepCount                         int64
	ExtraMainPRepCount                   int64
	Irep                                 int64
	Rrep                                 int64
	UnbondingPeriodMultiplier            int64
	UnstakeSlotMax                       int64
	LockMinMultiplier                    int64
	LockMaxMultiplier                    int64
	UnbondingMax                         int64
	ValidationPenaltyCondition           int64
	DelegationSlotMax                    int64
	ConsistentValidationPenaltyCondition int64
	ConsistentValidationPenaltyMask      int64
	ConsistentValidationPenaltySlashRate icmodule.Rate
	NonVotePenaltySlashRate              icmodule.Rate
	BondRequirement                      icmodule.Rate
	RewardFund
}

func NewSimConfig added in v1.4.0

func NewSimConfig() *SimConfig

func NewSimConfigWithParams added in v1.4.0

func NewSimConfigWithParams(params map[SimConfigOption]interface{}) *SimConfig

func (*SimConfig) TotalMainPRepCount added in v1.4.0

func (cfg *SimConfig) TotalMainPRepCount() int64

type SimConfigOption added in v1.4.0

type SimConfigOption int
const (
	SCOBondRequirement SimConfigOption = iota
	SCOTermPeriod
	SCOValidationFailurePenaltyCondition
	SCOAccumulatedValidationFailurePenaltyCondition
	SCOAccumulatedValidationFailurePenaltySlashingRate
	SCOMissedNetworkProposalVotePenaltySlashingRate
	SCOMainPReps
	SCOSubPReps
	SCOExtraMainPReps
)

type Simulator

type Simulator interface {
	Database() db.Database
	BlockHeight() int64
	Revision() module.Revision
	GetBalance(from module.Address) *big.Int
	TotalBond() *big.Int
	TotalStake() *big.Int
	TotalSupply() *big.Int
	ValidatorList() []module.Validator
	ValidatorIndexOf(address module.Address) int
	GetStateContext() icmodule.StateContext
	TermSnapshot() *icstate.TermSnapshot
	PRepCountConfig() icstate.PRepCountConfig
	GetPReps(grade icstate.Grade) []*icstate.PRep
	GetAccountSnapshot(address module.Address) *icstate.AccountSnapshot

	GetPRepTermInJSON() map[string]interface{}
	GetMainPRepsInJSON() map[string]interface{}
	GetSubPRepsInJSON() map[string]interface{}
	GetPRepsInJSON() map[string]interface{}
	GetNetworkInfoInJSON() map[string]interface{}
	GetPRepStatsInJSON(address module.Address) map[string]interface{}

	Go(csi module.ConsensusInfo, blocks int64) error
	GoTo(csi module.ConsensusInfo, blockHeight int64) error
	GoToTermEnd(csi module.ConsensusInfo) error
	GoByBlock(csi module.ConsensusInfo, block Block) ([]Receipt, error)
	GoByTransaction(csi module.ConsensusInfo, txs ...Transaction) ([]Receipt, error)

	Transfer(from, to module.Address, amount *big.Int) Transaction
	GoByTransfer(csi module.ConsensusInfo, from, to module.Address, amount *big.Int) ([]Receipt, error)

	SetRevision(from module.Address, revision module.Revision) Transaction
	GoBySetRevision(csi module.ConsensusInfo, from module.Address, revision module.Revision) ([]Receipt, error)

	GetStakeInJSON(from module.Address) map[string]interface{}
	SetStake(from module.Address, amount *big.Int) Transaction
	GoBySetStake(csi module.ConsensusInfo, from module.Address, amount *big.Int) ([]Receipt, error)

	QueryIScore(address module.Address) *big.Int
	ClaimIScore(from module.Address) Transaction
	GoByClaimIScore(csi module.ConsensusInfo, from module.Address) ([]Receipt, error)

	GetPRepByOwner(owner module.Address) *icstate.PRep
	GetPRepByNode(node module.Address) *icstate.PRep
	SetPRep(from module.Address, info *icstate.PRepInfo) Transaction
	GoBySetPRep(csi module.ConsensusInfo, from module.Address, info *icstate.PRepInfo) ([]Receipt, error)

	GetDelegationInJSON(address module.Address) map[string]interface{}
	SetDelegation(from module.Address, ds icstate.Delegations) Transaction
	GoBySetDelegation(csi module.ConsensusInfo, from module.Address, ds *icstate.Delegations) ([]Receipt, error)

	GetBondInJSON(address module.Address) map[string]interface{}
	SetBond(from module.Address, bonds icstate.Bonds) Transaction
	GoBySetBond(csi module.ConsensusInfo, from module.Address, bonds icstate.Bonds) ([]Receipt, error)

	GetBonderListInJSON(address module.Address) map[string]interface{}
	GetBonderList(address module.Address) icstate.BonderList
	SetBonderList(from module.Address, bl icstate.BonderList) Transaction
	GoBySetBonderList(csi module.ConsensusInfo, from module.Address, bl icstate.BonderList) ([]Receipt, error)

	RegisterPRep(from module.Address, info *icstate.PRepInfo) Transaction
	GoByRegisterPRep(csi module.ConsensusInfo, from module.Address, info *icstate.PRepInfo) ([]Receipt, error)
	UnregisterPRep(from module.Address) Transaction
	GoByUnregisterPRep(csi module.ConsensusInfo, from module.Address) ([]Receipt, error)
	DisqualifyPRep(from, address module.Address) Transaction
	GoByDisqualifyPRep(csi module.ConsensusInfo, from, address module.Address) ([]Receipt, error)

	// After RevisionIISS4R0
	GetSlashingRate(pt icmodule.PenaltyType) (icmodule.Rate, error)
	GetSlashingRates() (map[string]interface{}, error)
	SetSlashingRates(from module.Address, rates map[string]icmodule.Rate) Transaction
	GoBySetSlashingRates(csi module.ConsensusInfo, from module.Address, rates map[string]icmodule.Rate) ([]Receipt, error)

	GetMinimumBond() *big.Int
	SetMinimumBond(from module.Address, bond *big.Int) Transaction
	GoBySetMinimumBond(csi module.ConsensusInfo, from module.Address, bond *big.Int) ([]Receipt, error)

	InitCommissionRate(from module.Address, rate, maxRate, maxChangeRate icmodule.Rate) Transaction
	GoByInitCommissionRate(csi module.ConsensusInfo, from module.Address, rate, maxRate, maxChangeRate icmodule.Rate) ([]Receipt, error)
	SetCommissionRate(from module.Address, rate icmodule.Rate) Transaction
	GoBySetCommissionRate(csi module.ConsensusInfo, from module.Address, rate icmodule.Rate) ([]Receipt, error)

	HandleDoubleSignReport(from module.Address, dsType string, dsBlockHeight int64, signer module.Address) Transaction
	GoByHandleDoubleSignReport(csi module.ConsensusInfo,
		from module.Address, dsType string, dsBlockHeight int64, signer module.Address) ([]Receipt, error)
	RequestUnjail(from module.Address) Transaction
	GoByRequestUnjail(csi module.ConsensusInfo, from module.Address) ([]Receipt, error)

	GetPRepCountConfig() (map[string]interface{}, error)
	SetPRepCountConfig(from module.Address, counts map[string]int64) Transaction
	GoBySetPRepCountConfig(csi module.ConsensusInfo, from module.Address, counts map[string]int64) ([]Receipt, error)

	GetRewardFundAllocation2() *icstate.RewardFund
	SetRewardFundAllocation2(from module.Address, values map[icstate.RFundKey]icmodule.Rate) Transaction
	GoBySetRewardFundAllocation2(
		csi module.ConsensusInfo, from module.Address, values map[icstate.RFundKey]icmodule.Rate) ([]Receipt, error)
}

func NewSimulator

func NewSimulator(
	revision module.Revision, initValidators []module.Validator, initBalances map[string]*big.Int, config *SimConfig,
) (Simulator, error)

type Transaction

type Transaction interface {
	Type() TxType
	From() module.Address
	Args() []interface{}
}

func NewTransaction

func NewTransaction(txType TxType, from module.Address, args ...interface{}) Transaction

type TxType

type TxType int
const (
	TypeTransfer TxType = iota
	TypeSetStake
	TypeSetDelegation
	TypeSetBond
	TypeSetBonderList
	TypeRegisterPRep
	TypeUnregisterPRep
	TypeDisqualifyPRep
	TypeSetPRep
	TypeSetRevision
	TypeClaimIScore
	TypeSetSlashingRates
	TypeSetMinimumBond
	TypeInitCommissionRate
	TypeSetCommissionRate
	TypeRequestUnjail
	TypeHandleDoubleSignReport
	TypeSetPRepCountConfig
	TypeSetRewardFundAllocation2
)

type WorldContext

type WorldContext interface {
	icmodule.WorldContext
	GetExtensionState() state.ExtensionState
	BlockTimeStamp() int64
	Database() db.Database
	GetAccountState(id []byte) state.AccountState
	GetSnapshot() state.WorldSnapshot
	Reset(snapshot state.WorldSnapshot) error
}

func NewWorldContext

func NewWorldContext(
	ws state.WorldState, blockHeight int64, revision module.Revision,
	csi module.ConsensusInfo, stepPrice *big.Int,
) WorldContext

Jump to

Keyboard shortcuts

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