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

Events: Support indexed array attributes in tests #87

Closed
svenstucki opened this issue Mar 4, 2019 · 6 comments
Closed

Events: Support indexed array attributes in tests #87

svenstucki opened this issue Mar 4, 2019 · 6 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@svenstucki
Copy link

The current to.emit().withArgs() matcher does not support indexed (variable length) arrays. Indexed attributes must be fixed size (32 bytes), so solidity stores a hash of the array content. This is not checked for and the comparison in a test fails.

Example contract:

pragma solidity ^0.5.4;

contract Test {
  event Event (bytes a, bytes indexed b);

  function emitEvent() public {
    bytes memory test = abi.encode(0x01);
    emit Event(test, test);
  }
}

Example test case:

import chai from 'chai';
import { createMockProvider, deployContract, getWallets, solidity } from 'ethereum-waffle';

import Test from '../build/Test';

chai.use(solidity);
const { expect } = chai;

describe('Test', () => {
  const provider = createMockProvider();
  const [wallet] = getWallets(provider);

  const packed = '0x0000000000000000000000000000000000000000000000000000000000000001';

  it('Should emit', async () => {
    const t = await deployContract(wallet, Test, []);

    await expect(t.emitEvent())
      .to.emit(t, 'Event')
      .withArgs(packed, packed);
  });
});

The actualArgs.values in matchers.ts line 113 contains the following:

     '0': '0x0000000000000000000000000000000000000000000000000000000000000001',
     '1':
      _Indexed {
        hash: '0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6' },

Which is not unexpected, but the comparison fails for the indexed argument. When passing an object in the test (i.e. { hash: '0xb10...' } instead of the 0x0..01 string), the comparison fails as well.

It would be great to have a simple way to test indexed attributes.

@sz-piotr
Copy link
Contributor

We would gladly merge a PR that adds this functionality!

@sz-piotr sz-piotr added good first issue Good for newcomers help wanted Extra attention is needed labels Dec 20, 2019
@zgorizzo69
Copy link
Contributor

@sz-piotr I have a simple PR for that. Can you give me the creds to push a branch ?

@sz-piotr
Copy link
Contributor

@zgorizzo69 You can fork the repository and open a PR this way :)

@wachulski
Copy link
Contributor

Shouldn't this one be closed? @sz-piotr ?

@sz-piotr
Copy link
Contributor

Thanks @wachulski
Closing.
Please note that I am no longer a maintainer and ping @marekkirejczyk in the future.

@wachulski
Copy link
Contributor

Yup, I noticed that @sz-piotr and hence created #467 Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants