11import { 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"
93import { account , provider } from "./setup"
104import {
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 ( )
0 commit comments