Skip to content

Commit

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

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

* fix: missing event emissions(EventSetSwap, EventAddDenomMetadata)

* chore: update changelog

(cherry picked from commit baab526)

# Conflicts:
#	CHANGELOG.md

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

* fix: missing event emissions(EventSetSwap, EventAddDenomMetadata)

* chore: update changelog

---------

Co-authored-by: jaeseung-bae <[email protected]>
  • Loading branch information
mergify[bot] and jaeseung-bae authored May 20, 2024
1 parent 2b4474c commit 27c7599
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 55 deletions.
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 @@ 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)
}

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)
}
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 27c7599

Please sign in to comment.