-
Notifications
You must be signed in to change notification settings - Fork 166
/
price-feeder.go
122 lines (102 loc) · 3.17 KB
/
price-feeder.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
122
package setup
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"time"
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
PriceFeederContainerRepo = "ghcr.io/ojo-network/price-feeder-umee-47"
PriceFeederServerPort = "7171/tcp"
PriceFeederMaxStartupTime = 20 // seconds
)
// runPriceFeeder runs the price feeder using one of the chain's validators to vote on prices.
// The container accesses the validator's key using the test keyring located in the validator's config directory.
func (s *E2ETestSuite) runPriceFeeder(valIndex int) {
s.T().Log("starting price-feeder container...")
umeeVal := s.Chain.Validators[valIndex]
umeeValAddr, err := umeeVal.KeyInfo.GetAddress()
s.Require().NoError(err)
grpcEndpoint := fmt.Sprintf("tcp://%s:%s", umeeVal.instanceName(), "9090")
tmrpcEndpoint := fmt.Sprintf("http://%s:%s", umeeVal.instanceName(), "26657")
s.priceFeederResource, err = s.DkrPool.RunWithOptions(
&dockertest.RunOptions{
Name: "umee-price-feeder",
NetworkID: s.DkrNet.Network.ID,
Repository: PriceFeederContainerRepo,
Mounts: []string{
fmt.Sprintf("%s/:/root/.umee", umeeVal.configDir()),
},
PortBindings: map[docker.Port][]docker.PortBinding{
PriceFeederServerPort: {{HostIP: "", HostPort: "7171"}},
},
Env: []string{
fmt.Sprintf("PRICE_FEEDER_PASS=%s", keyringPassphrase),
fmt.Sprintf("ACCOUNT_ADDRESS=%s", umeeValAddr),
fmt.Sprintf("ACCOUNT_VALIDATOR=%s", sdk.ValAddress(umeeValAddr)),
fmt.Sprintf("KEYRING_DIR=%s", "/root/.umee"),
fmt.Sprintf("ACCOUNT_CHAIN_ID=%s", s.Chain.ID),
fmt.Sprintf("RPC_GRPC_ENDPOINT=%s", grpcEndpoint),
fmt.Sprintf("RPC_TMRPC_ENDPOINT=%s", tmrpcEndpoint),
},
Cmd: []string{
"--skip-provider-check",
},
},
noRestart,
)
s.Require().NoError(err)
endpoint := fmt.Sprintf("http://%s/api/v1/prices", s.priceFeederResource.GetHostPort(PriceFeederServerPort))
checkHealth := func() bool {
resp, err := http.Get(endpoint)
if err != nil {
s.T().Log("Price feeder endpoint not available", err)
return false
}
defer resp.Body.Close()
bz, err := io.ReadAll(resp.Body)
if err != nil {
s.T().Log("Can't get price feeder response", err)
return false
}
var respBody map[string]interface{}
if err := json.Unmarshal(bz, &respBody); err != nil {
s.T().Log("Can't unmarshal price feed", err)
return false
}
prices, ok := respBody["prices"].(map[string]interface{})
if !ok {
s.T().Log("price feeder: no prices")
return false
}
return len(prices) > 0
}
isHealthy := false
for i := 0; i < PriceFeederMaxStartupTime; i++ {
isHealthy = checkHealth()
if isHealthy {
break
}
time.Sleep(time.Second)
}
if !isHealthy {
err := s.DkrPool.Client.Logs(docker.LogsOptions{
Container: s.priceFeederResource.Container.ID,
OutputStream: os.Stdout,
ErrorStream: os.Stderr,
Stdout: true,
Stderr: true,
Tail: "false",
})
if err != nil {
s.T().Log("Error retrieving price feeder logs", err)
}
s.T().Fatal("price-feeder not healthy")
}
s.T().Logf("started price-feeder container: %s", s.priceFeederResource.Container.ID)
}