protocol/contracts/zero-ex/test/features/selector_collision_test.ts
Elena 4d9b68d527
Removes references to tslint (#619)
* Removes references to tslint in contract-wrappers
which are obsoleted since https://github.com/0xProject/protocol/pull/584

* Remove tslint references in contracts/utils and test utils
obsoleted by https://github.com/0xProject/protocol/pull/589

* Remove tslint references in contracts/zeroex and test utils
obsoleted by https://github.com/0xProject/protocol/pull/587

* Remove other obsoleted tslint references

* Update contributing guidelines with eslint

* Fix prettier errors
2022-11-19 17:52:00 +02:00

33 lines
1.6 KiB
TypeScript

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 } = {};
selectorToSignature['bca8c7b5'] = 'executeCall(address,bytes)'; // legacy allowance target
selectorToSignature['a9059cbb'] = 'transfer(address,uint256)'; // ERC20Token transfer
selectorToSignature['23b872dd'] = 'transferFrom(address,address,uint256)'; // ERC20Token transferFrom
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;
});
}
}
});
});