Skip to content

Instantly share code, notes, and snippets.

@marekkirejczyk
Created May 3, 2020 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marekkirejczyk/fcc6d98c8b012863351384dc17fd56d1 to your computer and use it in GitHub Desktop.
Save marekkirejczyk/fcc6d98c8b012863351384dc17fd56d1 to your computer and use it in GitHub Desktop.
findEventFragment.test.ts
import {expect} from 'chai';
import {findEventFragment} from '../../src/matchers/findEventFragment';
const contract = {
interface: {
events:
{
'One(uint256,string,bytes32)':
{
name: 'One',
anonymous: false,
inputs: [Array],
type: 'event',
_isFragment: true
},
'Two(uint256,string)':
{
name: 'Two',
anonymous: false,
inputs: [Array],
type: 'event',
_isFragment: true
},
'Two(string)':
{
name: 'Two',
anonymous: false,
inputs: [Array],
type: 'event',
_isFragment: true
},
'Arrays(uint256[3],bytes32[2])':
{
name: 'Arrays',
anonymous: false,
inputs: [Array],
type: 'event',
_isFragment: true
}
},
}
} as any;
describe('UNIT: findEventFragment', () => {
it('Return undefined if can`t find', async () => {
expect(findEventFragment(contract, 'Seven')).to.be.undefined;
});
it('Find simple name', async () => {
expect(findEventFragment(contract, 'One')).to.include({
name: 'One',
anonymous: false,
type: 'event',
_isFragment: true
});
});
it('Find canonical name', async () => {
expect(findEventFragment(contract, 'One(uint256,string,bytes32)')).to.include({
name: 'One',
anonymous: false,
type: 'event',
_isFragment: true
});
});
it('Throw if ambiguous name', async () => {
expect(() => findEventFragment(contract, 'Two'))
.to.throw('Ambiguous event Two, could be Two(uint256,string) or Two(string)');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment