Skip to content
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

Merged
merged 3 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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

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") {
Copy link
Contributor

@mmulji-ic mmulji-ic Jun 9, 2023

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, this relayer output should also be parsed using JSON.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 :

2023-06-09T09:07:53.349739Z  INFO ThreadId(01) PacketRecvCmd{src_chain=chain-3Yoz03 src_port=transfer src_channel=channel-0 dst_chain=chain-c0lUEe}: unreceived packets found: 1
2023-06-09T09:07:53.362954Z  INFO ThreadId(01) PacketRecvCmd{src_chain=chain-3Yoz03 src_port=transfer src_channel=channel-0 dst_chain=chain-c0lUEe}: pulled packet data for 1 events; events_total=1 events_left=0
2023-06-09T09:07:53.697419Z  INFO ThreadId(01) PacketRecvCmd{src_chain=chain-3Yoz03 src_port=transfer src_channel=channel-0 dst_chain=chain-c0lUEe}:relay{odata=packet-recv ->Source @0-176; len=1}: assembled batch of 2 message(s)
2023-06-09T09:07:53.743368Z ERROR ThreadId(07) send_tx_with_account_sequence_retry{id=chain-3Yoz03}: broadcast_tx_sync: Response { code: Err(13), data: Data([]), log: Log("Insufficient fees; got: 0uatom required: 2uatom: insufficient fee"), hash: transaction::Hash(AF2B36D5298C6E79B233C0E10D8F7316307D47EE28AD231CBE6AFA56010F52D3) }: diagnostic: the price configuration for this chain may be too low! please check the `gas_price.price` Hermes config.toml
2023-06-09T09:07:53.746010Z  INFO ThreadId(07) wait_for_block_commits: waiting for commit of tx hashes(s) AF2B36D5298C6E79B233C0E10D8F7316307D47EE28AD231CBE6AFA56010F52D3 id=chain-3Yoz03
2023-06-09T09:07:53.746997Z  INFO ThreadId(01) PacketRecvCmd{src_chain=chain-3Yoz03 src_port=transfer src_channel=channel-0 dst_chain=chain-c0lUEe}:relay{odata=packet-recv ->Source @0-176; len=1}: [Sync->chain-3Yoz03] result events:
	ChainErrorEv(check_tx (broadcast_tx_sync) on chain chain-3Yoz03 for Tx hash AF2B36D5298C6E79B233C0E10D8F7316307D47EE28AD231CBE6AFA56010F52D3 reports error: code=Err(13), log=Log("Insufficient fees; got: 0uatom required: 2uatom: insufficient fee"))
	ChainErrorEv(check_tx (broadcast_tx_sync) on chain chain-3Yoz03 for Tx hash AF2B36D5298C6E79B233C0E10D8F7316307D47EE28AD231CBE6AFA56010F52D3 reports error: code=Err(13), log=Log("Insufficient fees; got: 0uatom required: 2uatom: insufficient fee"))
	```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I was suggesting, making this lower-case:

strings.Contains(strings.ToLower(string(stdout)) , "error")

... 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()

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") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

return false
}

return true
}

type Response struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would rename this type to sthg more self-explantory like RelayerPacketsOutput.

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 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) {
Expand Down