Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -26,6 +26,7 @@
- [\#774](https://github.com/cosmos/evm/pull/774) Emit proper allowance amount in erc20 event.
- [\#790](https://github.com/cosmos/evm/pull/790) fix panic in historical query due to missing EvmCoinInfo.
- [\#800](https://github.com/cosmos/evm/pull/800) Fix denom exponent validation in virtual fee deduct in vm module.
- [\#814](https://github.com/cosmos/evm/pull/814) Fix duplicated events in post tx processor.

## v0.5.0

Expand Down
19 changes: 18 additions & 1 deletion tests/integration/x/vm/test_state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,13 @@ func (s *KeeperTestSuite) TestApplyTransactionWithTxPostProcessing() {
keeper.NewMultiEvmHooks(
&testHooks{
postProcessing: func(ctx sdk.Context, sender common.Address, msg core.Message, receipt *gethtypes.Receipt) error {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
"test_post_processing_event",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this a const?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

sdk.NewAttribute("sender", sender.Hex()),
sdk.NewAttribute("tx_hash", hexutil.Encode(receipt.TxHash.Bytes())),
),
)
return nil
},
},
Expand Down Expand Up @@ -684,7 +691,17 @@ func (s *KeeperTestSuite) TestApplyTransactionWithTxPostProcessing() {
s.Require().Equal(senderBefore.Sub(sdkmath.NewIntFromBigInt(transferAmt)), senderAfter)
s.Require().Equal(recipientBefore.Add(sdkmath.NewIntFromBigInt(transferAmt)), recipientAfter)
},
func(s *KeeperTestSuite) {},
func(s *KeeperTestSuite) {
// check if the event emitted exactly once
events := s.Network.GetContext().EventManager().Events()
var postProcessingEvents []sdk.Event
for _, event := range events {
if event.Type == "test_post_processing_event" {
postProcessingEvents = append(postProcessingEvents, event)
}
}
s.Require().Len(postProcessingEvents, 1)
},
},
{
"pass - evm tx succeeds, post processing is called but fails, the balance is unchanged",
Expand Down
7 changes: 0 additions & 7 deletions x/vm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t
return nil, errorsmod.Wrap(err, "failed to extract sender address from ethereum transaction")
}

eventsLen := len(tmpCtx.EventManager().Events())

// Only call PostTxProcessing if there are hooks set, to avoid calling commitFn unnecessarily
if !k.HasHooks() {
// If there are no hooks, we can commit the state immediately if the tx is successful
Expand Down Expand Up @@ -297,11 +295,6 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t
} else {
res.Logs = types.NewLogsFromEth(receipt.Logs)
}

events := tmpCtx.EventManager().Events()
if len(events) > eventsLen {
ctx.EventManager().EmitEvents(events[eventsLen:])
}
}
}

Expand Down
Loading