Skip to content

Commit

Permalink
Add unit test for makeNamespacedInputCopy
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Sep 19, 2023
1 parent 2d3234c commit 473b642
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/core/src/storage/namespace.test.ts
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);
});
189 changes: 189 additions & 0 deletions packages/core/src/storage/namespace.test.ts.md
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 added packages/core/src/storage/namespace.test.ts.snap
Binary file not shown.

0 comments on commit 473b642

Please sign in to comment.