Skip to content

Commit

Permalink
test: parsing result of query hermes pending packets (#2571)
Browse files Browse the repository at this point in the history
* fix: e2e test

* fix: parsing hermes pending packet query result

* fix: rename response RelayerPacketsOutput
  • Loading branch information
yaruwangway authored Jun 9, 2023
1 parent 9e111ce commit e42e13f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions tests/e2e/e2e_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ func (s *IntegrationTestSuite) executeGaiaTxCommand(ctx context.Context, c *chai
}
}

func (s *IntegrationTestSuite) executeHermesCommand(ctx context.Context, hermesCmd []string) (string, string) {
func (s *IntegrationTestSuite) executeHermesCommand(ctx context.Context, hermesCmd []string) ([]byte, []byte) {
var (
outBuf bytes.Buffer
errBuf bytes.Buffer
Expand All @@ -643,7 +643,7 @@ func (s *IntegrationTestSuite) executeHermesCommand(ctx context.Context, hermesC
stdOut := outBuf.Bytes()
stdErr := errBuf.Bytes()

return string(stdOut), string(stdErr)
return stdOut, stdErr
}

func (s *IntegrationTestSuite) expectErrExecValidation(chain *chain, valIdx int, expectErr bool) func([]byte, []byte) bool {
Expand Down
27 changes: 21 additions & 6 deletions tests/e2e/e2e_ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ func (s *IntegrationTestSuite) hermesTransfer(configPath, srcChainID, dstChainID
}

stdout, stderr := s.executeHermesCommand(ctx, hermesCmd)
if strings.Contains(stdout, "ERROR") || strings.Contains(stderr, "ERROR") {
if strings.Contains(string(stdout), "ERROR") || strings.Contains(string(stderr), "ERROR") {
return false
}

return true
}

func (s *IntegrationTestSuite) hermesClearPacket(configPath, chainID, channelID string) bool { //nolint:unparam
func (s *IntegrationTestSuite) hermesClearPacket(configPath, chainID, channelID string) (success bool) { //nolint:unparam
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

Expand All @@ -98,18 +98,31 @@ func (s *IntegrationTestSuite) hermesClearPacket(configPath, chainID, channelID
}

stdout, stderr := s.executeHermesCommand(ctx, hermesCmd)
if strings.Contains(stdout, "ERROR") || strings.Contains(stderr, "ERROR") {
if strings.Contains(string(stdout), "ERROR") || strings.Contains(string(stderr), "ERROR") {
return false
}

return true
}

type RelayerPacketsOutput struct {
Result struct {
Dst struct {
UnreceivedPackets []interface{} `json:"unreceived_packets"`
} `json:"dst"`
Src struct {
UnreceivedPackets []interface{} `json:"unreceived_packets"`
} `json:"src"`
} `json:"result"`
Status string `json:"status"`
}

func (s *IntegrationTestSuite) hermesPendingPackets(configPath, chainID, channelID string) (pendingPackets bool) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
hermesCmd := []string{
hermesBinary,
"--json",
fmt.Sprintf("--config=%s", configPath),
"query",
"packet",
Expand All @@ -120,11 +133,13 @@ func (s *IntegrationTestSuite) hermesPendingPackets(configPath, chainID, channel
}

stdout, _ := s.executeHermesCommand(ctx, hermesCmd)
stdout = strings.ReplaceAll(stdout, " ", "")
stdout = strings.ReplaceAll(stdout, "\n", "")

var relayerPacketsOutput RelayerPacketsOutput
err := json.Unmarshal(stdout, &relayerPacketsOutput)
s.Require().NoError(err)

// Check if "unreceived_packets" exists in "src"
return !strings.Contains(stdout, "src:pendingPackets{unreceived_packets:[]")
return len(relayerPacketsOutput.Result.Src.UnreceivedPackets) != 0
}

func (s *IntegrationTestSuite) queryRelayerWalletsBalances() (sdk.Coin, sdk.Coin) {
Expand Down

0 comments on commit e42e13f

Please sign in to comment.