Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-zack committed Sep 30, 2023
1 parent efcb50b commit d32cd4f
Show file tree
Hide file tree
Showing 30 changed files with 186 additions and 180 deletions.
1 change: 1 addition & 0 deletions rskj-core/src/main/java/co/rsk/peg/ErpFederation.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public Script getStandardP2SHScript() {
return standardP2SHScript;
}

@Override
public int getNumberOfSignaturesRequired() {
List<ScriptChunk> standardRedeemScriptChunks = getStandardRedeemScript().getChunks();

Expand Down
2 changes: 2 additions & 0 deletions rskj-core/src/main/java/co/rsk/peg/LegacyErpFederation.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public LegacyErpFederation(
validateRedeemScript();
}

@Override
public Script getRedeemScript() {
if (!activations.isActive(ConsensusRule.RSKIP284) &&
btcParams.getId().equals(NetworkParameters.ID_TESTNET)) {
Expand All @@ -53,6 +54,7 @@ public Script getRedeemScript() {
return redeemScript;
}

@Override
public Script getStandardRedeemScript() {
if (standardRedeemScript == null) {
// i think is not quite right to just "fix" the standardRedeemScript in the buggy fed.
Expand Down
2 changes: 2 additions & 0 deletions rskj-core/src/main/java/co/rsk/peg/P2shErpFederation.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public P2shErpFederation(
super(members, creationTime, creationBlockNumber, btcParams, erpPubKeys, activationDelay, activations);
}

@Override
public final Script getRedeemScript() {
if (redeemScript == null) {
logger.debug("[getRedeemScript] Creating the redeem script from the keys");
Expand All @@ -39,6 +40,7 @@ public final Script getRedeemScript() {
return redeemScript;
}

@Override
public final Script getStandardRedeemScript() {
if (standardRedeemScript == null) {
standardRedeemScript = P2shErpFederationRedeemScriptParser.extractStandardRedeemScript(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public StandardMultisigFederation(
super(members, creationTime, creationBlockNumber, btcParams);
}

@Override
public Script getRedeemScript() {
if (redeemScript == null) {
redeemScript = ScriptBuilder.createRedeemScript(getNumberOfSignaturesRequired(), getBtcPublicKeys());
Expand All @@ -52,6 +53,7 @@ public Script getRedeemScript() {
return redeemScript;
}

@Override
public int getNumberOfSignaturesRequired() {
List<ScriptChunk> standardRedeemScriptChunks = getRedeemScript().getChunks();

Expand All @@ -61,6 +63,7 @@ public int getNumberOfSignaturesRequired() {
return Integer.parseInt(thresholdChunk.toString());

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException Note

Potential uncaught 'java.lang.NumberFormatException'.
}

@Override
public int hashCode() {
// Can use java.util.Objects.hash since all of Instant, int and List<BtcECKey> have
// well-defined hashCode()s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void serializeFederationOnlyBtcKeys() throws Exception {
};

// Only actual keys serialized are BTC keys, so we don't really care about RSK or MST keys
Federation federation = new Federation(
Federation federation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembersWithBtcKeys(Arrays.asList(new BtcECKey[]{
BtcECKey.fromPublicOnly(publicKeyBytes[0]),
BtcECKey.fromPublicOnly(publicKeyBytes[1]),
Expand Down Expand Up @@ -302,7 +302,7 @@ void serializeFederation_serializedKeysAreCompressedAndThree() {
members.add(new FederationMember(new BtcECKey(), new ECKey(), new ECKey()));
}

Federation testFederation = new Federation(
Federation testFederation = new StandardMultisigFederation(
members, Instant.now(), 123, NetworkParameters.fromID(NetworkParameters.ID_REGTEST)
);

Expand Down Expand Up @@ -787,7 +787,7 @@ void serializeAndDeserializeFederationOnlyBtcKeysWithRealRLP() {
};

// Only actual keys serialized are BTC keys, so deserialization will fill RSK and MST keys with those
Federation federation = new Federation(
Federation federation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembersWithKeys(Arrays.asList(
BtcECKey.fromPublicOnly(publicKeyBytes[0]),
BtcECKey.fromPublicOnly(publicKeyBytes[1]),
Expand Down Expand Up @@ -1246,7 +1246,7 @@ private void testSerializeAndDeserializeFederation(
members.add(new FederationMember(new BtcECKey(), new ECKey(), new ECKey()));
}

Federation testFederation = new Federation(
Federation testFederation = new StandardMultisigFederation(
members,
Instant.now(),
123,
Expand All @@ -1259,7 +1259,7 @@ private void testSerializeAndDeserializeFederation(
bridgeConstants.getBtcParams()
);

Federation testErpFederation = new ErpFederation(
Federation testErpFederation = new LegacyErpFederation(
members,
Instant.now(),
123,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ private Federation createFederation(int version) {
activations
);
case ERP_FEDERATION_FORMAT_VERSION:
return new ErpFederation(
return new LegacyErpFederation(
members,
Instant.now(),
1L,
Expand All @@ -624,7 +624,7 @@ private Federation createFederation(int version) {
activations
);
default:
return new Federation(
return new StandardMultisigFederation(
members,
Instant.now(),
1L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void getNewFederation_multiKeyVersion() {
@Test
void getNewFederation_erp_fed() {
Federation newFederation = buildMockFederation(100, 200, 300);
ErpFederation erpFederation = new ErpFederation(
ErpFederation erpFederation = new LegacyErpFederation(
newFederation.getMembers(),
newFederation.getCreationTime(),
newFederation.getCreationBlockNumber(),
Expand Down Expand Up @@ -546,7 +546,7 @@ void saveNewFederation_postMultiKey_RSKIP_201_active_erp_fed() {
BridgeConstants bridgeConstants = config.getNetworkConstants().getBridgeConstants();
Federation newFederation = buildMockFederation(100, 200, 300);

ErpFederation erpFederation = new ErpFederation(
ErpFederation erpFederation = new LegacyErpFederation(
newFederation.getMembers(),
newFederation.getCreationTime(),
newFederation.getCreationBlockNumber(),
Expand Down Expand Up @@ -680,7 +680,7 @@ void getOldFederation_multiKeyVersion() {
void getOldFederation_erp_fed() {
BridgeConstants bridgeConstants = config.getNetworkConstants().getBridgeConstants();
Federation oldFederation = buildMockFederation(100, 200, 300);
ErpFederation erpFederation = new ErpFederation(
ErpFederation erpFederation = new LegacyErpFederation(
oldFederation.getMembers(),
oldFederation.getCreationTime(),
oldFederation.getCreationBlockNumber(),
Expand Down Expand Up @@ -820,7 +820,7 @@ void saveOldFederation_postMultikey_RSKIP_201_active_erp_fed() {

BridgeConstants bridgeConstants = config.getNetworkConstants().getBridgeConstants();
Federation oldFederation = buildMockFederation(100, 200, 300);
ErpFederation erpFederation = new ErpFederation(
ErpFederation erpFederation = new LegacyErpFederation(
oldFederation.getMembers(),
oldFederation.getCreationTime(),
oldFederation.getCreationBlockNumber(),
Expand Down Expand Up @@ -3912,7 +3912,7 @@ private Address getBtcAddress(String addr) {
}

private Federation buildMockFederation(Integer... pks) {
return new Federation(
return new StandardMultisigFederation(
FederationTestUtils.getFederationMembersFromPks(pks),
Instant.ofEpochMilli(1000),
0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void addSignature_fedPubKey_belongs_to_active_federation() throws Exception {
);
federation1Keys.sort(BtcECKey.PUBKEY_COMPARATOR);

Federation activeFederation = new Federation(
Federation activeFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembersWithBtcKeys(federation1Keys),
Instant.ofEpochMilli(1000L),
0L,
Expand Down Expand Up @@ -133,7 +133,7 @@ void addSignature_fedPubKey_belongs_to_retiring_federation() throws Exception {
BtcECKey.fromPrivate(Hex.decode("fa02")));
federation1Keys.sort(BtcECKey.PUBKEY_COMPARATOR);

Federation retiringFederation = new Federation(
Federation retiringFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembersWithBtcKeys(federation1Keys),
Instant.ofEpochMilli(1000L),
0L,
Expand All @@ -147,7 +147,7 @@ void addSignature_fedPubKey_belongs_to_retiring_federation() throws Exception {
);
activeFederationKeys.sort(BtcECKey.PUBKEY_COMPARATOR);

Federation activeFederation = new Federation(
Federation activeFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembersWithBtcKeys(activeFederationKeys),
Instant.ofEpochMilli(1000L),
0L,
Expand Down Expand Up @@ -191,7 +191,7 @@ void addSignature_fedPubKey_no_belong_to_retiring_or_active_federation() throws
);
federation1Keys.sort(BtcECKey.PUBKEY_COMPARATOR);

Federation retiringFederation = new Federation(
Federation retiringFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembersWithBtcKeys(federation1Keys),
Instant.ofEpochMilli(1000L),
0L,
Expand All @@ -205,7 +205,7 @@ void addSignature_fedPubKey_no_belong_to_retiring_or_active_federation() throws
);
activeFederationKeys.sort(BtcECKey.PUBKEY_COMPARATOR);

Federation activeFederation = new Federation(
Federation activeFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembersWithBtcKeys(activeFederationKeys),
Instant.ofEpochMilli(1000L),
0L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void getTransactionType_sentFromOldFed(ActivationConfig.ForBlock activations, Pe
.withProvider(provider)
.build();

Federation activeFederation = new Federation(
Federation activeFederation = new StandardMultisigFederation(
bridgeRegTestConstants.getGenesisFederation().getMembers(),
bridgeRegTestConstants.getGenesisFederation().getCreationTime(),
5L,
Expand Down Expand Up @@ -258,7 +258,7 @@ void getTransactionType_pegout_tx() {
new String[]{"fa01", "fa02", "fa03"}, true
);

Federation activeFederation = new Federation(
Federation activeFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembersWithBtcKeys(fedKeys),
Instant.ofEpochMilli(1000L),
0L,
Expand Down Expand Up @@ -304,7 +304,7 @@ void getTransactionType_migration_tx() {
new String[]{"fa01", "fa02", "fa03"}, true
);;

Federation retiringFederation = new Federation(
Federation retiringFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembersWithBtcKeys(retiringFedKeys),
Instant.ofEpochMilli(1000L),
0L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void test_processFundsMigration(
federationActivationAge +
bridgeConstants.getFundsMigrationAgeSinceActivationEnd(activations) + 1;

Federation newFederation = new Federation(
Federation newFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembers(1),
Instant.EPOCH,
federationCreationBlockNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ private static Repository createRepository() {
}

private static Federation getFederation() {
return new Federation(
return new StandardMultisigFederation(
FederationTestUtils.getFederationMembers(3),
Instant.ofEpochMilli(1000),
0L,
Expand Down
28 changes: 14 additions & 14 deletions rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ void registerBtcTransactionLockTxNotWhitelisted_before_rskip_146_activation() th
BtcECKey.fromPrivate(Hex.decode("fa02"))
);

Federation federation1 = new Federation(
Federation federation1 = new StandardMultisigFederation(
FederationTestUtils.getFederationMembersWithBtcKeys(federation1Keys),
Instant.ofEpochMilli(1000L),
0L,
Expand All @@ -983,7 +983,7 @@ void registerBtcTransactionLockTxNotWhitelisted_before_rskip_146_activation() th
BtcECKey.fromPrivate(Hex.decode("fb02")),
BtcECKey.fromPrivate(Hex.decode("fb03")));

Federation federation2 = new Federation(
Federation federation2 = new StandardMultisigFederation(
FederationTestUtils.getFederationMembersWithBtcKeys(federation2Keys),
Instant.ofEpochMilli(2000L),
0L,
Expand Down Expand Up @@ -1140,7 +1140,7 @@ void registerBtcTransactionLockTxNotWhitelisted_after_rskip_146_activation() thr
BtcECKey.fromPrivate(Hex.decode("fa02"))
);

Federation federation1 = new Federation(
Federation federation1 = new StandardMultisigFederation(
FederationTestUtils.getFederationMembersWithBtcKeys(federation1Keys),
Instant.ofEpochMilli(1000L),
0L,
Expand All @@ -1153,7 +1153,7 @@ void registerBtcTransactionLockTxNotWhitelisted_after_rskip_146_activation() thr
BtcECKey.fromPrivate(Hex.decode("fb02")),
BtcECKey.fromPrivate(Hex.decode("fb03")));

Federation federation2 = new Federation(
Federation federation2 = new StandardMultisigFederation(
FederationTestUtils.getFederationMembersWithBtcKeys(federation2Keys),
Instant.ofEpochMilli(2000L),
0L,
Expand Down Expand Up @@ -1324,7 +1324,7 @@ void registerBtcTransaction_sending_segwit_tx_twice_locks_just_once() throws Blo
BtcECKey.fromPrivate(Hex.decode("fa02"))
);

Federation fed = new Federation(
Federation fed = new StandardMultisigFederation(
FederationTestUtils.getFederationMembersWithBtcKeys(fedKeys),
Instant.ofEpochMilli(1000L),
0L,
Expand Down Expand Up @@ -1416,7 +1416,7 @@ void callProcessFundsMigration_is_migrating_before_rskip_146_activation() throws

Federation oldFederation = bridgeConstantsRegtest.getGenesisFederation();

Federation newFederation = new Federation(
Federation newFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembers(1),
Instant.EPOCH,
5L,
Expand Down Expand Up @@ -1479,7 +1479,7 @@ void callProcessFundsMigration_is_migrating_after_rskip_146_activation() throws

Federation oldFederation = bridgeConstantsRegtest.getGenesisFederation();

Federation newFederation = new Federation(
Federation newFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembers(1),
Instant.EPOCH,
5L,
Expand Down Expand Up @@ -1544,7 +1544,7 @@ void callProcessFundsMigration_is_migrated_before_rskip_146_activation() throws

Federation oldFederation = bridgeConstantsRegtest.getGenesisFederation();

Federation newFederation = new Federation(
Federation newFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembers(1),
Instant.EPOCH,
5L,
Expand Down Expand Up @@ -1607,7 +1607,7 @@ void callProcessFundsMigration_is_migrated_after_rskip_146_activation() throws I

Federation oldFederation = bridgeConstantsRegtest.getGenesisFederation();

Federation newFederation = new Federation(
Federation newFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembers(1),
Instant.EPOCH,
5L,
Expand Down Expand Up @@ -1671,7 +1671,7 @@ void updateFederationCreationBlockHeights_before_rskip_186_activation() throws I

Federation oldFederation = bridgeConstantsRegtest.getGenesisFederation();

Federation newFederation = new Federation(
Federation newFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembers(1),
Instant.EPOCH,
5L,
Expand Down Expand Up @@ -1734,7 +1734,7 @@ void updateFederationCreationBlockHeights_after_rskip_186_activation() throws IO

Federation oldFederation = bridgeConstantsRegtest.getGenesisFederation();

Federation newFederation = new Federation(
Federation newFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembers(1),
Instant.EPOCH,
5L,
Expand Down Expand Up @@ -2115,7 +2115,7 @@ void rskTxWaitingForSignature_fail_adding_an_already_existing_key_after_rskip_37

// Set state to make concur a pegout migration tx and pegout batch creation on the same updateCollection
Federation oldFederation = bridgeConstants.getGenesisFederation();
Federation newFederation = new Federation(
Federation newFederation = new StandardMultisigFederation(
FederationTestUtils.getFederationMembers(1),
Instant.EPOCH,
5L,
Expand Down Expand Up @@ -6410,13 +6410,13 @@ private void test_migrating_many_utxos(boolean isRskip294Active, int utxosToCrea
oldFedMembers.add(FederationMember.getFederationMemberFromKey(new BtcECKey()));
}

Federation oldFed = new Federation(
Federation oldFed = new StandardMultisigFederation(
oldFedMembers,
Instant.now(),
0,
btcRegTestParams
);
Federation newFed = new Federation(
Federation newFed = new StandardMultisigFederation(
Arrays.asList(
FederationMember.getFederationMemberFromKey(new BtcECKey()),
FederationMember.getFederationMemberFromKey(new BtcECKey()),
Expand Down
Loading

0 comments on commit d32cd4f

Please sign in to comment.