From cb064a0481cbe92ee4a7d2ec886dbf7e01805f88 Mon Sep 17 00:00:00 2001 From: Soham Zemse <22412996+zemse@users.noreply.github.com> Date: Mon, 5 Aug 2024 21:39:59 +0530 Subject: [PATCH] add test case involving evm_increaseTime (#74) --- .../hardhat-project/contracts/Hello.sol | 4 +++- .../hardhat-project/test/Hello.test.ts | 15 +++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/test/fixture-projects/hardhat-project/contracts/Hello.sol b/test/fixture-projects/hardhat-project/contracts/Hello.sol index 5987daf..201c610 100644 --- a/test/fixture-projects/hardhat-project/contracts/Hello.sol +++ b/test/fixture-projects/hardhat-project/contracts/Hello.sol @@ -42,7 +42,9 @@ contract Hello { uint256 id2; } - function sample(string memory input) external {} + function sample(string memory input) external { + emit WhatsUp2(block.timestamp); + } function hi2(Info[] memory) public payable { assembly { diff --git a/test/fixture-projects/hardhat-project/test/Hello.test.ts b/test/fixture-projects/hardhat-project/test/Hello.test.ts index ca6dd75..1f34283 100644 --- a/test/fixture-projects/hardhat-project/test/Hello.test.ts +++ b/test/fixture-projects/hardhat-project/test/Hello.test.ts @@ -188,21 +188,20 @@ describe("Hello", () => { await hre.ethers.provider.send("debug_traceTransaction", [tx.hash]); }); - it("sample", async () => { - await hre.network.provider.send("evm_mine"); - + it("sample evm_increaseTime", async () => { const contract = await hre.ethers.getContractAt( "Hello", "0x0000000000000000000000000000001234567890", wallet ); - // hre.tracer.printNext = true; + const tx1 = await contract.sample("hello"); - const tx2 = await contract.sample("hello2"); - await hre.network.provider.send("evm_mine"); + expect(hre.tracer.lastTrace()?.hash).to.eq(tx1.hash); - console.log("debug tt"); - await hre.ethers.provider.send("debug_traceTransaction", [tx1.hash]); + await hre.network.provider.send("evm_increaseTime", [1000]); + + const tx2 = await contract.sample("hello2"); + expect(hre.tracer.lastTrace()?.hash).to.eq(tx2.hash); }); });