以下契约使用接口方法(更改代码)调用另一个契约:
pragma solidity 0.8.7;
interface MyStorage {
function setStorageValue(uint256) external;
}
contract StorageFactory {
uint256 storageValue;
constructor(uint256 _storageValue) {
storage = _storageValue;
}
function initStorage(MyStorage store) public payable {
store.setStorageValue(storageValue);
address payable storeAddress = payable(address(store));
storeAddress.call{value: msg.value}("");
}
}以下是StorageContract (代码不能更改):
pragma solidity 0.8.7;
contract Storage {
int _storageValue;
function setStorageValue(int storageValue) public {
_storageValue = storageValue;
}
receive() external payable {
require(_storageValue == -1 || address(this).balance <= uint(_storageValue), "Invalid storage value");
}
fallback() external {
_storageValue = -1;
}
}通过传递一个存储对象,我使用一个测试来调用第一个契约的initStorage,在这个对象中,由于值设置为大量,所以测试将失败。但是不知怎么的,fallback()函数似乎被调用了,将值设置为-1。我搞不懂为什么。任何帮助都是非常感谢的。
发布于 2022-02-25 04:34:40
由于坚固医生
The fallback function is executed on a call to the contract if none of the other functions match the given function signature, or if no data was supplied at all and there is no receive Ether function. The fallback function always receives data, but in order to also receive Ether it must be marked payable.您的函数被调用,因为函数没有重载
function setStorageValue(uint256 storageValue) public因此,将storageValue从int更改为uint256将有帮助。
https://stackoverflow.com/questions/71255699
复制相似问题