From 50ffa87f573469061efea4ffe8a571f8de146b7e Mon Sep 17 00:00:00 2001 From: Marcos Date: Thu, 20 Oct 2022 16:46:52 -0300 Subject: [PATCH 01/16] Set bitcoinj-thin dependency to 0.14.4-rsk-14-alphanet --- build.gradle | 2 +- gradle/verification-metadata.xml | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 20d159ad..68414f61 100644 --- a/build.gradle +++ b/build.gradle @@ -54,7 +54,7 @@ tasks.withType(AbstractArchiveTask) { ext { bitcoinjcoreVersion = '0.15.6-rsk-2' - bitcoinjVersion = '0.14.4-rsk-12' + bitcoinjVersion = '0.14.4-rsk-14-alphanet' commonsLang3Version = '3.5' commonsIoVersion = '2.5' slf4jVersion = '1.7.25' diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 0d7a3c5a..93503b52 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -56,14 +56,14 @@ - - - - - - - - + + + + + + + + From 23d1d32c4e084f9b25150e58aab0ea854d1aba73 Mon Sep 17 00:00:00 2001 From: Marcos Date: Thu, 20 Oct 2022 16:48:01 -0300 Subject: [PATCH 02/16] Set version to RC-4.0.1.0 --- src/main/resources/version.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/version.properties b/src/main/resources/version.properties index 8827eaa6..166c31dc 100644 --- a/src/main/resources/version.properties +++ b/src/main/resources/version.properties @@ -1,2 +1,2 @@ -versionNumber='4.0.0.1' -modifier="HOP" +versionNumber='4.0.1.0' +modifier="RC" From 89a1f5fd9d28dfaa8f1bd2e60d2763a65163b71f Mon Sep 17 00:00:00 2001 From: Marcos Date: Thu, 20 Oct 2022 16:48:37 -0300 Subject: [PATCH 03/16] Set rskj dependency version to 4.0.1-RC --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 68414f61..0832d85f 100644 --- a/build.gradle +++ b/build.gradle @@ -65,7 +65,7 @@ ext { junitVersion = '4.12' mockitoVersion = '2.23.4' powermockitoVersion = '2.0.2' - rskjcoreVersion = '4.0.0-HOP' + rskjcoreVersion = '4.0.1-RC' } dependencies { From c24550d98465835ae5f32beffd2fedada19429d2 Mon Sep 17 00:00:00 2001 From: Marcos Date: Thu, 3 Nov 2022 15:50:44 -0300 Subject: [PATCH 04/16] Consider P2shErpFederation in FederationProvider --- ...ederationProviderFromFederatorSupport.java | 93 +++++++++++-------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java b/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java index b9fa6bca..86e720fa 100644 --- a/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java +++ b/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java @@ -24,6 +24,7 @@ import co.rsk.peg.ErpFederation; import co.rsk.peg.Federation; import co.rsk.peg.FederationMember; +import co.rsk.peg.P2shErpFederation; import org.ethereum.crypto.ECKey; import java.time.Instant; @@ -75,25 +76,14 @@ public Federation getActiveFederation() { Instant creationTime = federatorSupport.getFederationCreationTime(); long creationBlockNumber = federatorSupport.getFederationCreationBlockNumber(); - Federation initialFederation = - new Federation(members, creationTime, creationBlockNumber, federatorSupport.getBtcParams()); - - Address federationAddress = federatorSupport.getFederationAddress(); - - if (initialFederation.getAddress().equals(federationAddress)) { - return initialFederation; - } - - // There is no reason for addresses not to match but being an ERP federation - return new ErpFederation( + Federation initialFederation = new Federation( members, creationTime, creationBlockNumber, - federatorSupport.getBtcParams(), - bridgeConstants.getErpFedPubKeysList(), - bridgeConstants.getErpFedActivationDelay(), - federatorSupport.getConfigForBestBlock() + federatorSupport.getBtcParams() ); + + return getExpectedFederation(initialFederation, getActiveFederationAddress()); } @Override @@ -104,10 +94,13 @@ public Address getActiveFederationAddress() { @Override public Optional getRetiringFederation() { Integer federationSize = federatorSupport.getRetiringFederationSize(); - if (federationSize == -1) { + Optional
optionalRetiringFederationAddress = getRetiringFederationAddress(); + + if (federationSize == -1 || !optionalRetiringFederationAddress.isPresent()) { return Optional.empty(); } + Address retiringFederationAddress = optionalRetiringFederationAddress.get(); boolean useTypedPublicKeyGetter = federatorSupport.getConfigForBestBlock().isActive(RSKIP123); List members = new ArrayList<>(); for (int i = 0; i < federationSize; i++) { @@ -133,31 +126,14 @@ public Optional getRetiringFederation() { Instant creationTime = federatorSupport.getRetiringFederationCreationTime(); long creationBlockNumber = federatorSupport.getRetiringFederationCreationBlockNumber(); - Federation initialFederation = - new Federation(members, creationTime, creationBlockNumber, federatorSupport.getBtcParams()); - - Optional
optionalFederationAddress = federatorSupport.getRetiringFederationAddress(); - Address federationAddress = null; - - if (optionalFederationAddress.isPresent()) { - federationAddress = optionalFederationAddress.get(); - } - - if (initialFederation.getAddress().equals(federationAddress)) { - return Optional.of(initialFederation); - } - - return Optional.of( - new ErpFederation( - members, - creationTime, - creationBlockNumber, - federatorSupport.getBtcParams(), - bridgeConstants.getErpFedPubKeysList(), - bridgeConstants.getErpFedActivationDelay(), - federatorSupport.getConfigForBestBlock() - ) + Federation initialFederation = new Federation( + members, + creationTime, + creationBlockNumber, + federatorSupport.getBtcParams() ); + + return Optional.of(getExpectedFederation(initialFederation, retiringFederationAddress)); } @Override @@ -175,4 +151,41 @@ public List getLiveFederations() { return result; } + + private Federation getExpectedFederation(Federation initialFederation, Address expectedFederationAddress) { + // First check if the initial federation address matches the expected one + if (initialFederation.getAddress().equals(expectedFederationAddress)) { + return initialFederation; + } + + // If addresses do not match build an ERP federation + Federation erpFederation = new ErpFederation( + initialFederation.getMembers(), + initialFederation.getCreationTime(), + initialFederation.getCreationBlockNumber(), + federatorSupport.getBtcParams(), + bridgeConstants.getErpFedPubKeysList(), + bridgeConstants.getErpFedActivationDelay(), + federatorSupport.getConfigForBestBlock() + ); + + if (erpFederation.getAddress().equals(expectedFederationAddress)) { + return erpFederation; + } + + // Finally, try building a P2SH ERP federation + return new P2shErpFederation( + initialFederation.getMembers(), + initialFederation.getCreationTime(), + initialFederation.getCreationBlockNumber(), + federatorSupport.getBtcParams(), + bridgeConstants.getErpFedPubKeysList(), + bridgeConstants.getErpFedActivationDelay(), + federatorSupport.getConfigForBestBlock() + ); + + // TODO: what if no federation built matches the expected address? + // It could mean that there is a different type of federation in the Bridge that we are not considering here + // We should consider throwing an exception and shutting down the node + } } From d06f07ee0f0b26d153e760e76e90aff491feef89 Mon Sep 17 00:00:00 2001 From: Marcos Date: Thu, 3 Nov 2022 16:44:38 -0300 Subject: [PATCH 05/16] Update FederationProviderFromFederatorSupport tests --- ...ationProviderFromFederatorSupportTest.java | 82 ++++++++++++------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java index dd2d4f37..5064a7f4 100644 --- a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java +++ b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java @@ -38,6 +38,14 @@ public class FederationProviderFromFederatorSupportTest { private Address activeFedAddress; private Address retiringFedAddress; + private static final Address HARDCODED_TESTNET_FED_ADDRESS = Address.fromBase58( + NetworkParameters.fromID(NetworkParameters.ID_TESTNET), + "2Mw6KM642fbkypTzbgFi6DTgTFPRWZUD4BA" + ); + private static final Script HARDCODED_TESTNET_FED_REDEEM_SCRIPT = new Script( + Hex.decode("6453210208f40073a9e43b3e9103acec79767a6de9b0409749884e989960fee578012fce210225e892391625854128c5c4ea4340de0c2a70570f33db53426fc9c746597a03f42102afc230c2d355b1a577682b07bc2646041b5d0177af0f98395a46018da699b6da210344a3c38cd59afcba3edcebe143e025574594b001700dec41e59409bdbd0f2a0921039a060badbeb24bee49eb2063f616c0f0f0765d4ca646b20a88ce828f259fcdb955670300cd50b27552210216c23b2ea8e4f11c3f9e22711addb1d16a93964796913830856b568cc3ea21d3210275562901dd8faae20de0a4166362a4f82188db77dbed4ca887422ea1ec185f1421034db69f2112f4fb1bb6141bf6e2bd6631f0484d0bd95b16767902c9fe219d4a6f5368ae") + ); + @Before public void createProvider() { bridgeConstants = BridgeTestNetConstants.getInstance(); @@ -92,7 +100,7 @@ public void getActiveFederation_afterMultikey() { when(federatorSupportMock.getFederationSize()).thenReturn(4); when(federatorSupportMock.getFederationThreshold()).thenReturn(2); when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); - (when(federatorSupportMock.getFederationAddress())).thenReturn(activeFedAddress); + when(federatorSupportMock.getFederationAddress()).thenReturn(activeFedAddress); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 4; i++) { when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); @@ -112,10 +120,18 @@ public void getActiveFederation_afterMultikey() { public void getActiveFederation_erp_federation() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(true); + + Federation expectedFederation = createErpFederation( + getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), + configMock + ); + Address expectedFederationAddress = expectedFederation.getAddress(); + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); when(federatorSupportMock.getFederationSize()).thenReturn(5); when(federatorSupportMock.getFederationThreshold()).thenReturn(3); when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedFederationAddress); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 5; i++) { when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); @@ -123,15 +139,11 @@ public void getActiveFederation_erp_federation() { when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+2))); } - Federation expectedFederation = createErpFederation( - getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), - configMock - ); - Federation obtainedFederation = federationProvider.getActiveFederation(); - Assert.assertEquals(expectedFederation, obtainedFederation); Assert.assertTrue(obtainedFederation instanceof ErpFederation); + Assert.assertEquals(expectedFederation, obtainedFederation); + Assert.assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); verify(federatorSupportMock, times(1)).getFederationSize(); } @@ -144,7 +156,9 @@ public void getActiveFederation_erp_federation_testnet_hardcoded() { when(federatorSupportMock.getFederationSize()).thenReturn(5); when(federatorSupportMock.getFederationThreshold()).thenReturn(3); when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); + when(federatorSupportMock.getFederationAddress()).thenReturn(HARDCODED_TESTNET_FED_ADDRESS); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); + for (int i = 0; i < 5; i++) { when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.RSK)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+1))); @@ -160,7 +174,7 @@ public void getActiveFederation_erp_federation_testnet_hardcoded() { Assert.assertEquals(expectedFederation, obtainedFederation); Assert.assertTrue(obtainedFederation instanceof ErpFederation); - Assert.assertEquals(obtainedFederation.getRedeemScript(), new Script(Hex.decode("6453210208f40073a9e43b3e9103acec79767a6de9b0409749884e989960fee578012fce210225e892391625854128c5c4ea4340de0c2a70570f33db53426fc9c746597a03f42102afc230c2d355b1a577682b07bc2646041b5d0177af0f98395a46018da699b6da210344a3c38cd59afcba3edcebe143e025574594b001700dec41e59409bdbd0f2a0921039a060badbeb24bee49eb2063f616c0f0f0765d4ca646b20a88ce828f259fcdb955670300cd50b27552210216c23b2ea8e4f11c3f9e22711addb1d16a93964796913830856b568cc3ea21d3210275562901dd8faae20de0a4166362a4f82188db77dbed4ca887422ea1ec185f1421034db69f2112f4fb1bb6141bf6e2bd6631f0484d0bd95b16767902c9fe219d4a6f5368ae"))); + Assert.assertEquals(obtainedFederation.getRedeemScript(), HARDCODED_TESTNET_FED_REDEEM_SCRIPT); verify(federatorSupportMock, times(1)).getFederationSize(); } @@ -230,12 +244,18 @@ public void getRetiringFederation_present_afterMultikey() { public void getRetiringFederation_present_erp_federation() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(true); + + Federation expectedFederation = createErpFederation( + getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), + configMock + ); + Address expectedFederationAddress = expectedFederation.getAddress(); + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); when(federatorSupportMock.getRetiringFederationSize()).thenReturn(5); when(federatorSupportMock.getRetiringFederationThreshold()).thenReturn(3); when(federatorSupportMock.getRetiringFederationCreationTime()).thenReturn(creationTime); - when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(randomActiveAddress)); - + when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(expectedFederationAddress)); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 5; i++) { when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); @@ -243,15 +263,11 @@ public void getRetiringFederation_present_erp_federation() { when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+2))); } - Federation expectedFederation = createErpFederation( - getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), - configMock - ); - Federation obtainedFederation = federationProvider.getRetiringFederation().get(); Assert.assertTrue(obtainedFederation instanceof ErpFederation); Assert.assertEquals(expectedFederation, obtainedFederation); + Assert.assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); verify(federatorSupportMock, times(1)).getRetiringFederationSize(); } @@ -398,11 +414,23 @@ public void getLiveFederations_both_erp_federations() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(true); + Federation expectedActiveFederation = createErpFederation( + getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), + configMock + ); + Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); + + Federation expectedRetiringFederation = createErpFederation( + getFederationMembersFromPks(1,2000, 4000, 6000, 8000, 10000), + configMock + ); + Address expectedRetiringFederationAddress = expectedRetiringFederation.getAddress(); + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); when(federatorSupportMock.getFederationSize()).thenReturn(5); when(federatorSupportMock.getFederationThreshold()).thenReturn(3); when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); - when(federatorSupportMock.getFederationAddress()).thenReturn(randomActiveAddress); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedActiveFederationAddress); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 5; i++) { when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); @@ -413,7 +441,7 @@ public void getLiveFederations_both_erp_federations() { when(federatorSupportMock.getRetiringFederationSize()).thenReturn(5); when(federatorSupportMock.getRetiringFederationThreshold()).thenReturn(3); when(federatorSupportMock.getRetiringFederationCreationTime()).thenReturn(creationTime); - when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(randomRetiringAddress)); + when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(expectedRetiringFederationAddress)); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 5; i++) { when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000))); @@ -421,23 +449,17 @@ public void getLiveFederations_both_erp_federations() { when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000+2))); } - Federation expectedActiveFederation = createErpFederation( - getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), - configMock - ); - - - Federation expectedRetiringFederation = createErpFederation( - getFederationMembersFromPks(1,2000, 4000, 6000, 8000, 10000), - configMock - ); - List liveFederations = federationProvider.getLiveFederations(); Assert.assertEquals(2, liveFederations.size()); - Assert.assertEquals(expectedActiveFederation, liveFederations.get(0)); + Assert.assertTrue(liveFederations.get(0) instanceof ErpFederation); - Assert.assertEquals(expectedRetiringFederation, liveFederations.get(1)); + Assert.assertEquals(expectedActiveFederation, liveFederations.get(0)); + Assert.assertEquals(expectedActiveFederationAddress, liveFederations.get(0).getAddress()); + Assert.assertTrue(liveFederations.get(1) instanceof ErpFederation); + Assert.assertEquals(expectedRetiringFederation, liveFederations.get(1)); + Assert.assertEquals(expectedRetiringFederationAddress, liveFederations.get(1).getAddress()); + verify(federatorSupportMock, times(1)).getFederationSize(); verify(federatorSupportMock, times(1)).getRetiringFederationSize(); } From 9566f80dbb5ebcf470d331a678a32779ce19b4c3 Mon Sep 17 00:00:00 2001 From: Marcos Date: Thu, 3 Nov 2022 19:35:51 -0300 Subject: [PATCH 06/16] Add P2shErpFederation tests in FederationProviderFromFederatorSupportTest --- ...ationProviderFromFederatorSupportTest.java | 259 +++++++++++++++++- 1 file changed, 253 insertions(+), 6 deletions(-) diff --git a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java index 5064a7f4..c9a78e21 100644 --- a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java +++ b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java @@ -9,6 +9,7 @@ import co.rsk.peg.ErpFederation; import co.rsk.peg.Federation; import co.rsk.peg.FederationMember; +import co.rsk.peg.P2shErpFederation; import org.bouncycastle.util.encoders.Hex; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.crypto.ECKey; @@ -32,8 +33,6 @@ public class FederationProviderFromFederatorSupportTest { private FederationProvider federationProvider; private BridgeConstants bridgeConstants; private NetworkParameters testnetParams; - private Address randomActiveAddress; - private Address randomRetiringAddress; private Instant creationTime; private Address activeFedAddress; private Address retiringFedAddress; @@ -55,8 +54,6 @@ public void createProvider() { bridgeConstants ); testnetParams = NetworkParameters.fromID(NetworkParameters.ID_TESTNET); - randomActiveAddress = new BtcECKey().toAddress(testnetParams); - randomRetiringAddress = new BtcECKey().toAddress(testnetParams); creationTime = Instant.ofEpochMilli(5005L); activeFedAddress = Address.fromBase58( @@ -147,6 +144,37 @@ public void getActiveFederation_erp_federation() { verify(federatorSupportMock, times(1)).getFederationSize(); } + @Test + public void getActiveFederation_p2sh_erp_federation() { + ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); + when(configMock.isActive(RSKIP123)).thenReturn(true); + + Federation expectedFederation = createP2shErpFederation( + getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), + configMock + ); + Address expectedFederationAddress = expectedFederation.getAddress(); + + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); + when(federatorSupportMock.getFederationSize()).thenReturn(5); + when(federatorSupportMock.getFederationThreshold()).thenReturn(3); + when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedFederationAddress); + when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); + for (int i = 0; i < 5; i++) { + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.RSK)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+1))); + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+2))); + } + + Federation obtainedFederation = federationProvider.getActiveFederation(); + + Assert.assertTrue(obtainedFederation instanceof P2shErpFederation); + Assert.assertEquals(expectedFederation, obtainedFederation); + Assert.assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); + verify(federatorSupportMock, times(1)).getFederationSize(); + } + @Test public void getActiveFederation_erp_federation_testnet_hardcoded() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); @@ -180,10 +208,12 @@ public void getActiveFederation_erp_federation_testnet_hardcoded() { @Test public void getActiveFederationAddress() { + Address randomAddress = new BtcECKey().toAddress(testnetParams); + when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); - when(federatorSupportMock.getFederationAddress()).thenReturn(randomActiveAddress); + when(federatorSupportMock.getFederationAddress()).thenReturn(randomAddress); - Assert.assertEquals(randomActiveAddress, federationProvider.getActiveFederationAddress()); + Assert.assertEquals(randomAddress, federationProvider.getActiveFederationAddress()); } @Test @@ -192,6 +222,16 @@ public void getRetiringFederation_none() { Assert.assertEquals(Optional.empty(), federationProvider.getRetiringFederation()); verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + verify(federatorSupportMock, times(1)).getRetiringFederationAddress(); + } + + @Test + public void getRetiringFederation_no_address() { + when(federatorSupportMock.getRetiringFederationSize()).thenReturn(5); + + Assert.assertEquals(Optional.empty(), federationProvider.getRetiringFederation()); + verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + verify(federatorSupportMock, times(1)).getRetiringFederationAddress(); } @Test @@ -271,6 +311,37 @@ public void getRetiringFederation_present_erp_federation() { verify(federatorSupportMock, times(1)).getRetiringFederationSize(); } + @Test + public void getRetiringFederation_present_p2sh_erp_federation() { + ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); + when(configMock.isActive(RSKIP123)).thenReturn(true); + + Federation expectedFederation = createP2shErpFederation( + getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), + configMock + ); + Address expectedFederationAddress = expectedFederation.getAddress(); + + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); + when(federatorSupportMock.getRetiringFederationSize()).thenReturn(5); + when(federatorSupportMock.getRetiringFederationThreshold()).thenReturn(3); + when(federatorSupportMock.getRetiringFederationCreationTime()).thenReturn(creationTime); + when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(expectedFederationAddress)); + when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); + for (int i = 0; i < 5; i++) { + when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); + when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.RSK)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+1))); + when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+2))); + } + + Federation obtainedFederation = federationProvider.getRetiringFederation().get(); + + Assert.assertTrue(obtainedFederation instanceof P2shErpFederation); + Assert.assertEquals(expectedFederation, obtainedFederation); + Assert.assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); + verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + } + @Test public void getLiveFederations_onlyActive_beforeMultikey() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); @@ -464,6 +535,170 @@ public void getLiveFederations_both_erp_federations() { verify(federatorSupportMock, times(1)).getRetiringFederationSize(); } + @Test + public void getLiveFederations_retiring_multikey_active_erp() { + ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); + when(configMock.isActive(RSKIP123)).thenReturn(true); + + Federation expectedActiveFederation = createErpFederation( + getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), + configMock + ); + Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); + + Federation expectedRetiringFederation = createFederation( + getFederationMembersFromPks(1,2000, 4000, 6000, 8000, 10000) + ); + Address expectedRetiringFederationAddress = expectedRetiringFederation.getAddress(); + + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); + when(federatorSupportMock.getFederationSize()).thenReturn(5); + when(federatorSupportMock.getFederationThreshold()).thenReturn(3); + when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedActiveFederationAddress); + when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); + for (int i = 0; i < 5; i++) { + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.RSK)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+1))); + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+2))); + } + + when(federatorSupportMock.getRetiringFederationSize()).thenReturn(5); + when(federatorSupportMock.getRetiringFederationThreshold()).thenReturn(3); + when(federatorSupportMock.getRetiringFederationCreationTime()).thenReturn(creationTime); + when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(expectedRetiringFederationAddress)); + when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); + for (int i = 0; i < 5; i++) { + when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000))); + when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.RSK)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000+1))); + when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000+2))); + } + + List liveFederations = federationProvider.getLiveFederations(); + Assert.assertEquals(2, liveFederations.size()); + + Assert.assertTrue(liveFederations.get(0) instanceof ErpFederation); + Assert.assertEquals(expectedActiveFederation, liveFederations.get(0)); + Assert.assertEquals(expectedActiveFederationAddress, liveFederations.get(0).getAddress()); + + Assert.assertTrue(liveFederations.get(1) instanceof Federation); + Assert.assertEquals(expectedRetiringFederation, liveFederations.get(1)); + Assert.assertEquals(expectedRetiringFederationAddress, liveFederations.get(1).getAddress()); + + verify(federatorSupportMock, times(1)).getFederationSize(); + verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + } + + @Test + public void getLiveFederations_retiring_erp_active_p2sh_erp() { + ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); + when(configMock.isActive(RSKIP123)).thenReturn(true); + + Federation expectedActiveFederation = createP2shErpFederation( + getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), + configMock + ); + Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); + + Federation expectedRetiringFederation = createErpFederation( + getFederationMembersFromPks(1,2000, 4000, 6000, 8000, 10000), + configMock + ); + Address expectedRetiringFederationAddress = expectedRetiringFederation.getAddress(); + + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); + when(federatorSupportMock.getFederationSize()).thenReturn(5); + when(federatorSupportMock.getFederationThreshold()).thenReturn(3); + when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedActiveFederationAddress); + when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); + for (int i = 0; i < 5; i++) { + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.RSK)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+1))); + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+2))); + } + + when(federatorSupportMock.getRetiringFederationSize()).thenReturn(5); + when(federatorSupportMock.getRetiringFederationThreshold()).thenReturn(3); + when(federatorSupportMock.getRetiringFederationCreationTime()).thenReturn(creationTime); + when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(expectedRetiringFederationAddress)); + when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); + for (int i = 0; i < 5; i++) { + when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000))); + when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.RSK)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000+1))); + when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000+2))); + } + + List liveFederations = federationProvider.getLiveFederations(); + Assert.assertEquals(2, liveFederations.size()); + + Assert.assertTrue(liveFederations.get(0) instanceof ErpFederation); + Assert.assertEquals(expectedActiveFederation, liveFederations.get(0)); + Assert.assertEquals(expectedActiveFederationAddress, liveFederations.get(0).getAddress()); + + Assert.assertTrue(liveFederations.get(1) instanceof P2shErpFederation); + Assert.assertEquals(expectedRetiringFederation, liveFederations.get(1)); + Assert.assertEquals(expectedRetiringFederationAddress, liveFederations.get(1).getAddress()); + + verify(federatorSupportMock, times(1)).getFederationSize(); + verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + } + + @Test + public void getLiveFederations_both_p2sh_erp_federations() { + ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); + when(configMock.isActive(RSKIP123)).thenReturn(true); + + Federation expectedActiveFederation = createP2shErpFederation( + getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), + configMock + ); + Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); + + Federation expectedRetiringFederation = createP2shErpFederation( + getFederationMembersFromPks(1,2000, 4000, 6000, 8000, 10000), + configMock + ); + Address expectedRetiringFederationAddress = expectedRetiringFederation.getAddress(); + + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); + when(federatorSupportMock.getFederationSize()).thenReturn(5); + when(federatorSupportMock.getFederationThreshold()).thenReturn(3); + when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedActiveFederationAddress); + when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); + for (int i = 0; i < 5; i++) { + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.RSK)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+1))); + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+2))); + } + + when(federatorSupportMock.getRetiringFederationSize()).thenReturn(5); + when(federatorSupportMock.getRetiringFederationThreshold()).thenReturn(3); + when(federatorSupportMock.getRetiringFederationCreationTime()).thenReturn(creationTime); + when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(expectedRetiringFederationAddress)); + when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); + for (int i = 0; i < 5; i++) { + when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000))); + when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.RSK)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000+1))); + when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000+2))); + } + + List liveFederations = federationProvider.getLiveFederations(); + Assert.assertEquals(2, liveFederations.size()); + + Assert.assertTrue(liveFederations.get(0) instanceof P2shErpFederation); + Assert.assertEquals(expectedActiveFederation, liveFederations.get(0)); + Assert.assertEquals(expectedActiveFederationAddress, liveFederations.get(0).getAddress()); + + Assert.assertTrue(liveFederations.get(1) instanceof P2shErpFederation); + Assert.assertEquals(expectedRetiringFederation, liveFederations.get(1)); + Assert.assertEquals(expectedRetiringFederationAddress, liveFederations.get(1).getAddress()); + + verify(federatorSupportMock, times(1)).getFederationSize(); + verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + } + private Federation createFederation(List members) { return new Federation( members, @@ -485,6 +720,18 @@ private Federation createErpFederation(List members, Activatio ); } + private Federation createP2shErpFederation(List members, ActivationConfig.ForBlock activations) { + return new P2shErpFederation( + members, + creationTime, + 0L, + testnetParams, + bridgeConstants.getErpFedPubKeysList(), + bridgeConstants.getErpFedActivationDelay(), + activations + ); + } + private List getFederationMembersFromPks(int offset, Integer... pks) { return Arrays.stream(pks).map(n -> new FederationMember( BtcECKey.fromPrivate(BigInteger.valueOf(n)), From 8b823ceafa25c072e518a3a1a89d7892e62e9054 Mon Sep 17 00:00:00 2001 From: Marcos Date: Thu, 3 Nov 2022 20:18:33 -0300 Subject: [PATCH 07/16] Refactor FederationProviderFromFederatorSupport tests --- ...ationProviderFromFederatorSupportTest.java | 376 +++++++++++------- 1 file changed, 240 insertions(+), 136 deletions(-) diff --git a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java index c9a78e21..7974c681 100644 --- a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java +++ b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java @@ -34,8 +34,6 @@ public class FederationProviderFromFederatorSupportTest { private BridgeConstants bridgeConstants; private NetworkParameters testnetParams; private Instant creationTime; - private Address activeFedAddress; - private Address retiringFedAddress; private static final Address HARDCODED_TESTNET_FED_ADDRESS = Address.fromBase58( NetworkParameters.fromID(NetworkParameters.ID_TESTNET), @@ -55,49 +53,50 @@ public void createProvider() { ); testnetParams = NetworkParameters.fromID(NetworkParameters.ID_TESTNET); creationTime = Instant.ofEpochMilli(5005L); - - activeFedAddress = Address.fromBase58( - testnetParams, - "2Mutaga98GgQJEmCj1TqhwLdJ3u8DFVUTw8" - ); - - retiringFedAddress = Address.fromBase58( - testnetParams, - "2Mtdr1Ci3bX4XRfDGYbmGbuaquNspWqeqcC" - ); } @Test public void getActiveFederation_beforeMultikey() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(false); + + Federation expectedFederation = createFederation( + getFederationMembersFromPks(0, 1000, 2000, 3000, 4000) + ); + Address expectedFederationAddress = expectedFederation.getAddress(); + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); when(federatorSupportMock.getFederationSize()).thenReturn(4); when(federatorSupportMock.getFederationThreshold()).thenReturn(2); when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); - when(federatorSupportMock.getFederationAddress()).thenReturn(activeFedAddress); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedFederationAddress); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 4; i++) { when(federatorSupportMock.getFederatorPublicKey(i)).thenReturn(BtcECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); } - Federation expectedFederation = createFederation( - getFederationMembersFromPks(0, 1000, 2000, 3000, 4000) - ); + Federation obtainedFederation = federationProvider.getActiveFederation(); - Assert.assertEquals(expectedFederation, federationProvider.getActiveFederation()); - verify(federatorSupportMock, times(1)).getFederationSize(); + Assert.assertTrue(obtainedFederation instanceof Federation); + Assert.assertEquals(expectedFederation, obtainedFederation); + Assert.assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); } @Test public void getActiveFederation_afterMultikey() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(true); + + Federation expectedFederation = createFederation( + getFederationMembersFromPks(1, 1000, 2000, 3000, 4000) + ); + Address expectedFederationAddress = expectedFederation.getAddress(); + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); when(federatorSupportMock.getFederationSize()).thenReturn(4); when(federatorSupportMock.getFederationThreshold()).thenReturn(2); when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); - when(federatorSupportMock.getFederationAddress()).thenReturn(activeFedAddress); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedFederationAddress); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 4; i++) { when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); @@ -105,12 +104,11 @@ public void getActiveFederation_afterMultikey() { when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+2))); } - Federation expectedFederation = createFederation( - getFederationMembersFromPks(1, 1000, 2000, 3000, 4000) - ); + Federation obtainedFederation = federationProvider.getActiveFederation(); - Assert.assertEquals(expectedFederation, federationProvider.getActiveFederation()); - verify(federatorSupportMock, times(1)).getFederationSize(); + Assert.assertTrue(obtainedFederation instanceof Federation); + Assert.assertEquals(expectedFederation, obtainedFederation); + Assert.assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); } @Test @@ -141,15 +139,15 @@ public void getActiveFederation_erp_federation() { Assert.assertTrue(obtainedFederation instanceof ErpFederation); Assert.assertEquals(expectedFederation, obtainedFederation); Assert.assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); - verify(federatorSupportMock, times(1)).getFederationSize(); } @Test - public void getActiveFederation_p2sh_erp_federation() { + public void getActiveFederation_erp_federation_testnet_hardcoded() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(true); + when(configMock.isActive(RSKIP284)).thenReturn(false); - Federation expectedFederation = createP2shErpFederation( + Federation expectedFederation = createErpFederation( getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), configMock ); @@ -161,6 +159,7 @@ public void getActiveFederation_p2sh_erp_federation() { when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); when(federatorSupportMock.getFederationAddress()).thenReturn(expectedFederationAddress); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); + for (int i = 0; i < 5; i++) { when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.RSK)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+1))); @@ -169,41 +168,40 @@ public void getActiveFederation_p2sh_erp_federation() { Federation obtainedFederation = federationProvider.getActiveFederation(); - Assert.assertTrue(obtainedFederation instanceof P2shErpFederation); + Assert.assertTrue(obtainedFederation instanceof ErpFederation); Assert.assertEquals(expectedFederation, obtainedFederation); - Assert.assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); - verify(federatorSupportMock, times(1)).getFederationSize(); + Assert.assertEquals(HARDCODED_TESTNET_FED_ADDRESS, obtainedFederation.getAddress()); + Assert.assertEquals(obtainedFederation.getRedeemScript(), HARDCODED_TESTNET_FED_REDEEM_SCRIPT); } @Test - public void getActiveFederation_erp_federation_testnet_hardcoded() { + public void getActiveFederation_p2sh_erp_federation() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(true); - when(configMock.isActive(RSKIP284)).thenReturn(false); + + Federation expectedFederation = createP2shErpFederation( + getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), + configMock + ); + Address expectedFederationAddress = expectedFederation.getAddress(); + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); when(federatorSupportMock.getFederationSize()).thenReturn(5); when(federatorSupportMock.getFederationThreshold()).thenReturn(3); when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); - when(federatorSupportMock.getFederationAddress()).thenReturn(HARDCODED_TESTNET_FED_ADDRESS); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedFederationAddress); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); - for (int i = 0; i < 5; i++) { when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.RSK)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+1))); when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+2))); } - Federation expectedFederation = createErpFederation( - getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), - configMock - ); - Federation obtainedFederation = federationProvider.getActiveFederation(); + Assert.assertTrue(obtainedFederation instanceof P2shErpFederation); Assert.assertEquals(expectedFederation, obtainedFederation); - Assert.assertTrue(obtainedFederation instanceof ErpFederation); - Assert.assertEquals(obtainedFederation.getRedeemScript(), HARDCODED_TESTNET_FED_REDEEM_SCRIPT); - verify(federatorSupportMock, times(1)).getFederationSize(); + Assert.assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); } @Test @@ -238,33 +236,47 @@ public void getRetiringFederation_no_address() { public void getRetiringFederation_present_beforeMultikey() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(false); + + Federation expectedFederation = createFederation( + getFederationMembersFromPks(0, 2000, 4000, 6000, 8000, 10000, 12000) + ); + Address expectedFederationAddress = expectedFederation.getAddress(); + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); when(federatorSupportMock.getRetiringFederationSize()).thenReturn(6); when(federatorSupportMock.getRetiringFederationThreshold()).thenReturn(3); when(federatorSupportMock.getRetiringFederationCreationTime()).thenReturn(creationTime); - when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(retiringFedAddress)); + when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(expectedFederationAddress)); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 6; i++) { when(federatorSupportMock.getRetiringFederatorPublicKey(i)).thenReturn(BtcECKey.fromPrivate(BigInteger.valueOf((i+1)*2000))); } - Federation expectedFederation = createFederation( - getFederationMembersFromPks(0, 2000, 4000, 6000, 8000, 10000, 12000) - ); + Optional obtainedFederationOptional = federationProvider.getRetiringFederation(); + Assert.assertTrue(obtainedFederationOptional.isPresent()); - Assert.assertEquals(Optional.of(expectedFederation), federationProvider.getRetiringFederation()); - verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + Federation obtainedFederation = obtainedFederationOptional.get(); + + Assert.assertTrue(obtainedFederation instanceof Federation); + Assert.assertEquals(expectedFederation, obtainedFederation); + Assert.assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); } @Test public void getRetiringFederation_present_afterMultikey() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(true); + + Federation expectedFederation = createFederation( + getFederationMembersFromPks(1,2000, 4000, 6000, 8000, 10000, 12000) + ); + Address expectedFederationAddress = expectedFederation.getAddress(); + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); when(federatorSupportMock.getRetiringFederationSize()).thenReturn(6); when(federatorSupportMock.getRetiringFederationThreshold()).thenReturn(3); when(federatorSupportMock.getRetiringFederationCreationTime()).thenReturn(creationTime); - when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(retiringFedAddress)); + when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(expectedFederationAddress)); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 6; i++) { when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000))); @@ -272,12 +284,14 @@ public void getRetiringFederation_present_afterMultikey() { when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000+2))); } - Federation expectedFederation = createFederation( - getFederationMembersFromPks(1,2000, 4000, 6000, 8000, 10000, 12000) - ); + Optional obtainedFederationOptional = federationProvider.getRetiringFederation(); + Assert.assertTrue(obtainedFederationOptional.isPresent()); - Assert.assertEquals(Optional.of(expectedFederation), federationProvider.getRetiringFederation()); - verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + Federation obtainedFederation = obtainedFederationOptional.get(); + + Assert.assertTrue(obtainedFederation instanceof Federation); + Assert.assertEquals(expectedFederation, obtainedFederation); + Assert.assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); } @Test @@ -303,12 +317,14 @@ public void getRetiringFederation_present_erp_federation() { when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+2))); } - Federation obtainedFederation = federationProvider.getRetiringFederation().get(); + Optional obtainedFederationOptional = federationProvider.getRetiringFederation(); + Assert.assertTrue(obtainedFederationOptional.isPresent()); + + Federation obtainedFederation = obtainedFederationOptional.get(); Assert.assertTrue(obtainedFederation instanceof ErpFederation); Assert.assertEquals(expectedFederation, obtainedFederation); Assert.assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); - verify(federatorSupportMock, times(1)).getRetiringFederationSize(); } @Test @@ -334,79 +350,164 @@ public void getRetiringFederation_present_p2sh_erp_federation() { when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+2))); } - Federation obtainedFederation = federationProvider.getRetiringFederation().get(); + Optional obtainedFederationOptional = federationProvider.getRetiringFederation(); + Assert.assertTrue(obtainedFederationOptional.isPresent()); + + Federation obtainedFederation = obtainedFederationOptional.get(); Assert.assertTrue(obtainedFederation instanceof P2shErpFederation); Assert.assertEquals(expectedFederation, obtainedFederation); Assert.assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); - verify(federatorSupportMock, times(1)).getRetiringFederationSize(); } @Test public void getLiveFederations_onlyActive_beforeMultikey() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(false); + + Federation expectedActiveFederation = createFederation( + getFederationMembersFromPks(0, 1000, 2000, 3000, 4000) + ); + Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); when(federatorSupportMock.getFederationSize()).thenReturn(4); when(federatorSupportMock.getFederationThreshold()).thenReturn(2); when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); - when(federatorSupportMock.getFederationAddress()).thenReturn(activeFedAddress); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedActiveFederationAddress); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 4; i++) { when(federatorSupportMock.getFederatorPublicKey(i)).thenReturn(BtcECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); } - when(federatorSupportMock.getRetiringFederationSize()).thenReturn(-1); + List liveFederations = federationProvider.getLiveFederations(); + Assert.assertEquals(1, liveFederations.size()); + + Federation activeFederation = liveFederations.get(0); + Assert.assertTrue(activeFederation instanceof Federation); + Assert.assertEquals(expectedActiveFederation, activeFederation); + Assert.assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); + } + + @Test + public void getLiveFederations_onlyActive_afterMultikey() { + ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); + when(configMock.isActive(RSKIP123)).thenReturn(true); + Federation expectedActiveFederation = createFederation( - getFederationMembersFromPks(0, 1000, 2000, 3000, 4000) + getFederationMembersFromPks(1,1000, 2000, 3000, 4000) ); + Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); + + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); + when(federatorSupportMock.getFederationSize()).thenReturn(4); + when(federatorSupportMock.getFederationThreshold()).thenReturn(2); + when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedActiveFederationAddress); + when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); + for (int i = 0; i < 4; i++) { + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.RSK)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+1))); + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+2))); + } + when(federatorSupportMock.getRetiringFederationSize()).thenReturn(-1); List liveFederations = federationProvider.getLiveFederations(); Assert.assertEquals(1, liveFederations.size()); - Assert.assertEquals(expectedActiveFederation, liveFederations.get(0)); - verify(federatorSupportMock, times(1)).getFederationSize(); - verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + + Federation activeFederation = liveFederations.get(0); + Assert.assertTrue(activeFederation instanceof Federation); + Assert.assertEquals(expectedActiveFederation, activeFederation); + Assert.assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); } @Test - public void getLiveFederations_onlyActive_afterMultikey() { + public void getLiveFederations_onlyActive_erp_federation() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(true); + + Federation expectedActiveFederation = createErpFederation( + getFederationMembersFromPks(1,1000, 2000, 3000, 4000), + configMock + ); + Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); when(federatorSupportMock.getFederationSize()).thenReturn(4); when(federatorSupportMock.getFederationThreshold()).thenReturn(2); when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); - when(federatorSupportMock.getFederationAddress()).thenReturn(activeFedAddress); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedActiveFederationAddress); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 4; i++) { when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.RSK)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+1))); when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+2))); } - when(federatorSupportMock.getRetiringFederationSize()).thenReturn(-1); - Federation expectedActiveFederation = createFederation( - getFederationMembersFromPks(1,1000, 2000, 3000, 4000) + List liveFederations = federationProvider.getLiveFederations(); + Assert.assertEquals(1, liveFederations.size()); + + Federation activeFederation = liveFederations.get(0); + Assert.assertTrue(activeFederation instanceof ErpFederation); + Assert.assertEquals(expectedActiveFederation, activeFederation); + Assert.assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); + } + + @Test + public void getLiveFederations_onlyActive_p2sh_erp_federation() { + ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); + when(configMock.isActive(RSKIP123)).thenReturn(true); + + Federation expectedActiveFederation = createP2shErpFederation( + getFederationMembersFromPks(1,1000, 2000, 3000, 4000), + configMock ); + Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); + + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); + when(federatorSupportMock.getFederationSize()).thenReturn(4); + when(federatorSupportMock.getFederationThreshold()).thenReturn(2); + when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedActiveFederationAddress); + when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); + for (int i = 0; i < 4; i++) { + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.RSK)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+1))); + when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000+2))); + } + when(federatorSupportMock.getRetiringFederationSize()).thenReturn(-1); List liveFederations = federationProvider.getLiveFederations(); Assert.assertEquals(1, liveFederations.size()); - Assert.assertEquals(expectedActiveFederation, liveFederations.get(0)); - verify(federatorSupportMock, times(1)).getFederationSize(); - verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + + Federation activeFederation = liveFederations.get(0); + Assert.assertTrue(activeFederation instanceof P2shErpFederation); + Assert.assertEquals(expectedActiveFederation, activeFederation); + Assert.assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); } @Test public void getLiveFederations_both_beforeMultikey() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(false); + + Federation expectedActiveFederation = createFederation( + getFederationMembersFromPks(0,1000, 2000, 3000, 4000) + ); + Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); + + Federation expectedRetiringFederation = createFederation( + getFederationMembersFromPks(0, 2000, 4000, 6000, 8000, 10000, 12000) + ); + Address expectedRetiringFederationAddress = expectedRetiringFederation.getAddress(); + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); when(federatorSupportMock.getFederationSize()).thenReturn(4); when(federatorSupportMock.getFederationThreshold()).thenReturn(2); when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); - when(federatorSupportMock.getFederationAddress()).thenReturn(activeFedAddress); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedActiveFederationAddress); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 4; i++) { when(federatorSupportMock.getFederatorPublicKey(i)).thenReturn(BtcECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); @@ -415,37 +516,46 @@ public void getLiveFederations_both_beforeMultikey() { when(federatorSupportMock.getRetiringFederationSize()).thenReturn(6); when(federatorSupportMock.getRetiringFederationThreshold()).thenReturn(3); when(federatorSupportMock.getRetiringFederationCreationTime()).thenReturn(creationTime); - when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(retiringFedAddress)); + when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(expectedRetiringFederationAddress)); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 6; i++) { when(federatorSupportMock.getRetiringFederatorPublicKey(i)).thenReturn(BtcECKey.fromPrivate(BigInteger.valueOf((i+1)*2000))); } - Federation expectedActiveFederation = createFederation( - getFederationMembersFromPks(0,1000, 2000, 3000, 4000) - ); - - Federation expectedRetiringFederation = createFederation( - getFederationMembersFromPks(0, 2000, 4000, 6000, 8000, 10000, 12000) - ); - List liveFederations = federationProvider.getLiveFederations(); Assert.assertEquals(2, liveFederations.size()); - Assert.assertEquals(expectedActiveFederation, liveFederations.get(0)); - Assert.assertEquals(expectedRetiringFederation, liveFederations.get(1)); - verify(federatorSupportMock, times(1)).getFederationSize(); - verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + + Federation activeFederation = liveFederations.get(0); + Assert.assertTrue(activeFederation instanceof Federation); + Assert.assertEquals(expectedActiveFederation, activeFederation); + Assert.assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); + + Federation retiringFederation = liveFederations.get(1); + Assert.assertTrue(retiringFederation instanceof Federation); + Assert.assertEquals(expectedRetiringFederation, retiringFederation); + Assert.assertEquals(expectedRetiringFederationAddress, retiringFederation.getAddress()); } @Test public void getLiveFederations_both_afterMultikey() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(true); + + Federation expectedActiveFederation = createFederation( + getFederationMembersFromPks(1,1000, 2000, 3000, 4000) + ); + Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); + + Federation expectedRetiringFederation = createFederation( + getFederationMembersFromPks(1,2000, 4000, 6000, 8000, 10000, 12000) + ); + Address expectedRetiringFederationAddress = expectedRetiringFederation.getAddress(); + when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock); when(federatorSupportMock.getFederationSize()).thenReturn(4); when(federatorSupportMock.getFederationThreshold()).thenReturn(2); when(federatorSupportMock.getFederationCreationTime()).thenReturn(creationTime); - when(federatorSupportMock.getFederationAddress()).thenReturn(activeFedAddress); + when(federatorSupportMock.getFederationAddress()).thenReturn(expectedActiveFederationAddress); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 4; i++) { when(federatorSupportMock.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*1000))); @@ -456,7 +566,7 @@ public void getLiveFederations_both_afterMultikey() { when(federatorSupportMock.getRetiringFederationSize()).thenReturn(6); when(federatorSupportMock.getRetiringFederationThreshold()).thenReturn(3); when(federatorSupportMock.getRetiringFederationCreationTime()).thenReturn(creationTime); - when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(retiringFedAddress)); + when(federatorSupportMock.getRetiringFederationAddress()).thenReturn(Optional.of(expectedRetiringFederationAddress)); when(federatorSupportMock.getBtcParams()).thenReturn(testnetParams); for (int i = 0; i < 6; i++) { when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000))); @@ -464,20 +574,18 @@ public void getLiveFederations_both_afterMultikey() { when(federatorSupportMock.getRetiringFederatorPublicKeyOfType(i, FederationMember.KeyType.MST)).thenReturn(ECKey.fromPrivate(BigInteger.valueOf((i+1)*2000+2))); } - Federation expectedActiveFederation = createFederation( - getFederationMembersFromPks(1,1000, 2000, 3000, 4000) - ); - - Federation expectedRetiringFederation = createFederation( - getFederationMembersFromPks(1,2000, 4000, 6000, 8000, 10000, 12000) - ); - List liveFederations = federationProvider.getLiveFederations(); Assert.assertEquals(2, liveFederations.size()); - Assert.assertEquals(expectedActiveFederation, liveFederations.get(0)); - Assert.assertEquals(expectedRetiringFederation, liveFederations.get(1)); - verify(federatorSupportMock, times(1)).getFederationSize(); - verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + + Federation activeFederation = liveFederations.get(0); + Assert.assertTrue(activeFederation instanceof Federation); + Assert.assertEquals(expectedActiveFederation, activeFederation); + Assert.assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); + + Federation retiringFederation = liveFederations.get(1); + Assert.assertTrue(retiringFederation instanceof Federation); + Assert.assertEquals(expectedRetiringFederation, retiringFederation); + Assert.assertEquals(expectedRetiringFederationAddress, retiringFederation.getAddress()); } @Test @@ -523,16 +631,15 @@ public void getLiveFederations_both_erp_federations() { List liveFederations = federationProvider.getLiveFederations(); Assert.assertEquals(2, liveFederations.size()); - Assert.assertTrue(liveFederations.get(0) instanceof ErpFederation); - Assert.assertEquals(expectedActiveFederation, liveFederations.get(0)); - Assert.assertEquals(expectedActiveFederationAddress, liveFederations.get(0).getAddress()); - - Assert.assertTrue(liveFederations.get(1) instanceof ErpFederation); - Assert.assertEquals(expectedRetiringFederation, liveFederations.get(1)); - Assert.assertEquals(expectedRetiringFederationAddress, liveFederations.get(1).getAddress()); + Federation activeFederation = liveFederations.get(0); + Assert.assertTrue(activeFederation instanceof ErpFederation); + Assert.assertEquals(expectedActiveFederation, activeFederation); + Assert.assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); - verify(federatorSupportMock, times(1)).getFederationSize(); - verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + Federation retiringFederation = liveFederations.get(1); + Assert.assertTrue(retiringFederation instanceof ErpFederation); + Assert.assertEquals(expectedRetiringFederation, retiringFederation); + Assert.assertEquals(expectedRetiringFederationAddress, retiringFederation.getAddress()); } @Test @@ -577,16 +684,15 @@ public void getLiveFederations_retiring_multikey_active_erp() { List liveFederations = federationProvider.getLiveFederations(); Assert.assertEquals(2, liveFederations.size()); - Assert.assertTrue(liveFederations.get(0) instanceof ErpFederation); - Assert.assertEquals(expectedActiveFederation, liveFederations.get(0)); - Assert.assertEquals(expectedActiveFederationAddress, liveFederations.get(0).getAddress()); - - Assert.assertTrue(liveFederations.get(1) instanceof Federation); - Assert.assertEquals(expectedRetiringFederation, liveFederations.get(1)); - Assert.assertEquals(expectedRetiringFederationAddress, liveFederations.get(1).getAddress()); + Federation activeFederation = liveFederations.get(0); + Assert.assertTrue(activeFederation instanceof ErpFederation); + Assert.assertEquals(expectedActiveFederation, activeFederation); + Assert.assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); - verify(federatorSupportMock, times(1)).getFederationSize(); - verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + Federation retiringFederation = liveFederations.get(1); + Assert.assertTrue(retiringFederation instanceof Federation); + Assert.assertEquals(expectedRetiringFederation, retiringFederation); + Assert.assertEquals(expectedRetiringFederationAddress, retiringFederation.getAddress()); } @Test @@ -632,16 +738,15 @@ public void getLiveFederations_retiring_erp_active_p2sh_erp() { List liveFederations = federationProvider.getLiveFederations(); Assert.assertEquals(2, liveFederations.size()); - Assert.assertTrue(liveFederations.get(0) instanceof ErpFederation); - Assert.assertEquals(expectedActiveFederation, liveFederations.get(0)); - Assert.assertEquals(expectedActiveFederationAddress, liveFederations.get(0).getAddress()); - - Assert.assertTrue(liveFederations.get(1) instanceof P2shErpFederation); - Assert.assertEquals(expectedRetiringFederation, liveFederations.get(1)); - Assert.assertEquals(expectedRetiringFederationAddress, liveFederations.get(1).getAddress()); + Federation activeFederation = liveFederations.get(0); + Assert.assertTrue(activeFederation instanceof P2shErpFederation); + Assert.assertEquals(expectedActiveFederation, activeFederation); + Assert.assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); - verify(federatorSupportMock, times(1)).getFederationSize(); - verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + Federation retiringFederation = liveFederations.get(1); + Assert.assertTrue(retiringFederation instanceof ErpFederation); + Assert.assertEquals(expectedRetiringFederation, retiringFederation); + Assert.assertEquals(expectedRetiringFederationAddress, retiringFederation.getAddress()); } @Test @@ -687,16 +792,15 @@ public void getLiveFederations_both_p2sh_erp_federations() { List liveFederations = federationProvider.getLiveFederations(); Assert.assertEquals(2, liveFederations.size()); - Assert.assertTrue(liveFederations.get(0) instanceof P2shErpFederation); - Assert.assertEquals(expectedActiveFederation, liveFederations.get(0)); - Assert.assertEquals(expectedActiveFederationAddress, liveFederations.get(0).getAddress()); - - Assert.assertTrue(liveFederations.get(1) instanceof P2shErpFederation); - Assert.assertEquals(expectedRetiringFederation, liveFederations.get(1)); - Assert.assertEquals(expectedRetiringFederationAddress, liveFederations.get(1).getAddress()); + Federation activeFederation = liveFederations.get(0); + Assert.assertTrue(activeFederation instanceof P2shErpFederation); + Assert.assertEquals(expectedActiveFederation, activeFederation); + Assert.assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); - verify(federatorSupportMock, times(1)).getFederationSize(); - verify(federatorSupportMock, times(1)).getRetiringFederationSize(); + Federation retiringFederation = liveFederations.get(1); + Assert.assertTrue(retiringFederation instanceof P2shErpFederation); + Assert.assertEquals(expectedRetiringFederation, retiringFederation); + Assert.assertEquals(expectedRetiringFederationAddress, retiringFederation.getAddress()); } private Federation createFederation(List members) { From 0de44c6c60f312bd95f2a52db936722de1cb9b18 Mon Sep 17 00:00:00 2001 From: Marcos Date: Wed, 9 Nov 2022 15:33:14 -0300 Subject: [PATCH 08/16] Update bitcoinj-thin dependency to 0.14.4-rsk-14-alphanet2 --- build.gradle | 2 +- gradle/verification-metadata.xml | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 0832d85f..3d6e88bc 100644 --- a/build.gradle +++ b/build.gradle @@ -54,7 +54,7 @@ tasks.withType(AbstractArchiveTask) { ext { bitcoinjcoreVersion = '0.15.6-rsk-2' - bitcoinjVersion = '0.14.4-rsk-14-alphanet' + bitcoinjVersion = '0.14.4-rsk-14-alphanet2' commonsLang3Version = '3.5' commonsIoVersion = '2.5' slf4jVersion = '1.7.25' diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 93503b52..1f664690 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -56,14 +56,14 @@ - - - - - - - - + + + + + + + + From b496194fdf6c09e0339fe0442c1de07fb6907b7a Mon Sep 17 00:00:00 2001 From: Marcos Date: Tue, 15 Nov 2022 09:53:57 -0300 Subject: [PATCH 09/16] Update bitcoinj-thin dependency version to 0.14.4-rsk-14 --- build.gradle | 2 +- gradle/verification-metadata.xml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 3d6e88bc..d91624e7 100644 --- a/build.gradle +++ b/build.gradle @@ -54,7 +54,7 @@ tasks.withType(AbstractArchiveTask) { ext { bitcoinjcoreVersion = '0.15.6-rsk-2' - bitcoinjVersion = '0.14.4-rsk-14-alphanet2' + bitcoinjVersion = '0.14.4-rsk-14' commonsLang3Version = '3.5' commonsIoVersion = '2.5' slf4jVersion = '1.7.25' diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 1f664690..22273622 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -56,12 +56,12 @@ - - - + + + - - + + From bfbc625a283f206f79713bc1a8f27fe52d67f50e Mon Sep 17 00:00:00 2001 From: Marcos Date: Tue, 15 Nov 2022 16:57:48 -0300 Subject: [PATCH 10/16] Set version to HOP-TESTNET-4.0.1.0 --- src/main/resources/version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/version.properties b/src/main/resources/version.properties index 166c31dc..863ea4d5 100644 --- a/src/main/resources/version.properties +++ b/src/main/resources/version.properties @@ -1,2 +1,2 @@ versionNumber='4.0.1.0' -modifier="RC" +modifier="HOP-TESTNET" From 97ce9ec118b757973fcf5d33b74b84df95de95c1 Mon Sep 17 00:00:00 2001 From: Marcos Date: Tue, 15 Nov 2022 17:04:10 -0300 Subject: [PATCH 11/16] Set rskj dependency version to 4.0.1-HOP-TESTNET --- build.gradle | 2 +- gradle/verification-metadata.xml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index d91624e7..8dbc9ca3 100644 --- a/build.gradle +++ b/build.gradle @@ -65,7 +65,7 @@ ext { junitVersion = '4.12' mockitoVersion = '2.23.4' powermockitoVersion = '2.0.2' - rskjcoreVersion = '4.0.1-RC' + rskjcoreVersion = '4.0.1-HOP-TESTNET' } dependencies { diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 22273622..93806553 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -48,12 +48,12 @@ - - - + + + - - + + From 94f259eaf2faf2c73c128dfeb33fd575609f3805 Mon Sep 17 00:00:00 2001 From: Marcos Date: Tue, 15 Nov 2022 17:14:47 -0300 Subject: [PATCH 12/16] Update test in FederationProviderFromFederatorSupportTest --- .../federate/FederationProviderFromFederatorSupportTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java index 7974c681..dffdce01 100644 --- a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java +++ b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java @@ -171,7 +171,7 @@ public void getActiveFederation_erp_federation_testnet_hardcoded() { Assert.assertTrue(obtainedFederation instanceof ErpFederation); Assert.assertEquals(expectedFederation, obtainedFederation); Assert.assertEquals(HARDCODED_TESTNET_FED_ADDRESS, obtainedFederation.getAddress()); - Assert.assertEquals(obtainedFederation.getRedeemScript(), HARDCODED_TESTNET_FED_REDEEM_SCRIPT); + Assert.assertEquals(HARDCODED_TESTNET_FED_REDEEM_SCRIPT, obtainedFederation.getRedeemScript()); } @Test From d18d7ab799f0dfd4f35c6fe9feceefca9067e3e1 Mon Sep 17 00:00:00 2001 From: Marcos Date: Tue, 15 Nov 2022 18:21:21 -0300 Subject: [PATCH 13/16] Set version to HOP-TESTNET-4.1.1.0 --- src/main/resources/version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/version.properties b/src/main/resources/version.properties index 5cc5a342..9fbe7b88 100644 --- a/src/main/resources/version.properties +++ b/src/main/resources/version.properties @@ -1,2 +1,2 @@ versionNumber='4.1.1.0' -modifier="RC" +modifier="HOP-TESTNET" From 096b34b1daafe8708ccb27b29d7df87d2ba223c1 Mon Sep 17 00:00:00 2001 From: Marcos Date: Tue, 15 Nov 2022 18:45:39 -0300 Subject: [PATCH 14/16] Set version modifier to RC --- src/main/resources/version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/version.properties b/src/main/resources/version.properties index 9fbe7b88..5cc5a342 100644 --- a/src/main/resources/version.properties +++ b/src/main/resources/version.properties @@ -1,2 +1,2 @@ versionNumber='4.1.1.0' -modifier="HOP-TESTNET" +modifier="RC" From 349e6b2f0486927775265fdf0304c8f58bac51ed Mon Sep 17 00:00:00 2001 From: Marcos Date: Tue, 15 Nov 2022 21:56:31 -0300 Subject: [PATCH 15/16] Set rskj dependency to version 4.1.1-HOP-TESTNET --- build.gradle | 2 +- gradle/verification-metadata.xml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index f0d2599a..680e2a3e 100644 --- a/build.gradle +++ b/build.gradle @@ -65,7 +65,7 @@ ext { junitVersion = '4.12' mockitoVersion = '2.23.4' powermockitoVersion = '2.0.2' - rskjcoreVersion = '4.1.1-RC' + rskjcoreVersion = '4.1.1-HOP-TESTNET' } dependencies { diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 5f6e370c..01c52eb9 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -48,12 +48,12 @@ - - - + + + - - + + From 6a95c1dfd6e3a6f1a9cb81f2c8f1429e9073301d Mon Sep 17 00:00:00 2001 From: Marcos Date: Tue, 15 Nov 2022 21:57:51 -0300 Subject: [PATCH 16/16] Set version to HOP-TESTNET-4.1.1.0 --- src/main/resources/version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/version.properties b/src/main/resources/version.properties index 5cc5a342..9fbe7b88 100644 --- a/src/main/resources/version.properties +++ b/src/main/resources/version.properties @@ -1,2 +1,2 @@ versionNumber='4.1.1.0' -modifier="RC" +modifier="HOP-TESTNET"