-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add faucet status check test * add test for checking endpoint as well * only skip faucet tests if faucet port is not defined * fix running credit testcase * remove exposing faucet for simapp due to incompatibility issues with cosmjs and simapp * use big.Int instead of floats, check for expected difference between before and after balance is atleast the expected value * add comment * remove use of big.Int with float * fix typo in expected value
- Loading branch information
Showing
9 changed files
with
152 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ chains: | |
rest: 1313 | ||
rpc: 26653 | ||
exposer: 38083 | ||
faucet: 8000 | ||
resources: | ||
limits: | ||
cpu: "0.4" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ chains: | |
rest: 1313 | ||
rpc: 26653 | ||
exposer: 38083 | ||
faucet: 8003 | ||
resources: | ||
cpu: "0.5" | ||
memory: 500M | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ chains: | |
rest: 1313 | ||
rpc: 26653 | ||
exposer: 38083 | ||
faucet: 8003 | ||
resources: | ||
cpu: "0.5" | ||
memory: 500M | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ chains: | |
rest: 1313 | ||
rpc: 26653 | ||
exposer: 38083 | ||
faucet: 8003 | ||
resources: | ||
cpu: "0.5" | ||
memory: 500M | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ chains: | |
rest: 1317 | ||
rpc: 26657 | ||
grpc: 9091 | ||
faucet: 8001 | ||
exposer: 8002 | ||
resources: | ||
cpu: "0.2" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package e2e | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
pb "github.com/cosmology-tech/starship/registry/registry" | ||
"net/http" | ||
urlpkg "net/url" | ||
"strconv" | ||
) | ||
|
||
func (s *TestSuite) MakeFaucetRequest(chain *Chain, req *http.Request, unmarshal map[string]interface{}) { | ||
host := fmt.Sprintf("http://0.0.0.0:%d%s", chain.Ports.Faucet, req.URL.String()) | ||
|
||
url, err := urlpkg.Parse(host) | ||
s.Require().NoError(err) | ||
|
||
req.URL = url | ||
|
||
body := s.MakeRequest(req, 200) | ||
|
||
err = json.NewDecoder(body).Decode(&unmarshal) | ||
s.Require().NoError(err) | ||
} | ||
|
||
func (s *TestSuite) TestFaucet_Status() { | ||
s.T().Log("running test for /status endpoint for faucet") | ||
|
||
for _, chain := range s.config.Chains { | ||
s.Run(fmt.Sprintf("facuet test for: %s", chain.Name), func() { | ||
if chain.Ports.Faucet == 0 { | ||
s.T().Skip("faucet not exposed via ports") | ||
} | ||
|
||
req, err := http.NewRequest(http.MethodGet, "/status", nil) | ||
s.Require().NoError(err) | ||
|
||
resp := map[string]interface{}{} | ||
s.MakeFaucetRequest(chain, req, resp) | ||
|
||
s.Require().Equal("ok", resp["status"]) | ||
}) | ||
} | ||
} | ||
|
||
func (s *TestSuite) MakeChainGetRequest(chain *Chain, endpoint string, unmarshal any) { | ||
url := fmt.Sprintf("http://0.0.0.0:%d%s", chain.Ports.Rest, endpoint) | ||
req, err := http.NewRequest(http.MethodGet, url, nil) | ||
s.Require().NoError(err) | ||
body := s.MakeRequest(req, 200) | ||
|
||
err = json.NewDecoder(body).Decode(&unmarshal) | ||
s.Require().NoError(err) | ||
} | ||
|
||
func (s *TestSuite) getChainAccounts(chain *Chain) []string { | ||
var accounts []string | ||
|
||
data := map[string]interface{}{} | ||
s.MakeChainGetRequest(chain, "/cosmos/auth/v1beta1/accounts", &data) | ||
s.Require().Contains(data, "accounts") | ||
|
||
for _, acc := range data["accounts"].([]interface{}) { | ||
accMap := acc.(map[string]interface{}) | ||
s.Require().Contains(accMap, "@type") | ||
if accMap["@type"].(string) != "/cosmos.auth.v1beta1.BaseAccount" { | ||
continue | ||
} | ||
s.Require().NotEmpty(accMap["address"].(string)) | ||
accounts = append(accounts, accMap["address"].(string)) | ||
} | ||
|
||
s.Require().GreaterOrEqual(len(accounts), 1) | ||
return accounts | ||
} | ||
|
||
func (s *TestSuite) getChainDenoms(chain *Chain) string { | ||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("/chains/%s", chain.Name), nil) | ||
s.Require().NoError(err) | ||
|
||
respChain := &pb.ChainRegistry{} | ||
s.MakeRegistryRequest(req, respChain) | ||
s.Require().Equal(chain.Name, respChain.ChainId) | ||
|
||
s.Require().NotEmpty(respChain.Fees.FeeTokens[0].Denom) | ||
|
||
return respChain.Fees.FeeTokens[0].Denom | ||
} | ||
|
||
func (s *TestSuite) getAccountBalance(chain *Chain, address string, denom string) float64 { | ||
data := map[string]interface{}{} | ||
s.MakeChainGetRequest(chain, fmt.Sprintf("/cosmos/bank/v1beta1/balances/%s", address), &data) | ||
s.Require().Contains(data, "balances") | ||
|
||
for _, bal := range data["balances"].([]interface{}) { | ||
balMap := bal.(map[string]interface{}) | ||
if balMap["denom"].(string) == denom { | ||
b, err := strconv.ParseFloat(balMap["amount"].(string), 64) | ||
s.Require().NoError(err) | ||
return b | ||
} | ||
} | ||
return float64(0) | ||
} | ||
|
||
func (s *TestSuite) TestFaucet_Credit() { | ||
s.T().Log("running test for /credit endpoint for faucet") | ||
|
||
// expected amount to be credited via faucet | ||
expCreditedAmt := float64(10000000000) | ||
|
||
for _, chain := range s.config.Chains { | ||
s.Run(fmt.Sprintf("facuet test for: %s", chain.Name), func() { | ||
if chain.Ports.Faucet == 0 { | ||
s.T().Skip("faucet not exposed via ports") | ||
} | ||
|
||
// fetch denom and address from an account on chain | ||
accounts := s.getChainAccounts(chain) | ||
denom := s.getChainDenoms(chain) | ||
addr := accounts[len(accounts)-1] | ||
beforeBalance := s.getAccountBalance(chain, addr, denom) | ||
|
||
body := map[string]string{ | ||
"denom": denom, | ||
"address": addr, | ||
} | ||
postBody, err := json.Marshal(body) | ||
s.Require().NoError(err) | ||
resp, err := http.Post( | ||
fmt.Sprintf("http://0.0.0.0:%d/credit", chain.Ports.Faucet), | ||
"application/json", | ||
bytes.NewBuffer(postBody)) | ||
s.Require().NoError(err) | ||
s.Require().Equal(200, resp.StatusCode) | ||
|
||
afterBalance := s.getAccountBalance(chain, addr, denom) | ||
|
||
// note sometimes expected difference is 9x expected value (bug due to using holder address for test) | ||
// hence checking for difference is atleast expected value | ||
s.Require().GreaterOrEqual(afterBalance-beforeBalance, expCreditedAmt) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters