diff --git a/evmrpc/block_test.go b/evmrpc/block_test.go index 4c394ead3..5a9678126 100644 --- a/evmrpc/block_test.go +++ b/evmrpc/block_test.go @@ -80,36 +80,30 @@ func TestGetBlockReceipts(t *testing.T) { // Query by block height resObj := sendRequestGood(t, "getBlockReceipts", "0x2") result := resObj["result"].([]interface{}) - require.Equal(t, 3, len(result)) + require.Equal(t, 6, len(result)) receipt1 := result[0].(map[string]interface{}) require.Equal(t, "0x2", receipt1["blockNumber"]) - require.Equal(t, "0x0", receipt1["transactionIndex"]) - require.Equal(t, multiTxBlockTx1.Hash().Hex(), receipt1["transactionHash"]) + require.Equal(t, "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", receipt1["transactionHash"]) receipt2 := result[1].(map[string]interface{}) require.Equal(t, "0x2", receipt2["blockNumber"]) - require.Equal(t, "0x1", receipt2["transactionIndex"]) - require.Equal(t, multiTxBlockTx2.Hash().Hex(), receipt2["transactionHash"]) + require.Equal(t, multiTxBlockTx1.Hash().Hex(), receipt2["transactionHash"]) receipt3 := result[2].(map[string]interface{}) require.Equal(t, "0x2", receipt3["blockNumber"]) - require.Equal(t, "0x2", receipt3["transactionIndex"]) - require.Equal(t, multiTxBlockTx3.Hash().Hex(), receipt3["transactionHash"]) + require.Equal(t, "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", receipt3["transactionHash"]) // Query by block hash resObj2 := sendRequestGood(t, "getBlockReceipts", "0x0000000000000000000000000000000000000000000000000000000000000002") result = resObj2["result"].([]interface{}) - require.Equal(t, 3, len(result)) + require.Equal(t, 6, len(result)) receipt1 = result[0].(map[string]interface{}) require.Equal(t, "0x2", receipt1["blockNumber"]) - require.Equal(t, "0x0", receipt1["transactionIndex"]) - require.Equal(t, multiTxBlockTx1.Hash().Hex(), receipt1["transactionHash"]) + require.Equal(t, "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", receipt1["transactionHash"]) receipt2 = result[1].(map[string]interface{}) require.Equal(t, "0x2", receipt2["blockNumber"]) - require.Equal(t, "0x1", receipt2["transactionIndex"]) - require.Equal(t, multiTxBlockTx2.Hash().Hex(), receipt2["transactionHash"]) + require.Equal(t, multiTxBlockTx1.Hash().Hex(), receipt2["transactionHash"]) receipt3 = result[2].(map[string]interface{}) require.Equal(t, "0x2", receipt3["blockNumber"]) - require.Equal(t, "0x2", receipt3["transactionIndex"]) - require.Equal(t, multiTxBlockTx3.Hash().Hex(), receipt3["transactionHash"]) + require.Equal(t, "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", receipt3["transactionHash"]) // Query by tag latest => retrieves block 8 resObj3 := sendRequestGood(t, "getBlockReceipts", "latest") @@ -117,15 +111,7 @@ func TestGetBlockReceipts(t *testing.T) { require.Equal(t, 2, len(result)) receipt1 = result[0].(map[string]interface{}) require.Equal(t, "0x8", receipt1["blockNumber"]) - require.Equal(t, "0x0", receipt1["transactionIndex"]) - require.Equal(t, multiTxBlockTx4.Hash().Hex(), receipt1["transactionHash"]) - receiptWithSyntheticLog := result[1].(map[string]interface{}) - require.Equal(t, "0x8", receiptWithSyntheticLog["blockNumber"]) - logs := receiptWithSyntheticLog["logs"].([]interface{}) - firstLog := logs[0].(map[string]interface{}) - topics := firstLog["topics"].([]interface{}) - syntheticLogFirstTopic := "0x0000000000000000000000000000000000000000000000000000000000000234" - require.Equal(t, syntheticLogFirstTopic, topics[0].(string)) + require.Equal(t, tx1.Hash().Hex(), receipt1["transactionHash"]) } func verifyGenesisBlockResult(t *testing.T, resObj map[string]interface{}) { @@ -160,7 +146,7 @@ func verifyBlockResult(t *testing.T, resObj map[string]interface{}) { require.Equal(t, "0x5", resObj["gasUsed"]) require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000001", resObj["hash"]) // see setup_tests.go, which have one transaction for block 0x8 (latest) - require.Equal(t, "0x00002000040000000000000000000080000000200000000000000000000000080000000000000000000000000000000000000000000000000800000000000000001000000000000000000000000000000000000000000000000000000000000100000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000200000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000010200000000000000", resObj["logsBloom"]) + require.Equal(t, "0x00002000040000000000000000000080000000200000000000002000000000080000000000000000000000000000000000000000000000000800000000000000001000000000000000000000000000000000020000000000000000000000000100000000000000002000000000200000000000000000000000000000000000100000000000000000000000000400000000000000200000000000000000000000000000000000000100000000000000020000200000000000000000002000000000000000000000000000000000000000000000000000000000000000000200000000010000000002000000000000000000000000000000010200000000000000", resObj["logsBloom"]) require.Equal(t, "0x0000000000000000000000000000000000000005", resObj["miner"]) require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000000", resObj["mixHash"]) require.Equal(t, "0x0000000000000000", resObj["nonce"]) diff --git a/evmrpc/filter_test.go b/evmrpc/filter_test.go index fa0a4f145..8fa73c77b 100644 --- a/evmrpc/filter_test.go +++ b/evmrpc/filter_test.go @@ -131,10 +131,10 @@ func getCommonFilterLogTests() []GetFilterLogTests { }, { name: "filter by single topic with default range", - topics: [][]common.Hash{{common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000123")}}, + topics: [][]common.Hash{{common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111")}}, wantErr: false, check: func(t *testing.T, log map[string]interface{}) { - require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000123", log["topics"].([]interface{})[0].(string)) + require.Equal(t, "0x1111111111111111111111111111111111111111111111111111111111111111", log["topics"].([]interface{})[0].(string)) }, wantLen: 1, }, @@ -283,7 +283,7 @@ func TestFilterGetFilterLogs(t *testing.T) { resObj = sendRequest(t, TestPort, "getFilterLogs", filterId) logs := resObj["result"].([]interface{}) - require.Equal(t, 4, len(logs)) + require.Equal(t, 7, len(logs)) for _, log := range logs { logObj := log.(map[string]interface{}) require.Equal(t, "0x2", logObj["blockNumber"].(string)) diff --git a/evmrpc/setup_test.go b/evmrpc/setup_test.go index d252f3167..635b2f91d 100644 --- a/evmrpc/setup_test.go +++ b/evmrpc/setup_test.go @@ -2,6 +2,7 @@ package evmrpc_test import ( "context" + "crypto/sha256" "encoding/hex" "encoding/json" "errors" @@ -76,6 +77,7 @@ var multiTxBlockSynthTx *ethtypes.Transaction var DebugTraceTx sdk.Tx var TxNonEvm sdk.Tx +var TxNonEvmWithSyntheticLog sdk.Tx var UnconfirmedTx sdk.Tx var SConfig = evmrpc.SimulateConfig{GasCap: 10000000} @@ -176,7 +178,7 @@ func (c *MockClient) mockBlock(height int64) *coretypes.ResultBlock { return bz }(), func() []byte { - bz, _ := Encoder(TxNonEvm) + bz, _ := Encoder(TxNonEvmWithSyntheticLog) return bz }(), }, @@ -564,6 +566,12 @@ func generateTxData() { MultiTxBlockSynthTx = synthTxBuilder.GetTx() DebugTraceTx = debugTraceTxBuilder.GetTx() TxNonEvm = app.TestTx{} + TxNonEvmWithSyntheticLog = app.TestTx{} + bloomTx1 := ethtypes.CreateBloom(ethtypes.Receipts{ðtypes.Receipt{Logs: []*ethtypes.Log{{ + Address: common.HexToAddress("0x1111111111111111111111111111111111111111"), + Topics: []common.Hash{common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111"), + common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111112")}, + }}}}) if err := EVMKeeper.MockReceipt(Ctx, tx1.Hash(), &types.Receipt{ From: "0x1234567890123456789012345678901234567890", To: "0x1234567890123456789012345678901234567890", @@ -580,6 +588,7 @@ func generateTxData() { Address: "0x1111111111111111111111111111111111111111", Topics: []string{"0x1111111111111111111111111111111111111111111111111111111111111111", "0x1111111111111111111111111111111111111111111111111111111111111112"}, }}, + LogsBloom: bloomTx1[:], }); err != nil { panic(err) } @@ -747,8 +756,8 @@ func setupLogs() { }, }}}}) EVMKeeper.MockReceipt(Ctx, multiTxBlockSynthTx.Hash(), &types.Receipt{ - BlockNumber: MockHeight, - TransactionIndex: 0, + BlockNumber: MultiTxBlockHeight, + TransactionIndex: 5, TxHashHex: multiTxBlockSynthTx.Hash().Hex(), LogsBloom: bloomSynth[:], Logs: []*types.Log{{ @@ -763,6 +772,20 @@ func setupLogs() { TransactionIndex: 0, TxHashHex: DebugTraceHashHex, }) + txNonEvmBz, _ := Encoder(TxNonEvmWithSyntheticLog) + txNonEvmHash := sha256.Sum256(txNonEvmBz) + EVMKeeper.MockReceipt(Ctx, txNonEvmHash, &types.Receipt{ + BlockNumber: MultiTxBlockHeight, + TransactionIndex: 1, + TxHashHex: common.Hash(txNonEvmHash).Hex(), + LogsBloom: bloomSynth[:], + Logs: []*types.Log{{ + Address: "0x1111111111111111111111111111111111111116", + Topics: []string{"0x0000000000000000000000000000000000000000000000000000000000000234", "0x0000000000000000000000000000000000000000000000000000000000000789"}, + Synthetic: true, + }}, + EffectiveGasPrice: 100, + }) EVMKeeper.SetTxHashesOnHeight(Ctx, MultiTxBlockHeight, []common.Hash{ multiTxBlockTx1.Hash(), multiTxBlockTx2.Hash(), @@ -772,8 +795,13 @@ func setupLogs() { multiTxBlockTx4.Hash(), multiTxBlockSynthTx.Hash(), }) + bloomTx1 := ethtypes.CreateBloom(ethtypes.Receipts{ðtypes.Receipt{Logs: []*ethtypes.Log{{ + Address: common.HexToAddress("0x1111111111111111111111111111111111111111"), + Topics: []common.Hash{common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111"), + common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111112")}, + }}}}) EVMKeeper.SetBlockBloom(MultiTxCtx, []ethtypes.Bloom{bloom1, bloom2, bloom3}) - EVMKeeper.SetBlockBloom(Ctx, []ethtypes.Bloom{bloom4, bloomSynth}) + EVMKeeper.SetBlockBloom(Ctx, []ethtypes.Bloom{bloom4, bloomSynth, bloomTx1}) } //nolint:deadcode diff --git a/evmrpc/utils.go b/evmrpc/utils.go index 47ac51be9..0d494c949 100644 --- a/evmrpc/utils.go +++ b/evmrpc/utils.go @@ -3,6 +3,7 @@ package evmrpc import ( "context" "crypto/ecdsa" + "crypto/sha256" "encoding/hex" "fmt" "math/big" @@ -215,6 +216,7 @@ func getEvmTxHashesFromBlock(block *coretypes.ResultBlock, txConfig client.TxCon continue } if len(sdkTx.GetMsgs()) == 0 { + txHashes = append(txHashes, sha256.Sum256(tx)) continue } if evmTx, ok := sdkTx.GetMsgs()[0].(*types.MsgEVMTransaction); ok { @@ -224,6 +226,7 @@ func getEvmTxHashesFromBlock(block *coretypes.ResultBlock, txConfig client.TxCon ethtx, _ := evmTx.AsTransaction() txHashes = append(txHashes, ethtx.Hash()) } + txHashes = append(txHashes, sha256.Sum256(tx)) } return txHashes }