Skip to content

Commit

Permalink
Refactor test setup to make tests independent
Browse files Browse the repository at this point in the history
  • Loading branch information
marcos-iov committed Nov 22, 2024
1 parent d7979b4 commit 3228083
Showing 1 changed file with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -464,41 +464,46 @@ void getFederationContext() {
@Tag("non null new and old federations")
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class ActiveFederationTestsWithNonNullFederations {
// new federation should be active if we are past the activation block number
// old federation should be active if we are before the activation block number
// activation block number is smaller for hop than for fingerroot
Federation oldFederation;
Federation newFederation;

// create old and new federations
long oldFederationCreationBlockNumber = 20;
long newFederationCreationBlockNumber = 65;
Federation oldFederation = P2shErpFederationBuilder.builder()
.withCreationBlockNumber(oldFederationCreationBlockNumber)
.build();
List<BtcECKey> newFederationKeys = BitcoinTestUtils.getBtcEcKeysFromSeeds(
new String[]{"fa01", "fa02", "fa03", "fa04", "fa05", "fa06", "fa07", "fa08", "fa09"}, true
);
Federation newFederation = P2shErpFederationBuilder.builder()
.withMembersBtcPublicKeys(newFederationKeys)
.withCreationBlockNumber(newFederationCreationBlockNumber)
.build();
long blockNumberFederationActivationHop;
long blockNumberFederationActivationFingerroot;

// get block number activations for hop and fingerroot
ActivationConfig.ForBlock hopActivations = ActivationConfigsForTest.hop400().forBlock(0);
long newFederationActivationAgeHop = federationMainnetConstants.getFederationActivationAge(hopActivations);
long blockNumberFederationActivationHop = newFederationCreationBlockNumber + newFederationActivationAgeHop;
ActivationConfig.ForBlock fingerrootActivations = ActivationConfigsForTest.fingerroot500().forBlock(0);
long newFederationActivationAgeFingerroot = federationMainnetConstants.getFederationActivationAge(fingerrootActivations);
long blockNumberFederationActivationFingerroot = newFederationCreationBlockNumber + newFederationActivationAgeFingerroot;

FederationStorageProvider storageProvider;

@BeforeEach
void setUp() {
long oldFederationCreationBlockNumber = 20;
oldFederation = P2shErpFederationBuilder.builder()
.withCreationBlockNumber(oldFederationCreationBlockNumber)
.build();

long newFederationCreationBlockNumber = 65;
List<BtcECKey> newFederationKeys = BitcoinTestUtils.getBtcEcKeysFromSeeds(
new String[]{"fa01", "fa02", "fa03", "fa04", "fa05", "fa06", "fa07", "fa08", "fa09"}, true
);
newFederation = P2shErpFederationBuilder.builder()
.withMembersBtcPublicKeys(newFederationKeys)
.withCreationBlockNumber(newFederationCreationBlockNumber)
.build();

// save federations in storage
storageAccessor = new InMemoryStorage();
storageProvider = new FederationStorageProviderImpl(storageAccessor);
storageProvider.setOldFederation(oldFederation);
storageProvider.setNewFederation(newFederation);

// get block number activations for hop and fingerroot
// new federation should be active if we are past the activation block number
// old federation should be active if we are before the activation block number
// activation block number is smaller for hop than for fingerroot
long newFederationActivationAgeHop = federationMainnetConstants.getFederationActivationAge(hopActivations);
blockNumberFederationActivationHop = newFederationCreationBlockNumber + newFederationActivationAgeHop;

long newFederationActivationAgeFingerroot = federationMainnetConstants.getFederationActivationAge(fingerrootActivations);
blockNumberFederationActivationFingerroot = newFederationCreationBlockNumber + newFederationActivationAgeFingerroot;
}

@ParameterizedTest
Expand Down

0 comments on commit 3228083

Please sign in to comment.