Skip to content

Commit

Permalink
Adds RSKIP123 check to addFederatorPublicKey
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-then authored and marcos-iov committed Aug 16, 2024
1 parent a16c3dd commit cd75f52
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ private ABICallVoteResult executeVoteFederationChangeFunction(boolean dryRun, AB
result = new ABICallVoteResult(executionResult == 1, executionResult);
break;
case "add":
if(activations.isActive(RSKIP123)) {
throw new IllegalStateException("The \"add\" function is disabled.");
}
byte[] publicKeyBytes = callSpec.getArguments()[0];
BtcECKey publicKey;
ECKey publicKeyEc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3078,6 +3078,72 @@ void voteFederationChange_addFederatorMultiKey_returnsExpectedPendingFederationS
assertArrayEquals(expectedMstKey.getPubKey(true), actualMstKey);
}

@Test
void voteFederationChange_addFederatorPublicKeyPreWasabi_returnsSuccessfulResponseCode() {
ActivationConfig.ForBlock activationsPreWasabi = ActivationConfigsForTest.orchid().forBlock(0L);

FederationSupport federationSupport = federationSupportBuilder
.withFederationConstants(federationMainnetConstants)
.withFederationStorageProvider(storageProvider)
.withActivations(activationsPreWasabi)
.build();

// Arrange
BtcECKey federatorBtcECKey = BtcECKey.fromPrivate(BigInteger.valueOf(100));

Transaction firstAuthorizedTx = TransactionUtils.getTransactionFromCaller(signatureCache, FederationChangeCaller.FIRST_AUTHORIZED.getRskAddress());
Transaction secondAuthorizedTx = TransactionUtils.getTransactionFromCaller(signatureCache, FederationChangeCaller.SECOND_AUTHORIZED.getRskAddress());

voteToCreateFederation(firstAuthorizedTx, secondAuthorizedTx);

ABICallSpec addFederatorMultiKeyAbiCallSpec = new ABICallSpec(FederationChangeFunction.ADD.getKey(), new byte[][]{
federatorBtcECKey.getPubKey(),
});

// Act

// Voting add new fed with m of n authorizers
int firstVoteAddFederatorMultiKeyResult = federationSupport.voteFederationChange(firstAuthorizedTx, addFederatorMultiKeyAbiCallSpec, signatureCache, bridgeEventLogger);
int secondVoteAddFederatorMultiKeyResult = federationSupport.voteFederationChange(secondAuthorizedTx, addFederatorMultiKeyAbiCallSpec, signatureCache, bridgeEventLogger);

// Assert
assertEquals(FederationChangeResponseCode.SUCCESSFUL.getCode(), firstVoteAddFederatorMultiKeyResult);
assertEquals(FederationChangeResponseCode.SUCCESSFUL.getCode(), secondVoteAddFederatorMultiKeyResult);
}

@Test
void voteFederationChange_addFederatorPublicKeyPostWasabi_ThrowsIllegalStateException() {
// Arrange
BtcECKey federatorBtcECKey = BtcECKey.fromPrivate(BigInteger.valueOf(100));

Transaction firstAuthorizedTx = TransactionUtils.getTransactionFromCaller(
signatureCache,
FederationChangeCaller.FIRST_AUTHORIZED.getRskAddress()
);
Transaction secondAuthorizedTx = TransactionUtils.getTransactionFromCaller(
signatureCache,
FederationChangeCaller.SECOND_AUTHORIZED.getRskAddress()
);

voteToCreateFederation(firstAuthorizedTx, secondAuthorizedTx);

ABICallSpec addFederatorMultiKeyAbiCallSpec = new ABICallSpec(FederationChangeFunction.ADD.getKey(), new byte[][]{
federatorBtcECKey.getPubKey(),
});

// Act and assert
Exception exception = assertThrows(
IllegalStateException.class,
() -> federationSupport.voteFederationChange(
firstAuthorizedTx,
addFederatorMultiKeyAbiCallSpec,
signatureCache,
bridgeEventLogger
)
);
assertEquals("The \"add\" function is disabled.", exception.getMessage());
}

private void voteToCreateFederation(Transaction firstAuthorizedTx, Transaction secondAuthorizedTx) {
ABICallSpec createFederationAbiCallSpec = new ABICallSpec(
FederationChangeFunction.CREATE.getKey(),
Expand Down

0 comments on commit cd75f52

Please sign in to comment.