I'm running into some trouble testing in Remix. The contribute function doesn't give me an input filed when I deploy the campaign. I want to test if the contribute function meets the minimumContribution criteria.
pragma solidity ^0.4.17;
contract CampaignFactory {
address[] public deployedCampaigns;
function createCampaign(string description, uint minimumContribution, string campaignCategory, string endDate) public {
address newlyCreatedCampaign = new Campaign(description, minimumContribution, campaignCategory, endDate, msg.sender);
deployedCampaigns.push(newlyCreatedCampaign);
}
function getDeployedCampaigns() public view returns (address[]) {
return deployedCampaigns;
} }
contract Campaign {
struct NewCampaignType {
string description;
uint minimumContribution;
string campaignCategory;
string endDate;
address managerAddress;
}
struct Request {
string description;
uint value;
address recipient;
bool complete;
uint approvalCount;
mapping(address => bool) approvals;
}
mapping(address => NewCampaignType) public campaigns;
Request[] public requests;
mapping(address => bool) public approvers;
uint public approversCount;
address public currentManagerAddress;
modifier restricted() {
require(msg.sender == campaigns[currentManagerAddress].managerAddress);
_;
}
function Campaign(string description, uint minimumContribution, string campaignCategory, string endDate, address managerAddress) public {
NewCampaignType memory createCampaign = NewCampaignType({
description: description,
minimumContribution: minimumContribution,
campaignCategory: campaignCategory,
endDate: endDate,
managerAddress: managerAddress
});
campaigns[managerAddress] = createCampaign;
}
function contribute() public payable {
require(msg.value > campaigns[currentManagerAddress].minimumContribution);
approvers[msg.sender] = true;
approversCount++;
}
function createRequest(string description, uint value, address recipient) public restricted {
Request memory newRequest = Request({
description: description,
value: value,
recipient: recipient,
complete: false,
approvalCount: 0
});
requests.push(newRequest);
}
function approveRequest(uint index) public {
Request storage request = requests[index];
require(approvers[msg.sender]);
require(!request.approvals[msg.sender]);
request.approvals[msg.sender] = true;
request.approvalCount++;
}
function finalizeRequest(uint index) public restricted {
Request storage request = requests[index];
require(request.approvalCount > (approversCount / 2));
require(!request.complete);
request.recipient.transfer(request.value);
request.complete = true;
}
function setCurrentManager(address managerAddress) public {
currentManagerAddress = managerAddress;
}
function getSummary() public view returns (
uint, uint, uint, uint, address
) {
return (
campaigns[currentManagerAddress].minimumContribution,
this.balance,
requests.length,
approversCount,
campaigns[currentManagerAddress].managerAddress
);
}
function getRequestsCount() public view returns (uint) {
return requests.length;
} }