testchain

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: LGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultForkConfig = thor.ForkConfig{
	BLOCKLIST: 0,
	VIP191:    1,
	VIP214:    2,
	ETH_CONST: math.MaxUint32,
	ETH_IST:   math.MaxUint32,
	FINALITY:  math.MaxUint32,
	GALACTICA: math.MaxUint32,
	HAYABUSA:  math.MaxUint32,
}

Functions

This section is empty.

Types

type Chain

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

Chain represents the blockchain structure. It includes database (db), genesis information (genesis), consensus engine (engine), repository for blocks and state (repo), state manager (stater), and the genesis block (genesisBlock).

func New

func New(
	db *muxdb.MuxDB,
	genesis *genesis.Genesis,
	engine bft.Committer,
	repo *chain.Repository,
	stater *state.Stater,
	genesisBlock *block.Block,
	logDB *logdb.LogDB,
	forkConfig *thor.ForkConfig,
) *Chain

func NewDefault added in v2.3.0

func NewDefault() (*Chain, error)

NewDefault is a wrapper function that creates a Chain for testing with the default fork config.

func NewIntegrationTestChain

func NewIntegrationTestChain(config genesis.DevConfig, epochLength uint32) (*Chain, error)

NewIntegrationTestChain is a convenience function that creates a Chain for testing. It uses an in-memory database, development network genesis, and a solo BFT engine.

func NewIntegrationTestChainWithGenesis added in v2.4.0

func NewIntegrationTestChainWithGenesis(gene *genesis.Genesis, forkConfig *thor.ForkConfig, epochLength uint32) (*Chain, error)

func NewWithFork added in v2.3.0

func NewWithFork(forkConfig *thor.ForkConfig, epochLength uint32) (*Chain, error)

NewWithFork is a wrapper function that creates a Chain for testing with custom forkConfig.

func (*Chain) AddBlock added in v2.4.0

func (c *Chain) AddBlock(newBlk *block.Block, stage *state.Stage, receipts tx.Receipts) error

AddBlock manually adds a new block to the chain.

func (*Chain) BestBlock

func (c *Chain) BestBlock() (*block.Block, error)

BestBlock returns the current best (latest) block in the chain.

func (*Chain) ChainTag added in v2.4.0

func (c *Chain) ChainTag() byte

ChainTag returns the chain tag of the genesis block.

func (*Chain) ClauseCall added in v2.4.0

func (c *Chain) ClauseCall(account genesis.DevAccount, trx *tx.Transaction, clauseIdx int) ([]byte, uint64, error)

ClauseCall executes contract call with clause referenced by the clauseIdx parameter, the rest of tx is passed as is.

func (*Chain) Contract added in v2.4.0

func (c *Chain) Contract(addr thor.Address, abi *abi.ABI, acc genesis.DevAccount) *Contract

Contract creates a new contract instance with the provided address and ABI.

func (*Chain) Database

func (c *Chain) Database() *muxdb.MuxDB

Database returns the current database.

func (*Chain) Engine

func (c *Chain) Engine() bft.Committer

Engine returns the consensus engine responsible for the blockchain's consensus mechanism.

func (*Chain) Genesis added in v2.4.0

func (c *Chain) Genesis() *genesis.Genesis

Genesis returns the genesis information of the chain, which includes the initial state and configuration.

func (*Chain) GenesisBlock

func (c *Chain) GenesisBlock() *block.Block

GenesisBlock returns the genesis block of the chain, which is the first block in the blockchain.

func (*Chain) GetAllBlocks

func (c *Chain) GetAllBlocks() ([]*block.Block, error)

GetAllBlocks retrieves all blocks from the blockchain, starting from the best block and moving backward to the genesis block. It limits the retrieval time to 5 seconds to avoid excessive delays.

func (*Chain) GetForkConfig

func (c *Chain) GetForkConfig() *thor.ForkConfig

GetForkConfig returns the current fork configuration based on the ID of the genesis block.

func (*Chain) GetTxBlock added in v2.4.0

func (c *Chain) GetTxBlock(txID *thor.Bytes32) (*block.Block, error)

func (*Chain) GetTxReceipt added in v2.4.0

func (c *Chain) GetTxReceipt(txID thor.Bytes32) (*tx.Receipt, error)

func (*Chain) LogDB

func (c *Chain) LogDB() *logdb.LogDB

LogDB returns the current logdb.

func (*Chain) MintBlock

func (c *Chain) MintBlock(account genesis.DevAccount, transactions ...*tx.Transaction) error

MintBlock creates and finalizes a new block with the given transactions. It schedules a new block, adopts transactions, packs them into a block, and commits it to the chain.

func (*Chain) MintClauses added in v2.2.0

func (c *Chain) MintClauses(account genesis.DevAccount, clauses []*tx.Clause) error

MintClauses creates a transaction with the provided clauses and adds it to the blockchain.

func (*Chain) MintTransactions

func (c *Chain) MintTransactions(account genesis.DevAccount, transactions ...*tx.Transaction) error

MintTransactions creates a block with the provided transactions and adds it to the blockchain. It wraps the transactions with receipts and passes them to MintTransactionsWithReceiptFunc.

func (*Chain) Repo

func (c *Chain) Repo() *chain.Repository

Repo returns the blockchain's repository, which stores blocks and other data.

func (*Chain) Stater

func (c *Chain) Stater() *state.Stater

Stater returns the current state manager of the chain, which is responsible for managing the state of accounts and other elements.

type Contract added in v2.4.0

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

func NewContract added in v2.4.0

func NewContract(chain *Chain, acc genesis.DevAccount, addr thor.Address, abi *abi.ABI) *Contract

func (*Contract) Attach added in v2.4.0

func (c *Contract) Attach(acc genesis.DevAccount) *Contract

func (*Contract) BuildClause added in v2.4.0

func (c *Contract) BuildClause(method string, args ...any) (*tx.Clause, error)

func (*Contract) BuildTransaction added in v2.4.0

func (c *Contract) BuildTransaction(method string, vet *big.Int, args ...any) (*tx.Transaction, error)

func (*Contract) Call added in v2.4.0

func (c *Contract) Call(method string, args ...any) ([]byte, error)

Call calls a contract method and returns the result.

func (*Contract) CallInto added in v2.4.0

func (c *Contract) CallInto(method string, result any, args ...any) error

CallInto calls a contract method and decodes the result into the result argument.

func (*Contract) MintTransaction added in v2.4.0

func (c *Contract) MintTransaction(method string, vet *big.Int, args ...any) error

Jump to

Keyboard shortcuts

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