Skip to content

Commit aff01b5

Browse files
XinyuCROthomas-nguyJayT106
authored
test: add eip-7702 tests (#1865)
* test: update py deps in integration tests * fmt: nix * fix: py deps * fix: lint nix * fix: py dep * fix: py dep * fix: tests * test: add batch tx test for 7702 * fix: audit * fix: tests * fix: gas * fix: deps * test: add revoke logic * fix: set hooks cause the states failed to commit * deps: * fix: tests * fix: audit * fix: deps * test: remove unsupported test * test: * fix comments * test * Revert "test" This reverts commit 6021c9f. --------- Signed-off-by: JayT106 <[email protected]> Co-authored-by: Thomas N. <[email protected]> Co-authored-by: Thomas Nguy <[email protected]> Co-authored-by: JayT106 <[email protected]>
1 parent 65ac223 commit aff01b5

27 files changed

+6302
-2534
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ lint-py:
148148
lint-nix:
149149
find . -name "*.nix" ! -path './integration_tests/contracts/*' ! -path "./contracts/*" | xargs nixfmt -c
150150

151-
.PHONY: lint lint-fix lint-py
151+
lint-nix-fix:
152+
find . -name "*.nix" ! -path './integration_tests/contracts/*' ! -path "./contracts/*" | xargs nixfmt
153+
154+
.PHONY: lint-install lint lint-fix lint-py lint-nix lint-nix-fix
152155

153156
###############################################################################
154157
### Releasing ###
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.28;
3+
4+
contract Counter {
5+
uint public count;
6+
7+
function increase() public {
8+
count++;
9+
}
10+
11+
function decrease() public {
12+
count--;
13+
}
14+
}

integration_tests/contracts/contracts/Gravity.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import "@openzeppelin/contracts/access/Ownable.sol";
55
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
66
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
77
import "@openzeppelin/contracts/utils/Address.sol";
8-
import "@openzeppelin/contracts/security/Pausable.sol";
9-
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
8+
import "@openzeppelin/contracts/utils/Pausable.sol";
9+
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
1010
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
1111
import "./CosmosToken.sol";
1212

@@ -787,7 +787,7 @@ contract Gravity is ReentrancyGuard, AccessControl, Pausable, Ownable {
787787
address[] memory _validators,
788788
uint256[] memory _powers,
789789
address relayerAdmin
790-
) {
790+
) Ownable(relayerAdmin) {
791791
// CHECKS
792792

793793
// Check that validators, powers, and signatures (v,r,s) set is well-formed
@@ -825,7 +825,7 @@ contract Gravity is ReentrancyGuard, AccessControl, Pausable, Ownable {
825825

826826
// ACL
827827

828-
_setupRole(RELAYER_ADMIN, relayerAdmin);
828+
_grantRole(RELAYER_ADMIN, relayerAdmin);
829829
_setRoleAdmin(RELAYER, RELAYER_ADMIN);
830830
_setRoleAdmin(RELAYER_ADMIN, RELAYER_ADMIN);
831831

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.28;
3+
4+
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
5+
import "@openzeppelin/contracts/interfaces/IERC1271.sol";
6+
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
7+
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
8+
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
9+
import "account-abstraction/contracts/core/Helpers.sol";
10+
import "account-abstraction/contracts/core/BaseAccount.sol";
11+
12+
/**
13+
* Simple7702Account.sol
14+
* A minimal account to be used with EIP-7702 (for batching) and ERC-4337 (for gas sponsoring)
15+
*/
16+
contract Simple7702Account is BaseAccount, IERC165, IERC1271, ERC1155Holder, ERC721Holder {
17+
18+
// address of entryPoint v0.8
19+
function entryPoint() public pure override returns (IEntryPoint) {
20+
return IEntryPoint(0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108);
21+
}
22+
23+
/**
24+
* Make this account callable through ERC-4337 EntryPoint.
25+
* The UserOperation should be signed by this account's private key.
26+
*/
27+
function _validateSignature(
28+
PackedUserOperation calldata userOp,
29+
bytes32 userOpHash
30+
) internal virtual override returns (uint256 validationData) {
31+
32+
return _checkSignature(userOpHash, userOp.signature) ? SIG_VALIDATION_SUCCESS : SIG_VALIDATION_FAILED;
33+
}
34+
35+
function isValidSignature(bytes32 hash, bytes memory signature) public view returns (bytes4 magicValue) {
36+
return _checkSignature(hash, signature) ? this.isValidSignature.selector : bytes4(0xffffffff);
37+
}
38+
39+
function _checkSignature(bytes32 hash, bytes memory signature) internal view returns (bool) {
40+
return ECDSA.recover(hash, signature) == address(this);
41+
}
42+
43+
function _requireForExecute() internal view virtual override {
44+
require(
45+
msg.sender == address(this) ||
46+
msg.sender == address(entryPoint()),
47+
"not from self or EntryPoint"
48+
);
49+
}
50+
51+
function supportsInterface(bytes4 id) public override(ERC1155Holder, IERC165) pure returns (bool) {
52+
return
53+
id == type(IERC165).interfaceId ||
54+
id == type(IAccount).interfaceId ||
55+
id == type(IERC1271).interfaceId ||
56+
id == type(IERC1155Receiver).interfaceId ||
57+
id == type(IERC721Receiver).interfaceId;
58+
}
59+
60+
// accept incoming calls (with or without value), to mimic an EOA.
61+
fallback() external payable {
62+
}
63+
64+
receive() external payable {
65+
}
66+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.28;
3+
4+
contract Simple7702Counter {
5+
uint public count;
6+
7+
function increase() public {
8+
count++;
9+
}
10+
11+
function decrease() public {
12+
count--;
13+
}
14+
15+
receive() external payable { }
16+
fallback() external payable { }
17+
}

integration_tests/contracts/contracts/TestERC20A.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity 0.8.10;
1+
pragma solidity ^0.8.20;
22
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
33

44
contract TestERC20A is ERC20 {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pragma solidity ^0.8.20;
2+
3+
contract Utils {
4+
function getCodeHash(address _account) public view returns (bytes32) {
5+
bytes32 codeHash;
6+
assembly {
7+
codeHash := extcodehash(_account)
8+
}
9+
return codeHash;
10+
}
11+
}

integration_tests/contracts/hardhat.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import "hardhat-typechain";
33
module.exports = {
44
solidity: {
55
compilers: [
6+
{
7+
version: "0.8.28",
8+
settings: {
9+
optimizer: {
10+
enabled: true
11+
},
12+
evmVersion: "prague"
13+
}
14+
},
615
{
716
version: "0.8.21",
817
settings: {

0 commit comments

Comments
 (0)