Skip to content

Commit

Permalink
Add logs count in transaction receipt tests. (#5352) (#3803)
Browse files Browse the repository at this point in the history
  • Loading branch information
its-saeed committed Oct 10, 2023
1 parent 3aec58e commit 2155fa3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/EvmAcceptanceTests/contracts/Event.sol
Expand Up @@ -9,9 +9,12 @@ contract Event {
event Log(address indexed sender, string message);
event AnotherLog();

function test() public {
function one_log() public {
emit Log(msg.sender, "Hello World!");
}

function two_logs() public {
emit Log(msg.sender, "Hello World!");
emit Log(msg.sender, "Hello EVM!");
emit AnotherLog();
}
}
29 changes: 29 additions & 0 deletions tests/EvmAcceptanceTests/test/EventsLogs.ts
@@ -0,0 +1,29 @@
import {expect} from "chai";
import {Contract} from "ethers";
import hre, {ethers} from "hardhat";

const FUND = ethers.utils.parseUnits("1", "gwei");

async function getFee(hash: string) {
const res = await ethers.provider.getTransactionReceipt(hash);
return res.gasUsed.mul(res.effectiveGasPrice);
}

describe("Events and logs #parallel", function () {
let contract: Contract;
before(async function () {
contract = await hre.deployContract("Event");
});

it("Should return 1 log whenever a function with one event is called @block-1", async function () {
const tx = await contract.one_log();
const receipt = await ethers.provider.getTransactionReceipt(tx.hash);
expect(receipt.logs.length).to.be.eq(1);
});

it("Should return 2 logs whenever a function with two events is called @block-1", async function () {
const tx = await contract.two_logs();
const receipt = await ethers.provider.getTransactionReceipt(tx.hash);
expect(receipt.logs.length).to.be.eq(2);
});
});

0 comments on commit 2155fa3

Please sign in to comment.