I have a function that returns multiple values

function getInfo(string id) returns(string x,string y){ bytes32 _id= strToBytes(id);
    return (infostruct[_id].x,infostruct[_id].y) ; }

Now i want to test this function using solidity test in truffle

function testBaseContract(){
 BaseContract basecontract= BaseContract(DeployedAddresses.BaseContract());

        var (x,y) = basecontract.getInfo("1");
        Assert.equal(x,"198/180","this id data is not accessible to you or doesn't exist at all.");

i don't know how to access multiple return values in solidity, this was my best guess and I am getting the error

TypeError: Member "equal" is not available in type(library Assert) outside of storage.
  • The problems appear to be with the function returning strings not with it being a tuple. It work when you use bytes32 instead.
    – Ismael
    Commented Jan 5, 2018 at 5:45

3 Answers 3


Basically the result it gives you back is truffle, you can either use explode to compare the result with expected in terms or object/array. But you access the result like the following -

            // data returns a tuple  
            var rowdata = data.toString().split(',')

            // you can access the values through array rowdata[0]
            // do the comparison

  • this is how one can do in JavaScript, how do I do this in Solidity Commented Jan 4, 2018 at 5:49

Change this:

var (x,y) = basecontract.getInfo("1");

To this:

var [x,y] = await basecontract.getInfo("1");

Doing this puts the return values in the response array. var repsonse = await basecontract.getInfo("1");

Now you can read the items as array elements like response[0] and response[1].

It worked for me.

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.