0

I have a solidity function like the one below,

pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2;

contract Funding {
    function sum(uint input1, uint input2) public returns (uint) {
        return input1 + input2;
    }

    struct patient{
        uint id;
        string fullName;
        mapping(uint => string[]) DoctorAccess;        
    }

    function getPatient(uint patientId, uint doctorId) public returns (string[]) {
        patient p;
        p.id = 1;
        p.fullName="Saran";
        p.DoctorAccess[doctorId].push("Doctor1Key");
        return p.DoctorAccess[doctorId];
    }
}

The compilation of the code looks good. Hence, i have created a test case for the above one as given below.

pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2;

import "truffle/Assert.sol";
import "../contracts/Funding.sol";

contract FundingTest {

    function testSum() public {
        Funding  f= new Funding();
        Assert.equal(f.sum(1,2),3," two plus one should be three");
    }

    function test_getPatient() public {
        Funding f = new Funding();
        string[] doctorKeys;
        doctorKeys.push("Doctor1Key");
        Assert.equal(f.getPatient(1,1),doctorKeys, "The doctor mapping should be a valid one");
    }
}

When I try to run the test case, i am getting the below error

,/H/ethereum/PM/test/FundingTest.sol:18:9: TypeError: Member "equal" not found or not visible after argument-dependent lookup in type(library Assert) Assert.equal(f.getPatient(1,1),doctorKeys, "The doctor mapping should be a valid one");

Is the above test case wrong or is there something that needs to be addressed.

  • Similarly, i have created a solidity function that returns the struct, however, i don't find any example that can be used to consume the struct returned from the method within the test case. – Saravanan Oct 21 '18 at 7:58
1

The equal Method in solidity's Assert does not support arrays.

As mentioned here you would need to create a seperate Assert.equal statement for each entry in the array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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