Skip to content

Commit 227e309

Browse files
committed
Merge branch 'main' into releases/v2.0.0
2 parents 5950a5b + e2bc002 commit 227e309

File tree

5 files changed

+29
-79
lines changed

5 files changed

+29
-79
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
115115
- [#2017](https://github.com/NibiruChain/nibiru/pull/2017) - fix(evm): Fix DynamicFeeTx gas cap parameters
116116
- [#2019](https://github.com/NibiruChain/nibiru/pull/2019) - chore(evm): enabled debug rpc api on localnet.
117117
- [#2020](https://github.com/NibiruChain/nibiru/pull/2020) - test(evm): e2e tests for debug namespace
118+
- [#2023](https://github.com/NibiruChain/nibiru/pull/2023) - fix(evm)!: adjusted generation and parsing of the block bloom events
118119

119120
#### Dapp modules: perp, spot, oracle, etc
120121

e2e/evm/test/eth_queries.test.ts

Lines changed: 12 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { describe, expect, it, jest } from "@jest/globals"
2-
import {
3-
toBigInt,
4-
parseEther,
5-
keccak256,
6-
AbiCoder,
7-
TransactionRequest,
8-
} from "ethers"
2+
import { parseEther, keccak256, AbiCoder, TransactionRequest } from "ethers"
93
import { account, provider } from "./setup"
104
import {
115
INTRINSIC_TX_GAS,
@@ -16,48 +10,9 @@ import {
1610
sendTestNibi,
1711
} from "./utils"
1812

19-
describe("Basic Queries", () => {
13+
describe("eth queries", () => {
2014
jest.setTimeout(15e3)
2115

22-
it("Simple transfer, balance check", async () => {
23-
const amountToSend = toBigInt(5e12) * toBigInt(1e6) // unibi
24-
const senderBalanceBefore = await provider.getBalance(account)
25-
const recipientBalanceBefore = await provider.getBalance(alice)
26-
expect(senderBalanceBefore).toBeGreaterThan(0)
27-
expect(recipientBalanceBefore).toEqual(BigInt(0))
28-
29-
const tenPow12 = toBigInt(1e12)
30-
31-
// Execute EVM transfer
32-
const transaction: TransactionRequest = {
33-
gasLimit: toBigInt(100e3),
34-
to: alice,
35-
value: amountToSend,
36-
}
37-
const txResponse = await account.sendTransaction(transaction)
38-
await txResponse.wait(1, 10e3)
39-
expect(txResponse).toHaveProperty("blockHash")
40-
41-
const senderBalanceAfter = await provider.getBalance(account)
42-
const recipientBalanceAfter = await provider.getBalance(alice)
43-
44-
// Assert balances with logging
45-
const gasUsed = 50000n // 50k gas for the transaction
46-
const txCostMicronibi = amountToSend / tenPow12 + gasUsed
47-
const txCostWei = txCostMicronibi * tenPow12
48-
const expectedSenderWei = senderBalanceBefore - txCostWei
49-
console.debug("DEBUG should send via transfer method %o:", {
50-
senderBalanceBefore,
51-
amountToSend,
52-
expectedSenderWei,
53-
senderBalanceAfter,
54-
})
55-
expect(senderBalanceAfter).toEqual(expectedSenderWei)
56-
expect(recipientBalanceAfter).toEqual(amountToSend)
57-
})
58-
})
59-
60-
describe("eth queries", () => {
6116
it("eth_accounts", async () => {
6217
const accounts = await provider.listAccounts()
6318
expect(accounts).not.toHaveLength(0)
@@ -153,7 +108,7 @@ describe("eth queries", () => {
153108
const contract = await deployContractTestERC20()
154109
const contractAddr = await contract.getAddress()
155110
const filter = {
156-
fromBlock: "latest",
111+
fromBlock: "0x1",
157112
address: contractAddr,
158113
}
159114
// Create the filter for a contract
@@ -177,17 +132,18 @@ describe("eth queries", () => {
177132
})
178133

179134
// Skipping as the method is not implemented
180-
it.skip("eth_getFilterLogs", async () => {
135+
it("eth_getFilterLogs", async () => {
181136
// Deploy ERC-20 contract
182137
const contract = await deployContractTestERC20()
183138
const contractAddr = await contract.getAddress()
184139
const filter = {
185-
fromBlock: "latest",
140+
fromBlock: "0x1",
186141
address: contractAddr,
187142
}
188143
// Execute some contract TX
189144
const tx = await contract.transfer(alice, parseEther("0.01"))
190145
await tx.wait(1, 5e3)
146+
await new Promise((resolve) => setTimeout(resolve, 3000))
191147

192148
// Create the filter for a contract
193149
const filterId = await provider.send("eth_newFilter", [filter])
@@ -202,16 +158,19 @@ describe("eth queries", () => {
202158
})
203159

204160
// Skipping as the method is not implemented
205-
it.skip("eth_getLogs", async () => {
161+
it("eth_getLogs", async () => {
206162
// Deploy ERC-20 contract
207163
const contract = await deployContractTestERC20()
208164
const contractAddr = await contract.getAddress()
165+
console.log(contractAddr)
209166
const filter = {
210-
fromBlock: "latest",
167+
fromBlock: "0x1",
211168
address: contractAddr,
212169
}
213170
// Execute some contract TX
214-
const _tx = await contract.transfer(alice, parseEther("0.01"))
171+
const tx = await contract.transfer(alice, parseEther("0.01"))
172+
await tx.wait(1, 5e3)
173+
await new Promise((resolve) => setTimeout(resolve, 3000))
215174

216175
// Assert logs
217176
const changes = await provider.send("eth_getLogs", [filter])
@@ -252,27 +211,6 @@ describe("eth queries", () => {
252211
}
253212
})
254213

255-
// Skipping as the method is not implemented
256-
it.skip("eth_getLogs", async () => {
257-
// Deploy ERC-20 contract
258-
const contract = await deployContractTestERC20()
259-
const contractAddr = await contract.getAddress()
260-
const filter = {
261-
fromBlock: "latest",
262-
address: contractAddr,
263-
}
264-
// Execute some contract TX
265-
const tx = await contract.transfer(alice, parseEther("0.01"))
266-
await tx.wait(1, 5e3)
267-
268-
// Assert logs
269-
const logs = await provider.send("eth_getLogs", [filter])
270-
expect(logs.length).toBeGreaterThan(0)
271-
expect(logs[0]).toHaveProperty("address")
272-
expect(logs[0]).toHaveProperty("data")
273-
expect(logs[0]).toHaveProperty("topics")
274-
})
275-
276214
it("eth_getProof", async () => {
277215
const contract = await deployContractTestERC20()
278216
const contractAddr = await contract.getAddress()

eth/rpc/backend/blocks.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ import (
66
"math"
77
"math/big"
88
"strconv"
9+
"strings"
910

1011
tmrpcclient "github.com/cometbft/cometbft/rpc/client"
1112
tmrpctypes "github.com/cometbft/cometbft/rpc/core/types"
1213
sdk "github.com/cosmos/cosmos-sdk/types"
1314
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
15+
"github.com/cosmos/gogoproto/proto"
1416
"github.com/ethereum/go-ethereum/common"
1517
"github.com/ethereum/go-ethereum/common/hexutil"
1618
gethcore "github.com/ethereum/go-ethereum/core/types"
1719
"github.com/ethereum/go-ethereum/trie"
1820
"github.com/pkg/errors"
21+
"github.com/status-im/keycard-go/hexutils"
1922
"google.golang.org/grpc"
2023
"google.golang.org/grpc/metadata"
2124

@@ -352,14 +355,19 @@ func (b *Backend) HeaderByHash(blockHash common.Hash) (*gethcore.Header, error)
352355

353356
// BlockBloom query block bloom filter from block results
354357
func (b *Backend) BlockBloom(blockRes *tmrpctypes.ResultBlockResults) (gethcore.Bloom, error) {
358+
msgType := proto.MessageName((*evm.EventBlockBloom)(nil))
355359
for _, event := range blockRes.EndBlockEvents {
356-
if event.Type != evm.EventTypeBlockBloom {
360+
if event.Type != msgType {
357361
continue
358362
}
359363

360364
for _, attr := range event.Attributes {
361365
if attr.Key == evm.AttributeKeyEthereumBloom {
362-
return gethcore.BytesToBloom([]byte(attr.Value)), nil
366+
return gethcore.BytesToBloom(
367+
hexutils.HexToBytes( // Bloom stores hex bytes
368+
strings.ReplaceAll(attr.Value, `"`, ""), // Unquote typed event
369+
),
370+
), nil
363371
}
364372
}
365373
}

eth/rpc/backend/blocks_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"math/big"
66

77
"cosmossdk.io/math"
8+
"github.com/cosmos/gogoproto/proto"
89

910
"github.com/cometbft/cometbft/abci/types"
1011
cmtrpc "github.com/cometbft/cometbft/rpc/core/types"
@@ -845,7 +846,7 @@ func (s *BackendSuite) TestBlockBloom() {
845846
&cmtrpc.ResultBlockResults{
846847
EndBlockEvents: []types.Event{
847848
{
848-
Type: evm.EventTypeBlockBloom,
849+
Type: proto.MessageName((*evm.EventBlockBloom)(nil)),
849850
Attributes: []types.EventAttribute{
850851
{Key: evm.AttributeKeyEthereumTxHash},
851852
},
@@ -860,7 +861,7 @@ func (s *BackendSuite) TestBlockBloom() {
860861
&cmtrpc.ResultBlockResults{
861862
EndBlockEvents: []types.Event{
862863
{
863-
Type: evm.EventTypeBlockBloom,
864+
Type: proto.MessageName((*evm.EventBlockBloom)(nil)),
864865
Attributes: []types.EventAttribute{
865866
{Key: evm.AttributeKeyEthereumBloom},
866867
},

x/evm/keeper/hooks.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ package keeper
44
import (
55
abci "github.com/cometbft/cometbft/abci/types"
66

7+
"github.com/NibiruChain/nibiru/v2/eth"
8+
79
"github.com/NibiruChain/nibiru/v2/x/evm"
810

911
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -18,7 +20,7 @@ func (k *Keeper) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Valida
1820
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
1921
bloom := gethcoretypes.BytesToBloom(k.EvmState.GetBlockBloomTransient(ctx).Bytes())
2022
_ = ctx.EventManager().EmitTypedEvent(&evm.EventBlockBloom{
21-
Bloom: string(bloom.Bytes()),
23+
Bloom: eth.BytesToHex(bloom.Bytes()),
2224
})
2325
// The bloom logic doesn't update the validator set.
2426
return []abci.ValidatorUpdate{}

0 commit comments

Comments
 (0)