diff --git a/e2e/tests/interchain_accounts/query_test.go b/e2e/tests/interchain_accounts/query_test.go index abb66031709..3159d1e91e6 100644 --- a/e2e/tests/interchain_accounts/query_test.go +++ b/e2e/tests/interchain_accounts/query_test.go @@ -110,34 +110,21 @@ func (s *InterchainAccountsQueryTestSuite) TestInterchainAccountsQuery() { s.Require().NoError(err) s.Require().Len(txSearchRes.Txs, 1) - // get acknowledgement - ackFound := false - ack := &channeltypes.Acknowledgement_Result{} - - search_ack: - for _, event := range txSearchRes.Txs[0].Events { - if event.Type != channeltypes.EventTypeWriteAck { - continue - } - - for _, attr := range event.Attributes { - if attr.Key != channeltypes.AttributeKeyAckHex { - continue - } - - ackBz, err := hex.DecodeString(attr.Value) - s.Require().NoError(err) + ackHexValue, isFound := s.ExtractValueFromEvents( + txSearchRes.Txs[0].Events, + channeltypes.EventTypeWriteAck, + channeltypes.AttributeKeyAckHex, + ) - err = json.Unmarshal(ackBz, ack) - s.Require().NoError(err) + s.Require().True(isFound) + s.Require().NotEmpty(ackHexValue) - ackFound = true + ack := &channeltypes.Acknowledgement_Result{} + ackBz, err := hex.DecodeString(ackHexValue) + s.Require().NoError(err) - break search_ack - } - } - s.Require().True(ackFound) - s.Require().NotZero(ack) + err = json.Unmarshal(ackBz, ack) + s.Require().NoError(err) // unmarshal the ica response icaAck := &sdk.TxMsgData{} diff --git a/e2e/testsuite/tx.go b/e2e/testsuite/tx.go index 1f92600a1f4..c172fd695c6 100644 --- a/e2e/testsuite/tx.go +++ b/e2e/testsuite/tx.go @@ -24,6 +24,8 @@ import ( govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/ibc-go/e2e/testsuite/sanitize" "github.com/cosmos/ibc-go/e2e/testvalues" feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" @@ -331,3 +333,24 @@ func (*E2ETestSuite) QueryTxsByEvents( return result, nil } + +// ExtractValueFromEvents extracts the value of an attribute from a list of events. +// If the attribute is not found, the function returns an empty string and false. +// If the attribute is found, the function returns the value and true. +func (*E2ETestSuite) ExtractValueFromEvents(events []abci.Event, eventType, attrKey string) (string, bool) { + for _, event := range events { + if event.Type != eventType { + continue + } + + for _, attr := range event.Attributes { + if attr.Key != attrKey { + continue + } + + return attr.Value, true + } + } + + return "", false +}