Skip to content

Commit

Permalink
Addressing some comments
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Stefanov <[email protected]>
  • Loading branch information
stefan-stefanooov committed Oct 19, 2023
1 parent b1db954 commit 15781f9
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions test/solidity/errors/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { ethers } = require('hardhat')
const Constants = require('../../constants')

describe('@solidityequiv2 Solidity Errors', function () {
let contract
let contract, hasError

before(async function () {
const factoryErrorsExternal = await ethers.getContractFactory(Constants.Contract.ErrorsExternal)
Expand All @@ -13,55 +13,69 @@ describe('@solidityequiv2 Solidity Errors', function () {
contract = await factory.deploy(contractExternal.address)
})

beforeEach(async function () {
hasError = false
})

it('should confirm assert works', async function () {
try {
const res = await contract.assertCheck(1 == 1)
expect(res).to.equal(true)

await contract.assertCheck(1 > 1)
} catch (err) {
hasError = true
expect(err).to.exist
}
expect(hasError).to.equal(true)
})

it('should confirm require works', async function () {
try {
const resReverted = await contract.requireCheck(true)
expect(resReverted).to.equal(true)

const res = await contract.requireCheck(false)
await contract.requireCheck(false)
} catch (err) {
hasError = true
expect(err).to.exist
}
expect(hasError).to.equal(true)
})

it('should confirm revert works', async function () {
try {
await contract.revertCheck()
} catch (err) {
hasError = true
expect(err).to.exist
}
expect(hasError).to.equal(true)
})

it('should confirm revert with message works', async function () {
const message = "We unfortunalty need to revert this transaction"
try {
await contract.revertWithMessageCheck(message)
} catch (err) {
hasError = true
expect(err.reason).to.exist
expect(err.reason).to.equal(message)
}
expect(hasError).to.equal(true)
})

it('should confirm revert with custom error works', async function () {
try {
await contract.revertWithCustomError()
} catch (err) {
hasError = true
expect(err.code).to.equal('CALL_EXCEPTION')
expect(err.errorName).to.equal('InsufficientBalance')
expect(err.errorArgs.available).to.equal(ethers.BigNumber.from(1))
expect(err.errorArgs.required).to.equal(ethers.BigNumber.from(100))
}
expect(hasError).to.equal(true)
})

it('should confirm try/catch with simple revert', async function () {
Expand Down

0 comments on commit 15781f9

Please sign in to comment.