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 Jan 5 '18 at 5:45

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 – Brij Raj Singh - MSFT Jan 4 '18 at 5:49

Change this:

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

To this:

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

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.