I'm developing a contract and when I try to test it on Remix, sometimes I can create it, sometimes not.
creation of ContractName errored: transaction execution failed
It seems that the environment requires a huge amount of gas to execute this creation.
And no matter how I increase the Gas Limit it is never enough.
The funny stuff is that sometimes the very same contract (with no change in its code) can be created without any problem.
There's also a curious fact that when I take a function off that contract it always require a non-infinite amount of gas on its creation:
function Redeem(address account, uint amount) public onlyOwner returns(uint) {
require(_yield[account] >= amount, "Not enought funds.");
_yield[account] -= amount;
return amount;
}
Does anybody has a reasonable explanation for all that. I appreciate very much!
EDIT:
I took some time evaluating the code, and I realized one thing:
There are the contract A and the contract B. A has a function that creates an instance of B.
function AddB(Someinterface x) public onlyOwner {
require(address(_bs[x.Name()]) == 0x0, "B for this name already exists.");
require(keccak256(abi.encodePacked(x.Name())) != keccak256(abi.encodePacked("text")), "text name is reserved.");
_bs[x.Name()] = B(new B(x));
}
When I try to deploy A, I have the problem I told above.
I can always deploy B directly from Remix without any problem.
When I took off the function in A that creates an instance of B, I can deploy A without any problem.
When I keep this function in A, and took off some random functions from B that doesn't seem to have any relation to the problem, A can be deployed normally.
When I keep this function in A, and comment out some random lines in A, A can be deployed normally.
For example:
function _Redeem(address account, uint amount) internal returns(uint) {
require(address(_bs[_selectedB[msg.sender]]) != 0x0, "This is not redeemable.");
amount = _bs[_selectedB[msg.sender]].Redeem(account, amount);
_totalDeposits += amount;
_deposits[account] += amount;
return amount;
}
function _RedeemAll(address account) internal returns(uint) {
require(address(_bs[_selectedB[msg.sender]]) != 0x0, "This is not redeemable.");
uint amount = _bs[_selectedB[msg.sender]].RedeemAll(account);
_totalDeposits += amount;
_deposits[account] += amount;
return amount;
}
This contract is not created.
function _Redeem(address account, uint amount) internal returns(uint) {
//require(address(_bs[_selectedB[msg.sender]]) != 0x0, "This is not redeemable.");
amount = _bs[_selectedB[msg.sender]].Redeem(account, amount);
_totalDeposits += amount;
_deposits[account] += amount;
return amount;
}
function _RedeemAll(address account) internal returns(uint) {
require(address(_bs[_selectedB[msg.sender]]) != 0x0, "This is not redeemable.");
uint amount = _bs[_selectedB[msg.sender]].RedeemAll(account);
_totalDeposits += amount;
_deposits[account] += amount;
return amount;
}
This contract goes ok.
function _Redeem(address account, uint amount) internal returns(uint) {
require(address(_bs[_selectedB[msg.sender]]) != 0x0, "This is not redeemable.");
amount = _bs[_selectedB[msg.sender]].Redeem(account, amount);
_totalDeposits += amount;
_deposits[account] += amount;
return amount;
}
function _RedeemAll(address account) internal returns(uint) {
//require(address(_bs[_selectedB[msg.sender]]) != 0x0, "This is not redeemable.");
uint amount = _bs[_selectedB[msg.sender]].RedeemAll(account);
_totalDeposits += amount;
_deposits[account] += amount;
return amount;
}
This also goes ok.
Any thoughts on that?
_yield[account]
instead ofamount
in your function. Now it will return the same value as you passed to the function.B(new B(x));