diff --git a/e2e/cloudwalk-contracts/integration/test/relayer.test.ts b/e2e/cloudwalk-contracts/integration/test/relayer.test.ts index 91549defb..7b7afaee3 100644 --- a/e2e/cloudwalk-contracts/integration/test/relayer.test.ts +++ b/e2e/cloudwalk-contracts/integration/test/relayer.test.ts @@ -78,14 +78,12 @@ describe("Relayer integration test", function () { const amount = Math.floor(Math.random() * 10) + 1; try { - const tx = await brlcToken - .connect(sender) - .transfer(receiver.address, amount, { - gasPrice: 0, - gasLimit: GAS_LIMIT_OVERRIDE, - type: 0, - nonce: nonces[senderIndex], - }); + const tx = await brlcToken.connect(sender).transfer(receiver.address, amount, { + gasPrice: 0, + gasLimit: GAS_LIMIT_OVERRIDE, + type: 0, + nonce: nonces[senderIndex], + }); txHashList.push(tx.hash); } catch (error) {} @@ -210,14 +208,12 @@ describe("Relayer integration test", function () { let sender = wallets[i % 2]; let receiver = wallets[(i + 1) % 2]; - const tx = await brlcToken - .connect(sender) - .transfer(receiver.address, 10, { - gasPrice: 0, - gasLimit: GAS_LIMIT_OVERRIDE, - type: 0, - nonce: nonces[i % 2], - }); + const tx = await brlcToken.connect(sender).transfer(receiver.address, 10, { + gasPrice: 0, + gasLimit: GAS_LIMIT_OVERRIDE, + type: 0, + nonce: nonces[i % 2], + }); txHashList.push(tx.transactionHash); diff --git a/e2e/test/automine/e2e-json-rpc.test.ts b/e2e/test/automine/e2e-json-rpc.test.ts index 480573309..796caab04 100644 --- a/e2e/test/automine/e2e-json-rpc.test.ts +++ b/e2e/test/automine/e2e-json-rpc.test.ts @@ -1,16 +1,18 @@ import { expect } from "chai"; -import { Block, Bytes } from "web3-types"; +import { Block, Bytes, TransactionReceipt } from "web3-types"; import { ALICE, BOB } from "../helpers/account"; import { isStratus } from "../helpers/network"; import { CHAIN_ID, CHAIN_ID_DEC, + ETHERJS, HASH_ZERO, HEX_PATTERN, ONE, TEST_BALANCE, ZERO, + deployTestContractBalances, send, sendAndGetError, sendEvmMine, @@ -18,6 +20,7 @@ import { sendReset, subscribeAndGetEvent, subscribeAndGetEventWithContract, + toHex, } from "../helpers/rpc"; describe("JSON-RPC", () => { @@ -123,6 +126,26 @@ describe("JSON-RPC", () => { }); }); + describe("Logs", () => { + describe("eth_getLogs", () => { + it("return no logs for queries after the last mined block", async () => { + // mine a test transaction + const contract = await deployTestContractBalances(); + const txResponse = await contract.connect(ALICE.signer()).add(ALICE.address, 10); + const txReceipt = await ETHERJS.getTransactionReceipt(txResponse.hash); + expect(txReceipt).exist; + expect(txReceipt?.status).eq(1); + + // check log queries starting at the last mined block and starting after it + const txBlockNumber = txReceipt?.blockNumber ?? 0; + const filter = { address: contract.target }; + expect(await send("eth_getLogs", [{ ...filter, fromBlock: toHex(txBlockNumber) }])).length(1); // last mined block + expect(await send("eth_getLogs", [{ ...filter, fromBlock: toHex(txBlockNumber + 1) }])).length(0); // 1 after mined block + expect(await send("eth_getLogs", [{ ...filter, fromBlock: toHex(txBlockNumber + 2) }])).length(0); // 2 after mined block + }); + }); + }); + describe("Evm", () => { async function latest(): Promise<{ timestamp: number; block_number: number }> { const block = await send("eth_getBlockByNumber", ["latest", false]); diff --git a/e2e/test/automine/e2e-tx-serial-contract.test.ts b/e2e/test/automine/e2e-tx-serial-contract.test.ts index a11c44ada..9388c22e7 100644 --- a/e2e/test/automine/e2e-tx-serial-contract.test.ts +++ b/e2e/test/automine/e2e-tx-serial-contract.test.ts @@ -165,7 +165,7 @@ describe("Transaction: serial TestContractBalances", () => { (await sendExpect("eth_getLogs", [{ ...filter, fromBlock: toHex(_block + 1) }])).length(3); (await sendExpect("eth_getLogs", [{ ...filter, fromBlock: toHex(_block + 2) }])).length(2); (await sendExpect("eth_getLogs", [{ ...filter, fromBlock: toHex(_block + 3) }])).length(1); - (await sendExpect("eth_getLogs", [{ ...filter, fromBlock: toHex(_block + 4) }])).length(1); + (await sendExpect("eth_getLogs", [{ ...filter, fromBlock: toHex(_block + 4) }])).length(0); // filter topics (await sendExpect("eth_getLogs", [{ ...filter, topics: [CONTRACT_TOPIC_ADD] }])).length(2); diff --git a/e2e/test/issues/automine/e2e-abm-logs.ts b/e2e/test/issues/automine/e2e-abm-logs.ts deleted file mode 100644 index 13961c554..000000000 --- a/e2e/test/issues/automine/e2e-abm-logs.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { expect } from "chai"; -import { TransactionReceipt } from "ethers"; - -import { ALICE } from "../../helpers/account"; -import { BlockMode, currentBlockMode } from "../../helpers/network"; -import { ETHERJS, deployTestContractBalances, send, toHex } from "../../helpers/rpc"; - -describe("Known issues for the auto block mining mode. The results of the 'eth_getLogs' API call are", async () => { - before(async () => { - expect(currentBlockMode()).eq(BlockMode.Automine, "Wrong block mining mode is used"); - }); - - it("Correct for next non-existent blocks after a contract transaction", async () => { - const contract = await deployTestContractBalances(); - - const txResponse = await contract.connect(ALICE.signer()).add(ALICE.address, 10); - const txReceipt: TransactionReceipt | null = await ETHERJS.getTransactionReceipt(txResponse.hash); - expect(txReceipt).exist; - - const txBlockNumber = txReceipt?.blockNumber ?? 0; - - expect(await send("eth_getLogs", [{ fromBlock: toHex(txBlockNumber), address: contract.target }])).length(1); - expect(await send("eth_getLogs", [{ fromBlock: toHex(txBlockNumber + 1), address: contract.target }])).length( - 0, - ); - expect(await send("eth_getLogs", [{ fromBlock: toHex(txBlockNumber + 2), address: contract.target }])).length( - 0, - ); - }); -}); diff --git a/e2e/test/issues/external/e2e-ebm-logs.ts b/e2e/test/issues/external/e2e-ebm-logs.ts deleted file mode 100644 index e284d9b87..000000000 --- a/e2e/test/issues/external/e2e-ebm-logs.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { expect } from "chai"; -import { TransactionReceipt } from "ethers"; - -import { ALICE } from "../../helpers/account"; -import { BlockMode, currentBlockMode } from "../../helpers/network"; -import { ETHERJS, deployTestContractBalances, send, sendEvmMine, toHex } from "../../helpers/rpc"; - -describe("Known issues for the external block mining mode. The 'eth_getLogs' API call", async () => { - before(async () => { - expect(currentBlockMode()).eq(BlockMode.External, "Wrong block mining mode is used"); - }); - - it("Returns an expected array for next non-existent blocks after a contract transaction", async () => { - const contract = await deployTestContractBalances(); - await sendEvmMine(); - - const txResponse = await contract.connect(ALICE.signer()).add(ALICE.address, 10); - await sendEvmMine(); - const txReceipt: TransactionReceipt | null = await ETHERJS.getTransactionReceipt(txResponse.hash); - expect(txReceipt).exist; - - const txBlockNumber = txReceipt?.blockNumber ?? 0; - - expect(await send("eth_getLogs", [{ fromBlock: toHex(txBlockNumber), address: contract.target }])).length(1); - expect(await send("eth_getLogs", [{ fromBlock: toHex(txBlockNumber + 1), address: contract.target }])).length( - 0, - ); - expect(await send("eth_getLogs", [{ fromBlock: toHex(txBlockNumber + 2), address: contract.target }])).length( - 0, - ); - }); -}); diff --git a/e2e/test/issues/interval/e2e-ibm-logs.ts b/e2e/test/issues/interval/e2e-ibm-logs.ts deleted file mode 100644 index c5ba26684..000000000 --- a/e2e/test/issues/interval/e2e-ibm-logs.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { expect } from "chai"; - -import { ALICE } from "../../helpers/account"; -import { checkTimeEnough } from "../../helpers/misc"; -import { BlockMode, currentBlockMode, currentMiningIntervalInMs } from "../../helpers/network"; -import { HASH_ZERO, deployTestContractBalances, pollForTransaction, send, toHex } from "../../helpers/rpc"; - -describe("Known issues for the interval block mining mode. The 'eth_getLogs' API call", async () => { - let blockIntervalInMs: number; - - before(async () => { - expect(currentBlockMode()).eq(BlockMode.Interval, "Wrong block mining mode is used"); - blockIntervalInMs = currentMiningIntervalInMs() ?? 0; - expect(blockIntervalInMs).gte(1000, "Block interval must be at least 1000 ms"); - }); - - it("Returns an expected array for next non-existent blocks after a contract transaction", async () => { - const contract = await deployTestContractBalances(); - await pollForTransaction(contract.deploymentTransaction()?.hash ?? HASH_ZERO, { - timeoutInMs: blockIntervalInMs * 1.1, - }); - - const txSendingTime = Date.now(); - const txResponse = await contract.connect(ALICE.signer()).add(ALICE.address, 10); - const txReceipt = await pollForTransaction(txResponse.hash, { timeoutInMs: blockIntervalInMs * 1.1 }); - - const txBlockNumber = txReceipt.blockNumber; - - expect(await send("eth_getLogs", [{ fromBlock: toHex(txBlockNumber), address: contract.target }])).length(1); - expect(await send("eth_getLogs", [{ fromBlock: toHex(txBlockNumber + 1), address: contract.target }])).length( - 0, - ); - expect(await send("eth_getLogs", [{ fromBlock: toHex(txBlockNumber + 2), address: contract.target }])).length( - 0, - ); - - checkTimeEnough(txSendingTime, blockIntervalInMs * 1.7); - }); -}); diff --git a/src/eth/primitives/block_selection.rs b/src/eth/primitives/block_selection.rs index 28f0e3ab3..85ecb6d05 100644 --- a/src/eth/primitives/block_selection.rs +++ b/src/eth/primitives/block_selection.rs @@ -1,9 +1,10 @@ use crate::eth::primitives::BlockNumber; use crate::eth::primitives::Hash; -#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)] +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Serialize)] pub enum BlockSelection { /// Retrieve the most recent block. + #[default] Latest, /// Retrieve the most early block. @@ -16,11 +17,9 @@ pub enum BlockSelection { Number(BlockNumber), } -impl Default for BlockSelection { - fn default() -> Self { - Self::Latest - } -} +// ----------------------------------------------------------------------------- +// Serialization / Deserilization +// ----------------------------------------------------------------------------- impl<'de> serde::Deserialize<'de> for BlockSelection { fn deserialize(deserializer: D) -> Result @@ -48,6 +47,10 @@ impl<'de> serde::Deserialize<'de> for BlockSelection { } } +// ----------------------------------------------------------------------------- +// Tests +// ----------------------------------------------------------------------------- + #[cfg(test)] mod tests { use serde_json::json; diff --git a/src/eth/storage/stratus_storage.rs b/src/eth/storage/stratus_storage.rs index f856160be..844f5e7d6 100644 --- a/src/eth/storage/stratus_storage.rs +++ b/src/eth/storage/stratus_storage.rs @@ -523,14 +523,7 @@ impl StratusStorage { pub fn translate_to_point_in_time(&self, block_selection: &BlockSelection) -> anyhow::Result { match block_selection { BlockSelection::Latest => Ok(StoragePointInTime::Present), - BlockSelection::Number(number) => { - let current_block = self.perm.read_mined_block_number()?; - if number <= ¤t_block { - Ok(StoragePointInTime::Past(*number)) - } else { - Ok(StoragePointInTime::Past(current_block)) - } - } + BlockSelection::Number(number) => Ok(StoragePointInTime::Past(*number)), BlockSelection::Earliest | BlockSelection::Hash(_) => match self.read_block(block_selection)? { Some(block) => Ok(StoragePointInTime::Past(block.header.number)), None => Err(anyhow!(