testsuite

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindFreePort added in v1.7.0

func FindFreePort() int

func GenerateSeed added in v0.15.0

func GenerateSeed() int64

func ProposalWithKey added in v1.7.0

func ProposalWithKey(key *bls.ValidatorKey) func(*ProposalMaker)

ProposalWithKey sets the private key of the proposer.

Types

type AccountMaker added in v1.7.0

type AccountMaker struct {
	Number  int32
	Balance amount.Amount
	Address crypto.Address
}

type AccountMakerOption added in v1.11.0

type AccountMakerOption func(*AccountMaker)

func AccountWithAddress added in v1.10.0

func AccountWithAddress(address crypto.Address) AccountMakerOption

AccountWithAddress sets the address for the generated test account.

func AccountWithBalance added in v1.7.0

func AccountWithBalance(balance amount.Amount) AccountMakerOption

AccountWithBalance sets the balance for the generated test account.

func AccountWithNumber added in v1.7.0

func AccountWithNumber(number int32) AccountMakerOption

AccountWithNumber sets the account number for the generated test account.

type BlockMaker added in v1.4.0

type BlockMaker struct {
	Version   protocol.Version
	Txs       block.Txs
	Proposer  crypto.Address
	Time      time.Time
	StateHash hash.Hash
	PrevHash  hash.Hash
	Seed      sortition.VerifiableSeed
	PrevCert  *certificate.Certificate
}

type BlockMakerOption added in v1.11.0

type BlockMakerOption func(*BlockMaker)

func BlockWithPrevCert added in v1.4.0

func BlockWithPrevCert(cert *certificate.Certificate) BlockMakerOption

BlockWithPrevCert sets previous block certificate to the block.

func BlockWithPrevHash added in v1.4.0

func BlockWithPrevHash(h hash.Hash) BlockMakerOption

BlockWithPrevHash sets previous block hash to the block.

func BlockWithProposer added in v1.4.0

func BlockWithProposer(addr crypto.Address) BlockMakerOption

BlockWithProposer sets proposer address to the block.

func BlockWithSeed added in v1.4.0

func BlockWithSeed(seed sortition.VerifiableSeed) BlockMakerOption

BlockWithSeed sets verifiable seed to the block.

func BlockWithStateHash added in v1.4.0

func BlockWithStateHash(h hash.Hash) BlockMakerOption

BlockWithStateHash sets state hash to the block.

func BlockWithTime added in v1.4.0

func BlockWithTime(t time.Time) BlockMakerOption

BlockWithTime sets block creation time to the block.

func BlockWithTransactions added in v1.4.0

func BlockWithTransactions(txs block.Txs) BlockMakerOption

BlockWithTransactions adds transactions to the block.

func BlockWithVersion added in v1.4.0

func BlockWithVersion(ver protocol.Version) BlockMakerOption

BlockWithVersion sets version to the block.

type OverrideStringer added in v0.17.0

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

func NewOverrideLogStringer added in v1.11.0

func NewOverrideLogStringer(name string, obj logger.LogStringer) *OverrideStringer

func (*OverrideStringer) LogString added in v1.11.0

func (o *OverrideStringer) LogString() string

type ProposalMaker added in v1.6.0

type ProposalMaker struct {
	ProposerKey *bls.ValidatorKey
}

type TestSuite

type TestSuite struct {
	testsuite.TestSuite
	Ctrl *gomock.Controller
}

TestSuite provides a set of helper functions for testing purposes. All the random values are generated based on a logged seed. By using a pre-generated seed, it is possible to reproduce failed tests by re-evaluating all the random values. This helps in identifying and debugging failures in testing conditions.

func NewTestSuite

func NewTestSuite(t *testing.T) *TestSuite

NewTestSuite creates a new TestSuite by generating new seed.

func NewTestSuiteFromSeed added in v1.6.0

func NewTestSuiteFromSeed(t *testing.T, seed int64) *TestSuite

NewTestSuiteFromSeed creates a new TestSuite with the given seed.

func (*TestSuite) DecodingHex

func (*TestSuite) DecodingHex(in string) []byte

DecodingHex decodes the input string from hexadecimal format and returns the resulting byte slice.

func (*TestSuite) GenerateTestAccount

func (ts *TestSuite) GenerateTestAccount(opts ...AccountMakerOption) (*account.Account, crypto.Address)

GenerateTestAccount generates an account for testing purposes.

func (*TestSuite) GenerateTestBatchTransferTx added in v1.8.0

func (ts *TestSuite) GenerateTestBatchTransferTx(opts ...TransactionMakerOption) *tx.Tx

GenerateTestBatchTransferTx generate a batch transfer transaction for test.

func (*TestSuite) GenerateTestBlock

func (ts *TestSuite) GenerateTestBlock(height uint32, opts ...BlockMakerOption) (
	*block.Block, *certificate.Certificate,
)

GenerateTestBlock generates a block for testing purposes with optional configuration.

func (*TestSuite) GenerateTestBondTx

func (ts *TestSuite) GenerateTestBondTx(opts ...TransactionMakerOption) *tx.Tx

GenerateTestBondTx generates a bond transaction for testing purposes.

func (*TestSuite) GenerateTestCertificate

func (ts *TestSuite) GenerateTestCertificate(height uint32) *certificate.Certificate

GenerateTestCertificate generates a block certificate for testing purposes.

func (*TestSuite) GenerateTestCommittee

func (ts *TestSuite) GenerateTestCommittee(num int) (committee.Committee, []*bls.ValidatorKey)

GenerateTestCommittee generates a committee for testing purposes. All committee members have the same power.

func (*TestSuite) GenerateTestPrecommitVote

func (ts *TestSuite) GenerateTestPrecommitVote(height uint32, round int16) (*vote.Vote, *bls.ValidatorKey)

GenerateTestPrecommitVote generates a precommit vote for testing purposes.

func (*TestSuite) GenerateTestPrepareVote

func (ts *TestSuite) GenerateTestPrepareVote(height uint32, round int16) (*vote.Vote, *bls.ValidatorKey)

GenerateTestPrepareVote generates a prepare vote for testing purposes.

func (*TestSuite) GenerateTestProposal

func (ts *TestSuite) GenerateTestProposal(height uint32, round int16,
	opts ...func(*ProposalMaker),
) *proposal.Proposal

GenerateTestProposal generates a proposal for testing purposes.

func (*TestSuite) GenerateTestSortitionTx

func (ts *TestSuite) GenerateTestSortitionTx(opts ...TransactionMakerOption) *tx.Tx

GenerateTestSortitionTx generates a sortition transaction for testing purposes.

func (*TestSuite) GenerateTestSubsidyTx added in v1.10.0

func (ts *TestSuite) GenerateTestSubsidyTx(opts ...TransactionMakerOption) *tx.Tx

GenerateTestSubsidyTx creates a subsidy transaction for testing.

func (*TestSuite) GenerateTestTransferTx

func (ts *TestSuite) GenerateTestTransferTx(opts ...TransactionMakerOption) *tx.Tx

GenerateTestTransferTx generates a transfer transaction for testing purposes.

func (*TestSuite) GenerateTestUnbondTx

func (ts *TestSuite) GenerateTestUnbondTx(opts ...TransactionMakerOption) *tx.Tx

GenerateTestUnbondTx generates an unbond transaction for testing purposes.

func (*TestSuite) GenerateTestValidator

func (ts *TestSuite) GenerateTestValidator(opts ...ValidatorMakerOption) *validator.Validator

GenerateTestValidator generates a validator for testing purposes.

func (*TestSuite) GenerateTestWithdrawTx

func (ts *TestSuite) GenerateTestWithdrawTx(opts ...TransactionMakerOption) *tx.Tx

GenerateTestWithdrawTx generates a withdraw transaction for testing purposes.

func (*TestSuite) HelperSignProposal added in v0.15.0

func (*TestSuite) HelperSignProposal(valKey *bls.ValidatorKey, p *proposal.Proposal)

func (*TestSuite) HelperSignTransaction added in v0.15.0

func (*TestSuite) HelperSignTransaction(prv crypto.PrivateKey, trx *tx.Tx)

func (*TestSuite) HelperSignVote added in v0.15.0

func (*TestSuite) HelperSignVote(valKey *bls.ValidatorKey, v *vote.Vote)

func (*TestSuite) MockingController added in v1.11.0

func (ts *TestSuite) MockingController() *gomock.Controller

func (*TestSuite) NewAccountMaker added in v1.7.0

func (ts *TestSuite) NewAccountMaker() *AccountMaker

NewAccountMaker creates a new instance of AccountMaker with random values.

func (*TestSuite) NewBlockMaker added in v1.4.0

func (ts *TestSuite) NewBlockMaker() *BlockMaker

NewBlockMaker creates a new BlockMaker instance.

func (*TestSuite) NewProposalMaker added in v1.6.0

func (ts *TestSuite) NewProposalMaker() *ProposalMaker

NewProposalMaker creates a new NewProposalMaker instance.

func (*TestSuite) NewTransactionMaker added in v1.4.0

func (ts *TestSuite) NewTransactionMaker() *TransactionMaker

NewTransactionMaker creates a new TransactionMaker instance.

func (*TestSuite) NewValidatorMaker added in v1.7.0

func (ts *TestSuite) NewValidatorMaker() *ValidatorMaker

NewValidatorMaker creates a new instance of ValidatorMaker with random values.

func (*TestSuite) RandAccAddress added in v0.15.0

func (ts *TestSuite) RandAccAddress() crypto.Address

RandAccAddress generates a random account address for testing purposes.

func (*TestSuite) RandAmount added in v0.19.0

func (ts *TestSuite) RandAmount(max ...amount.Amount) amount.Amount

RandAmount returns a random amount between [1e9, max). If max is not set, it defaults to 100e9.

func (*TestSuite) RandAmountRange added in v1.2.0

func (ts *TestSuite) RandAmountRange(min, max amount.Amount) amount.Amount

RandAmountRange returns a random amount between [min, max).

func (*TestSuite) RandBLSKeyPair added in v0.15.0

func (ts *TestSuite) RandBLSKeyPair() (*bls.PublicKey, *bls.PrivateKey)

RandBLSKeyPair generates a random BLS key pair for testing purposes.

func (*TestSuite) RandBLSSignature added in v0.15.0

func (ts *TestSuite) RandBLSSignature() *bls.Signature

RandBLSSignature generates a random BLS signature for testing purposes.

func (*TestSuite) RandBytes added in v0.15.0

func (ts *TestSuite) RandBytes(length int) []byte

RandBytes returns a slice of random bytes of the given length.

func (*TestSuite) RandEd25519KeyPair added in v1.5.0

func (ts *TestSuite) RandEd25519KeyPair() (*ed25519.PublicKey, *ed25519.PrivateKey)

RandEd25519KeyPair generates a random Ed25519 key pair for testing purposes.

func (*TestSuite) RandEd25519Signature added in v1.5.0

func (ts *TestSuite) RandEd25519Signature() *ed25519.Signature

RandEd25519Signature generates a random BLS signature for testing purposes.

func (*TestSuite) RandFee added in v1.2.0

func (ts *TestSuite) RandFee(max ...amount.Amount) amount.Amount

RandFee returns a random fee between [1e7, max). If max is not set, it defaults to 1e9.

func (*TestSuite) RandHash added in v0.15.0

func (ts *TestSuite) RandHash() hash.Hash

RandHash generates a random hash for testing purposes.

func (*TestSuite) RandHeight added in v0.15.0

func (ts *TestSuite) RandHeight() uint32

RandHeight returns a random number between [1000, 1000000] for block height.

func (*TestSuite) RandKeyPair added in v1.10.0

func (ts *TestSuite) RandKeyPair() (crypto.PublicKey, crypto.PrivateKey)

func (*TestSuite) RandMultiAddress added in v1.8.0

func (ts *TestSuite) RandMultiAddress() string

RandMultiAddress returns a random MultiAddress.

func (*TestSuite) RandPeerID added in v0.15.0

func (ts *TestSuite) RandPeerID() peer.ID

RandPeerID returns a random peer ID.

func (*TestSuite) RandProof added in v0.15.0

func (ts *TestSuite) RandProof() sortition.Proof

RandProof generates a random Proof for testing purposes.

func (*TestSuite) RandRound added in v0.15.0

func (ts *TestSuite) RandRound() int16

RandRound returns a random number between [0, 10) for block round.

func (*TestSuite) RandSeed added in v0.15.0

func (ts *TestSuite) RandSeed() sortition.VerifiableSeed

RandSeed generates a random VerifiableSeed for testing purposes.

func (*TestSuite) RandSlice added in v1.2.0

func (ts *TestSuite) RandSlice(length int) []int32

RandSlice generates a random non-repeating slice of int32 elements with the specified length.

func (*TestSuite) RandString added in v0.15.0

func (ts *TestSuite) RandString(length int) string

RandString generates a random string of the given length.

func (*TestSuite) RandValAddress added in v0.15.0

func (ts *TestSuite) RandValAddress() crypto.Address

RandValAddress generates a random validator address for testing purposes.

func (*TestSuite) RandValKey added in v0.15.0

func (ts *TestSuite) RandValKey() *bls.ValidatorKey

RandValKey generates a random validator key for testing purposes.

type TransactionMaker added in v1.4.0

type TransactionMaker struct {
	LockTime   uint32
	Amount     amount.Amount
	Fee        amount.Amount
	Signer     crypto.PrivateKey
	ValPubKey  *bls.PublicKey
	Recipients []payload.BatchRecipient
	Receiver   crypto.Address
}

func (*TransactionMaker) SignerAccountAddress added in v1.5.0

func (tm *TransactionMaker) SignerAccountAddress() crypto.Address

func (*TransactionMaker) SignerValidatorAddress added in v1.5.0

func (tm *TransactionMaker) SignerValidatorAddress() crypto.Address

type TransactionMakerOption added in v1.11.0

type TransactionMakerOption func(*TransactionMaker)

func TransactionWithAmount added in v1.4.0

func TransactionWithAmount(amt amount.Amount) TransactionMakerOption

TransactionWithAmount sets amount to the transaction.

func TransactionWithFee added in v1.4.0

func TransactionWithFee(fee amount.Amount) TransactionMakerOption

TransactionWithFee sets fee to the transaction.

func TransactionWithLockTime added in v1.4.0

func TransactionWithLockTime(lockTime uint32) TransactionMakerOption

TransactionWithLockTime sets lock-time to the transaction.

func TransactionWithReceiver added in v1.7.1

func TransactionWithReceiver(receiver crypto.Address) TransactionMakerOption

TransactionWithReceiver sets the receiver for the Transfer transaction.

func TransactionWithRecipients added in v1.10.0

func TransactionWithRecipients(recipients []payload.BatchRecipient) TransactionMakerOption

TransactionWithRecipients sets the recipients for the Bath Transfer transaction.

func TransactionWithSigner added in v1.4.0

func TransactionWithSigner(signer crypto.PrivateKey) TransactionMakerOption

TransactionWithSigner sets the BLS signer to sign the test transaction.

func TransactionWithValidatorPublicKey added in v1.6.0

func TransactionWithValidatorPublicKey(pubKey *bls.PublicKey) TransactionMakerOption

TransactionWithValidatorPublicKey sets the Validator's public key for the Bond transaction.

type ValidatorMaker added in v1.7.0

type ValidatorMaker struct {
	Number    int32
	Stake     amount.Amount
	PublicKey *bls.PublicKey
}

type ValidatorMakerOption added in v1.11.0

type ValidatorMakerOption func(*ValidatorMaker)

func ValidatorWithNumber added in v1.7.0

func ValidatorWithNumber(number int32) ValidatorMakerOption

ValidatorWithNumber sets the validator number for the generated test validator.

func ValidatorWithPublicKey added in v1.7.0

func ValidatorWithPublicKey(publicKey *bls.PublicKey) ValidatorMakerOption

ValidatorWithPublicKey sets the public Key for the generated test account.

func ValidatorWithStake added in v1.7.0

func ValidatorWithStake(stake amount.Amount) ValidatorMakerOption

ValidatorWithStake sets the stake for the generated test account.

Jump to

Keyboard shortcuts

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