0

Working in truffle with TDD testing and am getting some errors when evaluating the return values of some functions.

If a function is returning multiple values in Solidity, how are they presented? Is it in an array or an object?

    it('can put the star on sale if ownership passes', async function() {
        await this.contract.putOnSale(1,50000, {from: accounts[0]});
        assert.equal(await this.contract.isOnSale(1), {true, 50000});
    });

Errors I am getting are as such:

AssertionError: expected { Object (0, 1, ...) } to equal { Object (identifier, code, ...) }
  + expected - actual

   {
  -  "0": "Barcode"
  -  "1": "1234567890-abcde"
  -  "2": "This is asset #1. There is not much to say about this asset given that it is fictional."
     "code": "1234567890-abcde"
     "description": "This is asset #1. There is not much to say about this asset given that it is fictional."
     "identifier": "Barcode"
   }

Thanks in advance and take care.

  • Um.. It literally tells you what is expected and what is actually returned in the error.. – Thomas Clowes Dec 7 '18 at 12:31
  • Hey @ThomasClowes. I am aware that truffle tells me it is expecting an object but for some reason setting the expected return variables in an object does not seem to work. So I was wondering if something might be going wrong and I (and Mocha test) shouldn't expect an object. Hence, the question. Any thoughts? – Valentijn van den Hout Dec 7 '18 at 14:14
0

Change this:

assert.equal(await this.contract.isOnSale(1), {true, 50000});

To this:

var [x, y] = await this.contract.isOnSale(1);
assert(x === true && y.equals(50000));

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.