2

Such as WhitelistedCrowdsale.test.js in openzeppelin-solidity:

contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized, anotherAuthorized]) { ... } in line 12.

why the parametes of function(...) is _, wallet, authorized, unauthorized, anotherAuthorized? Can they be other things? why?

Thanks!

wsgzg
  • 21
  • 1
  • For those trying to help, I believe this is the file: https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/test/crowdsale/WhitelistedCrowdsale.test.js. – user94559 Jun 11 '18 at 13:18

1 Answers1

1

Truffle injects the list of accounts available from the node you’re connected to. From the Truffle docs:

The contract() function provides a list of accounts made available by your Ethereum client which you can use to write tests.

To use these accounts, you write your test case like this:

contract(‘MyContract’, function(accounts) {
  it(‘test1’, function() {
    const account = accounts[0];
    // do something with account
  }
});

accounts is just an array. The code from OpenZeppelin you posted is expecting there to be at least 5 accounts available in the node (the same array of accounts are available via web3.eth.getAccounts()). They are just decomposing the array into specific variable names. _ is accounts[0], wallet is accounts[1], etc. You can name them whatever you want.

Adam Kipnis
  • 10,175
  • 10
  • 35
  • 48