I'm new in solidity and I'm triying to build a kind of DAO system.
The issue is that when I call the proposalCreation function (which has 2 input parameters of string type) the code crash and I do not understand the error message or why it's happening.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract VotationContract is Ownable {
uint256 public proposalTime = 0;
uint256 public votationStartTime = 0;
IERC20 public governanceToken;
address public governanceTokenAddress =
0x3194cBDC3dbcd3E11a07892e7bA5c3394048Cc87;
constructor() {
governanceToken = IERC20(governanceTokenAddress);
}
// Mapping with title and proposal description
mapping(string => string) public publishedProposals;
struct VotationResult {
string proposalTitle;
uint256 approvedVotes;
uint256 refusedVotes;
uint256 abstentionVotes;
}
VotationResult votation_result = VotationResult("No proposal yet", 0, 0, 0);
mapping(string => VotationResult) public proposalResults;
enum Voting_state {
Open,
Closed,
About_To_Start
}
Voting_state public state_voting = Voting_state.Closed;
address[] public whiteList;
// Proposal creation under 2 cases, the msg.sender has some tokens or is in the whiteList
function proposalCreation(
string memory proposalTitle,
string memory proposalDescription
) public {
// only 1 proposal at time because of state_voting
// Verify that there are not ongoing votations during proposal creation
require(
state_voting == Voting_state.Closed,
"Hay una votacion en curso"
);
if (
governanceToken.balanceOf(msg.sender) >=
(governanceToken.totalSupply() / 10)
) {
// Publish proposal
publishedProposals[proposalTitle] = proposalDescription;
// Change votation state - only 1 proposal at time
state_voting = Voting_state.About_To_Start;
// We asure that votation results starts always empty
votation_result = VotationResult(proposalTitle, 0, 0, 0);
proposalTime = block.timestamp;
}
// Verify that sender account is in the whiteList
bool whiteList_ok = false;
for (uint256 i = 0; i == whiteList.length; i++) {
if (msg.sender == whiteList[i]) {
whiteList_ok = true;
}
}
if (whiteList_ok == true) {
publishedProposals[proposalTitle] = proposalDescription;
state_voting = Voting_state.About_To_Start;
votation_result = VotationResult(proposalTitle, 0, 0, 0);
proposalTime = block.timestamp;
}
}
And the script to run that transaction is:
from brownie import VotationContract, GOVToken
from scripts.helpful_scripts import set_account
def test_creation_proposal_with_tokens():
# Arrange
account = set_account()
votation_contract = VotationContract.deploy({"from": account})
token_contract = GOVToken.deploy({"from": account})
tx_mint = token_contract.mint(100, {"from": account, "value": 10000000000005000})
tx_mint.wait(1)
# Acting
tx_proposal = votation_contract.proposalCreation(
"Primera Propuesta",
"Descripcion Primera propuesta",
{"from": account},
)
tx_proposal.wait(1)
# Assert
assert (
votation_contract.state_voting == votation_contract.Voting_state.About_To_start
)
And the error is:
Anyone knows why I'm getting this error and the cause of it?
Thanks.