Commit e88e85d1 authored by platocrat's avatar platocrat Committed by GitHub

example: get revert msgs for hardhat (#841)

* example: get revert msgs for hardhat

* fix: remove chai-as-promised dep and logic

* re-add @types/mocha and @types/chai

* Update examples/hardhat/package.json
Co-authored-by: default avatarsmartcontracts <kelvinfichter@gmail.com>
parent fa4898aa
require('@nomiclabs/hardhat-ethers') require('@nomiclabs/hardhat-ethers')
require('@nomiclabs/hardhat-waffle') require('@nomiclabs/hardhat-waffle')
require('hardhat-deploy') require('hardhat-deploy')
require("@eth-optimism/hardhat-ovm") require('@eth-optimism/hardhat-ovm')
module.exports = { module.exports = {
networks: { networks: {
......
...@@ -14,18 +14,18 @@ ...@@ -14,18 +14,18 @@
"clean": "rimraf ./cache-ovm ./cache ./artifacts-ovm ./artifacts ./deployments" "clean": "rimraf ./cache-ovm ./cache ./artifacts-ovm ./artifacts ./deployments"
}, },
"devDependencies": { "devDependencies": {
"@eth-optimism/hardhat-ovm": "^0.2.0",
"@nomiclabs/hardhat-ethers": "^2.0.1", "@nomiclabs/hardhat-ethers": "^2.0.1",
"@nomiclabs/hardhat-waffle": "^2.0.1", "@nomiclabs/hardhat-waffle": "^2.0.1",
"@types/chai": "4.2.17", "@types/chai": "4.2.17",
"@types/chai-as-promised": "^7.1.3",
"@types/mocha": "^8.2.2", "@types/mocha": "^8.2.2",
"chai": "4.3.4", "chai": "4.3.4",
"chai-as-promised": "^7.1.1",
"ethereum-waffle": "^3.3.0", "ethereum-waffle": "^3.3.0",
"ethers": "^5.1.4", "ethers": "^5.1.4",
"hardhat": "^2.2.0", "hardhat": "^2.2.0",
"hardhat-deploy": "^0.7.5", "hardhat-deploy": "^0.7.5",
"mocha": "^8.2.1" "mocha": "^8.2.1"
},
"dependencies": {
"@eth-optimism/hardhat-ovm": "^0.2.0"
} }
} }
/* External Imports */ /* External Imports */
const { ethers } = require('hardhat') const { ethers, network } = require('hardhat')
const { expect } = require('chai') const chai = require('chai')
const { solidity } = require('ethereum-waffle')
const { expect } = chai
chai.use(solidity)
describe(`ERC20`, () => { describe(`ERC20`, () => {
const INITIAL_SUPPLY = 1000000 const INITIAL_SUPPLY = 1000000
...@@ -43,15 +46,15 @@ describe(`ERC20`, () => { ...@@ -43,15 +46,15 @@ describe(`ERC20`, () => {
it(`should revert when the sender does not have enough balance`, async () => { it(`should revert when the sender does not have enough balance`, async () => {
const tx = ERC20.connect(account1).transfer( const tx = ERC20.connect(account1).transfer(
await account2.getAddress(), await account2.getAddress(),
INITIAL_SUPPLY + 1, INITIAL_SUPPLY + 1
) )
await expect(tx).to.be.reverted await expect(tx).to.be.revertedWith("You don't have enough balance to make this transfer!")
}) })
it(`should succeed when the sender has enough balance`, async () => { it(`should succeed when the sender has enough balance`, async () => {
const tx = await ERC20.connect(account1).transfer( const tx = await ERC20.connect(account1).transfer(
await account2.getAddress(), await account2.getAddress(),
INITIAL_SUPPLY, INITIAL_SUPPLY
) )
await tx.wait() await tx.wait()
...@@ -73,22 +76,22 @@ describe(`ERC20`, () => { ...@@ -73,22 +76,22 @@ describe(`ERC20`, () => {
const tx = ERC20.connect(account2).transferFrom( const tx = ERC20.connect(account2).transferFrom(
await account1.getAddress(), await account1.getAddress(),
await account2.getAddress(), await account2.getAddress(),
INITIAL_SUPPLY, INITIAL_SUPPLY
) )
await expect(tx).to.be.reverted await expect(tx).to.be.revertedWith("Can't transfer from the desired account because you don't have enough of an allowance.")
}) })
it(`should succeed when the owner has enough balance and the sender has a large enough allowance`, async () => { it(`should succeed when the owner has enough balance and the sender has a large enough allowance`, async () => {
const tx1 = await ERC20.connect(account1).approve( const tx1 = await ERC20.connect(account1).approve(
await account2.getAddress(), await account2.getAddress(),
INITIAL_SUPPLY, INITIAL_SUPPLY
) )
await tx1.wait() await tx1.wait()
const tx2 = await ERC20.connect(account2).transferFrom( const tx2 = await ERC20.connect(account2).transferFrom(
await account1.getAddress(), await account1.getAddress(),
await account2.getAddress(), await account2.getAddress(),
INITIAL_SUPPLY, INITIAL_SUPPLY
) )
await tx2.wait() await tx2.wait()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment