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

feat(server/v2): refactor the server/v2 events #21785

Merged
merged 11 commits into from
Sep 18, 2024
Prev Previous commit
Next Next commit
fix bank test
  • Loading branch information
cool-develope committed Sep 18, 2024
commit dd9b2191d3566075ab115b314a1e3937cb134772
78 changes: 39 additions & 39 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1377,30 +1377,26 @@ func (suite *KeeperTestSuite) TestMsgSendEvents() {
suite.mockSendCoins(suite.ctx, acc0, accAddrs[1])
require.NoError(suite.bankKeeper.SendCoins(suite.ctx, accAddrs[0], accAddrs[1], newCoins))
event1 := coreevent.Event{
Type: banktypes.EventTypeTransfer,
Attributes: []coreevent.Attribute{},
Type: banktypes.EventTypeTransfer,
Attributes: func() ([]coreevent.Attribute, error) {
return []coreevent.Attribute{
{Key: banktypes.AttributeKeyRecipient, Value: acc1StrAddr},
{Key: banktypes.AttributeKeySender, Value: acc0StrAddr},
{Key: sdk.AttributeKeyAmount, Value: newCoins.String()},
}, nil
},
}
event1.Attributes = append(
event1.Attributes,
coreevent.Attribute{Key: banktypes.AttributeKeyRecipient, Value: acc1StrAddr},
)
event1.Attributes = append(
event1.Attributes,
coreevent.Attribute{Key: banktypes.AttributeKeySender, Value: acc0StrAddr},
)
event1.Attributes = append(
event1.Attributes,
coreevent.Attribute{Key: sdk.AttributeKeyAmount, Value: newCoins.String()},
)

ctx := sdk.UnwrapSDKContext(suite.ctx)
// events are shifted due to the funding account events
events := ctx.EventManager().Events()
require.Equal(8, len(events))
require.Equal(event1.Type, events[7].Type)
for i := range event1.Attributes {
require.Equal(event1.Attributes[i].Key, events[7].Attributes[i].Key)
require.Equal(event1.Attributes[i].Value, events[7].Attributes[i].Value)
attrs, err := event1.Attributes()
require.NoError(err)
for i := range attrs {
require.Equal(attrs[i].Key, events[7].Attributes[i].Key)
require.Equal(attrs[i].Value, events[7].Attributes[i].Value)
}
}

Expand Down Expand Up @@ -1462,36 +1458,40 @@ func (suite *KeeperTestSuite) TestMsgMultiSendEvents() {
require.Equal(25, len(events)) // 25 due to account funding + coin_spent + coin_recv events

event1 := coreevent.Event{
Type: banktypes.EventTypeTransfer,
Attributes: []coreevent.Attribute{},
Type: banktypes.EventTypeTransfer,
Attributes: func() ([]coreevent.Attribute, error) {
return []coreevent.Attribute{
{Key: banktypes.AttributeKeyRecipient, Value: acc2StrAddr},
{Key: sdk.AttributeKeySender, Value: acc0StrAddr},
{Key: sdk.AttributeKeyAmount, Value: newCoins.String()},
}, nil
},
}
event1.Attributes = append(
event1.Attributes,
coreevent.Attribute{Key: banktypes.AttributeKeyRecipient, Value: acc2StrAddr},
coreevent.Attribute{Key: sdk.AttributeKeySender, Value: acc0StrAddr},
coreevent.Attribute{Key: sdk.AttributeKeyAmount, Value: newCoins.String()},
)

event2 := coreevent.Event{
Type: banktypes.EventTypeTransfer,
Attributes: []coreevent.Attribute{},
Type: banktypes.EventTypeTransfer,
Attributes: func() ([]coreevent.Attribute, error) {
attrs := []coreevent.Attribute{
{Key: banktypes.AttributeKeyRecipient, Value: acc3StrAddr},
{Key: sdk.AttributeKeySender, Value: acc0StrAddr},
{Key: sdk.AttributeKeyAmount, Value: newCoins2.String()},
}
return attrs, nil
},
}
event2.Attributes = append(
event2.Attributes,
coreevent.Attribute{Key: banktypes.AttributeKeyRecipient, Value: acc3StrAddr},
coreevent.Attribute{Key: sdk.AttributeKeySender, Value: acc0StrAddr},
coreevent.Attribute{Key: sdk.AttributeKeyAmount, Value: newCoins2.String()},
)
// events are shifted due to the funding account events
require.Equal(event1.Type, events[22].Type)
for i := range event1.Attributes {
require.Equal(event1.Attributes[i].Key, events[22].Attributes[i].Key)
require.Equal(event1.Attributes[i].Value, events[22].Attributes[i].Value)
attrs1, err := event1.Attributes()
require.NoError(err)
for i := range attrs1 {
require.Equal(attrs1[i].Key, events[22].Attributes[i].Key)
require.Equal(attrs1[i].Value, events[22].Attributes[i].Value)
}
require.Equal(event2.Type, events[24].Type)
for i := range event2.Attributes {
require.Equal(event2.Attributes[i].Key, events[24].Attributes[i].Key)
require.Equal(event2.Attributes[i].Value, events[24].Attributes[i].Value)
attrs2, err := event2.Attributes()
for i := range attrs2 {
require.Equal(attrs2[i].Key, events[24].Attributes[i].Key)
require.Equal(attrs2[i].Value, events[24].Attributes[i].Value)
}
}

Expand Down
Loading