Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: the order in which fake are declared messes with the test's behaviour #105

Open
0xng opened this issue Dec 29, 2021 · 1 comment
Open

Comments

@0xng
Copy link
Member

0xng commented Dec 29, 2021

Describe the bug
When testing a function that uses fake.address and you have more than one fake declared/deployed, the behaviour of the tests changes according to the order in which these fakes are declared.
For example, let's say we have fakeA and fakeB, and a test that makes function fakeA.myFunction() revert and expects for it to actually revert when called with ethers.provider.call({ to: fakeA.address }). If fakeA is declared after fakeB, the test will pass, but if fakeB is declared after fakeA the test will fail.

Reproduction steps
I've pushed a branch that includes the failing test with this behaviour. In the beforeEach block of the text, you can switch the order in which the fakes are declared to see how the behaviour of the test changes.

  1. Go to this test on the feat/fake-test-at-address branch.
  2. Run yarn test. This test should fail.
  3. Switch the order in which fake and fakeAtAddress are declared in the beforeEach block
  4. Run yarn test. The test should work.

Expected behavior
Test should pass despite the order in which the fakes are declared.

@defi-wonderland defi-wonderland deleted a comment from gitcoinbot Dec 29, 2021
@defi-wonderland defi-wonderland deleted a comment from gitcoinbot Dec 29, 2021
@defi-wonderland defi-wonderland deleted a comment from gitcoinbot Dec 29, 2021
@austinbv
Copy link

austinbv commented Jan 5, 2022

This bug is actually more insidious than just the order of the functions

if you add this test

  it('not call other reverts', async () => {
    fake.fallback.reverts();
    try {
      await ethers.provider.call({to: fake.address})
    } catch {}

    expect(fakeAtAddress.fallback).not.to.have.been.called;
  });

The revert function actually references the same underlying object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants