Add naive selector collision test (#74)

This commit is contained in:
mzhu25 2020-12-07 19:49:37 -08:00 committed by GitHub
parent 907adf9145
commit e5eee96487
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View File

@ -1,4 +1,13 @@
[
{
"version": "0.12.0",
"changes": [
{
"note": "Add test for selector collisions on the proxy",
"pr": 74
}
]
},
{
"timestamp": 1607381756,
"version": "0.11.1",

View File

@ -0,0 +1,29 @@
import { blockchainTests, constants, expect } from '@0x/contracts-test-utils';
import { MethodAbi } from 'ethereum-types';
import * as wrappers from '../../src/wrappers';
blockchainTests('Selector collision test', env => {
it('Function selectors do not collide', () => {
const selectorToSignature: { [selector: string]: string } = {};
for (const wrapper of Object.values(wrappers)) {
if (typeof wrapper === 'function') {
const contract = new wrapper(constants.NULL_ADDRESS, env.provider, env.txDefaults);
contract.abi
.filter(abiDef => abiDef.type === 'function')
.map(method => {
const methodName = (method as MethodAbi).name;
const selector = contract.getSelector(methodName);
const signature = contract.getFunctionSignature(methodName);
if (selectorToSignature[selector]) {
expect(
signature,
`Selectors collide: ${signature}, ${selectorToSignature[selector]}`,
).to.equal(selectorToSignature[selector]);
}
selectorToSignature[selector] = signature;
});
}
}
});
});