Skip to content

Commit

Permalink
Add basic test for logs. Add launch configuration for debugging e2e t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
MexicanAce committed Sep 23, 2023
1 parent 2d6b2da commit a7169f8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,16 @@
"preLaunchTask": "rebuild-contracts",
"cwd": "${workspaceFolder}"
},
{
"name": "E2E Tests",
"type": "node",
"request": "launch",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}/e2e-tests",
"runtimeExecutable": "yarn",
"runtimeArgs": [
"test"
]
},
]
}
1 change: 1 addition & 0 deletions e2e-tests/test/evm-apis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ xdescribe("evm_mine", function () {
});
});

// TODO: Investigate why this fails on new node with no transactions
describe("evm_increaseTime", function () {
it("Should increase current timestamp of the node", async function () {
// Arrange
Expand Down
18 changes: 12 additions & 6 deletions e2e-tests/test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
expectThrowsAsync,
getTestProvider,
} from "../helpers/utils";
import { TransactionReceipt } from "zksync-web3/build/src/types";

const provider = getTestProvider();

Expand Down Expand Up @@ -53,18 +54,23 @@ describe("Greeter Smart Contract", function () {
});

it("Should produce event logs", async function () {
// TODO: Figure out a test for this
const wallet = new Wallet(RichAccounts[0].PrivateKey);
const deployer = new Deployer(hre, wallet);

const greeter = await deployContract(deployer, "Greeter", ["Hi"]);

expect(await greeter.greet()).to.eq("Hi");

const setGreetingTx = await greeter.setGreeting("Hola, mundo!");
// wait until the transaction is mined
await setGreetingTx.wait();

expect(await greeter.greet()).to.equal("Hola, mundo!");
const setGreetingTx = await greeter.setGreeting("Luke Skywalker");
const receipt: TransactionReceipt = await setGreetingTx.wait();

// Validate log is created
expect(receipt.logs.length).to.greaterThanOrEqual(1);
const setGreetingLog = receipt.logs[1];
expect(setGreetingLog.address).to.equal(greeter.address);
const normalizedSetGreetingLogData = ethers.utils.toUtf8String(setGreetingLog.data)
.replaceAll("\u0000", "")
.replace(" +", "");
expect(normalizedSetGreetingLogData).to.equal("Greeting is being updated to Luke Skywalker");
});
});

0 comments on commit a7169f8

Please sign in to comment.