Skip to content

Commit

Permalink
fix: revert changes from TypedEvents (evmos#1600)
Browse files Browse the repository at this point in the history
* fix: revert changes from TypedEvents

* fix: formatter and linter

* fix: double quote to prevent globbing and word splitting

* fix: added token to codecov

* fix: re-added events.proto for usage later
  • Loading branch information
Vvaradinov authored Jan 11, 2023
1 parent 9003b6f commit 20c82d0
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 1,946 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
with:
file: ./coverage.txt
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
if: env.GIT_DIFF

test-importer:
Expand Down
4 changes: 2 additions & 2 deletions scripts/integration-test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# "stable" mode tests assume data is static
# "live" mode tests assume data dynamic

SCRIPT=$(basename ${BASH_SOURCE[0]})
SCRIPT=$(basename "${BASH_SOURCE[0]}")
TEST=""
QTD=1
SLEEP_TIMEOUT=5
Expand Down Expand Up @@ -145,7 +145,7 @@ echo "done sleeping"
set +e

if [[ -z $TEST || $TEST == "rpc" || $TEST == "pending" ]]; then
time_out=900s
time_out=300s
if [[ $TEST == "pending" ]]; then
time_out=60m0s
fi
Expand Down
179 changes: 88 additions & 91 deletions tests/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,37 +347,36 @@ func TestEth_IncompleteSendTransaction(t *testing.T) {
require.NotEqual(t, err.Error(), "method handler crashed", "no from field dealt with incorrectly")
}

// TODO: Investigate why it's failing
//func TestEth_GetFilterChanges_NoTopics(t *testing.T) {
// rpcRes := call(t, "eth_blockNumber", []string{})
//
// var res hexutil.Uint64
// err := res.UnmarshalJSON(rpcRes.Result)
// require.NoError(t, err)
//
// param := make([]map[string]interface{}, 1)
// param[0] = make(map[string]interface{})
// param[0]["topics"] = []string{}
// param[0]["fromBlock"] = res.String()
//
// // instantiate new filter
// rpcRes = call(t, "eth_newFilter", param)
// require.Nil(t, rpcRes.Error)
// var ID string
// err = json.Unmarshal(rpcRes.Result, &ID)
// require.NoError(t, err)
//
// // deploy contract, emitting some event
// deployTestContract(t)
//
// // get filter changes
// changesRes := call(t, "eth_getFilterChanges", []string{ID})
//
// var logs []*ethtypes.Log
// err = json.Unmarshal(changesRes.Result, &logs)
// require.NoError(t, err)
// require.Equal(t, 1, len(logs))
//}
func TestEth_GetFilterChanges_NoTopics(t *testing.T) {
rpcRes := call(t, "eth_blockNumber", []string{})

var res hexutil.Uint64
err := res.UnmarshalJSON(rpcRes.Result)
require.NoError(t, err)

param := make([]map[string]interface{}, 1)
param[0] = make(map[string]interface{})
param[0]["topics"] = []string{}
param[0]["fromBlock"] = res.String()

// instantiate new filter
rpcRes = call(t, "eth_newFilter", param)
require.Nil(t, rpcRes.Error)
var ID string
err = json.Unmarshal(rpcRes.Result, &ID)
require.NoError(t, err)

// deploy contract, emitting some event
deployTestContract(t)

// get filter changes
changesRes := call(t, "eth_getFilterChanges", []string{ID})

var logs []*ethtypes.Log
err = json.Unmarshal(changesRes.Result, &logs)
require.NoError(t, err)
require.Equal(t, 1, len(logs))
}

// hash of Hello event
var helloTopic = "0x775a94827b8fd9b519d36cd827093c664f93347070a554f65e4a6f56cd738898"
Expand Down Expand Up @@ -427,68 +426,66 @@ func deployTestContractWithFunction(t *testing.T) hexutil.Bytes {
return hash
}

// TODO: Investigate why it's failing
// Tests topics case where there are topics in first two positions
//func TestEth_GetFilterChanges_Topics_AB(t *testing.T) {
// rpcRes := call(t, "eth_blockNumber", []string{})
//
// var res hexutil.Uint64
// err := res.UnmarshalJSON(rpcRes.Result)
// require.NoError(t, err)
//
// param := make([]map[string]interface{}, 1)
// param[0] = make(map[string]interface{})
// param[0]["topics"] = []string{helloTopic, worldTopic}
// param[0]["fromBlock"] = res.String()
//
// // instantiate new filter
// rpcRes = call(t, "eth_newFilter", param)
// var ID string
// err = json.Unmarshal(rpcRes.Result, &ID)
// require.NoError(t, err, string(rpcRes.Result))
//
// deployTestContractWithFunction(t)
//
// // get filter changes
// changesRes := call(t, "eth_getFilterChanges", []string{ID})
//
// var logs []*ethtypes.Log
// err = json.Unmarshal(changesRes.Result, &logs)
// require.NoError(t, err)
//
// require.Equal(t, 1, len(logs))
//}
func TestEth_GetFilterChanges_Topics_AB(t *testing.T) {
rpcRes := call(t, "eth_blockNumber", []string{})

// TODO: Investigate why it's failing
//func TestEth_GetFilterChanges_Topics_XB(t *testing.T) {
// rpcRes := call(t, "eth_blockNumber", []string{})
//
// var res hexutil.Uint64
// err := res.UnmarshalJSON(rpcRes.Result)
// require.NoError(t, err)
//
// param := make([]map[string]interface{}, 1)
// param[0] = make(map[string]interface{})
// param[0]["topics"] = []interface{}{nil, worldTopic}
// param[0]["fromBlock"] = res.String()
//
// // instantiate new filter
// rpcRes = call(t, "eth_newFilter", param)
// var ID string
// err = json.Unmarshal(rpcRes.Result, &ID)
// require.NoError(t, err)
//
// deployTestContractWithFunction(t)
//
// // get filter changes
// changesRes := call(t, "eth_getFilterChanges", []string{ID})
//
// var logs []*ethtypes.Log
// err = json.Unmarshal(changesRes.Result, &logs)
// require.NoError(t, err)
//
// require.Equal(t, 1, len(logs))
//}
var res hexutil.Uint64
err := res.UnmarshalJSON(rpcRes.Result)
require.NoError(t, err)

param := make([]map[string]interface{}, 1)
param[0] = make(map[string]interface{})
param[0]["topics"] = []string{helloTopic, worldTopic}
param[0]["fromBlock"] = res.String()

// instantiate new filter
rpcRes = call(t, "eth_newFilter", param)
var ID string
err = json.Unmarshal(rpcRes.Result, &ID)
require.NoError(t, err, string(rpcRes.Result))

deployTestContractWithFunction(t)

// get filter changes
changesRes := call(t, "eth_getFilterChanges", []string{ID})

var logs []*ethtypes.Log
err = json.Unmarshal(changesRes.Result, &logs)
require.NoError(t, err)

require.Equal(t, 1, len(logs))
}

func TestEth_GetFilterChanges_Topics_XB(t *testing.T) {
rpcRes := call(t, "eth_blockNumber", []string{})

var res hexutil.Uint64
err := res.UnmarshalJSON(rpcRes.Result)
require.NoError(t, err)

param := make([]map[string]interface{}, 1)
param[0] = make(map[string]interface{})
param[0]["topics"] = []interface{}{nil, worldTopic}
param[0]["fromBlock"] = res.String()

// instantiate new filter
rpcRes = call(t, "eth_newFilter", param)
var ID string
err = json.Unmarshal(rpcRes.Result, &ID)
require.NoError(t, err)

deployTestContractWithFunction(t)

// get filter changes
changesRes := call(t, "eth_getFilterChanges", []string{ID})

var logs []*ethtypes.Log
err = json.Unmarshal(changesRes.Result, &logs)
require.NoError(t, err)

require.Equal(t, 1, len(logs))
}

func TestEth_PendingTransactionFilter(t *testing.T) {
rpcRes := call(t, "eth_newPendingTransactionFilter", []string{})
Expand Down
3 changes: 2 additions & 1 deletion x/evm/keeper/abci_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/tendermint/tendermint/abci/types"
)

Expand All @@ -13,5 +14,5 @@ func (suite *KeeperTestSuite) TestEndBlock() {

// should emit 1 EventTypeBlockBloom event on EndBlock
suite.Require().Equal(1, len(em.Events()))
suite.Require().Equal("ethermint.evm.v1.EventBlockBloom", em.Events()[0].Type)
suite.Require().Equal(evmtypes.EventTypeBlockBloom, em.Events()[0].Type)
}
12 changes: 5 additions & 7 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,12 @@ func (k Keeper) ChainID() *big.Int {

// EmitBlockBloomEvent emit block bloom events
func (k Keeper) EmitBlockBloomEvent(ctx sdk.Context, bloom ethtypes.Bloom) {
err := ctx.EventManager().EmitTypedEvent(
&types.EventBlockBloom{
Bloom: string(bloom.Bytes()),
},
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeBlockBloom,
sdk.NewAttribute(types.AttributeKeyEthereumBloom, string(bloom.Bytes())),
),
)
if err != nil {
k.Logger(ctx).Error(err.Error())
}
}

// GetAuthority returns the x/evm module authority address
Expand Down
50 changes: 27 additions & 23 deletions x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,52 +89,56 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
}
}()

eventEthereumTx := &types.EventEthereumTx{
Amount: tx.Value().String(),
attrs := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyAmount, tx.Value().String()),
// add event for ethereum transaction hash format
EthHash: response.Hash,
sdk.NewAttribute(types.AttributeKeyEthereumTxHash, response.Hash),
// add event for index of valid ethereum tx
Index: strconv.FormatUint(txIndex, 10),
sdk.NewAttribute(types.AttributeKeyTxIndex, strconv.FormatUint(txIndex, 10)),
// add event for eth tx gas used, we can't get it from cosmos tx result when it contains multiple eth tx msgs.
GasUsed: strconv.FormatUint(response.GasUsed, 10),
sdk.NewAttribute(types.AttributeKeyTxGasUsed, strconv.FormatUint(response.GasUsed, 10)),
}

if len(ctx.TxBytes()) > 0 {
// add event for tendermint transaction hash format
hash := tmbytes.HexBytes(tmtypes.Tx(ctx.TxBytes()).Hash())
eventEthereumTx.Hash = hash.String()
attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyTxHash, hash.String()))
}

if to := tx.To(); to != nil {
eventEthereumTx.Recipient = to.Hex()
attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyRecipient, to.Hex()))
}

if response.Failed() {
eventEthereumTx.EthTxFailed = response.VmError
attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyEthereumTxFailed, response.VmError))
}

eventTxLogs := &types.EventTxLog{TxLogs: make([]string, len(response.Logs))}
txLogAttrs := make([]sdk.Attribute, len(response.Logs))
for i, log := range response.Logs {
value, err := json.Marshal(log)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to encode log")
}
eventTxLogs.TxLogs[i] = string(value)
txLogAttrs[i] = sdk.NewAttribute(types.AttributeKeyTxLog, string(value))
}

err = ctx.EventManager().EmitTypedEvents(
eventEthereumTx,
eventTxLogs,
&types.EventMessage{
Module: types.AttributeValueCategory,
Sender: sender,
TxType: fmt.Sprintf("%d", tx.Type()),
},
)

if err != nil {
k.Logger(ctx).Error(err.Error())
}
// emit events
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeEthereumTx,
attrs...,
),
sdk.NewEvent(
types.EventTypeTxLog,
txLogAttrs...,
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, sender),
sdk.NewAttribute(types.AttributeKeyTxType, fmt.Sprintf("%d", tx.Type())),
),
})

return response, nil
}
Expand Down
Loading

0 comments on commit 20c82d0

Please sign in to comment.