-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
120 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
contract DuplicateNamespace { | ||
/// @custom:storage-location erc7201:conflicting | ||
struct Conflicting1 { | ||
uint256 b; | ||
} | ||
|
||
/// @custom:storage-location erc7201:conflicting | ||
struct Conflicting2 { | ||
uint256 c; | ||
} | ||
} | ||
|
||
contract ConflictsWithParent is DuplicateNamespace { | ||
/// @custom:storage-location erc7201:conflicting | ||
struct Conflicting { | ||
uint256 a; | ||
} | ||
} | ||
|
||
contract ConflictsInBothParents is DuplicateNamespace, ConflictsWithParent { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import _test, { TestFn } from 'ava'; | ||
import { ContractDefinition } from 'solidity-ast'; | ||
import { findAll, astDereferencer } from 'solidity-ast/utils'; | ||
import { artifacts } from 'hardhat'; | ||
|
||
import { SolcOutput } from './solc-api'; | ||
import { StorageLayout } from './storage/layout'; | ||
import { extractStorageLayout } from './storage/extract'; | ||
import { solcInputOutputDecoder } from './src-decoder'; | ||
|
||
interface Context { | ||
extractStorageLayout: (contract: string) => ReturnType<typeof extractStorageLayout>; | ||
} | ||
|
||
const test = _test as TestFn<Context>; | ||
|
||
test.before(async t => { | ||
const buildInfo = await artifacts.getBuildInfo('contracts/test/NamespacedConflicts.sol:DuplicateNamespace'); | ||
if (buildInfo === undefined) { | ||
throw new Error('Build info not found'); | ||
} | ||
const solcOutput: SolcOutput = buildInfo.output; | ||
const contracts: Record<string, ContractDefinition> = {}; | ||
const storageLayouts: Record<string, StorageLayout> = {}; | ||
for (const def of findAll('ContractDefinition', solcOutput.sources['contracts/test/NamespacedConflicts.sol'].ast)) { | ||
contracts[def.name] = def; | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
storageLayouts[def.name] = solcOutput.contracts['contracts/test/NamespacedConflicts.sol'][def.name].storageLayout!; | ||
} | ||
const deref = astDereferencer(solcOutput); | ||
const decodeSrc = solcInputOutputDecoder(buildInfo.input, solcOutput); | ||
t.context.extractStorageLayout = name => | ||
extractStorageLayout(contracts[name], decodeSrc, deref, storageLayouts[name]); | ||
}); | ||
|
||
test('duplicate namespace', t => { | ||
const error = t.throws(() => t.context.extractStorageLayout('DuplicateNamespace')); | ||
t.snapshot(error?.message); | ||
}); | ||
|
||
test('conflicts with parent', t => { | ||
const error = t.throws(() => t.context.extractStorageLayout('ConflictsWithParent')); | ||
t.snapshot(error?.message); | ||
}); | ||
|
||
test('conflicts in both parents', t => { | ||
const error = t.throws(() => t.context.extractStorageLayout('ConflictsInBothParents')); | ||
t.snapshot(error?.message); | ||
}); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Snapshot report for `src/storage-namespaced-conflicts.test.ts` | ||
|
||
The actual snapshot is saved in `storage-namespaced-conflicts.test.ts.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## duplicate namespace | ||
|
||
> Snapshot 1 | ||
`Namespace erc7201:conflicting is defined multiple times for contract DuplicateNamespace␊ | ||
␊ | ||
The namespace erc7201:conflicting was found in structs at the following locations:␊ | ||
- contracts/test/NamespacedConflicts.sol:6␊ | ||
- contracts/test/NamespacedConflicts.sol:11␊ | ||
␊ | ||
Use a unique namespace id for each struct annotated with '@custom:storage-location erc7201:<NAMESPACE_ID>' in your contract and its inherited contracts.` | ||
|
||
## conflicts with parent | ||
|
||
> Snapshot 1 | ||
`Namespace erc7201:conflicting is defined multiple times for contract ConflictsWithParent␊ | ||
␊ | ||
The namespace erc7201:conflicting was found in structs at the following locations:␊ | ||
- contracts/test/NamespacedConflicts.sol:18␊ | ||
- contracts/test/NamespacedConflicts.sol:6␊ | ||
- contracts/test/NamespacedConflicts.sol:11␊ | ||
␊ | ||
Use a unique namespace id for each struct annotated with '@custom:storage-location erc7201:<NAMESPACE_ID>' in your contract and its inherited contracts.` | ||
|
||
## conflicts in both parents | ||
|
||
> Snapshot 1 | ||
`Namespace erc7201:conflicting is defined multiple times for contract ConflictsInBothParents␊ | ||
␊ | ||
The namespace erc7201:conflicting was found in structs at the following locations:␊ | ||
- contracts/test/NamespacedConflicts.sol:18␊ | ||
- contracts/test/NamespacedConflicts.sol:6␊ | ||
- contracts/test/NamespacedConflicts.sol:11␊ | ||
␊ | ||
Use a unique namespace id for each struct annotated with '@custom:storage-location erc7201:<NAMESPACE_ID>' in your contract and its inherited contracts.` |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters