Skip to content

Commit

Permalink
Add getProposedFederation method in FederationSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-zack committed Aug 15, 2024
1 parent 759adf4 commit daa5846
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public interface FederationSupport {
byte[] getPendingFederatorBtcPublicKey(int index);
byte[] getPendingFederatorPublicKeyOfType(int index, FederationMember.KeyType keyType);

Optional<Federation> getProposedFederation();

int voteFederationChange(Transaction tx, ABICallSpec callSpec, SignatureCache signatureCache, BridgeEventLogger eventLogger);
long getActiveFederationCreationBlockHeight();
Optional<Script> getLastRetiredFederationP2SHScript();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ public byte[] getPendingFederatorPublicKeyOfType(int index, FederationMember.Key
return getFederationMemberPublicKeyOfType(currentPendingFederation.getMembers(), index, keyType, "Federator");
}

@Override
public Optional<Federation> getProposedFederation() {
return provider.getProposedFederation(constants, activations);
}

@Override
public int voteFederationChange(Transaction tx, ABICallSpec callSpec, SignatureCache signatureCache, BridgeEventLogger eventLogger) {
String calledFunction = callSpec.getFunction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class FederationSupportImplTest {

private static final FederationConstants federationMainnetConstants = FederationMainNetConstants.getInstance();
private final Federation genesisFederation = FederationTestUtils.getGenesisFederation(federationMainnetConstants);
private ActivationConfig.ForBlock activations;
private ErpFederation newFederation;
private StorageAccessor storageAccessor;
private FederationStorageProvider storageProvider;
Expand Down Expand Up @@ -3391,6 +3392,46 @@ private ABICallSpec getAddMultiKeysVote(FederationMember federationMember) {
}
}

@Test
void getProposedFederation_whenStorageProviderReturnsEmpty_shouldReturnEmpty() {
// arrange
activations = ActivationConfigsForTest.all().forBlock(0L);

storageProvider = mock(FederationStorageProvider.class);
when(storageProvider.getProposedFederation(federationMainnetConstants, activations)).thenReturn(Optional.empty());

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

// act
Optional<Federation> actualProposedFederation = federationSupport.getProposedFederation();

// assert
assertFalse(actualProposedFederation.isPresent());
}

@Test
void getProposedFederation_whenStorageProviderReturnsProposedFederation_shouldReturnProposedFederation() {
// arrange
activations = ActivationConfigsForTest.all().forBlock(0L);
Federation proposedFederation = new P2shErpFederationBuilder().build();

storageProvider = mock(FederationStorageProvider.class);
when(storageProvider.getProposedFederation(federationMainnetConstants, activations)).thenReturn(Optional.of(proposedFederation));

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

Optional<Federation> actualProposedFederation = federationSupport.getProposedFederation();
assertTrue(actualProposedFederation.isPresent());
assertEquals(proposedFederation, actualProposedFederation.get());
}

private List<ECKey> getRskPublicKeysFromFederationMembers(List<FederationMember> members) {
return members.stream()
Expand Down

0 comments on commit daa5846

Please sign in to comment.