Add naive selector collision test (#74)
This commit is contained in:
parent
907adf9145
commit
e5eee96487
@ -1,4 +1,13 @@
|
|||||||
[
|
[
|
||||||
|
{
|
||||||
|
"version": "0.12.0",
|
||||||
|
"changes": [
|
||||||
|
{
|
||||||
|
"note": "Add test for selector collisions on the proxy",
|
||||||
|
"pr": 74
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"timestamp": 1607381756,
|
"timestamp": 1607381756,
|
||||||
"version": "0.11.1",
|
"version": "0.11.1",
|
||||||
|
29
contracts/zero-ex/test/features/selector_collision_test.ts
Normal file
29
contracts/zero-ex/test/features/selector_collision_test.ts
Normal 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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user