testutils

package
v0.0.0-...-2c32341 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2019 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(t *testing.T, expected interface{}, value interface{})

func CompareAccount

func CompareAccount(t *testing.T, a, b *types.Account)

func CompareAccountStrict

func CompareAccountStrict(t *testing.T, a, b *types.Account)

func CompareEngineResponse

func CompareEngineResponse(t *testing.T, a, b *types.EngineResponse)

func CompareMatches

func CompareMatches(t *testing.T, a, b *types.Matches)

func CompareOrder

func CompareOrder(t *testing.T, a, b *types.Order)

func ComparePair

func ComparePair(t *testing.T, a, b *types.Pair)

func ComparePublicOrder

func ComparePublicOrder(t *testing.T, a, b *types.Order)

func ComparePublicTrade

func ComparePublicTrade(t *testing.T, a, b *types.Trade)

func CompareStructs

func CompareStructs(t *testing.T, expected interface{}, order interface{})

func CompareToken

func CompareToken(t *testing.T, a, b *types.Token)

func CompareTrade

func CompareTrade(t *testing.T, a, b *types.Trade)

func GetTestAddress1

func GetTestAddress1() common.Address

func GetTestAddress2

func GetTestAddress2() common.Address

func GetTestAddress3

func GetTestAddress3() common.Address

func GetTestOrder1

func GetTestOrder1() types.Order

func GetTestOrder2

func GetTestOrder2() types.Order

func GetTestOrder3

func GetTestOrder3() types.Order

func GetTestTrade1

func GetTestTrade1() types.Trade

func GetTestTrade2

func GetTestTrade2() types.Trade

func GetTestWETHToken

func GetTestWETHToken() types.Token

func GetTestWallet

func GetTestWallet() *types.Wallet

func GetTestWallet1

func GetTestWallet1() *types.Wallet

func GetTestWallet2

func GetTestWallet2() *types.Wallet

func GetTestWallet3

func GetTestWallet3() *types.Wallet

func GetTestWallet4

func GetTestWallet4() *types.Wallet

func GetTestWallet5

func GetTestWallet5() *types.Wallet

func GetTestZRXToken

func GetTestZRXToken() types.Token

func GetZRXWETHTestPair

func GetZRXWETHTestPair() *types.Pair

func Mine

func Mine(client *ethereum.SimulatedClient)

func NewDBTestServer

func NewDBTestServer() *dbtest.DBServer

Types

type Client

type Client struct {
	Requests     chan *types.WebsocketMessage
	Responses    chan *types.WebsocketMessage
	Logs         chan *ClientLogMessage
	Wallet       *types.Wallet
	RequestLogs  []types.WebsocketMessage
	ResponseLogs []types.WebsocketMessage

	NonceGenerator *rand.Rand
	// contains filtered or unexported fields
}

Client simulates the client websocket handler that will be used to perform trading. requests and responses are respectively the outbound and incoming messages. requestLogs and responseLogs are arrays of messages that denote the history of received messages wallet is the ethereum account used for orders and trades. mutex is used to prevent concurrent writes on the websocket connection

func NewClient

func NewClient(w *types.Wallet, s Server) *Client

NewClient a default client struct connected to the given server

func (*Client) SetNonce

func (c *Client) SetNonce(o *types.Order)

func (*Client) Start

func (c *Client) Start()

start listening and handling incoming messages

type ClientLogMessage

type ClientLogMessage struct {
	MessageType string         `json:"messageType"`
	Orders      []*types.Order `json:"order"`
	Trades      []*types.Trade `json:"trade"`
	Matches     *types.Matches `json:"matches"`
	Tx          *common.Hash   `json:"tx"`
	ErrorID     int8           `json:"errorID"`
}

The client log is mostly used for testing. It optionally takes orders, trade, error ids and transaction hashes. All these parameters are optional in order to allow the client log message to take in a lot of different types of messages An error id of -1 means that there was no error.

type Deployer

type Deployer struct {
	WalletService interfaces.WalletService
	TxService     interfaces.TxService
	Client        bind.ContractBackend
}

func (*Deployer) DeployExchange

func (d *Deployer) DeployExchange(wethToken common.Address, feeAccount common.Address) (*contracts.Exchange, common.Address, *ethTypes.Transaction, error)

DeployExchange

func (*Deployer) DeployToken

func (d *Deployer) DeployToken(receiver common.Address, amount *big.Int) (*contracts.Token, common.Address, *ethTypes.Transaction, error)

DeployToken

func (*Deployer) GetNonce

func (d *Deployer) GetNonce() (*big.Int, error)

GetNonce

func (*Deployer) NewExchange

func (d *Deployer) NewExchange(addr common.Address) (*contracts.Exchange, error)

NewExchange

func (*Deployer) NewToken

func (d *Deployer) NewToken(addr common.Address) (*contracts.Token, error)

func (*Deployer) WaitMined

func (d *Deployer) WaitMined(tx *ethTypes.Transaction) (*ethTypes.Receipt, error)

type MockDaos

type MockDaos struct {
	WalletDao  *mocks.WalletDao
	AccountDao *mocks.AccountDao
	OrderDao   *mocks.OrderDao
	TokenDao   *mocks.TokenDao
	TradeDao   *mocks.TradeDao
	PairDao    *mocks.PairDao
}

func NewMockDaos

func NewMockDaos() *MockDaos

type MockServices

type MockServices struct {
	WalletService    *mocks.WalletService
	AccountService   *mocks.AccountService
	EthereumService  *mocks.EthereumService
	OrderService     *mocks.OrderService
	OrderBookService *mocks.OrderBookService
	TokenService     *mocks.TokenService
	TxService        *mocks.TxService
	PairService      *mocks.PairService
	TradeService     *mocks.TradeService
}

func NewMockServices

func NewMockServices() *MockServices

type OrderFactory

type OrderFactory struct {
	Wallet         *types.Wallet
	Pair           *types.Pair
	Params         *OrderParams
	OrderNonce     uint64
	NonceGenerator *rand.Rand
}

Orderfactory simplifies creating orders, trades and cancelOrders objects Pair is the token pair for which the order is created Exchange is the Ethereum address of the exchange smart contract CurrentOrderID increments for each new order

func NewOrderFactory

func NewOrderFactory(p *types.Pair, w *types.Wallet, exchangeAddress common.Address) (*OrderFactory, error)

NewOrderFactory returns an order factory from a given token pair and a given wallet TODO: Refactor this function to send back an error

func (*OrderFactory) GetAddress

func (f *OrderFactory) GetAddress() common.Address

GetAddress returns the order factory address

func (*OrderFactory) GetExchangeAddress

func (f *OrderFactory) GetExchangeAddress() common.Address

func (*OrderFactory) GetWallet

func (f *OrderFactory) GetWallet() *types.Wallet

GetWallet returns the order factory wallet

func (*OrderFactory) NewBuyOrder

func (f *OrderFactory) NewBuyOrder(pricepoint int64, value float64, filled ...float64) (types.Order, error)

NewBuyOrder creates a new buy order from the order factory

func (*OrderFactory) NewBuyOrderMessage

func (f *OrderFactory) NewBuyOrderMessage(price int64, amount float64) (*types.WebsocketMessage, *types.Order, error)

func (*OrderFactory) NewCancelOrder

func (f *OrderFactory) NewCancelOrder(o *types.Order) (*types.OrderCancel, error)

func (*OrderFactory) NewCancelOrderMessage

func (f *OrderFactory) NewCancelOrderMessage(o *types.Order) (*types.WebsocketMessage, *types.OrderCancel, error)

func (*OrderFactory) NewLargeOrder

func (f *OrderFactory) NewLargeOrder(baseToken common.Address, quoteToken common.Address, amount *big.Int, pricepoint *big.Int) (*types.Order, error)

func (*OrderFactory) NewOrder

func (f *OrderFactory) NewOrder(baseToken common.Address, quoteToken common.Address, amount int64, pricepoint int64) (*types.Order, error)

NewOrder returns a new order with the given params. The order is signed by the factory wallet. Currently the nonce is chosen randomly which will be changed in the future

func (*OrderFactory) NewOrderMessage

func (f *OrderFactory) NewOrderMessage(baseToken, quoteToken common.Address, amount, pricepoint int64) (*types.WebsocketMessage, *types.Order, error)

NewOrderMessage creates an order with the given params and returns a new PLACE_ORDER message

func (*OrderFactory) NewSellOrder

func (f *OrderFactory) NewSellOrder(pricepoint int64, value float64, filled ...float64) (types.Order, error)

NewBuyOrder returns a new order with the given params. The order is signed by the factory wallet NewBuyOrder computes the AmountBuy and AmountSell parameters from the given amount and price. Currently, the amount, price and order type are also kept. This could be amended in the future (meaning we would let the engine compute OrderBuy, Amount and Price. Ultimately this does not really matter except maybe for convenience/readability purposes)

func (*OrderFactory) NewSellOrderMessage

func (f *OrderFactory) NewSellOrderMessage(price int64, amount float64) (*types.WebsocketMessage, *types.Order, error)

func (*OrderFactory) NewTrade

func (f *OrderFactory) NewTrade(o *types.Order, amount int64) (types.Trade, error)

NewTrade returns a new trade with the given params. The trade is signed by the factory wallet. Currently the nonce is chosen randomly which will be changed in the future

func (*OrderFactory) SetExchangeAddress

func (f *OrderFactory) SetExchangeAddress(addr common.Address) error

SetExchangeAddress changes the default exchange address for orders created by this factory

type OrderParams

type OrderParams struct {
	ExchangeAddress common.Address
	MakeFee         *big.Int
	TakeFee         *big.Int
	Nonce           *big.Int
}

OrderParams groups FeeMake, FeeTake, Nonce, Exipres FeeMake and FeeTake are the default fees imposed on makers and takers Nonce is the ethereum account nonce that tracks the numbers of transactions for the order factory account

type Server

type Server interface {
	ServeHTTP(res http.ResponseWriter, req *http.Request)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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