Where comes the "contract"-statement from in OZ-unit tests?

In Unit-tests from OZ there is code like

contract('ERC20Burnable', function (accounts) {
  const [ owner, ...otherAccounts ] = accounts;

  const initialBalance = new BN(1000);

  const name = 'My Token';
  const symbol = 'MTKN';

  beforeEach(async function () {
    this.token = await ERC20BurnableMock.new(name, symbol, owner, initialBalance, { from: owner });
  });

  shouldBehaveLikeERC20Burnable(owner, initialBalance, otherAccounts);
});

I could use the same blocks in my own hardhat-projects.

Where comes the contract-block-statement from?
Against to a describe-block, It seems to be able to have a this-statement where we can save some member variables for shared unit-test-functions ("shouldBehaveLikeSomething"). Also it seems to have the capabalities of executing beforeEach even when there is a function call and not an it-function.

I want this also in my own hardhat based projects :slight_smile: But the normal hardhat-stuff doesnt offer it.

Hey @oxuw4,

Not sure if I understand your question, but you can see the source code from these behavior tests, for example this for ERC1155.

The reason why there’s not it call, is because those calls are inside the should* function.

I see you want this to be available for hardhat, but I’m not sure if we can do that since it’d be tied to our configuration and implementations.

Hope this helps, best!

1 Like

The contract function comes from the hardhat-truffle5 plugin. It doesn't do anything significantly different from describe though. You should be able to use this in describe blocks as well, as long as you use function () { ... } as opposed to arrow functions like () => { ... }.

1 Like