0

I have a contract like so:


pragma solidity ^0.5.16;
pragma experimental ABIEncoderV2;

Contract Ballot {

constructor(string[] memory proposalNames) public {

    }
}

How do I create a test-instance of it in solidity?

I tried:

pragma solidity >=0.4.25 <0.6.0;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";

import "../contracts/voting.sol";
contract TestVoting {

    function testCounter() public {
     Ballot meta = Ballot(DeployedAddresses.Ballot());


    }

}

but i get an error:

 1) TestVoting
       testCounter:
     Error: Returned error: VM Exception while processing transaction: revert
      at Context.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/testing/SolidityTest.js:94:1)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

How do I pass it its constructor arguments?

Based on this issue, it doesn't seem like it's possible to create a parameterized test contract -- is this really the case?

1

You can just deploy a new instance.

function testCounter() public {
     string[] memory params = new string[](3);
     params[0] = "bambino";
     params[1] = "was";
     params[2] = "here";
     Ballot ballot = new Ballot(params);

}
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.