gpt4 book ai didi

testing - 使用js的truffle测试, `contract `后面的参数怎么设置?

转载 作者:行者123 更新时间:2023-11-28 20:49:56 24 4
gpt4 key购买 nike

openzeppelin-solidity中的WhitelistedCrowdsale.test.js:

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

为什么function(...)的参数是_, wallet, authorized, unauthorized, anotherAuthorized?它们可以是其他东西吗?为什么?

谢谢!

最佳答案

Truffle 会注入(inject)您所连接节点的可用帐户列表。来自Truffle docs :

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

要使用这些帐户,您可以像这样编写测试用例:

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

accounts 只是一个数组。您发布的来自 OpenZeppelin 的代码预计节点中至少有 5 个可用帐户(相同的帐户数组可通过 web3.eth.getAccounts() 获得)。他们只是将数组分解为特定的变量名。 _accounts[0]walletaccounts[1],等等,你可以随便命名想要。

关于testing - 使用js的truffle测试, `contract `后面的参数怎么设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50793521/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com