Skip to content
This repository has been archived by the owner on Jan 9, 2022. It is now read-only.

Commit

Permalink
introduction of chai-as-promised, modifed count down should fail test…
Browse files Browse the repository at this point in the history
… to demonstrate testing of expected reverts
  • Loading branch information
nharlow89 committed Feb 27, 2021
1 parent a420815 commit c627690
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@typechain/ethers-v5": "^5.0.0",
"@types/chai": "^4.2.15",
"@types/chai-as-promised": "^7.1.3",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.28",
"chai": "^4.3.0",
"chai-as-promised": "^7.1.1",
"dotenv": "^8.2.0",
"ethereum-waffle": "^3.2.2",
"ethers": "^5.0.31",
Expand Down
7 changes: 4 additions & 3 deletions test/counter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ethers } from "hardhat";
import chai from "chai";
import chaiAsPromised from "chai-as-promised";
import { solidity } from "ethereum-waffle";
import { Counter__factory, Counter } from "../typechain";

chai.use(solidity);
chai.use(chaiAsPromised);
const { expect } = chai;

describe("Counter", () => {
Expand Down Expand Up @@ -38,9 +40,8 @@ describe("Counter", () => {

describe("count down", async () => {
// 5
it("should fail", async () => {
// this test will fail
await counter.countDown();
it("should fail due to underflow exception", () => {
return expect(counter.countDown()).to.eventually.be.rejectedWith(Error, 'Uint256 underflow');
});

it("should count down", async () => {
Expand Down

0 comments on commit c627690

Please sign in to comment.