How to use a single Constructor-call in tests instead of "new" and "initialize"?

In openzeppelin-eth/tests, many tests uses a constructor to instantiate the contracts under test.

Instead of

const contract = new Contract();

they just use a contract, that overrides the original contract and call the initializer-functions directly into the constructor function, where all required arguments are passed.

I don’t know, why the tests in openzepplin are running through because I ran into issues using the same pattern.

import “…/MintedTokenSale.sol”;

contract MintedTokenSaleImpl is MintedTokenSale {
    constructor(uint256 openingTime, uint256 closingTime, MyToken token) public {
        super.initialize(openingTime, closingTime, token);

will not work. It reverts using

const c = new MintedTokenSaleImpl(openingTime, closingTime, token);

Also, if I change the constructors code into

        MintedTokenSale.initialize(openingTime, closingTime, token);

Any suggestions?


Hi @oxuw4

Suggest you have a look at the SampleCrowdsale and associated tests for how to set this up: