-
Notifications
You must be signed in to change notification settings - Fork 8
/
helper_test.go
84 lines (71 loc) · 2.18 KB
/
helper_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
package monitoring
import (
cryptoRand "crypto/rand"
"fmt"
"math/big"
"math/rand"
"testing"
"time"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
)
// Generators
func generateChainConfig(t *testing.T) CosmosConfig {
address, err := sdk.AccAddressFromBech32(randBech32())
require.NoError(t, err)
return CosmosConfig{
TendermintURL: "https://some-tendermint-url.com",
FCDURL: "https://fcd.terra.dev",
NetworkName: "cosmwasm",
NetworkID: "cosmwasm",
ChainID: "1",
ReadTimeout: 1 * time.Second,
PollInterval: 2 * time.Second,
LinkTokenAddress: address,
}
}
func generateFeedConfig(t *testing.T) CosmosFeedConfig {
coins := []string{"btc", "eth", "matic", "link", "avax", "ftt", "srm", "usdc", "sol", "ray"}
coin := coins[rand.Intn(len(coins))]
address, err := sdk.AccAddressFromBech32(randBech32())
require.NoError(t, err)
proxyAddress, err := sdk.AccAddressFromBech32(randBech32())
require.NoError(t, err)
return CosmosFeedConfig{
Name: fmt.Sprintf("%s / usd", coin),
Path: fmt.Sprintf("%s-usd", coin),
Symbol: "$",
HeartbeatSec: 1,
ContractType: "ocr2",
ContractStatus: "status",
Multiply: big.NewInt(1000),
ContractAddressBech32: address.String(),
ContractAddress: address,
ProxyAddressBech32: proxyAddress.String(),
ProxyAddress: proxyAddress,
}
}
func generateBigInt(bitSize uint8) *big.Int {
maxBigInt := new(big.Int)
maxBigInt.Exp(big.NewInt(2), big.NewInt(int64(bitSize)), nil).Sub(maxBigInt, big.NewInt(1))
//Generate cryptographically strong pseudo-random between 0 - max
num, err := cryptoRand.Int(cryptoRand.Reader, maxBigInt)
if err != nil {
panic(fmt.Sprintf("failed to generate a really big number: %v", err))
}
return num
}
func generateProxyData() ProxyData {
return ProxyData{
Answer: generateBigInt(128),
}
}
// Sources
func newNullLogger() logger.Logger {
return logger.Nop()
}
func randBech32() string {
return sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address().Bytes()).String()
}