-
Notifications
You must be signed in to change notification settings - Fork 715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: parsing result of query hermes pending packets #2571
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the strings.Contains function is case sensitive, so reporting like 'Error', 'error', won't give you the result that you expected. Its more defensive to make everything a certain case, and then check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, this relayer output should also be parsed using JSON. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is not possible to be parsed in json, the stderr looks like :
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what I was suggesting, making this lower-case:
... and check against '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() | ||
|
||
|
@@ -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") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. |
||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
type Response struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would rename this type to sthg more self-explantory like |
||
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", | ||
|
@@ -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 response Response | ||
err := json.Unmarshal(stdout, &response) | ||
s.Require().NoError(err) | ||
|
||
// Check if "unreceived_packets" exists in "src" | ||
return !strings.Contains(stdout, "src:pendingPackets{unreceived_packets:[]") | ||
return len(response.Result.Src.UnreceivedPackets) != 0 | ||
} | ||
|
||
func (s *IntegrationTestSuite) queryRelayerWalletsBalances() (sdk.Coin, sdk.Coin) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change from string to bytes here? You have a string comparison later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is for unmarshal json from byte, otherwise, unmarshal has to convert string to byte