Skip to content

Commit

Permalink
Simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Sep 27, 2024
1 parent 736b326 commit 006b3b1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 66 deletions.
11 changes: 5 additions & 6 deletions packages/core/contracts/test/NamespacedInLibrary.sol
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

// This is not valid according to ERC-7201 because the namespaced struct is outside of a contract.

library MyLibrary {
/// This is not considered a namespace according to ERC-7201 because the namespaced struct is outside of a contract.
library LibraryWithNamespace {
/// @custom:storage-location erc7201:example.main
struct MainStorage {
uint256 x;
uint256 y;
}
}

contract Example {
contract UsesLibraryWithNamespace {
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));
bytes32 private constant MAIN_STORAGE_LOCATION =
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500;

function _getMainStorage() private pure returns (MyLibrary.MainStorage storage $) {
function _getMainStorage() private pure returns (LibraryWithNamespace.MainStorage storage $) {
assembly {
$.slot := MAIN_STORAGE_LOCATION
}
}

function _getXTimesY() internal view returns (uint256) {
MyLibrary.MainStorage storage $ = _getMainStorage();
LibraryWithNamespace.MainStorage storage $ = _getMainStorage();
return $.x * $.y;
}
}
25 changes: 0 additions & 25 deletions packages/core/contracts/test/NamespacedToModify.sol
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ contract HasSpecialFunctions {
}

/// This is not considered a namespace according to ERC-7201 because the namespaced struct is outside of a contract.
/// Regardless, we should ensure this does not cause a compile error.
library LibraryWithNamespace {
/// @custom:storage-location erc7201:example.main
struct MainStorage {
Expand All @@ -316,34 +315,10 @@ library LibraryWithNamespace {
}
}

contract UsesLibraryWithNamespace {
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));
bytes32 private constant MAIN_STORAGE_LOCATION =
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500;

function _getMainStorage() private pure returns (LibraryWithNamespace.MainStorage storage $) {
assembly {
$.slot := MAIN_STORAGE_LOCATION
}
}
}

interface InterfaceWithNamespace {
/// @custom:storage-location erc7201:example.main
struct MainStorage {
uint256 x;
uint256 y;
}
}

contract UsesInterfaceWithNamespace is InterfaceWithNamespace {
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));
bytes32 private constant MAIN_STORAGE_LOCATION =
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500;

function _getMainStorage() private pure returns (MainStorage storage $) {
assembly {
$.slot := MAIN_STORAGE_LOCATION
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('namespace outside contract - error', async t => {
});

test('namespace in library - warning', async t => {
const contract = 'contracts/test/NamespacedInLibrary.sol:Example';
const contract = 'contracts/test/NamespacedInLibrary.sol:UsesLibraryWithNamespace';

const { solcOutput, decodeSrc } = await getOutputAndDecoder(contract);
validate(solcOutput, decodeSrc);
Expand Down
36 changes: 2 additions & 34 deletions packages/core/src/utils/make-namespaced.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ Generated by [AVA](https://avajs.dev).
}␊
library LibraryWithNamespace {␊
/// @custom:storage-location erc7201:example.main␊
struct MainStorage {␊
Expand All @@ -255,29 +254,14 @@ Generated by [AVA](https://avajs.dev).
}␊
}␊
abstract contract UsesLibraryWithNamespace {␊
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));␊
bytes32 private constant MAIN_STORAGE_LOCATION =␊
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500;␊
function _getMainStorage() private pure returns (bool $) {}␊
}␊
interface InterfaceWithNamespace {␊
/// @custom:storage-location erc7201:example.main␊
struct MainStorage {␊
uint256 x;␊
uint256 y;␊
}␊
}␊
abstract contract UsesInterfaceWithNamespace is InterfaceWithNamespace {␊
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));␊
bytes32 private constant MAIN_STORAGE_LOCATION =␊
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500;␊
function _getMainStorage() private pure returns (bool $) {}␊
}`,
`,
},
'contracts/test/NamespacedToModifyImported.sol': {
content: `// SPDX-License-Identifier: MIT␊
Expand Down Expand Up @@ -584,7 +568,6 @@ Generated by [AVA](https://avajs.dev).
}␊
/// This is not considered a namespace according to ERC-7201 because the namespaced struct is outside of a contract.␊
/// Regardless, we should ensure this does not cause a compile error.␊
library LibraryWithNamespace {␊
/// @custom:storage-location erc7201:example.main␊
struct MainStorage {␊
Expand All @@ -593,29 +576,14 @@ Generated by [AVA](https://avajs.dev).
}␊
}␊
abstract contract UsesLibraryWithNamespace {␊
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));␊
bytes32 private constant MAIN_STORAGE_LOCATION =␊
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500;␊
function _getMainStorage() private pure returns (bool $) {}␊
}␊
interface InterfaceWithNamespace {␊
/// @custom:storage-location erc7201:example.main␊
struct MainStorage {␊
uint256 x;␊
uint256 y;␊
}␊
}␊
abstract contract UsesInterfaceWithNamespace is InterfaceWithNamespace {␊
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));␊
bytes32 private constant MAIN_STORAGE_LOCATION =␊
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500;␊
function _getMainStorage() private pure returns (bool $) {}␊
}`,
`,
},
'contracts/test/NamespacedToModifyImported.sol': {
content: `// SPDX-License-Identifier: MIT␊
Expand Down
Binary file modified packages/core/src/utils/make-namespaced.test.ts.snap
Binary file not shown.

0 comments on commit 006b3b1

Please sign in to comment.