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

Add ParseProposalIDFromEvents helper function #4942

Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading