testutil

package
v0.0.0-...-a9c8dba Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Test Bitfinex Config
	BitfinexExchangeConfig = map[pricefeed.MarketId]pricefeed.MarketConfig{
		exchange_config.MARKET_BTC_USD: {
			Ticker: "tBTCUSD",
		},
		exchange_config.MARKET_ETH_USD: {
			Ticker: "tETHUSD",
		},
		exchange_config.MARKET_USDT_USD: {
			Ticker: "tUSTUSD",
		},
	}

	// Exchange responses.
	EmptyResponses_AllExchanges = map[ExchangeIdAndName]Response{
		{
			exchangeId:   exchange_common.EXCHANGE_ID_BINANCE,
			exchangeName: constants.BinanceExchangeName,
		}: {
			ResponseCode: responseErr,
		},
		{
			exchangeId:   exchange_common.EXCHANGE_ID_BINANCE_US,
			exchangeName: constants.BinanceUSExchangeName,
		}: {
			ResponseCode: responseErr,
		},
		{
			exchangeId:   exchange_common.EXCHANGE_ID_BITFINEX,
			exchangeName: constants.BitfinexExchangeName,
		}: {
			ResponseCode: responseErr,
		},
	}
	FullResponses_AllExchanges_Btc101_Eth9001 = map[ExchangeIdAndName]Response{
		{
			exchangeId:   exchange_common.EXCHANGE_ID_BINANCE,
			exchangeName: constants.BinanceExchangeName,
		}: {
			ResponseCode: responseOk,
			Tickers:      []JsonResponse{binanceTicker_Btc100, binanceTicker_Eth9001},
		},
		{
			exchangeId:   exchange_common.EXCHANGE_ID_BINANCE_US,
			exchangeName: constants.BinanceUSExchangeName,
		}: {
			ResponseCode: responseOk,
			Tickers:      []JsonResponse{binanceUSTicker_Btc101, binanceUSTicker_Eth9000},
		},
		{
			exchangeId:   exchange_common.EXCHANGE_ID_BITFINEX,
			exchangeName: constants.BitfinexExchangeName,
		}: {
			ResponseCode: responseOk,
			Tickers:      []JsonResponse{bitfinexTicker_Btc102, bitfinexTicker_Eth9002},
		},
	}
	PartialResponses_AllExchanges_Eth9001 = map[ExchangeIdAndName]Response{
		{
			exchangeId:   exchange_common.EXCHANGE_ID_BINANCE,
			exchangeName: constants.BinanceExchangeName,
		}: {
			ResponseCode: responseOk,
		},
		{
			exchangeId:   exchange_common.EXCHANGE_ID_BINANCE_US,
			exchangeName: constants.BinanceUSExchangeName,
		}: {
			ResponseCode: responseOk,
			Tickers:      []JsonResponse{binanceUSTicker_Eth9000},
		},
		{
			exchangeId:   exchange_common.EXCHANGE_ID_BITFINEX,
			exchangeName: constants.BitfinexExchangeName,
		}: {
			ResponseCode: responseOk,
			Tickers:      []JsonResponse{bitfinexTicker_Eth9002},
		},
	}

	// ValidAuthority is an authority address that passes basic validation.
	ValidAuthority = authtypes.NewModuleAddress("test").String()
)

Functions

func GetTickersSortedByMarketId

func GetTickersSortedByMarketId(marketToMarketConfig map[uint32]types.MarketConfig) []string

func MsgQueryAllMarketParamExec

func MsgQueryAllMarketParamExec(clientCtx client.Context) (testutil.BufferWriter, error)

MsgQueryAllMarketParamExec lists all markets params in `Prices`.

func MsgQueryAllMarketPriceExec

func MsgQueryAllMarketPriceExec() ([]byte, error)

MsgQueryAllMarketPriceExec lists all markets prices in `Prices`.

func NewGockBinanceResponse

func NewGockBinanceResponse(
	responseCode int,
	tickers []JsonResponse,
) *gock.Response

NewGockBinanceResponse creates and registers a new HTTP mock using `gock` for Binance.

func NewGockBinanceUSResponse

func NewGockBinanceUSResponse(
	responseCode int,
	tickers []JsonResponse,
) *gock.Response

NewGockBinanceResponse creates and registers a new HTTP mock using `gock` for BinanceUS.

func NewGockBitfinexResponse

func NewGockBitfinexResponse(
	responseCode int,
	tickers []JsonResponse,
) *gock.Response

NewGockBitfinexResponse creates and registers a new HTTP mock using `gock` for Bitfinex.

func SetupExchangeResponses

func SetupExchangeResponses(
	t *testing.T,
	responses map[ExchangeIdAndName]Response,
)

SetupExchangeResponses validates and sets up responses returned by exchange APIs using `gock`.

Types

type BinanceTicker

type BinanceTicker struct {
	Symbol    string
	AskPrice  string
	BidPrice  string
	LastPrice string
}

BinanceTicker represents ticker returned by Binance for testing purposes.

func NewBinanceTicker

func NewBinanceTicker(symbol, askPrice, bidPrice, lastPrice string) BinanceTicker

NewBinanceTicker returns a new BinanceTicker.

type BitfinexTicker

type BitfinexTicker struct {
	Symbol    string  // index 0
	BidPrice  float64 // index 1
	AskPrice  float64 // index 3
	LastPrice float64 // index 7
}

BitfinexTicker represents ticker in Bitfinex response for testing purposes.

func NewBitfinexTicker

func NewBitfinexTicker(symbol string, askPrice, bidPrice, lastPrice float64) BitfinexTicker

NewBitfinexTicker returns a new BitfinexTicker.

type ExchangeIdAndName

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

ExchangeIdAndName represents an exchange with an ID and a name.

type JsonResponse

type JsonResponse interface {
	// contains filtered or unexported methods
}

JsonResponse is an interface that encapsulates a JSON API response.

type Response

type Response struct {
	ResponseCode int
	Tickers      []JsonResponse
}

Response represents an API response from an exchange.

Jump to

Keyboard shortcuts

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