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

fix: missing event emissions(EventSetSwap, EventAddDenomMetadata) (backport #1385) #1386

Merged
merged 2 commits into from
May 20, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/fswap) [\#1365](https://github.com/Finschia/finschia-sdk/pull/1365) fix update swap keys for possibly overlapped keys(`(hello,world) should be different to (hel,loworld)`)
* (x/fswap) [\#1379](https://github.com/Finschia/finschia-sdk/pull/1379) add missing router registration
* (x/fswap, x/fbridge) [\#1380](https://github.com/Finschia/finschia-sdk/pull/1380) Fix bug where amino is not supported in fswap and fbridge (backport #1378)
* (x/fswap) [\#1385](https://github.com/Finschia/finschia-sdk/pull/1385) add accidentally deleted event emissions(EventSetSwap, EventAddDenomMetadata)

### Removed

Expand Down
6 changes: 3 additions & 3 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@

- [lbm/fswap/v1/event.proto](#lbm/fswap/v1/event.proto)
- [EventAddDenomMetadata](#lbm.fswap.v1.EventAddDenomMetadata)
- [EventMakeSwap](#lbm.fswap.v1.EventMakeSwap)
- [EventSetSwap](#lbm.fswap.v1.EventSetSwap)
- [EventSwapCoins](#lbm.fswap.v1.EventSwapCoins)

- [lbm/fswap/v1/genesis.proto](#lbm/fswap/v1/genesis.proto)
Expand Down Expand Up @@ -14636,9 +14636,9 @@ Msg defines the foundation Msg service.



<a name="lbm.fswap.v1.EventMakeSwap"></a>
<a name="lbm.fswap.v1.EventSetSwap"></a>

### EventMakeSwap
### EventSetSwap



Expand Down
2 changes: 1 addition & 1 deletion proto/lbm/fswap/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ message EventSwapCoins {
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
}

message EventMakeSwap {
message EventSetSwap {
Swap swap = 1 [(gogoproto.nullable) = false];
}

Expand Down
8 changes: 8 additions & 0 deletions x/fswap/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,17 @@
return err
}

eventManager := ctx.EventManager()
if err := eventManager.EmitTypedEvent(&types.EventSetSwap{Swap: swap}); err != nil {
panic(err)

Check warning on line 150 in x/fswap/keeper/keeper.go

View check run for this annotation

Codecov / codecov/patch

x/fswap/keeper/keeper.go#L150

Added line #L150 was not covered by tests
}

existingMetadata, ok := k.GetDenomMetaData(ctx, swap.ToDenom)
if !ok {
k.SetDenomMetaData(ctx, toDenomMetadata)
if err := eventManager.EmitTypedEvent(&(types.EventAddDenomMetadata{Metadata: toDenomMetadata})); err != nil {
panic(err)

Check warning on line 157 in x/fswap/keeper/keeper.go

View check run for this annotation

Codecov / codecov/patch

x/fswap/keeper/keeper.go#L157

Added line #L157 was not covered by tests
}
return nil
}
if !denomMetadataEqual(existingMetadata, toDenomMetadata) {
Expand Down
31 changes: 29 additions & 2 deletions x/fswap/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/Finschia/finschia-sdk/crypto/keys/secp256k1"
Expand Down Expand Up @@ -194,6 +195,7 @@ func (s *KeeperTestSuite) TestSetSwap() {
toDenomMeta bank.Metadata
existingMetadata bool
expectedError error
expectedEvents sdk.Events
}{
"valid": {
types.Swap{
Expand All @@ -205,6 +207,28 @@ func (s *KeeperTestSuite) TestSetSwap() {
s.toDenomMetadata,
false,
nil,
sdk.Events{
sdk.Event{
Type: "lbm.fswap.v1.EventSetSwap",
Attributes: []abci.EventAttribute{
{
Key: []byte("swap"),
Value: []uint8{0x7b, 0x22, 0x66, 0x72, 0x6f, 0x6d, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x66, 0x72, 0x6f, 0x6d, 0x44, 0x22, 0x2c, 0x22, 0x74, 0x6f, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x74, 0x6f, 0x44, 0x22, 0x2c, 0x22, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x63, 0x61, 0x70, 0x5f, 0x66, 0x6f, 0x72, 0x5f, 0x74, 0x6f, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x31, 0x22, 0x2c, 0x22, 0x73, 0x77, 0x61, 0x70, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x22, 0x3a, 0x22, 0x31, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x22, 0x7d},
Index: false,
},
},
},
sdk.Event{
Type: "lbm.fswap.v1.EventAddDenomMetadata",
Attributes: []abci.EventAttribute{
{
Key: []byte("metadata"),
Value: []uint8{0x7b, 0x22, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 0x22, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x2d, 0x63, 0x6f, 0x69, 0x6e, 0x22, 0x2c, 0x22, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x5f, 0x75, 0x6e, 0x69, 0x74, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x74, 0x6f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x2c, 0x22, 0x65, 0x78, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x65, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x5d, 0x2c, 0x22, 0x62, 0x61, 0x73, 0x65, 0x22, 0x3a, 0x22, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x22, 0x2c, 0x22, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x22, 0x3a, 0x22, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x63, 0x6f, 0x69, 0x6e, 0x22, 0x2c, 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x3a, 0x22, 0x44, 0x55, 0x4d, 0x4d, 0x59, 0x22, 0x2c, 0x22, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x22, 0x3a, 0x22, 0x44, 0x55, 0x4d, 0x22, 0x7d},
Index: false,
},
},
},
},
},
"to-denom metadata change not allowed": {
types.Swap{
Expand All @@ -223,6 +247,7 @@ func (s *KeeperTestSuite) TestSetSwap() {
},
true,
sdkerrors.ErrInvalidRequest,
sdk.Events{},
},
}
for name, tc := range testCases {
Expand All @@ -232,9 +257,11 @@ func (s *KeeperTestSuite) TestSetSwap() {
if tc.existingMetadata {
err := s.keeper.SetSwap(ctx, tc.swap, s.toDenomMetadata)
s.Require().ErrorIs(err, tc.expectedError)
} else {
s.Require().ErrorIs(err, tc.expectedError)
return
}
s.Require().ErrorIs(err, tc.expectedError)
events := ctx.EventManager().Events()
s.Require().Equal(tc.expectedEvents, events)
})
}
}
Expand Down
98 changes: 49 additions & 49 deletions x/fswap/types/event.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading