@0x/contracts-zero-ex: Use (scaled) enums for storage IDs

This commit is contained in:
Lawrence Forman
2020-04-20 15:53:21 -04:00
parent 220039ab00
commit 4446ac1ca3
11 changed files with 86 additions and 29 deletions

View File

@@ -5,9 +5,10 @@ import { promisify } from 'util';
describe('Storage ID uniqueness test', () => {
const STORAGE_SOURCES_DIR = resolve(__dirname, '../../contracts/src/storage');
async function findStorageIdFromSourceFileAsync(path: string): Promise<string | void> {
const contents = await promisify(readFile)(path, { encoding: 'utf-8' });
const m = /STORAGE_ID\s*=\s*(0x[a-fA-F0-9]{64})/m.exec(contents);
const m = /LibStorage\.\s*getStorageOffset\(\s*LibStorage\.\s*StorageId\.\s*(\w+)\s*\)/m.exec(contents);
if (m) {
return m[1];
}
@@ -17,7 +18,9 @@ describe('Storage ID uniqueness test', () => {
const sourcePaths = (await promisify(readdir)(STORAGE_SOURCES_DIR))
.filter(p => p.endsWith('.sol'))
.map(p => resolve(STORAGE_SOURCES_DIR, p));
const storageIds = await Promise.all(sourcePaths.map(async p => findStorageIdFromSourceFileAsync(p)));
const storageIds = (await Promise.all(sourcePaths.map(async p => findStorageIdFromSourceFileAsync(p)))).filter(
id => !!id,
);
for (let i = 0; i < storageIds.length; ++i) {
const storageId = storageIds[i];
for (let j = 0; j < storageIds.length; ++j) {