-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
49 lines (41 loc) · 1.41 KB
/
util.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
package cli
import (
"fmt"
"testing"
"github.com/jinxprotocol/v4-chain/protocol/testutil/constants"
"github.com/jinxprotocol/v4-chain/protocol/testutil/network"
"github.com/jinxprotocol/v4-chain/protocol/x/prices/types"
"github.com/stretchr/testify/require"
)
func NetworkWithMarketObjects(t *testing.T, n int) (*network.Network, []types.MarketParam, []types.MarketPrice) {
t.Helper()
cfg := network.DefaultConfig(nil)
state := types.GenesisState{}
require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state))
// Overwrite market params and prices in default genesis state.
state.MarketParams = []types.MarketParam{}
state.MarketPrices = []types.MarketPrice{}
// Market params
for i := 0; i < n; i++ {
marketParam := types.MarketParam{
Id: uint32(i),
Pair: fmt.Sprint(constants.BtcUsdPair, i),
MinExchanges: uint32(1),
MinPriceChangePpm: uint32((i + 1) * 2),
ExchangeConfigJson: "{}",
}
state.MarketParams = append(state.MarketParams, marketParam)
}
// Market prices
for i := 0; i < n; i++ {
marketPrice := types.MarketPrice{
Id: uint32(i),
Price: constants.FiveBillion,
}
state.MarketPrices = append(state.MarketPrices, marketPrice)
}
buf, err := cfg.Codec.MarshalJSON(&state)
require.NoError(t, err)
cfg.GenesisState[types.ModuleName] = buf
return network.New(t, cfg), state.MarketParams, state.MarketPrices
}