I am following kind of an outdated tutorial and trying to adapt it to the more recent changes in Solidity and other packages. Following one of my changes, I am running into a problem that I can't find an answer to.
The relevant part of my contract looks like this:
contract Campaign {
struct Request {
string description;
uint value;
address payable recipient;
bool complete;
mapping (address => bool) approvals;
uint approvalCount;
}
address public manager;
uint numRequests;
mapping (uint => Request) requests;
modifier restrictedToManager() {
require(msg.sender == manager);
_;
}
constructor(uint minimum, address creator) {
manager = creator;
minimumContribution = minimum;
}
function createRequest(string calldata description, uint value, address payable recipient) public restrictedToManager {
// get last index of requests from storage
Request storage newRequest = requests[numRequests];
// increase requests counter
numRequests ++;
// add information about new request
newRequest.description = description;
newRequest.value = value;
newRequest.recipient = recipient;
newRequest.approvalCount = 0;
}
Now I am testing the contract locally using the ganache provider. In one of the tests, I want to call the createRequest
method and then check if the request has been created. With the code I pasted above, this does not work because the property requests
has not been set public so I can't run the getter function.
However, once I change that line to mapping (uint => Request) public requests
and try to test again, the transaction immediately runs out of gas when running the beforeEach hook for the first time, even with a limit of 1.000.000
To be clear, I use the beforeEach hook to deploy the contract.
How can it be that this simple change results in such a big change in gas fees?