testutil

package
v0.0.0-...-e4f0010 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGasPrice = 1879048192 // 0x70000000
	DefaultGasLimit = 5242880    // 0x500000
)

Variables

View Source
var (
	DummyAddr = web3.HexToAddress("0x015f68893a39b3ba0681584387670ff8b00f4db2")
)

Functions

func CompareBlocks

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

func CompareLogs

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

func (*MockBlock) Extra

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

func (*MockBlock) GetLogs

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

func (*MockBlock) GetNum

func (m *MockBlock) GetNum() int

func (*MockBlock) Hash

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

func (*MockClient) GetBlockByHash

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

func (*MockClient) GetBlockByNumber

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

func (*MockClient) GetLastBlocks

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

func (*MockClient) GetLogs

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

func (*MockList) ToBlocks

func (m *MockList) ToBlocks() []*web3.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 NewTestServer

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

NewTestServer creates a new Geth test server

func (*TestServer) Account

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

Account returns a specific account

func (*TestServer) Call

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

Call sends a contract call

func (*TestServer) Close

func (t *TestServer) Close()

Close closes the server

func (*TestServer) DeployContract

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

DeployContract deploys a contract with account 0 and returns the address

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() (*web3.Receipt, error)

ProcessBlock processes a new block

func (*TestServer) SendTxn

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

SendTxn sends a transaction

func (*TestServer) Transfer

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

func (*TestServer) TxnTo

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

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 web3.Hash) (*web3.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