Skip to content

Commit a465e73

Browse files
authored
Merge pull request #95 from oasisprotocol/matevz/feature/sapphire-localnet-tests
solidity: Add sapphire-localnet tests
2 parents abc09af + b08ee0e commit a465e73

11 files changed

Lines changed: 346 additions & 428 deletions

File tree

.github/workflows/ci.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ jobs:
3939
test:
4040
name: Test
4141
runs-on: ubuntu-latest
42+
services:
43+
sapphire-localnet-ci:
44+
image: ghcr.io/oasisprotocol/sapphire-localnet
45+
ports:
46+
- 8545:8545
47+
env:
48+
OASIS_DOCKER_START_EXPLORER: no
49+
TO: "chimney theory present latin find behave ankle clock shadow earn suit reflect"
50+
options: >-
51+
--rm
52+
--health-cmd="test -f /CONTAINER_READY"
53+
--health-start-period=90s
4254
steps:
4355
- uses: actions/checkout@v4
4456

@@ -77,8 +89,6 @@ jobs:
7789
7890
- name: Run Solidity tests
7991
run: make solidity-test
80-
env:
81-
BASE_SEPOLIA_RPC_URL: ${{ secrets.BASE_SEPOLIA_RPC_URL }}
8292

8393
- name: Install dependencies
8494
run: make dev

solidity/bun.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

solidity/contracts/test/MockAccounting.sol

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {ChainType, HistoryKind, UnsupportedTokenType} from "../Types.sol";
1010
* @dev Overrides the keypair generation to avoid calling Sapphire precompiles.
1111
*/
1212
contract MockAccounting is Accounting {
13-
// Address matching the test transaction on Base Sepolia (block 32680090, tx 45)
14-
address private constant TEST_ADDRESS = 0x284a3Fe2939a4e4859e6321537d4264533E3D549;
15-
bytes32 private constant TEST_SECRET = bytes32(uint256(1));
13+
// Test keypair: #4 of "chimney theory present latin find behave ankle clock shadow earn suit reflect"
14+
address private constant TEST_ADDRESS = 0xe6F321Fb3D912Db48DE460560B8bB99B57AeAcA2;
15+
bytes32 private constant TEST_SECRET = bytes32(0x9147e5178b1ee427d704dcdb699f1adf9c8a3b58480a6118635a3486ad3a35ce);
1616

1717
/// @custom:oz-upgrades-unsafe-allow constructor
1818
constructor(address siweAuthAddress) Accounting(siweAuthAddress) {}
@@ -21,16 +21,6 @@ contract MockAccounting is Accounting {
2121
__Accounting_init(_roflAppID, _owner);
2222
}
2323

24-
function _deriveDepositKeypair(
25-
address beneficiary,
26-
ChainType /* chainType */,
27-
uint256 /* version */
28-
) internal pure override returns (address depositAddr, bytes32 depositSecret) {
29-
// Deterministic mock: derive from beneficiary address
30-
depositSecret = keccak256(abi.encode(TEST_SECRET, beneficiary));
31-
depositAddr = address(uint160(uint256(depositSecret)));
32-
}
33-
3424
function _generateKeypair() internal pure override returns (address, bytes32) {
3525
return (TEST_ADDRESS, TEST_SECRET);
3626
}
@@ -74,18 +64,6 @@ contract MockAccounting is Accounting {
7464
emit Deposit(tokenId, amount, depositId);
7565
}
7666

77-
/**
78-
* @notice Test helper: get deposit address for a beneficiary.
79-
* @dev Bypasses EIP-712 sig verification for testing.
80-
*/
81-
function mockGetDepositAddress(
82-
address beneficiary,
83-
ChainType chainType,
84-
uint256 version
85-
) external pure returns (address depositAddr) {
86-
(depositAddr, ) = _deriveDepositKeypair(beneficiary, chainType, version);
87-
}
88-
8967
/**
9068
* @notice Test helper: set roflSignerAddress without onlyROFL check.
9169
* @dev Bypasses ROFL auth for Hardhat testing; onlyROFL calls the Sapphire
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
import {MockAccounting} from "./MockAccounting.sol";
5+
6+
/**
7+
* @title MockAccountingHelper
8+
* @notice Helpers that should have been part of MockAccounting contract, but would exceed the contract code size limitation (EIP-170).
9+
*/
10+
contract MockAccountingHelper {
11+
MockAccounting public mockAccounting;
12+
13+
constructor(MockAccounting _mockAccounting) {
14+
mockAccounting = _mockAccounting;
15+
}
16+
17+
/**
18+
* @notice Calls creditDeposit n times from solidity to speed up the sapphire-localnet tests.
19+
*/
20+
function mockCreditDepositNTimes(
21+
address beneficiary,
22+
bytes32 tokenId,
23+
uint256 amount,
24+
bytes32 depositId,
25+
uint256 n
26+
) external {
27+
for (uint256 i=0; i<n; i++) {
28+
mockAccounting.mockCreditDeposit(beneficiary, tokenId, i+amount, keccak256(abi.encodePacked(depositId, i)));
29+
}
30+
}
31+
}

solidity/contracts/test/MockEVMSignerAndVerifier.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {EVMSignerAndVerifier} from "../EVMSignerAndVerifier.sol";
66
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
77

88
contract MockEVMSignerAndVerifier is EVMSignerAndVerifier, UUPSUpgradeable {
9-
// Test keypair - NOT for production use
10-
address private constant TEST_ADDRESS = 0x1234567890123456789012345678901234567890;
11-
bytes32 private constant TEST_SECRET = bytes32(uint256(1));
9+
// Test keypair: #4 of "chimney theory present latin find behave ankle clock shadow earn suit reflect"
10+
address private constant TEST_ADDRESS = 0xe6F321Fb3D912Db48DE460560B8bB99B57AeAcA2;
11+
bytes32 private constant TEST_SECRET = bytes32(0x9147e5178b1ee427d704dcdb699f1adf9c8a3b58480a6118635a3486ad3a35ce);
1212

1313
/// @custom:oz-upgrades-unsafe-allow constructor
1414
constructor() {

solidity/hardhat.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import {
66
} from '@oasisprotocol/sapphire-hardhat';
77
import '@nomicfoundation/hardhat-ignition-ethers';
88
import '@nomicfoundation/hardhat-toolbox';
9-
import '@openzeppelin/hardhat-upgrades';
109
import { HardhatUserConfig } from 'hardhat/config';
1110
import { HDAccountsUserConfig } from 'hardhat/types';
1211
import 'solidity-coverage';
1312
import './tasks';
1413

14+
import '@openzeppelin/hardhat-upgrades'; // NB: Must be imported after hardhat packages to preserve network configuration!
15+
1516
dotenvConfig();
1617

1718
const TEST_HDWALLET = {

solidity/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"format": "npm-run-all format:**",
1515
"build": "hardhat compile",
1616
"check:size": "hardhat run scripts/check-bytecode-size.ts --no-compile",
17-
"test": "hardhat test",
17+
"test:hardhat": "hardhat test",
18+
"test:sapphire-localnet": "hardhat test --network sapphire-localnet",
19+
"test": "npm-run-all test:**",
1820
"coverage": "hardhat coverage"
1921
},
2022
"devDependencies": {

0 commit comments

Comments
 (0)