testutil

package
v0.0.0-...-99888be Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultGasPrice = uint64(1879048192) // 0x70000000
	DefaultGasLimit = uint64(5242880)    // 0x500000
)
View Source
var (
	DummyAddr = ethgo.HexToAddress("0x015f68893a39b3ba0681584387670ff8b00f4db2")
)

Functions

func CompareBlocks

func CompareBlocks(one, two []*ethgo.Block) bool

func CompareLogs

func CompareLogs(one, two []*ethgo.Log) bool

func MethodSig

func MethodSig(name string) []byte

MethodSig returns the signature of a non-parametrized function

func MultiAddr

func MultiAddr(t *testing.T, c func(s *TestServer, addr string))

MultiAddr creates new servers to test different addresses

func TestInfuraEndpoint

func TestInfuraEndpoint(t *testing.T) string

TestInfuraEndpoint returns the testing infura endpoint to make testing requests

Types

type Contract

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

Contract is a test contract

func (*Contract) AddCallback

func (c *Contract) AddCallback(f func() string)

func (*Contract) AddConstructor

func (c *Contract) AddConstructor(args ...string)

AddConstructor creates a constructor with args that set contract variables

func (*Contract) AddDualCaller

func (c *Contract) AddDualCaller(funcName string, args ...string)

AddDualCaller adds a call function that returns the same values that takes

func (*Contract) AddEvent

func (c *Contract) AddEvent(e *Event)

AddEvent adds a new event to the contract

func (*Contract) AddOutputCaller

func (c *Contract) AddOutputCaller(funcName string)

AddOutputCaller adsd a view function that does not take any input

func (*Contract) Compile

func (c *Contract) Compile() (*compiler.Artifact, error)

Compile compiles the contract

func (*Contract) EmitEvent

func (c *Contract) EmitEvent(funcName string, name string, args ...string)

EmitEvent emits a specific event

func (*Contract) GetEvent

func (c *Contract) GetEvent(name string) *Event

GetEvent returns the event with the given name

func (*Contract) Print

func (c *Contract) Print() string

Print prints the contract

type Event

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

Event is a test event

func NewEvent

func NewEvent(name string, args ...interface{}) *Event

NewEvent creates a new contract event

func (*Event) Add

func (e *Event) Add(typStr string, indexed bool) *Event

Add adds a new field to the event

func (*Event) Sig

func (e *Event) Sig() string

Sig returns the signature of the event

type MockBlock

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

func Mock

func Mock(number int) *MockBlock

func (*MockBlock) Block

func (m *MockBlock) Block() *ethgo.Block

func (*MockBlock) Extra

func (m *MockBlock) Extra(data string) *MockBlock

func (*MockBlock) GetLogs

func (m *MockBlock) GetLogs() (logs []*ethgo.Log)

func (*MockBlock) GetNum

func (m *MockBlock) GetNum() int

func (*MockBlock) Hash

func (m *MockBlock) Hash() ethgo.Hash

func (*MockBlock) Log

func (m *MockBlock) Log(data string) *MockBlock

func (*MockBlock) Num

func (m *MockBlock) Num(i int) *MockBlock

func (*MockBlock) Parent

func (m *MockBlock) Parent(i int) *MockBlock

type MockClient

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

func (*MockClient) AddLogs

func (d *MockClient) AddLogs(logs []*ethgo.Log)

func (*MockClient) AddScenario

func (d *MockClient) AddScenario(m MockList)

func (*MockClient) BlockNumber

func (d *MockClient) BlockNumber() (uint64, error)

func (*MockClient) ChainID

func (d *MockClient) ChainID() (*big.Int, error)

func (*MockClient) GetAllLogs

func (d *MockClient) GetAllLogs() (res []*ethgo.Log)

func (*MockClient) GetBlockByHash

func (d *MockClient) GetBlockByHash(hash ethgo.Hash, full bool) (*ethgo.Block, error)

func (*MockClient) GetBlockByNumber

func (d *MockClient) GetBlockByNumber(i ethgo.BlockNumber, full bool) (*ethgo.Block, error)

func (*MockClient) GetLastBlocks

func (d *MockClient) GetLastBlocks(n uint64) (res []*ethgo.Block)

func (*MockClient) GetLogs

func (d *MockClient) GetLogs(filter *ethgo.LogFilter) ([]*ethgo.Log, error)

func (*MockClient) SetChainID

func (m *MockClient) SetChainID(id *big.Int)

type MockList

type MockList []*MockBlock

func (*MockList) Create

func (m *MockList) Create(from, to int, callback func(b *MockBlock))

func (*MockList) GetLogs

func (m *MockList) GetLogs() (res []*ethgo.Log)

func (*MockList) ToBlocks

func (m *MockList) ToBlocks() []*ethgo.Block

type MockLog

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

type ServerConfigCallback

type ServerConfigCallback func(c *TestServerConfig)

ServerConfigCallback is the callback to modify the config

type TestServer

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

TestServer is a Geth test server

func DeployTestServer

func DeployTestServer(t *testing.T, cb ServerConfigCallback) *TestServer

DeployTestServer creates a new Geth test server

func NewTestServer

func NewTestServer(t *testing.T, addrs ...string) *TestServer

func (*TestServer) Account

func (t *TestServer) Account(i int) ethgo.Address

Account returns a specific account

func (*TestServer) Call

func (t *TestServer) Call(msg *ethgo.CallMsg) (string, error)

Call sends a contract call

func (*TestServer) DeployContract

func (t *TestServer) DeployContract(c *Contract) (*compiler.Artifact, ethgo.Address, error)

DeployContract deploys a contract with account 0 and returns the address

func (*TestServer) Fund

func (t *TestServer) Fund(address ethgo.Address) (*ethgo.Receipt, error)

func (*TestServer) HTTPAddr

func (t *TestServer) HTTPAddr() string

HTTPAddr returns the http endpoint

func (*TestServer) IPCPath

func (t *TestServer) IPCPath() string

IPCPath returns the ipc endpoint

func (*TestServer) ProcessBlock

func (t *TestServer) ProcessBlock() error

func (*TestServer) ProcessBlockWithReceipt

func (t *TestServer) ProcessBlockWithReceipt() (*ethgo.Receipt, error)

ProcessBlock processes a new block

func (*TestServer) SendTxn

func (t *TestServer) SendTxn(txn *ethgo.Transaction) (*ethgo.Receipt, error)

SendTxn sends a transaction

func (*TestServer) Transfer

func (t *TestServer) Transfer(address ethgo.Address, value *big.Int) (*ethgo.Receipt, error)

func (*TestServer) TxnTo

func (t *TestServer) TxnTo(address ethgo.Address, method string) (*ethgo.Receipt, error)

TxnTo sends a transaction to a given method without any arguments

func (*TestServer) WSAddr

func (t *TestServer) WSAddr() string

WSAddr returns the websocket endpoint

func (*TestServer) WaitForReceipt

func (t *TestServer) WaitForReceipt(hash ethgo.Hash) (*ethgo.Receipt, error)

WaitForReceipt waits for the receipt

type TestServerConfig

type TestServerConfig struct {
	Period int
}

TestServerConfig is the configuration of the server

Jump to

Keyboard shortcuts

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