简体   繁体   English

在使用js的松露测试中,如何在`contract`之后设置参数?

[英]In truffle test using js, how to set the parameters after the `contract `?

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

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

why the parametes of function(...) is _, wallet, authorized, unauthorized, anotherAuthorized ? 为什么function(...)的参数是_, 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. contract()函数提供了以太坊客户端可用的帐户列表,您可以使用这些帐户编写测试。

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. accounts只是一个数组。 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() ). 您发布的OpenZeppelin中的代码期望该节点中至少有5个帐户可用(可通过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. _accounts[0]walletaccounts[1]等,您可以根据需要命名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM