Skip to content

Commit

Permalink
Add ParseProposalIDFromEvents helper function (#4942)
Browse files Browse the repository at this point in the history
* add ParseProposalIDFromEvents

* update with damian suggest
  • Loading branch information
ThanhNhann authored Oct 25, 2023
1 parent 75da9f5 commit 658b00f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
12 changes: 2 additions & 10 deletions testing/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ibctesting

import (
"fmt"
"strconv"
"strings"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -619,15 +618,8 @@ func (endpoint *Endpoint) ChanUpgradeInit() error {
return err
}

events := res.Events
for _, event := range events {
for _, attribute := range event.Attributes {
if attribute.Key == "proposal_id" {
proposalID, err = strconv.ParseUint(attribute.Value, 10, 64)
require.NoError(endpoint.Chain.TB, err)
}
}
}
proposalID, err = ParseProposalIDFromEvents(res.Events)
require.NoError(endpoint.Chain.TB, err)

return VoteAndCheckProposalStatus(endpoint, proposalID)
}
Expand Down
13 changes: 13 additions & 0 deletions testing/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ func ParseAckFromEvents(events []abci.Event) ([]byte, error) {
return nil, fmt.Errorf("acknowledgement event attribute not found")
}

// ParseProposalIDFromEvents parses events emitted from MsgSubmitProposal and returns proposalID
func ParseProposalIDFromEvents(events []abci.Event) (uint64, error) {
for _, event := range events {
for _, attribute := range event.Attributes {
if attribute.Key == "proposal_id" {
return strconv.ParseUint(attribute.Value, 10, 64)
}
}
}

return 0, fmt.Errorf("proposalID event attribute not found")
}

// AssertEventsLegacy asserts that expected events are present in the actual events.
// Expected map needs to be a subset of actual events to pass.
func AssertEventsLegacy(
Expand Down

0 comments on commit 658b00f

Please sign in to comment.