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 committed Aug 5, 2024
1 parent 8c202fe commit 7a19cec
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 @@ -442,6 +442,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 @@ -3077,6 +3077,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 7a19cec

Please sign in to comment.