@inco/lightning 0.8.0-devnet-2 → 0.8.0-devnet-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -67
- package/package.json +1 -1
- package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +75 -1
- package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +245 -0
- package/src/lightning-parts/EncryptedOperations.sol +1 -5
- package/src/lightning-parts/TrivialEncryption.sol +29 -0
- package/src/lightning-parts/primitives/SignatureVerifier.sol +42 -11
- package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +454 -29
- package/src/lightning-parts/test/HandleMetadata.t.sol +335 -1
- package/src/periphery/SessionVerifier.sol +3 -1
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +231 -1
- package/src/test/TestEventCounter.t.sol +43 -0
- package/src/test/TestFakeInfra.t.sol +9 -2
- package/src/test/TestFeeWithdrawal.t.sol +0 -1
- package/src/test/TestIncoUtils.t.sol +50 -0
- package/src/test/TestLib.t.sol +794 -0
- package/src/test/TestUpgrade.t.sol +114 -0
- package/src/test/TestVersion.t.sol +1 -0
|
@@ -9,6 +9,10 @@ import {IOwnerManager} from "safe-smart-account/interfaces/IOwnerManager.sol";
|
|
|
9
9
|
import {IncoTest} from "./IncoTest.sol";
|
|
10
10
|
import {inco} from "../Lib.sol";
|
|
11
11
|
import {IncoLightning} from "../IncoLightning.sol";
|
|
12
|
+
import {IncoVerifier} from "../IncoVerifier.sol";
|
|
13
|
+
import {SessionVerifier, Session} from "../periphery/SessionVerifier.sol";
|
|
14
|
+
import {ALLOWANCE_GRANTED_MAGIC_VALUE} from "../Types.sol";
|
|
15
|
+
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
|
|
12
16
|
import {IVersion} from "../version/interfaces/IVersion.sol";
|
|
13
17
|
import {Version} from "../version/Version.sol";
|
|
14
18
|
import {IIncoVerifier} from "../interfaces/IIncoVerifier.sol";
|
|
@@ -196,6 +200,116 @@ contract TestUpgrade is IncoTest {
|
|
|
196
200
|
inco.upgradeToAndCall(address(v2Impl), "");
|
|
197
201
|
}
|
|
198
202
|
|
|
203
|
+
// ============ IncoVerifier Tests ============
|
|
204
|
+
|
|
205
|
+
function test_IncoVerifier_GetEIP712Name() public view {
|
|
206
|
+
IncoVerifier verifier = IncoVerifier(address(inco.incoVerifier()));
|
|
207
|
+
string memory name = verifier.getEIP712Name();
|
|
208
|
+
// Name should not be empty
|
|
209
|
+
assertGt(bytes(name).length, 0, "EIP712 name should not be empty");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function test_IncoVerifier_GetEIP712Version() public view {
|
|
213
|
+
IncoVerifier verifier = IncoVerifier(address(inco.incoVerifier()));
|
|
214
|
+
string memory version = verifier.getEIP712Version();
|
|
215
|
+
// Version should not be empty
|
|
216
|
+
assertGt(bytes(version).length, 0, "EIP712 version should not be empty");
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function test_IncoVerifier_Upgrade_ByOwner_Succeeds() public {
|
|
220
|
+
IncoVerifier verifier = IncoVerifier(address(inco.incoVerifier()));
|
|
221
|
+
|
|
222
|
+
// Deploy a new IncoVerifier implementation
|
|
223
|
+
IncoVerifier newImpl = new IncoVerifier(address(inco));
|
|
224
|
+
|
|
225
|
+
// Upgrade by owner should succeed
|
|
226
|
+
vm.prank(owner);
|
|
227
|
+
verifier.upgradeToAndCall(address(newImpl), "");
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function test_IncoVerifier_Upgrade_ByNonOwner_Fails() public {
|
|
231
|
+
IncoVerifier verifier = IncoVerifier(address(inco.incoVerifier()));
|
|
232
|
+
|
|
233
|
+
// Deploy a new IncoVerifier implementation
|
|
234
|
+
IncoVerifier newImpl = new IncoVerifier(address(inco));
|
|
235
|
+
|
|
236
|
+
// Upgrade by non-owner should fail
|
|
237
|
+
vm.prank(alice);
|
|
238
|
+
vm.expectRevert();
|
|
239
|
+
verifier.upgradeToAndCall(address(newImpl), "");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ============ SessionVerifier Tests ============
|
|
243
|
+
|
|
244
|
+
function test_SessionVerifier_ValidSession_ReturnsAllowanceGranted() public {
|
|
245
|
+
SessionVerifier verifier = new SessionVerifier("");
|
|
246
|
+
|
|
247
|
+
bytes memory sharerArgData = abi.encode(Session({decrypter: bob, expiresAt: block.timestamp + 1 days}));
|
|
248
|
+
|
|
249
|
+
bytes32 result = verifier.canUseSession(bytes32(0), bob, sharerArgData, "");
|
|
250
|
+
assertEq(result, ALLOWANCE_GRANTED_MAGIC_VALUE, "Valid session should return ALLOWANCE_GRANTED_MAGIC_VALUE");
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function test_SessionVerifier_ExpiredSession_ReturnsZero() public {
|
|
254
|
+
SessionVerifier verifier = new SessionVerifier("");
|
|
255
|
+
|
|
256
|
+
// Create session that expired 1 second ago
|
|
257
|
+
bytes memory sharerArgData = abi.encode(Session({decrypter: bob, expiresAt: block.timestamp - 1}));
|
|
258
|
+
|
|
259
|
+
bytes32 result = verifier.canUseSession(bytes32(0), bob, sharerArgData, "");
|
|
260
|
+
assertEq(result, bytes32(0), "Expired session should return bytes32(0)");
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function test_SessionVerifier_WrongDecrypter_ReturnsZero() public {
|
|
264
|
+
SessionVerifier verifier = new SessionVerifier("");
|
|
265
|
+
|
|
266
|
+
// Session is valid but decrypter doesn't match caller
|
|
267
|
+
bytes memory sharerArgData = abi.encode(Session({decrypter: alice, expiresAt: block.timestamp + 1 days}));
|
|
268
|
+
|
|
269
|
+
bytes32 result = verifier.canUseSession(bytes32(0), bob, sharerArgData, "");
|
|
270
|
+
assertEq(result, bytes32(0), "Wrong decrypter should return bytes32(0)");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function test_SessionVerifier_Initialize() public {
|
|
274
|
+
SessionVerifier impl = new SessionVerifier("");
|
|
275
|
+
ERC1967Proxy proxy = new ERC1967Proxy(address(impl), "");
|
|
276
|
+
SessionVerifier verifier = SessionVerifier(address(proxy));
|
|
277
|
+
|
|
278
|
+
verifier.initialize(alice);
|
|
279
|
+
assertEq(verifier.owner(), alice, "Owner should be alice after initialize");
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function test_SessionVerifier_Upgrade_ByOwner_Succeeds() public {
|
|
283
|
+
SessionVerifier impl = new SessionVerifier("");
|
|
284
|
+
ERC1967Proxy proxy = new ERC1967Proxy(address(impl), "");
|
|
285
|
+
SessionVerifier verifier = SessionVerifier(address(proxy));
|
|
286
|
+
|
|
287
|
+
verifier.initialize(alice);
|
|
288
|
+
|
|
289
|
+
// Deploy new implementation
|
|
290
|
+
SessionVerifier newImpl = new SessionVerifier("");
|
|
291
|
+
|
|
292
|
+
// Upgrade by owner should succeed
|
|
293
|
+
vm.prank(alice);
|
|
294
|
+
verifier.upgradeToAndCall(address(newImpl), "");
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function test_SessionVerifier_Upgrade_ByNonOwner_Fails() public {
|
|
298
|
+
SessionVerifier impl = new SessionVerifier("");
|
|
299
|
+
ERC1967Proxy proxy = new ERC1967Proxy(address(impl), "");
|
|
300
|
+
SessionVerifier verifier = SessionVerifier(address(proxy));
|
|
301
|
+
|
|
302
|
+
verifier.initialize(alice);
|
|
303
|
+
|
|
304
|
+
// Deploy new implementation
|
|
305
|
+
SessionVerifier newImpl = new SessionVerifier("");
|
|
306
|
+
|
|
307
|
+
// Upgrade by non-owner should fail
|
|
308
|
+
vm.prank(bob);
|
|
309
|
+
vm.expectRevert();
|
|
310
|
+
verifier.upgradeToAndCall(address(newImpl), "");
|
|
311
|
+
}
|
|
312
|
+
|
|
199
313
|
// Helpers
|
|
200
314
|
function _txHash(Safe _safe, address to, uint256 value, bytes memory data) internal view returns (bytes32) {
|
|
201
315
|
return _safe.getTransactionHash(
|
|
@@ -25,6 +25,7 @@ contract TestVersion is Test {
|
|
|
25
25
|
assertEq(someContract.getName(), "SomeContract");
|
|
26
26
|
assertEq(someContract.getVersion(), "1_2_3");
|
|
27
27
|
assertEq(someContract.getVersionedName(), "SomeContract_1_2_3__12345678");
|
|
28
|
+
assertEq(someContract.salt(), bytes32(uint256(12345678)));
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
}
|