@@ -18,7 +18,6 @@ import {LCPOperator} from "../contracts/LCPOperator.sol";
1818contract LCPClientOperatorTest is BasicTest {
1919 using IBCHeight for Height.Data;
2020
21- string internal constant commandAvrFile = "test/data/client/03/001-avr " ;
2221 string internal constant commandResultSuffix = "_result " ;
2322
2423 LCPClient lc;
@@ -28,9 +27,7 @@ contract LCPClientOperatorTest is BasicTest {
2827 lc = new LCPClient (address (this ), true , vm.readFileBinary ("./test/data/certs/simulation_rootca.der " ));
2928 }
3029
31- function avr (string memory filename ) internal pure returns (string memory ) {
32- return string (abi.encodePacked ("test/data/client/03/ " , filename));
33- }
30+ // ---------------------------- Test Cases ----------------------------
3431
3532 function testPreComputationValues () public pure {
3633 assertEq (LCPOperator.domainSeparatorUniversal (), LCPOperator.DOMAIN_SEPARATOR_REGISTER_ENCLAVE_KEY);
@@ -97,7 +94,7 @@ contract LCPClientOperatorTest is BasicTest {
9794 }
9895 string memory clientId = generateClientId (1 );
9996 {
100- ClientState.Data memory clientState = createInitialState (commandAvrFile , operators, 2 , 3 );
97+ ClientState.Data memory clientState = createInitialState (avr ( " 001-avr " ) , operators, 2 , 3 );
10198 ConsensusState.Data memory consensusState;
10299 Height.Data memory height = lc.initializeClient (
103100 clientId, LCPProtoMarshaler.marshal (clientState), LCPProtoMarshaler.marshal (consensusState)
@@ -167,7 +164,7 @@ contract LCPClientOperatorTest is BasicTest {
167164 }
168165 string memory clientId = generateClientId (1 );
169166 {
170- ClientState.Data memory clientState = createInitialState (commandAvrFile , operators, 2 , 3 );
167+ ClientState.Data memory clientState = createInitialState (avr ( " 001-avr " ) , operators, 2 , 3 );
171168 ConsensusState.Data memory consensusState;
172169 Height.Data memory height = lc.initializeClient (
173170 clientId, LCPProtoMarshaler.marshal (clientState), LCPProtoMarshaler.marshal (consensusState)
@@ -290,6 +287,63 @@ contract LCPClientOperatorTest is BasicTest {
290287 }
291288 }
292289
290+ function testRegisterEnclaveKeyOperatorDedicatedAVR () public {
291+ Vm.Wallet[] memory wallets = createWallets (2 );
292+ address [] memory operators = new address [](1 );
293+ operators[0 ] = wallets[0 ].addr;
294+ string memory avrFile = "test/data/reports/valid/operator_0xc1eae5EF781f4EE5867eC6725630E7dC17fa3436 " ;
295+
296+ {
297+ string memory clientId = generateClientId (1 );
298+ ClientState.Data memory clientState = createInitialState (avrFile, operators, 1 , 1 );
299+ ConsensusState.Data memory consensusState;
300+ lc.initializeClient (
301+ clientId, LCPProtoMarshaler.marshal (clientState), LCPProtoMarshaler.marshal (consensusState)
302+ );
303+ // operator matches the operator address in the AVR
304+ lc.registerEnclaveKey (clientId, createRegisterEnclaveKeyMessage (avrFile, wallets[0 ].privateKey));
305+ }
306+ {
307+ string memory clientId = generateClientId (2 );
308+ ClientState.Data memory clientState = createInitialState (avrFile, operators, 1 , 1 );
309+ ConsensusState.Data memory consensusState;
310+ lc.initializeClient (
311+ clientId, LCPProtoMarshaler.marshal (clientState), LCPProtoMarshaler.marshal (consensusState)
312+ );
313+
314+ // operator does not match the operator address in the AVR
315+ RegisterEnclaveKeyMessage.Data memory msg_ = createRegisterEnclaveKeyMessage (avrFile, wallets[1 ].privateKey);
316+ vm.expectRevert (
317+ abi.encodeWithSelector (
318+ ILCPClientErrors.LCPClientAVRUnexpectedOperator.selector , wallets[1 ].addr, wallets[0 ].addr
319+ )
320+ );
321+ lc.registerEnclaveKey (clientId, msg_);
322+ }
323+ {
324+ string memory clientId = generateClientId (3 );
325+ ClientState.Data memory clientState = createInitialState (avrFile, operators, 1 , 1 );
326+ ConsensusState.Data memory consensusState;
327+ lc.initializeClient (
328+ clientId, LCPProtoMarshaler.marshal (clientState), LCPProtoMarshaler.marshal (consensusState)
329+ );
330+ // an operator dedicated AVR does not allow an empty signature
331+ RegisterEnclaveKeyMessage.Data memory msg_ = createRegisterEnclaveKeyMessage (avrFile, 0 );
332+ vm.expectRevert (
333+ abi.encodeWithSelector (
334+ ILCPClientErrors.LCPClientAVRUnexpectedOperator.selector , address (0 ), wallets[0 ].addr
335+ )
336+ );
337+ lc.registerEnclaveKey (clientId, msg_);
338+ }
339+ }
340+
341+ // ---------------------------- Helper Functions ----------------------------
342+
343+ function avr (string memory filename ) internal pure returns (string memory ) {
344+ return string (abi.encodePacked ("test/data/client/03/ " , filename));
345+ }
346+
293347 function generateSignature (Vm.Wallet memory wallet , bytes32 commitment , bool valid )
294348 internal
295349 pure
@@ -363,9 +417,11 @@ contract LCPClientOperatorTest is BasicTest {
363417 message.report = readJSON (avrFile, ".avr " );
364418 message.signature = readDecodedBytes (avrFile, ".signature " );
365419 message.signing_cert = readDecodedBytes (avrFile, ".signing_cert " );
366- (uint8 v , bytes32 r , bytes32 s ) =
367- vm.sign (privateKey, keccak256 (LCPOperatorTestHelper.computeEIP712RegisterEnclaveKey (message.report)));
368- message.operator_signature = abi.encodePacked (r, s, v);
420+ if (privateKey != 0 ) {
421+ (uint8 v , bytes32 r , bytes32 s ) =
422+ vm.sign (privateKey, keccak256 (LCPOperatorTestHelper.computeEIP712RegisterEnclaveKey (message.report)));
423+ message.operator_signature = abi.encodePacked (r, s, v);
424+ }
369425 }
370426
371427 function createUpdateClientMessage (string memory updateClientFilePrefix )
0 commit comments