Skip to content

Commit

Permalink
fix: missing event emissions(EventSetSwap, EventAddDenomMetadata) (#1385
Browse files Browse the repository at this point in the history
)

* fix: missing event emissions(EventSetSwap, EventAddDenomMetadata)

* chore: update changelog

(cherry picked from commit baab526)

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
jaeseung-bae authored and mergify[bot] committed May 17, 2024
1 parent 2b4474c commit ed368fa
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/fbridge) [\#1361](https://github.com/Finschia/finschia-sdk/pull/1361) Fixes fbridge auth checking bug
* (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
<<<<<<< HEAD
* (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)
>>>>>>> baab52684 (fix: missing event emissions(EventSetSwap, EventAddDenomMetadata) (#1385))
### 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 @@ func (k Keeper) SetSwap(ctx sdk.Context, swap types.Swap, toDenomMetadata bank.M
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.

0 comments on commit ed368fa

Please sign in to comment.