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!
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.