![](/img/trans.png)
[英]How to send wei/eth to contract address? (using truffle javascript test)
[英]In truffle test using js, how to set the parameters after the `contract `?
例如openzeppelin-solidity
WhitelistedCrowdsale.test.js
:
contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized, anotherAuthorized]) { ... }
第12行。
为什么function(...)
的参数是_, wallet, authorized, unauthorized, anotherAuthorized
? 它们可以是其他东西吗? 为什么?
谢谢!
松露注入您所连接的节点上可用的帐户列表。 从松露文档 :
contract()函数提供了以太坊客户端可用的帐户列表,您可以使用这些帐户编写测试。
要使用这些帐户,您可以这样编写测试用例:
contract(‘MyContract’, function(accounts) {
it(‘test1’, function() {
const account = accounts[0];
// do something with account
}
});
accounts
只是一个数组。 您发布的OpenZeppelin中的代码期望该节点中至少有5个帐户可用(可通过web3.eth.getAccounts()
获得相同的帐户数组)。 他们只是将数组分解为特定的变量名。 _
是accounts[0]
, wallet
是accounts[1]
等,您可以根据需要命名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.