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.

1 Answer 1

5

Yes, that is the case. accounts[0] is the default. If you like to test calling a function from 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 with:

var accounts = web3.eth.accounts;

I hope that helps.

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

Your Answer

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

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