Skip to content

Commit 96ff826

Browse files
committed
Merge branch 'master' into typo-fixes
2 parents 58cbf7b + e8745a6 commit 96ff826

File tree

6 files changed

+194
-143
lines changed

6 files changed

+194
-143
lines changed

docs/templates/properties.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports.fullname = function fullname({ item }) {
3535

3636
module.exports.inheritance = function ({ item, build }) {
3737
if (!isNodeType('ContractDefinition', item)) {
38-
throw new Error('used inherited-items on non-contract');
38+
throw new Error('inheritance modifier used on non-contract');
3939
}
4040

4141
return item.linearizedBaseContracts
@@ -65,14 +65,14 @@ module.exports['has-internal-variables'] = function ({ item }) {
6565

6666
module.exports.functions = function ({ item }) {
6767
return [
68-
...[...findAll('FunctionDefinition', item)].filter(f => f.visibility !== 'private'),
69-
...[...findAll('VariableDeclaration', item)].filter(f => f.visibility === 'public'),
68+
...findAll('FunctionDefinition', item).filter(f => f.visibility !== 'private'),
69+
...findAll('VariableDeclaration', item).filter(f => f.visibility === 'public'),
7070
];
7171
};
7272

7373
module.exports.returns2 = function ({ item }) {
7474
if (isNodeType('VariableDeclaration', item)) {
75-
return [{ type: item.typeDescriptions.typeString }];
75+
return [{ type: item.typeName.typeDescriptions.typeString }];
7676
} else {
7777
return item.returns;
7878
}

scripts/generate/templates/Packing.t.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import {Packing} from "@openzeppelin/contracts/utils/Packing.sol";
1111
`;
1212

1313
const testPack = (left, right) => `\
14-
function testPack(bytes${left} left, bytes${right} right) external pure {
14+
function testSymbolicPack(bytes${left} left, bytes${right} right) external pure {
1515
assertEq(left, Packing.pack_${left}_${right}(left, right).extract_${left + right}_${left}(0));
1616
assertEq(right, Packing.pack_${left}_${right}(left, right).extract_${left + right}_${right}(${left}));
1717
}
1818
`;
1919

2020
const testReplace = (outer, inner) => `\
21-
function testReplace(bytes${outer} container, bytes${inner} newValue, uint8 offset) external pure {
21+
function testSymbolicReplace(bytes${outer} container, bytes${inner} newValue, uint8 offset) external pure {
2222
offset = uint8(bound(offset, 0, ${outer - inner}));
2323
2424
bytes${inner} oldValue = container.extract_${outer}_${inner}(offset);

scripts/generate/templates/SlotDerivation.t.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function testSymbolicDeriveMapping${name}(${type} key) public view {
6262
`;
6363

6464
const mappingDirty = ({ type, name }) => `\
65-
function testSymbolicDeriveMapping${name}Dirty(bytes32 dirtyKey) public {
65+
function testSymbolicDeriveMapping${name}Dirty(bytes32 dirtyKey) public view {
6666
${type} key;
6767
assembly {
6868
key := dirtyKey

test/utils/NoncesKeyed.t.sol

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// SPDX-License-Identifier: MIT
2+
// This file was procedurally generated from scripts/generate/templates/Packing.t.js.
3+
4+
pragma solidity ^0.8.20;
5+
6+
import {Test} from "forge-std/Test.sol";
7+
import {NoncesKeyed} from "@openzeppelin/contracts/utils/NoncesKeyed.sol";
8+
import {Nonces} from "@openzeppelin/contracts/utils/Nonces.sol";
9+
10+
// CAUTION: Unsafe mock for testing purposes.
11+
contract NoncesKeyedMock is NoncesKeyed {
12+
function useNonce(address owner, uint192 key) public returns (uint256) {
13+
return _useNonce(owner, key);
14+
}
15+
16+
function useCheckedNonce(address owner, uint192 key, uint64 nonce) public {
17+
_useCheckedNonce(owner, key, nonce);
18+
}
19+
}
20+
21+
contract NoncesKeyedTest is Test {
22+
NoncesKeyedMock private _mock;
23+
24+
function setUp() public {
25+
_mock = new NoncesKeyedMock();
26+
}
27+
28+
function testSymbolicUseNonce(address owner, uint192 key) public {
29+
uint256 prevNonce = _mock.useNonce(owner, key);
30+
assertEq(prevNonce + 1, _mock.nonces(owner, key));
31+
}
32+
33+
function testSymbolicUseCheckedNonceLiveness(address owner, uint192 key) public {
34+
uint256 currNonce = _mock.nonces(owner, key);
35+
36+
// Does not revert
37+
_mock.useCheckedNonce(owner, key, uint64(currNonce));
38+
assertEq(currNonce + 1, _mock.nonces(owner, key));
39+
}
40+
41+
function testUseCheckedNonce(address owner, uint192 key, uint64 nonce) public {
42+
uint256 currNonce = _mock.nonces(owner, key);
43+
44+
if (uint64(currNonce) == nonce) {
45+
_mock.useCheckedNonce(owner, key, nonce);
46+
} else {
47+
vm.expectRevert(abi.encodeWithSelector(Nonces.InvalidAccountNonce.selector, owner, currNonce));
48+
_mock.useCheckedNonce(owner, key, nonce);
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)