testutil

package
v0.0.0-...-01e1646 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FromKey  string = "0a9b29e781f64c48a38a46d7a29b78f3c3a3b380e573cb50e2e917d5e7c3be3a"
	FromAddr string = "0x3A92a507acD85dcBE848680eD9D2340DB70be2d0"
	ToAddr   string = "0xdb04bd70d2D834D6845D515278E4De1F1Cba4572"
	Value    int64  = 1e18
)

Variables

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

Functions

func CompareBlocks

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

func CompareLogs

func CompareLogs(one, two []*core.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() *core.Block

func (*MockBlock) Extra

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

func (*MockBlock) GetLogs

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

func (*MockBlock) GetNum

func (m *MockBlock) GetNum() int

func (*MockBlock) Hash

func (m *MockBlock) Hash() core.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 []*core.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 []*core.Log)

func (*MockClient) GetBlockByHash

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

func (*MockClient) GetBlockByNumber

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

func (*MockClient) GetLastBlocks

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

func (*MockClient) GetLogs

func (d *MockClient) GetLogs(filter *core.LogFilter) ([]*core.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 []*core.Log)

func (*MockList) ToBlocks

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

type MockLog

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

type Server

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

Server is a Geth test server

func NewServer

func NewServer(addrs ...string) *Server

func NewTestingServer

func NewTestingServer(t *testing.T, addrs ...string) *Server

NewTestingServer just for testing

func (*Server) Account

func (t *Server) Account(i int) core.Address

Account returns a specific account

func (*Server) Call

func (t *Server) Call(msg *core.CallMsg) (string, error)

Call sends a contract call

func (*Server) DeployContract

func (t *Server) DeployContract(c *Contract) (*compiler.Artifact, core.Address, error)

DeployContract deploys a contract with account 0 and returns the address TODO Finish it

func (*Server) Fund

func (t *Server) Fund(address core.Address) (*core.Receipt, error)

func (*Server) HTTPAddr

func (t *Server) HTTPAddr() string

HTTPAddr returns the http endpoint

func (*Server) HttpClient

func (t *Server) HttpClient() *ethClient

func (*Server) IPCPath

func (t *Server) IPCPath() string

IPCPath returns the ipc endpoint

func (*Server) ProcessBlock

func (t *Server) ProcessBlock() error

func (*Server) ProcessBlockRaw

func (t *Server) ProcessBlockRaw() error

func (*Server) ProcessBlockWithReceipt

func (t *Server) ProcessBlockWithReceipt() (*core.Receipt, error)

ProcessBlockWithReceipt ProcessBlock processes a new block TODO Finish it

func (*Server) ProcessRawTxWithReceipt

func (t *Server) ProcessRawTxWithReceipt() (*core.Receipt, error)

ProcessRawTxWithReceipt ProcessBlock processes a new block via sendrawTransaction

func (*Server) SendRawTxn

func (t *Server) SendRawTxn(fromKey string, txn *core.Transaction) (*core.Receipt, error)

func (*Server) Transfer

func (t *Server) Transfer(address core.Address, value *big.Int) (*core.Receipt, error)

Transfer transfer eth to certain address TODO Finish it

func (*Server) TxnTo

func (t *Server) TxnTo(address core.Address, method string) (*core.Receipt, error)

TxnTo sends a transaction to a given method without any arguments TODO Finish it

func (*Server) WSAddr

func (t *Server) WSAddr() string

WSAddr returns the websocket endpoint

func (*Server) WaitForReceipt

func (t *Server) WaitForReceipt(hash core.Hash) (*core.Receipt, error)

WaitForReceipt waits for the receipt

func (*Server) WsClient

func (t *Server) WsClient() *ethClient

type ServerConfig

type ServerConfig struct {
	Period int
}

ServerConfig is the configuration of the server

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 NewTestServer

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

func (*TestServer) Account

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

Account returns a specific account

func (*TestServer) Call

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

Call sends a contract call

func (*TestServer) DeployContract

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

DeployContract deploys a contract with account 0 and returns the address

func (*TestServer) Fund

func (t *TestServer) Fund(address core.Address) (*core.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) ProcessBlockRaw

func (t *TestServer) ProcessBlockRaw() error

deep add

func (*TestServer) ProcessBlockWithReceipt

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

ProcessBlockWithReceipt ProcessBlock processes a new block

func (*TestServer) ProcessRawTxWithReceipt

func (t *TestServer) ProcessRawTxWithReceipt() (*core.Receipt, error)

ProcessRawTxWithReceipt ProcessBlock processes a new block via sendrawTransaction

func (*TestServer) SendRawTxn

func (t *TestServer) SendRawTxn(txn *core.Transaction) (*core.Receipt, error)

func (*TestServer) SendTxn

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

SendTxn sends a transaction

func (*TestServer) Transfer

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

func (*TestServer) TxnTo

func (t *TestServer) TxnTo(address core.Address, method string) (*core.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 core.Hash) (*core.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