我试图通过使用安全帽进行单元测试来部署我的智能合同。部署时的所有者被返回为0x0000。尽管在编写js脚本时,我以所有者的身份从安全帽网络中分配了一个特定的地址。
const hre = require('hardhat')
const { expect, assert } = require('chai')
describe('ProperSubsetFund', async function () {
// Initialize Contract Var
let deployERC20, deployer, user1, user2, trader1, trader2
let signers
beforeEach(async function () {
// Getting all the signers
signers = await hre.ethers.getSigners()
// console.log(signers.map(item => item.address));
// Assign addresses to roles for later use
deployer = signers[0].address
user1 = signers[1].address
user2 = signers[2].address
trader1 = signers[3].address
trader2 = signers[4].address
// Read Contract ERC20
const contractERC20 = await hre.ethers.getContractFactory('ProperSubsetERC20')
// Read Contract Launchpad
const contractLaunchpad = await hre.ethers.getContractFactory('ProperSubsetFactory')
// Read Contract Funds
const contractFunds = await hre.ethers.getContractFactory('ProperSubsetFund')
// Deploy the three contracts
deployERC20 = await contractERC20.connect(signers[0]).deploy(true)
});
describe('Deployment and Ownership', function () {
it('Check if the owner is the deployer', async function () {
expect(await deployERC20.owner()).to.equal(deployer)
});
});
})这些都是结果
ProperSubsetFund
Deployment and Ownership
Deployment
Should set the right owner:
AssertionError: expected '0x00000000000000000000000000000000000…' to equal '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb…'
+ expected - actual
-0x0000000000000000000000000000000000000000
+0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
at Context.<anonymous> (test/ProperSubsetFund.test.js:71:49)
at processTicksAndRejections (node:internal/process/task_queues:96:5)发布于 2022-11-12 05:24:53
“硬帽子”不返回address(0),您的合同owner()正在返回address(0)。如果你读了终端机上面写着
AssertionError: expected '0x00000000000000000000000000000000000…' to equal '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb…'既然你设定了这个:
expect(await deployERC20.owner()).to.equal(deployer)您的硬件部署地址是'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb…‘。但deployERC20.owner()是‘0x00000000000000000000000000000000000000000000000…’
https://stackoverflow.com/questions/74386781
复制相似问题