forked from skip-mev/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oracle_test.go
121 lines (106 loc) · 3.22 KB
/
oracle_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package oracle_test
import (
"math/rand"
"testing"
"time"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
"github.com/skip-mev/slinky/oracle"
"github.com/skip-mev/slinky/oracle/config"
"github.com/skip-mev/slinky/oracle/types"
mmtypes "github.com/skip-mev/slinky/x/marketmap/types"
)
var (
providerCfg1 = config.ProviderConfig{
Name: "api1",
API: config.APIConfig{
Interval: 500 * time.Millisecond,
Timeout: 250 * time.Millisecond,
ReconnectTimeout: 250 * time.Millisecond,
MaxQueries: 10,
Enabled: true,
Name: "api1",
Endpoints: []config.Endpoint{{URL: "http://test.com"}},
},
Type: "price_provider",
}
providerCfg2 = config.ProviderConfig{
Name: "websocket1",
WebSocket: config.WebSocketConfig{
MaxBufferSize: 10,
Enabled: true,
ReconnectionTimeout: 250 * time.Millisecond,
Endpoints: []config.Endpoint{
{
URL: "ws://localhost:8080",
},
},
Name: "websocket1",
ReadBufferSize: config.DefaultReadBufferSize,
WriteBufferSize: config.DefaultWriteBufferSize,
HandshakeTimeout: config.DefaultHandshakeTimeout,
EnableCompression: config.DefaultEnableCompression,
ReadTimeout: config.DefaultReadTimeout,
WriteTimeout: config.DefaultWriteTimeout,
PingInterval: config.DefaultPingInterval,
MaxSubscriptionsPerConnection: config.DefaultMaxSubscriptionsPerConnection,
},
Type: "price_provider",
}
)
type OracleTestSuite struct {
suite.Suite
random *rand.Rand
logger *zap.Logger
// Oracle config
currencyPairs []types.ProviderTicker
marketmap mmtypes.MarketMap
}
func TestOracleSuite(t *testing.T) {
suite.Run(t, new(OracleTestSuite))
}
func (s *OracleTestSuite) SetupTest() {
s.random = rand.New(rand.NewSource(time.Now().UnixNano()))
s.logger = zap.NewExample()
s.currencyPairs = []types.ProviderTicker{
types.NewProviderTicker("BTC/USD", "{}"),
types.NewProviderTicker("ETH/USD", "{}"),
types.NewProviderTicker("ATOM/USD", "{}"),
}
s.marketmap = mmtypes.MarketMap{Markets: map[string]mmtypes.Market{
btcusdtCP.String(): {
Ticker: mmtypes.Ticker{
CurrencyPair: btcusdtCP,
MinProviderCount: 1,
Decimals: 8,
Enabled: true,
},
ProviderConfigs: []mmtypes.ProviderConfig{
{
Name: providerCfg1.Name,
OffChainTicker: coinbasebtcusd.GetOffChainTicker(),
},
{
Name: providerCfg2.Name,
OffChainTicker: coinbasebtcusd.GetOffChainTicker(),
},
},
},
}}
}
func (s *OracleTestSuite) TestGetMarketMap() {
dummyMM := marketMap
o, err := oracle.New(oracleCfg, noOpPriceAggregator{}, oracle.WithMarketMap(dummyMM))
s.Require().NoError(err)
gotMM := o.GetMarketMap()
s.Require().Equal(dummyMM, gotMM)
// test when no option provided, should just give empty mm
o, err = oracle.New(oracleCfg, noOpPriceAggregator{})
s.Require().NoError(err)
gotMM = o.GetMarketMap()
s.Require().Equal(gotMM, mmtypes.MarketMap{})
}
func (s *OracleTestSuite) TestErrorsWhenNoAggregator() {
_, err := oracle.New(oracleCfg, nil)
s.Require().ErrorContains(err, "aggregator is required")
}