@@ -112,11 +112,10 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
112112
113113 // create genesis validators
114114 uint256 numGenesisValidators = 3 ;
115- uint256 startingPrivateKey = 100 ;
116115 gwConstructorParams.genesisValidators = new Validator [](numGenesisValidators);
117116
118117 for (uint256 i = 0 ; i < numGenesisValidators; i++ ) {
119- (address validator , , bytes memory publicKey ) = TestUtils.newValidator (startingPrivateKey + i);
118+ (address validator , , bytes memory publicKey ) = TestUtils.newValidator (i);
120119 gwConstructorParams.genesisValidators[i] = Validator ({addr: validator, weight: 100 , metadata: publicKey});
121120 }
122121
@@ -147,8 +146,8 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
147146
148147 /// @notice Testing the basic join, stake, leave lifecycle of validators
149148 function testSubnetActorDiamond_BasicLifeCycle () public {
150- (address validator1 , uint256 privKey1 , bytes memory publicKey1 ) = TestUtils.newValidator (100 );
151- (address validator2 , uint256 privKey2 , bytes memory publicKey2 ) = TestUtils.newValidator (101 );
149+ (address validator1 , uint256 privKey1 , bytes memory publicKey1 ) = TestUtils.newValidator (0 );
150+ (address validator2 , uint256 privKey2 , bytes memory publicKey2 ) = TestUtils.newValidator (1 );
152151
153152 // total collateral in the gateway
154153 uint256 collateral = 0 ;
@@ -427,7 +426,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
427426 }
428427
429428 function testSubnetActorDiamond_Bootstrap_Node () public {
430- (address validator , uint256 privKey , bytes memory publicKey ) = TestUtils.newValidator (100 );
429+ (address validator , uint256 privKey , bytes memory publicKey ) = TestUtils.newValidator (0 );
431430
432431 vm.deal (validator, DEFAULT_MIN_VALIDATOR_STAKE);
433432 vm.prank (validator);
@@ -463,7 +462,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
463462 }
464463
465464 function testSubnetActorDiamond_Leave_NotValidator () public {
466- (address validator , , ) = TestUtils.newValidator (100 );
465+ (address validator , , ) = TestUtils.newValidator (0 );
467466
468467 // non-empty subnet can't be killed
469468 vm.prank (validator);
@@ -472,9 +471,9 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
472471 }
473472
474473 function testSubnetActorDiamond_Leave_Subnet () public {
475- (address validator1 , uint256 privKey1 , bytes memory publicKey1 ) = TestUtils.newValidator (100 );
476- (address validator2 , uint256 privKey2 , bytes memory publicKey2 ) = TestUtils.newValidator (101 );
477- (address validator3 , uint256 privKey3 , bytes memory publicKey3 ) = TestUtils.newValidator (102 );
474+ (address validator1 , uint256 privKey1 , bytes memory publicKey1 ) = TestUtils.newValidator (0 );
475+ (address validator2 , uint256 privKey2 , bytes memory publicKey2 ) = TestUtils.newValidator (1 );
476+ (address validator3 , uint256 privKey3 , bytes memory publicKey3 ) = TestUtils.newValidator (2 );
478477
479478 vm.deal (validator1, DEFAULT_MIN_VALIDATOR_STAKE);
480479 vm.deal (validator2, 3 * DEFAULT_MIN_VALIDATOR_STAKE);
@@ -513,7 +512,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
513512 }
514513
515514 function testSubnetActorDiamond_Kill_NotBootstrappedSubnet () public {
516- (address validator1 , , ) = TestUtils.newValidator (100 );
515+ (address validator1 , , ) = TestUtils.newValidator (0 );
517516
518517 // not bootstrapped subnet can't be killed
519518 vm.expectRevert (SubnetNotBootstrapped.selector );
@@ -670,7 +669,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
670669 saDiamond.checkpointer ().validateActiveQuorumSignatures (validators, hash, signatures);
671670 }
672671
673- function testSubnetActorDiamond_validateActiveQuorumSignatures_InvalidSignatory () public {
672+ function testSubnetActorDiamond_validateActiveQuorumSignatures_DuplicatedValidators () public {
674673 (uint256 [] memory keys , address [] memory validators , ) = TestUtils.getThreeValidators (vm);
675674 bytes [] memory pubKeys = new bytes [](3 );
676675 bytes [] memory signatures = new bytes [](3 );
@@ -690,11 +689,35 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
690689 saDiamond.manager ().join {value: 10 }(pubKeys[i], 10 );
691690 }
692691
693- // swap validators to trigger `InvalidSignatory` error;
694- address a;
695- a = validators[0 ];
692+ signatures[0 ] = signatures[1 ];
696693 validators[0 ] = validators[1 ];
697- validators[1 ] = a;
694+
695+ vm.expectRevert (abi.encodeWithSelector (DuplicateValidatorSignaturesFound.selector ));
696+ saDiamond.checkpointer ().validateActiveQuorumSignatures (validators, hash0, signatures);
697+ }
698+
699+ function testSubnetActorDiamond_validateActiveQuorumSignatures_InvalidSignatory () public {
700+ (uint256 [] memory keys , address [] memory validators , ) = TestUtils.getThreeValidators (vm);
701+ bytes [] memory pubKeys = new bytes [](3 );
702+ bytes [] memory signatures = new bytes [](3 );
703+
704+ bytes32 hash = keccak256 (abi.encodePacked ("test " ));
705+ bytes32 hash0 = keccak256 (abi.encodePacked ("test1 " ));
706+
707+ for (uint256 i = 0 ; i < 3 ; i++ ) {
708+ (uint8 v , bytes32 r , bytes32 s ) = vm.sign (keys[i], hash);
709+
710+ // create incorrect signature using `vv`
711+ signatures[i] = abi.encodePacked (r, s, v);
712+
713+ pubKeys[i] = TestUtils.deriveValidatorPubKeyBytes (keys[i]);
714+ vm.deal (validators[i], 10 gwei);
715+ vm.prank (validators[i]);
716+ saDiamond.manager ().join {value: 10 }(pubKeys[i], 10 );
717+ }
718+
719+ // use validator 1's signature for validator 0 to trigger `InvalidSignatory` error;
720+ signatures[0 ] = signatures[1 ];
698721
699722 vm.expectRevert (
700723 abi.encodeWithSelector (InvalidSignatureErr.selector , MultisignatureChecker.Error.InvalidSignatory)
@@ -1466,8 +1489,8 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
14661489 }
14671490
14681491 function test_second_validator_can_join () public {
1469- (address validatorAddress1 , uint256 privKey1 , bytes memory publicKey1 ) = TestUtils.newValidator (101 );
1470- (address validatorAddress2 , , bytes memory publicKey2 ) = TestUtils.newValidator (102 );
1492+ (address validatorAddress1 , uint256 privKey1 , bytes memory publicKey1 ) = TestUtils.newValidator (1 );
1493+ (address validatorAddress2 , , bytes memory publicKey2 ) = TestUtils.newValidator (2 );
14711494
14721495 join (validatorAddress1, publicKey1);
14731496
@@ -1728,7 +1751,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
17281751
17291752 saDiamond.manager ().setFederatedPower (validators, publicKeys, powers);
17301753
1731- confirmChange (validators[2 ], privKeys[2 ], validators[1 ], privKeys[1 ]);
1754+ confirmChange (validators[1 ], privKeys[1 ], validators[2 ], privKeys[2 ]);
17321755
17331756 require (saDiamond.getter ().isActiveValidator (validators[0 ]), "not active validator 0 " );
17341757 require (saDiamond.getter ().isActiveValidator (validators[1 ]), "not active validator 1 " );
@@ -1867,8 +1890,8 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
18671890 // Tests for collateral token
18681891 // ----------------------------
18691892 function testSubnetActorDiamond_CollateralERC20_SupplyERC20_RegisteredInGateway () public {
1870- (address validator , uint256 privKey , bytes memory publicKey ) = TestUtils.newValidator (100 );
1871- (address validator2 , , ) = TestUtils.newValidator (101 );
1893+ (address validator , uint256 privKey , bytes memory publicKey ) = TestUtils.newValidator (0 );
1894+ (address validator2 , , ) = TestUtils.newValidator (1 );
18721895
18731896 // a bit of gas for execution, should not be needed
18741897 vm.deal (validator, DEFAULT_MIN_VALIDATOR_STAKE - 100 );
@@ -2005,8 +2028,8 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
20052028 }
20062029
20072030 function testSubnetActorDiamond_CollateralERC20_SupplyERC20_SameToken_RegisteredInGateway () public {
2008- (address validator , uint256 privKey , bytes memory publicKey ) = TestUtils.newValidator (100 );
2009- (address validator2 , , ) = TestUtils.newValidator (101 );
2031+ (address validator , uint256 privKey , bytes memory publicKey ) = TestUtils.newValidator (0 );
2032+ (address validator2 , , ) = TestUtils.newValidator (1 );
20102033
20112034 // a bit of gas for execution, should not be needed
20122035 vm.deal (validator, DEFAULT_MIN_VALIDATOR_STAKE - 100 );
@@ -2128,8 +2151,8 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
21282151 }
21292152
21302153 function testSubnetActorDiamond_CollateralERC20_SupplyNative_RegisteredInGateway () public {
2131- (address validator , uint256 privKey , bytes memory publicKey ) = TestUtils.newValidator (100 );
2132- (address validator2 , , ) = TestUtils.newValidator (101 );
2154+ (address validator , uint256 privKey , bytes memory publicKey ) = TestUtils.newValidator (0 );
2155+ (address validator2 , , ) = TestUtils.newValidator (1 );
21332156
21342157 // a bit of gas for execution, should not be needed
21352158 vm.deal (validator, DEFAULT_MIN_VALIDATOR_STAKE - 100 );
@@ -2232,8 +2255,8 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
22322255 }
22332256
22342257 function testSubnetActorDiamond_CollateralNative_SupplyNative_RegisteredInGateway () public {
2235- (address validator , uint256 privKey , bytes memory publicKey ) = TestUtils.newValidator (100 );
2236- (address validator2 , , ) = TestUtils.newValidator (101 );
2258+ (address validator , uint256 privKey , bytes memory publicKey ) = TestUtils.newValidator (0 );
2259+ (address validator2 , , ) = TestUtils.newValidator (1 );
22372260
22382261 // a bit of gas for execution, should not be needed
22392262 vm.deal (validator, DEFAULT_MIN_VALIDATOR_STAKE * 10 );
@@ -2303,8 +2326,8 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
23032326 }
23042327
23052328 function testSubnetActorDiamond_CollateralNative_SupplyERC20_RegisteredInGateway () public {
2306- (address validator , uint256 privKey , bytes memory publicKey ) = TestUtils.newValidator (100 );
2307- (address validator2 , , ) = TestUtils.newValidator (101 );
2329+ (address validator , uint256 privKey , bytes memory publicKey ) = TestUtils.newValidator (0 );
2330+ (address validator2 , , ) = TestUtils.newValidator (1 );
23082331
23092332 // a bit of gas for execution, should not be needed
23102333 vm.deal (validator, DEFAULT_MIN_VALIDATOR_STAKE * 10 );
@@ -2745,7 +2768,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase {
27452768
27462769 saDiamond.manager ().setValidatorGater (address (gater));
27472770
2748- (address validator , , bytes memory publicKey ) = TestUtils.newValidator (100 );
2771+ (address validator , , bytes memory publicKey ) = TestUtils.newValidator (0 );
27492772
27502773 vm.deal (validator, DEFAULT_MIN_VALIDATOR_STAKE * 3 );
27512774 vm.prank (validator);
0 commit comments