此函数部署一个新的erc721智能契约。它可以工作,因为当我试图从函数中调用契约的实例时,它可以工作。但是,当我写我的硬帽子测试时,这是我得到的错误:
来自原木:
Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="name()", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.6.4)来自本地节点:WARNING: Calling an account which is not a contract
我的职能:
function createCollection(string memory name_, string memory symbol_, string memory baseURI_, uint256 maxSupply,address owner) external returns (address collection) {
bytes memory bytecode = type(ERC721W).creationCode;
bytes32 salt = keccak256(abi.encodePacked(name_, symbol_, block.number ));
assembly {
collection := create2(0, add(bytecode, 32), mload(bytecode), salt)
}
ERC721W(collection).initialize(name_, symbol_, baseURI_, maxSupply, owner);
console.log('Inside contract', ERC721W(collection).symbol()); // for testing (works)
allCollections.push(address(collection));
emit CollectionCreated(name_, symbol_, baseURI_, allCollections.length, address(collection));
return collection;
}我的测试:
it("Should deploy a contract", async function () {
const { ercFactory, owner, account1 } = await loadFixture(deployFixture);
let name = "test";
let symbol = "tst";
let baseURI = "https://test";
let maxSupply = 10;
let ownerAddress = account1.address;
let newAddress = await ercFactory.callStatic.createCollection(
name,
symbol,
baseURI,
maxSupply,
ownerAddress
);
console.log("new address", newAddress);
let ERC721 = await ethers.getContractAt("ERC721W", newAddress);
//console.log(ERC721);
console.log(await ERC721.name());
console.log(await ethers.provider.getCode(newAddress));
//expect(await ERC721.owner()).to.be.equal(account1.address);
});调用任何函数都会抛出这个错误,我已经全部尝试过了。我没有任何其他合同的同名,所以getContractAt应该在工作。这里不太确定
发布于 2022-07-20 14:08:02
嘿,你能分享命令行的输出吗.
您是否可以尝试在newAddress中调用像在合同中一样生成的函数,或者是否有任何契约的输出显示?
https://ethereum.stackexchange.com/questions/132053
复制相似问题