4

I've noticed that the deploying address in my truffle .js tests is equal to the address at accounts[0].

Since it's important to me to test the ownership of a contract, I'd like to know if it's guaranteed that contacts deployed by accounts[0] in the test suite.

5

Yes that is the case. accounts[0] is the default. If you like to test to call a function form an another account you can pass {from: accounts[1]} as the last parameter of your function. If you would have a function like this:

MyContract.getBalance(address);

It would look like this:

MyContract.getBalance.call(address, {from: accounts[1]});

You can get your accounts in truffle console wtith:

var accounts = web3.eth.accounts;

I hope that helps

  • Thanks! The answer would be even better if you'd change to MyContract.getBalance.call(address); – Frank Bonnet May 10 '17 at 12:28

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.