-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…5574) * imp(core): allow huckleberry events with a prefix (#5541) * feat: initial impl * imp: moved event helpers to types and added tests * imp(testing): added mock events to mock module * test: added msg_server tests for application events * imp: converted suffix to prefix * docs: updated inline comments * imp: review item * test: review items * imp: review items (cherry picked from commit 2375109) # Conflicts: # modules/core/keeper/msg_server.go # modules/core/keeper/msg_server_test.go * fix: merge conflicts * nit * ci: removed link checker --------- Co-authored-by: srdtrk <59252793+srdtrk@users.noreply.github.com> Co-authored-by: srdtrk <srdtrk@hotmail.com>
- Loading branch information
1 parent
bef2278
commit 825fe90
Showing
9 changed files
with
258 additions
and
53 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/ibc-go/v7/modules/core/keeper" | ||
"github.com/cosmos/ibc-go/v7/modules/core/types" | ||
) | ||
|
||
func TestConvertToErrorEvents(t *testing.T) { | ||
var ( | ||
events sdk.Events | ||
expEvents sdk.Events | ||
) | ||
|
||
tc := []struct { | ||
name string | ||
malleate func() | ||
}{ | ||
{ | ||
"success: nil events", | ||
func() { | ||
events = nil | ||
expEvents = nil | ||
}, | ||
}, | ||
{ | ||
"success: empty events", | ||
func() { | ||
events = sdk.Events{} | ||
expEvents = sdk.Events{} | ||
}, | ||
}, | ||
{ | ||
"success: event with no attributes", | ||
func() { | ||
events = sdk.Events{ | ||
sdk.NewEvent("testevent"), | ||
} | ||
expEvents = sdk.Events{ | ||
sdk.NewEvent(types.ErrorAttributeKeyPrefix + "testevent"), | ||
} | ||
}, | ||
}, | ||
{ | ||
"success: event with attributes", | ||
func() { | ||
events = sdk.Events{ | ||
sdk.NewEvent("testevent", | ||
sdk.NewAttribute("key1", "value1"), | ||
sdk.NewAttribute("key2", "value2"), | ||
), | ||
} | ||
expEvents = sdk.Events{ | ||
sdk.NewEvent(types.ErrorAttributeKeyPrefix+"testevent", | ||
sdk.NewAttribute(types.ErrorAttributeKeyPrefix+"key1", "value1"), | ||
sdk.NewAttribute(types.ErrorAttributeKeyPrefix+"key2", "value2"), | ||
), | ||
} | ||
}, | ||
}, | ||
{ | ||
"success: multiple events with attributes", | ||
func() { | ||
events = sdk.Events{ | ||
sdk.NewEvent("testevent1", | ||
sdk.NewAttribute("key1", "value1"), | ||
sdk.NewAttribute("key2", "value2"), | ||
), | ||
sdk.NewEvent("testevent2", | ||
sdk.NewAttribute("key3", "value3"), | ||
sdk.NewAttribute("key4", "value4"), | ||
), | ||
} | ||
expEvents = sdk.Events{ | ||
sdk.NewEvent(types.ErrorAttributeKeyPrefix+"testevent1", | ||
sdk.NewAttribute(types.ErrorAttributeKeyPrefix+"key1", "value1"), | ||
sdk.NewAttribute(types.ErrorAttributeKeyPrefix+"key2", "value2"), | ||
), | ||
sdk.NewEvent(types.ErrorAttributeKeyPrefix+"testevent2", | ||
sdk.NewAttribute(types.ErrorAttributeKeyPrefix+"key3", "value3"), | ||
sdk.NewAttribute(types.ErrorAttributeKeyPrefix+"key4", "value4"), | ||
), | ||
} | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range tc { | ||
t.Run(tc.name, func(t *testing.T) { | ||
// initial events and expected events are reset so that the test fails if | ||
// the malleate function does not set them | ||
events = nil | ||
expEvents = sdk.Events{} | ||
|
||
tc.malleate() | ||
|
||
newEvents := keeper.ConvertToErrorEvents(events) | ||
require.Equal(t, expEvents, newEvents) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package keeper | ||
|
||
import sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
// ConvertToErrorEvents is a wrapper around convertToErrorEvents | ||
// to allow the function to be directly called in tests. | ||
func ConvertToErrorEvents(events sdk.Events) sdk.Events { | ||
return convertToErrorEvents(events) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.