-
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.
Add unit test for makeNamespacedInputCopy
- Loading branch information
Showing
3 changed files
with
203 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import test from 'ava'; | ||
import { artifacts } from 'hardhat'; | ||
|
||
import { makeNamespacedInputCopy } from './namespace'; | ||
|
||
test('make namespaced input copy', async t => { | ||
const origBuildInfo = await artifacts.getBuildInfo('contracts/test/Namespaced.sol:Example'); | ||
if (origBuildInfo === undefined) { | ||
throw new Error('Build info not found'); | ||
} | ||
|
||
const modifiedInput = makeNamespacedInputCopy(origBuildInfo.input, origBuildInfo.output); | ||
t.snapshot(modifiedInput); | ||
}); |
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,189 @@ | ||
# Snapshot report for `src/storage/namespace.test.ts` | ||
|
||
The actual snapshot is saved in `namespace.test.ts.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## make namespaced input copy | ||
|
||
> Snapshot 1 | ||
{ | ||
language: 'Solidity', | ||
settings: { | ||
outputSelection: { | ||
'*': { | ||
'': [ | ||
'ast', | ||
], | ||
'*': [ | ||
'storageLayout', | ||
], | ||
}, | ||
}, | ||
}, | ||
sources: { | ||
'contracts/test/Namespaced.sol': { | ||
content: `// SPDX-License-Identifier: MIT␊ | ||
pragma solidity ^0.8.20;␊ | ||
␊ | ||
contract Example {␊ | ||
/// @custom:storage-location erc7201:example.main␊ | ||
struct MainStorage {␊ | ||
uint256 x;␊ | ||
uint256 y;␊ | ||
} MainStorage $MainStorage;␊ | ||
␊ | ||
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));␊ | ||
bytes32 private constant MAIN_STORAGE_LOCATION =␊ | ||
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500;␊ | ||
␊ | ||
␊ | ||
␊ | ||
␊ | ||
}␊ | ||
␊ | ||
contract MultipleNamespaces {␊ | ||
/// @custom:storage-location erc7201:one␊ | ||
struct S1 {␊ | ||
uint256 a;␊ | ||
} S1 $S1;␊ | ||
␊ | ||
/// @custom:storage-location erc7201:two␊ | ||
struct S2 {␊ | ||
uint128 a;␊ | ||
} S2 $S2;␊ | ||
}␊ | ||
␊ | ||
contract ExampleV2_Ok {␊ | ||
/// @custom:storage-location erc7201:example.main␊ | ||
struct MainStorage {␊ | ||
uint256 x;␊ | ||
uint256 y;␊ | ||
uint256 z;␊ | ||
} MainStorage $MainStorage;␊ | ||
␊ | ||
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));␊ | ||
bytes32 private constant MAIN_STORAGE_LOCATION =␊ | ||
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500;␊ | ||
␊ | ||
␊ | ||
␊ | ||
␊ | ||
}␊ | ||
␊ | ||
contract ExampleV2_Bad {␊ | ||
/// @custom:storage-location erc7201:example.main␊ | ||
struct MainStorage {␊ | ||
uint256 y;␊ | ||
} MainStorage $MainStorage;␊ | ||
␊ | ||
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));␊ | ||
bytes32 private constant MAIN_STORAGE_LOCATION =␊ | ||
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500;␊ | ||
␊ | ||
␊ | ||
␊ | ||
␊ | ||
}␊ | ||
␊ | ||
contract RecursiveStruct {␊ | ||
struct MyStruct {␊ | ||
uint128 a;␊ | ||
uint256 b;␊ | ||
}␊ | ||
␊ | ||
/// @custom:storage-location erc7201:example.main␊ | ||
struct MainStorage {␊ | ||
MyStruct s;␊ | ||
uint256 y;␊ | ||
} MainStorage $MainStorage;␊ | ||
}␊ | ||
␊ | ||
contract RecursiveStructV2_Outer_Ok {␊ | ||
struct MyStruct {␊ | ||
uint128 a;␊ | ||
uint256 b;␊ | ||
}␊ | ||
␊ | ||
/// @custom:storage-location erc7201:example.main␊ | ||
struct MainStorage {␊ | ||
MyStruct s;␊ | ||
uint256 y;␊ | ||
uint256 z;␊ | ||
} MainStorage $MainStorage;␊ | ||
}␊ | ||
␊ | ||
contract RecursiveStructV2_Bad {␊ | ||
struct MyStruct {␊ | ||
uint128 a;␊ | ||
uint256 b;␊ | ||
uint256 c;␊ | ||
}␊ | ||
␊ | ||
/// @custom:storage-location erc7201:example.main␊ | ||
struct MainStorage {␊ | ||
MyStruct s;␊ | ||
uint256 y;␊ | ||
} MainStorage $MainStorage;␊ | ||
}␊ | ||
␊ | ||
contract MultipleNamespacesAndRegularVariables {␊ | ||
/// @custom:storage-location erc7201:one␊ | ||
struct S1 {␊ | ||
uint128 a;␊ | ||
uint256 b;␊ | ||
} S1 $S1;␊ | ||
␊ | ||
/// @custom:storage-location erc7201:two␊ | ||
struct S2 {␊ | ||
uint128 a;␊ | ||
uint256 b;␊ | ||
} S2 $S2;␊ | ||
␊ | ||
uint128 public a;␊ | ||
uint256 public b;␊ | ||
}␊ | ||
␊ | ||
contract MultipleNamespacesAndRegularVariablesV2_Ok {␊ | ||
/// @custom:storage-location erc7201:one␊ | ||
struct S1 {␊ | ||
uint128 a;␊ | ||
uint256 b;␊ | ||
uint256 c;␊ | ||
} S1 $S1;␊ | ||
␊ | ||
/// @custom:storage-location erc7201:two␊ | ||
struct S2 {␊ | ||
uint128 a;␊ | ||
uint256 b;␊ | ||
uint256 c;␊ | ||
} S2 $S2;␊ | ||
␊ | ||
uint128 public a;␊ | ||
uint256 public b;␊ | ||
uint256 public c;␊ | ||
}␊ | ||
␊ | ||
contract MultipleNamespacesAndRegularVariablesV2_Bad {␊ | ||
/// @custom:storage-location erc7201:one␊ | ||
struct S1 {␊ | ||
uint256 c;␊ | ||
uint128 a;␊ | ||
uint256 b;␊ | ||
} S1 $S1;␊ | ||
␊ | ||
/// @custom:storage-location erc7201:two␊ | ||
struct S2 {␊ | ||
uint256 c;␊ | ||
uint128 a;␊ | ||
uint256 b;␊ | ||
} S2 $S2;␊ | ||
␊ | ||
uint256 public c;␊ | ||
uint128 public a;␊ | ||
uint256 public b;␊ | ||
}`, | ||
}, | ||
}, | ||
} |
Binary file not shown.