testutils

package
v0.0.0-...-5207ebf Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: MIT, MIT Imports: 20 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() string

func GetTestAddress2

func GetTestAddress2() string

func GetTestAddress3

func GetTestAddress3() string

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 GetTestZRXToken

func GetTestZRXToken() types.Token

func GetZRXWETHTestPair

func GetZRXWETHTestPair() *types.Pair

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
	// 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 Obyte account used for orders and trades. mutex is used to prevent concurrent writes on the websocket connection

func NewClient

func NewClient(s Server) *Client

NewClient a default client struct connected to the given server

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          *string        `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 MockDaos

type MockDaos struct {
	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 {
	AccountService   *mocks.AccountService
	OrderService     *mocks.OrderService
	OrderBookService *mocks.OrderBookService
	TokenService     *mocks.TokenService
	PairService      *mocks.PairService
	TradeService     *mocks.TradeService
}

func NewMockServices

func NewMockServices() *MockServices

type OrderFactory

type OrderFactory struct {
	Wallet *Wallet
	Pair   *types.Pair
	Params *OrderParams
}

Orderfactory simplifies creating orders, trades and cancelOrders objects Pair is the token pair for which the order is created

func NewOrderFactory

func NewOrderFactory(p *types.Pair, w *Wallet, matcherAddress string) (*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() string

GetAddress returns the order factory address

func (*OrderFactory) GetMatcherAddress

func (f *OrderFactory) GetMatcherAddress() string

func (*OrderFactory) GetWallet

func (f *OrderFactory) GetWallet() *Wallet

GetWallet returns the order factory wallet

func (*OrderFactory) NewBuyOrder

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

NewBuyOrder creates a new buy order from the order factory

func (*OrderFactory) NewBuyOrderMessage

func (f *OrderFactory) NewBuyOrderMessage(price float64, amount int64) (*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 string, quoteToken string, amount int64, pricepoint float64) (*types.Order, error)

func (*OrderFactory) NewOrder

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

NewOrder returns a new order with the given params. The order is signed by the factory wallet.

func (*OrderFactory) NewOrderMessage

func (f *OrderFactory) NewOrderMessage(baseToken, quoteToken string, 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 float64, value int64, filled ...int64) (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 float64, amount int64) (*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.

func (*OrderFactory) SetMatcherAddress

func (f *OrderFactory) SetMatcherAddress(addr string) error

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

type OrderParams

type OrderParams struct {
	MatcherAddress string
}

type Server

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

type Wallet

type Wallet struct {
	Address string
}

func GetTestWallet

func GetTestWallet() *Wallet

func GetTestWallet1

func GetTestWallet1() *Wallet

func GetTestWallet2

func GetTestWallet2() *Wallet

func GetTestWallet3

func GetTestWallet3() *Wallet

func GetTestWallet4

func GetTestWallet4() *Wallet

func GetTestWallet5

func GetTestWallet5() *Wallet

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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