question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error with `from` in tests

See original GitHub issue
  • I’ve asked for help in the Truffle Gitter before filing this issue.

Issue

When running tests with the {from: account} is ignored in tests. I have debugged it through the SolidityFunction.prototype.sendTransaction function where there are two options objects with the argument I pass in the test and the default options (I assume).

Regardless, the {from: account} is ignored (see the github repo below).

More debugging. I updated the sendTransaction() function with a console.log:

SolidityFunction.prototype.execute = function () {
    var transaction = !this._constant;

	console.log('execute ------->', transaction, Array.prototype.slice.call(arguments))

    // send transaction
    if (transaction) {
        return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments));
    }

    // call
    return this.call.apply(this, Array.prototype.slice.call(arguments));
};

This results in:

Notice the second {from} options object. The first {from} options object contains the address I am passing in while the second one contains the accounts[0] address.

Steps to Reproduce

git clone https://github.com/auser/truffle-bug
npm install

In one terminal, run ganache:

npm run ganache

In another, run the test:

./node_modules/.bin/truffle test --network development test/multisig/testMultiSig.js

Expected Behavior

I expect the msg.sender address to be the address I pass in instead of the default account (accounts[0]).

Actual Results

The msg.sender value is the default account (accounts[0]) instead of the address I pass in using the from option.

Environment

  • Operating System: OSX High Sierra
  • Ethereum client: truffle test
  • Truffle version (truffle version): Truffle v4.1.5 (core: 4.1.5) Solidity v0.4.21 (solc-js)
  • node version (node --version): v9.5.0
  • npm version (npm --version): 5.8.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:22 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ausercommented, Apr 24, 2018

@cgewecke okay, I created a branch called simplification (https://github.com/auser/truffle-bug/tree/simplification) that reproduces the behavior.

The contract method:

pragma solidity ^0.4.18;

contract MultiSig {
    event MultiSigSigned(uint index, address signer);

    function sign(uint index)
        public
    {
        emit MultiSigSigned(index, msg.sender);
    }
}

The javascript test:

const th = require('../lib/testHelper');
const should = th.should();

const MultiSig = artifacts.require('./MultiSig');

contract('MultiSig', ([owner, user1]) => {
  let multisig;

  beforeEach(async () => {
    multisig = await MultiSig.new();
  });

  describe('events', async () => {

    it('fires MultiSigSigned when signed', async () => {
      const {logs} = await multisig.sign(0, {from: user1});
      logs.length.should.equal(1);
      logs[0].event.should.equal('MultiSigSigned');
      logs[0].args.index.should.be.bignumber.equal(0);

      logs[0].args.signer.should.equal(user1);
    });

  });
});

In addition, I’m using the local truffle version from the repo (./node_modules/.bin/truffle test --network development test/multisig/testMultiSig.js)

Truffle v4.1.7 (core: 4.1.7)
Solidity v0.4.23 (solc-js)

And the issue occurs on my globally installed truffle (truffle test --network development test/multisig/testMultiSig.js):

Truffle v4.1.5 (core: 4.1.5)
Solidity v0.4.21 (solc-js)

FYI: I’m not trying to find a shortcut here, hence why I created a repo to demonstrate the issue. I wanted a way to demonstrate the issue in a reproducible way.

0reactions
cgeweckecommented, Apr 26, 2018

@emmonspired No, I’m not sure what’s going on here. If you discover something please report. It’s possible there’s a compatibility issue between chai-bignumber (at some version) and truffle. Zeppelin is using them in combination without any obvious issues. They’re at:

truffle: 4.1.5
chai-bignumber: ^2.0.0
Read more comments on GitHub >

github_iconTop Results From Across the Web

The Six Types of Test-Taking Errors
The Six Types of Test-Taking Errors · Misread direction errors - these errors occur when you skip directions or misunderstand directions but answer...
Read more >
How to test a function that's expected to throw error in jest…
Say, I want to write a test for the function below and want to ensure I test if it actually fails when the...
Read more >
Software Testing Errors to look out for (with examples)
In this article, we discuss some common software testing errors that a tester should be aware of. These errors are explained with examples...
Read more >
Test errors versus test failures | Django 1.1 Testing and ...
Failures mean actual results didn't match what was expected, whereas errors mean some other problem (exception) was encountered during the test run. Errors...
Read more >
How to test the type of a thrown exception in Jest
My current testing framework is AVA and I can test it as a second argument t.throws method, like here: it('should throw Error with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found