Skip to content

Commit

Permalink
Fix invalid tests to look in response for events
Browse files Browse the repository at this point in the history
  • Loading branch information
iramiller committed Apr 30, 2021
1 parent 136822e commit 0297f14
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions x/attribute/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ type CommonTest struct {
expectedEvent proto.Message
}

func (s HandlerTestSuite) containsMessage(msg proto.Message) bool {
events := s.ctx.EventManager().Events().ToABCIEvents()
func (s HandlerTestSuite) containsMessage(result *sdk.Result, msg proto.Message) bool {
events := result.GetEvents().ToABCIEvents()
for _, event := range events {
typeEvent, _ := sdk.ParseTypedEvent(event)
if assert.ObjectsAreEqual(msg, typeEvent) {
Expand All @@ -89,13 +89,13 @@ func (s HandlerTestSuite) containsMessage(msg proto.Message) bool {
func (s HandlerTestSuite) runTests(cases []CommonTest) {
for _, tc := range cases {
s.T().Run(tc.name, func(t *testing.T) {
_, err := s.handler(s.ctx, tc.msg)
response, err := s.handler(s.ctx, tc.msg)

if len(tc.errorMsg) > 0 {
assert.EqualError(t, err, tc.errorMsg)
} else {
if tc.expectedEvent != nil {
result := s.containsMessage(tc.expectedEvent)
result := s.containsMessage(response, tc.expectedEvent)
s.True(result, fmt.Sprintf("Expected typed event was not found: %v", tc.expectedEvent))
}

Expand Down
8 changes: 4 additions & 4 deletions x/marker/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func TestInvalidProposal(t *testing.T) {
require.True(t, strings.Contains(err.Error(), "unrecognized marker proposal content type: *types.TextProposal"))
}

func (s HandlerTestSuite) containsMessage(msg proto.Message) bool {
events := s.ctx.EventManager().Events().ToABCIEvents()
func (s HandlerTestSuite) containsMessage(result *sdk.Result, msg proto.Message) bool {
events := result.GetEvents().ToABCIEvents()
for _, event := range events {
typeEvent, _ := sdk.ParseTypedEvent(event)
if assert.ObjectsAreEqual(msg, typeEvent) {
Expand All @@ -103,13 +103,13 @@ type CommonTest struct {
func (s HandlerTestSuite) runTests(cases []CommonTest) {
for _, tc := range cases {
s.T().Run(tc.name, func(t *testing.T) {
_, err := s.handler(s.ctx, tc.msg)
response, err := s.handler(s.ctx, tc.msg)

if len(tc.errorMsg) > 0 {
assert.EqualError(t, err, tc.errorMsg)
} else {
if tc.expectedEvent != nil {
result := s.containsMessage(tc.expectedEvent)
result := s.containsMessage(response, tc.expectedEvent)
s.True(result, fmt.Sprintf("Expected typed event was not found: %v", tc.expectedEvent))
}

Expand Down
16 changes: 8 additions & 8 deletions x/name/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestCreateName(t *testing.T) {
accs := authtypes.GenesisAccounts{acc1}
app := simapp.SetupWithGenesisAccounts(accs)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
em := ctx.EventManager()

var nameData nametypes.GenesisState
nameData.Bindings = append(nameData.Bindings, nametypes.NewNameRecord("name", addr1, false))
nameData.Bindings = append(nameData.Bindings, nametypes.NewNameRecord("example.name", addr1, false))
Expand All @@ -80,15 +80,15 @@ func TestCreateName(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
_, err := handler(ctx, tc.msg)
response, err := handler(ctx, tc.msg)
if tc.expectedError != nil {
require.EqualError(t, err, tc.expectedError.Error())
} else {
require.NoError(t, err)
}
if tc.expectedEvent != nil {
require.Equal(t, 1, len(em.Events().ToABCIEvents()))
msg1, _ := sdk.ParseTypedEvent(em.Events().ToABCIEvents()[0])
require.Equal(t, 1, len(response.GetEvents().ToABCIEvents()))
msg1, _ := sdk.ParseTypedEvent(response.GetEvents().ToABCIEvents()[0])
require.Equal(t, tc.expectedEvent, msg1)
}
})
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestDeleteName(t *testing.T) {
accs := authtypes.GenesisAccounts{acc1}
app := simapp.SetupWithGenesisAccounts(accs)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
em := ctx.EventManager()

var nameData nametypes.GenesisState
nameData.Bindings = append(nameData.Bindings, nametypes.NewNameRecord("name", addr1, false))
nameData.Bindings = append(nameData.Bindings, nametypes.NewNameRecord("example.name", addr1, false))
Expand All @@ -144,15 +144,15 @@ func TestDeleteName(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
_, err := handler(ctx, tc.msg)
response, err := handler(ctx, tc.msg)
if tc.expectedError != nil {
require.EqualError(t, err, tc.expectedError.Error())
} else {
require.NoError(t, err)
}
if tc.expectedEvent != nil {
require.Equal(t, 1, len(em.Events().ToABCIEvents()))
msg1, _ := sdk.ParseTypedEvent(em.Events().ToABCIEvents()[0])
require.Equal(t, 1, len(response.GetEvents().ToABCIEvents()))
msg1, _ := sdk.ParseTypedEvent(response.GetEvents().ToABCIEvents()[0])
require.Equal(t, tc.expectedEvent, msg1)
}
})
Expand Down

0 comments on commit 0297f14

Please sign in to comment.