This is a follow-up question to How can I use deployed with a constructor argument

For testing purposes with mocha, I would like to configure my default deployed contract so that it is instantiated with the correct parameter. Is there a way to configure truffle / pudding so that the contract is always deployed with a certain parameter value?

1 Answer 1


I'm afraid you can't do it easily (but you can set up a more complex deploy management).

However, you can just create a new instance in a test just by calling


(Where 'Contract' is the name of a specific contract class name, like in Ballot.new() or MetaCoin.new() ). You could set up a contract instance in the before() function of your test and then just use that instance to test (you should set some contract() scope vars in the before() call and then test them within it() tests).


var expect      = require('chai').expect;

var log = console.log;

function clearBytes32(str){
    return str.replace(/\u0000/g, '');

function toInteger( bigNumber){
    return parseInt(bigNumber.toString() );

contract("Ballot" , function(accounts){
var ballot = null;

describe("new()" , function(){

    var chairperson = null;
    var proposalsCount = null;
    var firstProposal = null;


        Ballot.new(["hard fork" , "soft fork" , "do nothing"])
            ballot = contract;
        .then( function(){
            return ballot.chairperson();
            chairperson = response;
            return ballot.getProposal(0);
            firstProposal = response;
            return ballot.proposalsCount();
            proposalsCount = response;


    it("ballot should be set" , function(){
    } );

    it("ballot chairperson should be coinbase" , function(){

    it("ballot first proposal should be set" , function(){
        var ascii = web3.toAscii(firstProposal[0]);
        expect(clearBytes32(ascii)).to.be.equal("hard fork");

    it("ballot proposals count should be 3" , function(){
        expect( toInteger(proposalsCount) ).to.be.equal(3);

    describe("vote()" , function(){
        //ballot instance is available here.


  • this neeeds to get fixed Apr 24, 2017 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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