Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dc59988

Browse files
authoredJun 6, 2025··
feat: creates user with private key and adds ERC-1271 wallet mock (#31)
* feat: generates user and returns it with private key * ci: revert lint ci build: fix script name * feat: adds ERC-1271 wallet mocks * fix: use relative path in source code * docs: adds AI recommendations
1 parent e169fd1 commit dc59988

File tree

8 files changed

+51
-13
lines changed

8 files changed

+51
-13
lines changed
 

‎.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414

1515
jobs:
1616
check:
17-
uses: "sablier-labs/gha-utils/.github/workflows/full-check.yml@main"
17+
uses: "sablier-labs/gha-utils/.github/workflows/evm-lint.yml@main"
1818

1919
build:
2020
uses: "sablier-labs/gha-utils/.github/workflows/forge-build.yml@main"

‎package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@
4343
"clean": "rm -rf broadcast cache out out-*",
4444
"forge:check": "forge fmt --check",
4545
"forge:write": "forge fmt",
46-
"full-check": "bun run solhint:check && bun run forge:write && bun run prettier:check",
47-
"full-write": "bun run solhint:write && bun run forge:write && bun run prettier:write",
46+
"full:check": "bun run solhint:check && bun run forge:write && bun run prettier:check",
47+
"full:write": "bun run solhint:write && bun run forge:write && bun run prettier:write",
48+
"lint": "bun run full:check",
4849
"solhint:check": "solhint \"{precompiles,script,src,tests}/**/*.sol\"",
4950
"solhint:write": "solhint --fix --noPrompt \"{precompiles,script,src,tests}/**/*.sol\"",
5051
"prepack": "bun install",

‎src/mocks/AdminableMock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity >=0.8.22;
33

4-
import { Adminable } from "src/Adminable.sol";
4+
import { Adminable } from "../../src/Adminable.sol";
55

66
contract AdminableMock is Adminable {
77
constructor(address initialAdmin) Adminable(initialAdmin) { }

‎src/mocks/BatchMock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity >=0.8.22;
33

4-
import { Batch } from "src/Batch.sol";
4+
import { Batch } from "../../src/Batch.sol";
55

66
contract BatchMock is Batch {
77
error InvalidNumber(uint256);

‎src/mocks/ERC1271WalletMock.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity >=0.8.22;
3+
4+
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
5+
import { Adminable } from "../../src/Adminable.sol";
6+
7+
contract ERC1271WalletMock is Adminable {
8+
constructor(address initialAdmin) Adminable(initialAdmin) { }
9+
10+
function isValidSignature(bytes32 hash, bytes memory signature) public view returns (bytes4 magicValue) {
11+
return
12+
ECDSA.recover(hash, signature) == admin ? bytes4(keccak256("isValidSignature(bytes32,bytes)")) : bytes4(0);
13+
}
14+
}

‎src/mocks/NoDelegateCallMock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity >=0.8.22;
33

4-
import { NoDelegateCall } from "src/NoDelegateCall.sol";
4+
import { NoDelegateCall } from "../../src/NoDelegateCall.sol";
55

66
contract NoDelegateCallMock is NoDelegateCall {
77
/// @dev An empty function that uses the `noDelegateCall` modifier.

‎src/mocks/RoleAdminableMock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity >=0.8.22;
33

4-
import { RoleAdminable } from "src/RoleAdminable.sol";
4+
import { RoleAdminable } from "../../src/RoleAdminable.sol";
55

66
contract RoleAdminableMock is RoleAdminable {
77
constructor(address initialAdmin) RoleAdminable(initialAdmin) { }

‎src/tests/BaseTest.sol

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { console2 } from "forge-std/src/console2.sol";
88
import { StdCheats } from "forge-std/src/StdCheats.sol";
99
import { StdStyle } from "forge-std/src/StdStyle.sol";
1010
import { StdUtils } from "forge-std/src/StdUtils.sol";
11-
import { IRoleAdminable } from "src/interfaces/IRoleAdminable.sol";
1211

12+
import { IRoleAdminable } from "../interfaces/IRoleAdminable.sol";
1313
import { ERC20MissingReturn } from "../mocks/erc20/ERC20MissingReturn.sol";
1414
import { ERC20Mock } from "../mocks/erc20/ERC20Mock.sol";
1515
import { ContractWithoutReceive, ContractWithReceive } from "../mocks/Receive.sol";
@@ -108,12 +108,37 @@ contract BaseTest is StdBase, StdCheats, StdUtils {
108108
return new ERC20Mock(name, symbol, decimals);
109109
}
110110

111-
/// @dev Generates a user, label its address, funds it with test tokens and approve `spenders` contracts.
112-
function createUser(string memory name, address[] memory spenders) internal returns (address payable) {
113-
address payable user = payable(makeAddr(name));
111+
/// @dev Generates a user, labels its address, funds it with test tokens, approves `spenders` contracts and returns
112+
/// the user's address.
113+
function createUser(string memory name, address[] memory spenders) internal returns (address payable user) {
114+
user = payable(makeAddr(name));
114115
vm.label(user, name);
115116
vm.deal({ account: user, newBalance: 100 ether });
116117

118+
dealAndApproveSpenders(user, spenders);
119+
}
120+
121+
/// @dev Generates a user, labels its address, funds it with test tokens, approves `spenders` contracts and returns
122+
/// the user's address and the private key.
123+
function createUserAndKey(
124+
string memory name,
125+
address[] memory spenders
126+
)
127+
internal
128+
returns (address payable user, uint256 privateKey)
129+
{
130+
address addr;
131+
(addr, privateKey) = makeAddrAndKey(name);
132+
133+
user = payable(addr);
134+
vm.label(user, name);
135+
vm.deal({ account: user, newBalance: 100 ether });
136+
137+
dealAndApproveSpenders(user, spenders);
138+
}
139+
140+
/// @dev Deals tokens to user and approve contracts from spenders list.
141+
function dealAndApproveSpenders(address user, address[] memory spenders) internal {
117142
for (uint256 i = 0; i < spenders.length; ++i) {
118143
for (uint256 j = 0; j < tokens.length; ++j) {
119144
deal({
@@ -124,8 +149,6 @@ contract BaseTest is StdBase, StdCheats, StdUtils {
124149
approveContract(address(tokens[j]), user, spenders[i]);
125150
}
126151
}
127-
128-
return user;
129152
}
130153

131154
/// @dev Retrieves the current block timestamp as an `uint40`.

0 commit comments

Comments
 (0)
Please sign in to comment.