diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f2c06f44..9df469730 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -116,6 +116,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#2019](https://github.com/NibiruChain/nibiru/pull/2019) - chore(evm): enabled debug rpc api on localnet. - [#2020](https://github.com/NibiruChain/nibiru/pull/2020) - test(evm): e2e tests for debug namespace - [#2022](https://github.com/NibiruChain/nibiru/pull/2022) - feat(evm): debug_traceCall method implemented +- [#2023](https://github.com/NibiruChain/nibiru/pull/2023) - fix(evm)!: adjusted generation and parsing of the block bloom events #### Dapp modules: perp, spot, oracle, etc diff --git a/e2e/evm/test/eth_queries.test.ts b/e2e/evm/test/eth_queries.test.ts index 14f0c7aa5..ac648e274 100644 --- a/e2e/evm/test/eth_queries.test.ts +++ b/e2e/evm/test/eth_queries.test.ts @@ -1,11 +1,5 @@ import { describe, expect, it, jest } from "@jest/globals" -import { - toBigInt, - parseEther, - keccak256, - AbiCoder, - TransactionRequest, -} from "ethers" +import { parseEther, keccak256, AbiCoder, TransactionRequest } from "ethers" import { account, provider } from "./setup" import { INTRINSIC_TX_GAS, @@ -16,48 +10,9 @@ import { sendTestNibi, } from "./utils" -describe("Basic Queries", () => { +describe("eth queries", () => { jest.setTimeout(15e3) - it("Simple transfer, balance check", async () => { - const amountToSend = toBigInt(5e12) * toBigInt(1e6) // unibi - const senderBalanceBefore = await provider.getBalance(account) - const recipientBalanceBefore = await provider.getBalance(alice) - expect(senderBalanceBefore).toBeGreaterThan(0) - expect(recipientBalanceBefore).toEqual(BigInt(0)) - - const tenPow12 = toBigInt(1e12) - - // Execute EVM transfer - const transaction: TransactionRequest = { - gasLimit: toBigInt(100e3), - to: alice, - value: amountToSend, - } - const txResponse = await account.sendTransaction(transaction) - await txResponse.wait(1, 10e3) - expect(txResponse).toHaveProperty("blockHash") - - const senderBalanceAfter = await provider.getBalance(account) - const recipientBalanceAfter = await provider.getBalance(alice) - - // Assert balances with logging - const gasUsed = 50000n // 50k gas for the transaction - const txCostMicronibi = amountToSend / tenPow12 + gasUsed - const txCostWei = txCostMicronibi * tenPow12 - const expectedSenderWei = senderBalanceBefore - txCostWei - console.debug("DEBUG should send via transfer method %o:", { - senderBalanceBefore, - amountToSend, - expectedSenderWei, - senderBalanceAfter, - }) - expect(senderBalanceAfter).toEqual(expectedSenderWei) - expect(recipientBalanceAfter).toEqual(amountToSend) - }) -}) - -describe("eth queries", () => { it("eth_accounts", async () => { const accounts = await provider.listAccounts() expect(accounts).not.toHaveLength(0) @@ -153,7 +108,7 @@ describe("eth queries", () => { const contract = await deployContractTestERC20() const contractAddr = await contract.getAddress() const filter = { - fromBlock: "latest", + fromBlock: "0x1", address: contractAddr, } // Create the filter for a contract @@ -177,17 +132,18 @@ describe("eth queries", () => { }) // Skipping as the method is not implemented - it.skip("eth_getFilterLogs", async () => { + it("eth_getFilterLogs", async () => { // Deploy ERC-20 contract const contract = await deployContractTestERC20() const contractAddr = await contract.getAddress() const filter = { - fromBlock: "latest", + fromBlock: "0x1", address: contractAddr, } // Execute some contract TX const tx = await contract.transfer(alice, parseEther("0.01")) await tx.wait(1, 5e3) + await new Promise((resolve) => setTimeout(resolve, 3000)) // Create the filter for a contract const filterId = await provider.send("eth_newFilter", [filter]) @@ -202,16 +158,19 @@ describe("eth queries", () => { }) // Skipping as the method is not implemented - it.skip("eth_getLogs", async () => { + it("eth_getLogs", async () => { // Deploy ERC-20 contract const contract = await deployContractTestERC20() const contractAddr = await contract.getAddress() + console.log(contractAddr) const filter = { - fromBlock: "latest", + fromBlock: "0x1", address: contractAddr, } // Execute some contract TX - const _tx = await contract.transfer(alice, parseEther("0.01")) + const tx = await contract.transfer(alice, parseEther("0.01")) + await tx.wait(1, 5e3) + await new Promise((resolve) => setTimeout(resolve, 3000)) // Assert logs const changes = await provider.send("eth_getLogs", [filter]) @@ -252,27 +211,6 @@ describe("eth queries", () => { } }) - // Skipping as the method is not implemented - it.skip("eth_getLogs", async () => { - // Deploy ERC-20 contract - const contract = await deployContractTestERC20() - const contractAddr = await contract.getAddress() - const filter = { - fromBlock: "latest", - address: contractAddr, - } - // Execute some contract TX - const tx = await contract.transfer(alice, parseEther("0.01")) - await tx.wait(1, 5e3) - - // Assert logs - const logs = await provider.send("eth_getLogs", [filter]) - expect(logs.length).toBeGreaterThan(0) - expect(logs[0]).toHaveProperty("address") - expect(logs[0]).toHaveProperty("data") - expect(logs[0]).toHaveProperty("topics") - }) - it("eth_getProof", async () => { const contract = await deployContractTestERC20() const contractAddr = await contract.getAddress() diff --git a/eth/rpc/backend/blocks.go b/eth/rpc/backend/blocks.go index dda1affef..a56201c4e 100644 --- a/eth/rpc/backend/blocks.go +++ b/eth/rpc/backend/blocks.go @@ -6,16 +6,19 @@ import ( "math" "math/big" "strconv" + "strings" tmrpcclient "github.com/cometbft/cometbft/rpc/client" tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" sdk "github.com/cosmos/cosmos-sdk/types" grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" + "github.com/cosmos/gogoproto/proto" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" gethcore "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/trie" "github.com/pkg/errors" + "github.com/status-im/keycard-go/hexutils" "google.golang.org/grpc" "google.golang.org/grpc/metadata" @@ -352,14 +355,19 @@ func (b *Backend) HeaderByHash(blockHash common.Hash) (*gethcore.Header, error) // BlockBloom query block bloom filter from block results func (b *Backend) BlockBloom(blockRes *tmrpctypes.ResultBlockResults) (gethcore.Bloom, error) { + msgType := proto.MessageName((*evm.EventBlockBloom)(nil)) for _, event := range blockRes.EndBlockEvents { - if event.Type != evm.EventTypeBlockBloom { + if event.Type != msgType { continue } for _, attr := range event.Attributes { if attr.Key == evm.AttributeKeyEthereumBloom { - return gethcore.BytesToBloom([]byte(attr.Value)), nil + return gethcore.BytesToBloom( + hexutils.HexToBytes( // Bloom stores hex bytes + strings.ReplaceAll(attr.Value, `"`, ""), // Unquote typed event + ), + ), nil } } } diff --git a/eth/rpc/backend/blocks_test.go b/eth/rpc/backend/blocks_test.go index d65dbf421..2cefc8748 100644 --- a/eth/rpc/backend/blocks_test.go +++ b/eth/rpc/backend/blocks_test.go @@ -5,6 +5,7 @@ import ( "math/big" "cosmossdk.io/math" + "github.com/cosmos/gogoproto/proto" "github.com/cometbft/cometbft/abci/types" cmtrpc "github.com/cometbft/cometbft/rpc/core/types" @@ -845,7 +846,7 @@ func (s *BackendSuite) TestBlockBloom() { &cmtrpc.ResultBlockResults{ EndBlockEvents: []types.Event{ { - Type: evm.EventTypeBlockBloom, + Type: proto.MessageName((*evm.EventBlockBloom)(nil)), Attributes: []types.EventAttribute{ {Key: evm.AttributeKeyEthereumTxHash}, }, @@ -860,7 +861,7 @@ func (s *BackendSuite) TestBlockBloom() { &cmtrpc.ResultBlockResults{ EndBlockEvents: []types.Event{ { - Type: evm.EventTypeBlockBloom, + Type: proto.MessageName((*evm.EventBlockBloom)(nil)), Attributes: []types.EventAttribute{ {Key: evm.AttributeKeyEthereumBloom}, }, diff --git a/x/evm/keeper/hooks.go b/x/evm/keeper/hooks.go index 48ab57704..177708d64 100644 --- a/x/evm/keeper/hooks.go +++ b/x/evm/keeper/hooks.go @@ -4,6 +4,8 @@ package keeper import ( abci "github.com/cometbft/cometbft/abci/types" + "github.com/NibiruChain/nibiru/v2/eth" + "github.com/NibiruChain/nibiru/v2/x/evm" sdk "github.com/cosmos/cosmos-sdk/types" @@ -18,7 +20,7 @@ func (k *Keeper) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Valida ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) bloom := gethcoretypes.BytesToBloom(k.EvmState.GetBlockBloomTransient(ctx).Bytes()) _ = ctx.EventManager().EmitTypedEvent(&evm.EventBlockBloom{ - Bloom: string(bloom.Bytes()), + Bloom: eth.BytesToHex(bloom.Bytes()), }) // The bloom logic doesn't update the validator set. return []abci.ValidatorUpdate{}