我正在用草帽为智能合同编写单元测试。在测试合同中的不同功能之前,我必须先部署合同。
我读了一些例子,代码如下:
const [deployer] = await ethers.getSigners()
const tokenFactory = await ethers.getContractFactory("Token");
const token = await tokenFactory.connect(deployer).deploy();
但当我尝试
const tokenFactory = await ethers.getContractFactory("Token");
const token = await tokenFactory.deploy();
我的测试也成功了。
我的问题是:在智能合同工厂之后,哪个帐户使用的是有.connect(deployer)
的。我查过ethers.js的文件,但没有运气。
当我想使用特定地址进行部署时,在ethers.js中指定智能合同工厂的地址的最佳实践是什么?
提前谢谢!
发布于 2022-12-30 15:12:47
在用硬帽子进行本地测试时:
const [deployer] = await ethers.getSigners()
返回由安全帽测试帐户提供的第一个帐户( account 0)。例如,如果你愿意
const [deployer,user1] = await ethers.getSigners()
您将检索第一次和第二次。
希望能帮上忙!
https://ethereum.stackexchange.com/questions/142054
复制相似问题