0

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;
    } }

1 Answer 1

0

When testing by sending Eth you use the value input field located in Remix. Just fill in the value you want the user to send to the contract, if no error comes up it has met the requirements, otherwise you'll get the funds minus the transaction cost back. I hope that was your question answered?

3
  • My contribute function does not have an input field when loaded in Remix. When I try to click the contribute button, the error of "Note: The constructor should be payable if you send value" appears.
    – PLO
    Commented Mar 12, 2018 at 15:29
  • Could you tell me how you produce your error? I called the constructor, followed by calling the contribute function with a value of 1000 wei, which worked correctly.
    – Gabe
    Commented Mar 12, 2018 at 15:35
  • I actually just went back on it and looked at it again and you are correct. I originally had thought the input would be next to the contribute button, while rather the input is at the top with the option to select the currency (WEI, ETHER). It works now, cheers!
    – PLO
    Commented Mar 12, 2018 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.