Say I have a contract:
contract Reverts{
constructor(param1){
require(param1);
}
}
If param1
is false, the constructor should fail and revert state.
truffle-assertions
allows me to check if an existing contract abstraction's function will revert using await truffleAssertions.reverts(Reverts.someFunc());
That doesn't apply to constructors, since they are what make the contract abstraction in the first place.
How can I achieve this functionality with a constructor, instead of a regular function?
In a Truffle JavaScript testing file:
const truffleAssertions = require("truffle-assertions");
const Reverts = artifacts.require("Reverts");
let reverts;
contract("Reverts", (accounts) => {
it("Check that param1=false, constructor reverts.", async () =>{
// What to do here?
});
});