Skip to content

Instantly share code, notes, and snippets.

@PaulRBerg
Created August 13, 2020 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulRBerg/9e3253c22940bed179681dbc7d8313c2 to your computer and use it in GitHub Desktop.
Save PaulRBerg/9e3253c22940bed179681dbc7d8313c2 to your computer and use it in GitHub Desktop.
Logging block timestamps
import { BigNumber } from "@ethersproject/bignumber";
import { Signer } from "@ethersproject/abstract-signer";
import { waffle } from "@nomiclabs/buidler";
import { expect } from "chai";
export function shouldBehaveLikeGreeter(_signers: Signer[]): void {
describe("1st Block", function () {
beforeEach(async function () {
await waffle.provider.send("evm_setNextBlockTimestamp", [1597348800]);
const blockTimestamp: BigNumber = await this.testotron.getBlockTimestamp();
console.log({ "1stTimestamp": blockTimestamp.toString() });
});
it("should pass the 1st test", async function () {
expect(await this.greeter.greet()).to.equal("Hello, world!");
await this.greeter.setGreeting("Hola, mundo!");
expect(await this.greeter.greet()).to.equal("Hola, mundo!");
});
});
describe("2nd Block", function () {
it("pass the 2nd test", async function () {
expect(await this.greeter.greet()).to.equal("Hello, world!");
await this.greeter.setGreeting("Hola, mundo!");
expect(await this.greeter.greet()).to.equal("Hola, mundo!");
});
beforeEach(async function () {
const blockTimestamp: BigNumber = await this.testotron.getBlockTimestamp();
console.log({ "2ndTimestamp": blockTimestamp.toString() });
});
});
describe("3rd Block", function () {
it("pass the 2nd test", async function () {
expect(await this.greeter.greet()).to.equal("Hello, world!");
await this.greeter.setGreeting("Hola, mundo!");
expect(await this.greeter.greet()).to.equal("Hola, mundo!");
});
beforeEach(async function () {
const blockTimestamp: BigNumber = await this.testotron.getBlockTimestamp();
console.log({ "3rdTimestamp": blockTimestamp.toString() });
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment