Last active
May 23, 2020 09:33
-
-
Save rhlsthrm/3b9680de7c2694b8a2971d72aeba3b12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ethers } from "@nomiclabs/buidler"; | |
import { Signer, Wallet } from "ethers"; | |
import chai from "chai"; | |
import { deployContract, solidity } from "ethereum-waffle"; | |
import CounterArtifact from "../artifacts/Counter.json"; | |
import { Counter } from "../typechain/Counter"; | |
chai.use(solidity); | |
const { expect } = chai; | |
describe("Counter", () => { | |
let counter: Counter; | |
beforeEach(async () => { | |
// 1 | |
const signers = await ethers.signers(); | |
// 2 | |
counter = (await deployContract( | |
<Wallet>signers[0], | |
CounterArtifact | |
)) as Counter; | |
const initialCount = await counter.getCount(); | |
// 3 | |
expect(initialCount).to.eq(0); | |
expect(counter.address).to.properAddress; | |
}); | |
// 4 | |
describe("count up", async () => { | |
it("should count up", async () => { | |
await counter.countUp(); | |
let count = await counter.getCount(); | |
expect(count).to.eq(1); | |
}); | |
}); | |
describe("count down", async () => { | |
// 5 | |
it("should fail", async () => { | |
await counter.countDown(); | |
}); | |
it("should count down", async () => { | |
await counter.countUp(); | |
await counter.countDown(); | |
const count = await counter.getCount(); | |
expect(count).to.eq(0); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment