diff --git a/rskj-core/src/main/java/co/rsk/peg/Bridge.java b/rskj-core/src/main/java/co/rsk/peg/Bridge.java index 0e2d73266a5..f5671f66edd 100644 --- a/rskj-core/src/main/java/co/rsk/peg/Bridge.java +++ b/rskj-core/src/main/java/co/rsk/peg/Bridge.java @@ -22,7 +22,7 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.store.BlockStoreException; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.panic.PanicProcessor; diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeSerializationUtils.java b/rskj-core/src/main/java/co/rsk/peg/BridgeSerializationUtils.java index e055c9b84af..8a3a7d8ccfb 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSerializationUtils.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSerializationUtils.java @@ -20,7 +20,7 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.script.Script; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.peg.vote.ABICallElection; diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeState.java b/rskj-core/src/main/java/co/rsk/peg/BridgeState.java index 355d9b34435..0fd1c089e74 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeState.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeState.java @@ -20,7 +20,7 @@ import co.rsk.bitcoinj.core.BtcTransaction; import co.rsk.bitcoinj.core.UTXO; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.crypto.Keccak256; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ConsensusRule; diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java b/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java index 2962e83ece8..7a66814ac4a 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java @@ -20,7 +20,7 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.script.Script; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.peg.vote.ABICallElection; diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java index cee4baf5ca6..6334164c704 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java @@ -28,7 +28,7 @@ import co.rsk.bitcoinj.store.BlockStoreException; import co.rsk.bitcoinj.wallet.SendRequest; import co.rsk.bitcoinj.wallet.Wallet; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.panic.PanicProcessor; @@ -788,11 +788,12 @@ private void saveNewUTXOs(BtcTransaction btcTx) throws IOException { * @throws IOException */ public void releaseBtc(Transaction rskTx) throws IOException { - Coin pegoutValue = rskTx.getValue().toBitcoin(); + final co.rsk.core.Coin pegoutValueInWeis = rskTx.getValue(); + final Coin pegoutValueInSatoshis = pegoutValueInWeis.toBitcoin(); final RskAddress senderAddress = rskTx.getSender(signatureCache); logger.debug( - "[releaseBtc] Releasing {} RBTC from RSK address {} in tx {}", - pegoutValue, + "[releaseBtc] Releasing {} weis from RSK address {} in tx {}", + pegoutValueInWeis, senderAddress, rskTx.getHash() ); @@ -804,7 +805,7 @@ public void releaseBtc(Transaction rskTx) throws IOException { senderAddress ); if (activations.isActive(ConsensusRule.RSKIP185)) { - emitRejectEvent(pegoutValue, senderAddress, RejectedPegoutReason.CALLER_CONTRACT); + emitRejectEvent(pegoutValueInSatoshis, senderAddress, RejectedPegoutReason.CALLER_CONTRACT); return; } else { String message = "Contract calling releaseBTC"; @@ -818,7 +819,7 @@ public void releaseBtc(Transaction rskTx) throws IOException { Address btcDestinationAddress = BridgeUtils.recoverBtcAddressFromEthTransaction(rskTx, btcParams); logger.debug("[releaseBtc] BTC destination address: {}", btcDestinationAddress); - requestRelease(btcDestinationAddress, pegoutValue, rskTx); + requestRelease(btcDestinationAddress, pegoutValueInSatoshis, rskTx); } private void refundAndEmitRejectEvent(Coin value, RskAddress senderAddress, RejectedPegoutReason reason) { @@ -868,7 +869,7 @@ private void requestRelease(Address destinationAddress, Coin value, Transaction ); // add the gap // The pegout value should be greater or equals than the max of these two values - Coin minValue = Coin.valueOf(Math.max(bridgeConstants.getMinimumPegoutTxValueInSatoshis().value, requireFundsForFee.value)); + Coin minValue = Coin.valueOf(Math.max(bridgeConstants.getMinimumPegoutTxValue().value, requireFundsForFee.value)); // Since Iris the peg-out the rule is that the minimum is inclusive if (value.isLessThan(minValue)) { @@ -880,7 +881,7 @@ private void requestRelease(Address destinationAddress, Coin value, Transaction } } else { // For legacy peg-outs the rule stated that the minimum was exclusive - if (!value.isGreaterThan(bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis())) { + if (!value.isGreaterThan(bridgeConstants.getLegacyMinimumPegoutTxValue())) { optionalRejectedPegoutReason = Optional.of(RejectedPegoutReason.LOW_AMOUNT); } } diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeSupportFactory.java b/rskj-core/src/main/java/co/rsk/peg/BridgeSupportFactory.java index 4c68f041258..eedfb287b49 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSupportFactory.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSupportFactory.java @@ -18,7 +18,7 @@ package co.rsk.peg; import co.rsk.bitcoinj.core.Context; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.core.RskAddress; import co.rsk.peg.BtcBlockStoreWithCache.Factory; import co.rsk.peg.btcLockSender.BtcLockSenderProvider; diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeUtils.java b/rskj-core/src/main/java/co/rsk/peg/BridgeUtils.java index acd39675783..89979f5c14f 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeUtils.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeUtils.java @@ -25,7 +25,7 @@ import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptChunk; import co.rsk.bitcoinj.wallet.Wallet; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.core.RskAddress; import co.rsk.peg.bitcoin.RskAllowUnconfirmedCoinSelector; import co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType; @@ -38,14 +38,17 @@ import org.ethereum.config.blockchain.upgrades.ConsensusRule; import org.ethereum.core.SignatureCache; import org.ethereum.core.Transaction; +import org.ethereum.crypto.ECKey; import org.ethereum.util.ByteUtil; import org.ethereum.vm.PrecompiledContracts; +import org.ethereum.vm.program.InternalTransaction; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -56,11 +59,12 @@ /** * @author Oscar Guindzberg */ -public class BridgeUtils { +public final class BridgeUtils { private static final Logger logger = LoggerFactory.getLogger(BridgeUtils.class); - private BridgeUtils() {} + private BridgeUtils() { + } public static Wallet getFederationNoSpendWallet( Context btcContext, @@ -153,7 +157,7 @@ public static Coin getAmountSentToAddresses( if (addresses == null || addresses.isEmpty()){ return Coin.ZERO; } - if (activations.isActive(ConsensusRule.RSKIP293)){ + if (activations.isActive(RSKIP293)){ return getAmountSentToAddresses( context, btcTx, @@ -252,7 +256,7 @@ public static List<UTXO> getUTXOsSentToAddresses( List<Address> addresses ) { - if (activations.isActive(ConsensusRule.RSKIP293)){ + if (activations.isActive(RSKIP293)){ return getUTXOsSentToAddresses(context, btcTx, addresses); } else { return BridgeUtilsLegacy.getUTXOsSentToAddress( @@ -379,8 +383,8 @@ public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btc return true; } - public static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters) { - org.ethereum.crypto.ECKey key = tx.getKey(); + public static Address recoverBtcAddressFromEthTransaction(Transaction tx, NetworkParameters networkParameters) { + ECKey key = tx.getKey(); byte[] pubKey = key.getPubKey(true); return BtcECKey.fromPublicOnly(pubKey).toAddress(networkParameters); } @@ -392,6 +396,7 @@ public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, Act } BridgeConstants bridgeConstants = constants.getBridgeConstants(); + RskAddress senderAddress = rskTx.getSender(signatureCache); // Temporary assumption: if areBridgeTxsFree() is true then the current federation // must be the genesis federation. @@ -400,7 +405,7 @@ public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, Act !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( - isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation(), signatureCache) || + isFromGenesisFederation(senderAddress, bridgeConstants.getGenesisFederationPublicKeys()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants, signatureCache) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants, signatureCache) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants, signatureCache) @@ -414,13 +419,28 @@ public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, Act */ public static boolean isContractTx(Transaction rskTx) { // Calls between contracts are done through internal transactions - return rskTx.getClass() == org.ethereum.vm.program.InternalTransaction.class; + return rskTx.getClass() == InternalTransaction.class; } - public static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation, SignatureCache signatureCache) { + public static boolean isFromFederateMember(Transaction rskTx, Federation federation, SignatureCache signatureCache) { return federation.hasMemberWithRskAddress(rskTx.getSender(signatureCache).getBytes()); } + /** + * Method that verify if an RskAddress is part of the Genesis Federation + * + * @param rskAddress RskAddress to find in Genesis Federation + * @param genesisFederationPublicKeys List of BtcECKey part of Genesis Federation + * @return boolean + */ + private static boolean isFromGenesisFederation(RskAddress rskAddress, List<BtcECKey> genesisFederationPublicKeys) { + return genesisFederationPublicKeys.stream().anyMatch(genesisBtcPublicKey -> { + ECKey genesisEcKey = ECKey.fromPublicOnly(genesisBtcPublicKey.getPubKey()); + return Arrays.equals(genesisEcKey.getAddress(), rskAddress.getBytes()); + } + ); + } + public static Coin getCoinFromBigInteger(BigInteger value) throws BridgeIllegalArgumentException { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); @@ -432,17 +452,17 @@ public static Coin getCoinFromBigInteger(BigInteger value) throws BridgeIllegalA } } - private static boolean isFromFederationChangeAuthorizedSender(org.ethereum.core.Transaction rskTx, BridgeConstants bridgeConfiguration, SignatureCache signatureCache) { + private static boolean isFromFederationChangeAuthorizedSender(Transaction rskTx, BridgeConstants bridgeConfiguration, SignatureCache signatureCache) { AddressBasedAuthorizer authorizer = bridgeConfiguration.getFederationChangeAuthorizer(); return authorizer.isAuthorized(rskTx, signatureCache); } - private static boolean isFromLockWhitelistChangeAuthorizedSender(org.ethereum.core.Transaction rskTx, BridgeConstants bridgeConfiguration, SignatureCache signatureCache) { + private static boolean isFromLockWhitelistChangeAuthorizedSender(Transaction rskTx, BridgeConstants bridgeConfiguration, SignatureCache signatureCache) { AddressBasedAuthorizer authorizer = bridgeConfiguration.getLockWhitelistChangeAuthorizer(); return authorizer.isAuthorized(rskTx, signatureCache); } - private static boolean isFromFeePerKbChangeAuthorizedSender(org.ethereum.core.Transaction rskTx, BridgeConstants bridgeConfiguration, SignatureCache signatureCache) { + private static boolean isFromFeePerKbChangeAuthorizedSender(Transaction rskTx, BridgeConstants bridgeConfiguration, SignatureCache signatureCache) { AddressBasedAuthorizer authorizer = bridgeConfiguration.getFeePerKbChangeAuthorizer(); return authorizer.isAuthorized(rskTx, signatureCache); } @@ -541,7 +561,7 @@ public static Address deserializeBtcAddressWithVersion( ActivationConfig.ForBlock activations, byte[] addressBytes) throws BridgeIllegalArgumentException { - if (!activations.isActive(ConsensusRule.RSKIP284)) { + if (!activations.isActive(RSKIP284)) { return BridgeUtilsLegacy.deserializeBtcAddressWithVersionLegacy(networkParameters, activations, addressBytes); } diff --git a/rskj-core/src/main/java/co/rsk/peg/BtcBlockStoreWithCache.java b/rskj-core/src/main/java/co/rsk/peg/BtcBlockStoreWithCache.java index bb65d4ca910..7d6f543433b 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BtcBlockStoreWithCache.java +++ b/rskj-core/src/main/java/co/rsk/peg/BtcBlockStoreWithCache.java @@ -22,7 +22,7 @@ import co.rsk.bitcoinj.core.StoredBlock; import co.rsk.bitcoinj.store.BlockStoreException; import co.rsk.bitcoinj.store.BtcBlockStore; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import org.ethereum.config.blockchain.upgrades.ActivationConfig.ForBlock; import org.ethereum.core.Repository; diff --git a/rskj-core/src/main/java/co/rsk/peg/FederationSupport.java b/rskj-core/src/main/java/co/rsk/peg/FederationSupport.java index 0aa9ed223a0..aa249e52670 100644 --- a/rskj-core/src/main/java/co/rsk/peg/FederationSupport.java +++ b/rskj-core/src/main/java/co/rsk/peg/FederationSupport.java @@ -19,14 +19,17 @@ import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.UTXO; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationArgs; +import co.rsk.peg.federation.FederationFactory; import co.rsk.peg.federation.FederationMember; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.core.Block; import javax.annotation.Nullable; import java.io.IOException; +import java.time.Instant; import java.util.Collections; import java.util.List; @@ -110,7 +113,7 @@ public Federation getActiveFederation() { return provider.getOldFederation(); case GENESIS: default: - return bridgeConstants.getGenesisFederation(); + return this.getGenesisFederation(); } } @@ -233,4 +236,18 @@ private boolean shouldFederationBeActive(Federation federation) { long federationAge = executionBlock.getNumber() - federation.getCreationBlockNumber(); return federationAge >= bridgeConstants.getFederationActivationAge(activations); } + + /** + * Get the Genesis Federation from a List of Genesis Federation Public Keys + * + * @return Federation + */ + private Federation getGenesisFederation() { + final long GENESIS_FEDERATION_CREATION_BLOCK_NUMBER = 1L; + final List<BtcECKey> genesisFederationPublicKeys = bridgeConstants.getGenesisFederationPublicKeys(); + final List<FederationMember> federationMembers = FederationMember.getFederationMembersFromKeys(genesisFederationPublicKeys); + final Instant genesisFederationCreationTime = bridgeConstants.getGenesisFederationCreationTime(); + final FederationArgs federationArgs = new FederationArgs(federationMembers, genesisFederationCreationTime, GENESIS_FEDERATION_CREATION_BLOCK_NUMBER, bridgeConstants.getBtcParams()); + return FederationFactory.buildStandardMultiSigFederation(federationArgs); + } } diff --git a/rskj-core/src/main/java/co/rsk/peg/PegUtils.java b/rskj-core/src/main/java/co/rsk/peg/PegUtils.java index c93df550fbe..cd815cd9a24 100644 --- a/rskj-core/src/main/java/co/rsk/peg/PegUtils.java +++ b/rskj-core/src/main/java/co/rsk/peg/PegUtils.java @@ -13,7 +13,7 @@ import co.rsk.bitcoinj.core.TransactionOutput; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.wallet.Wallet; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.peg.bitcoin.BitcoinUtils; import co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType; import co.rsk.peg.federation.Federation; diff --git a/rskj-core/src/main/java/co/rsk/peg/PegUtilsLegacy.java b/rskj-core/src/main/java/co/rsk/peg/PegUtilsLegacy.java index 7e1af3bbe7f..f57e070ae87 100644 --- a/rskj-core/src/main/java/co/rsk/peg/PegUtilsLegacy.java +++ b/rskj-core/src/main/java/co/rsk/peg/PegUtilsLegacy.java @@ -14,7 +14,7 @@ import co.rsk.bitcoinj.script.ScriptChunk; import co.rsk.bitcoinj.script.ScriptOpCodes; import co.rsk.bitcoinj.wallet.Wallet; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.peg.bitcoin.BitcoinUtils; import java.util.ArrayList; import java.util.Arrays; diff --git a/rskj-core/src/main/java/co/rsk/peg/RepositoryBtcBlockStoreWithCache.java b/rskj-core/src/main/java/co/rsk/peg/RepositoryBtcBlockStoreWithCache.java index 5ed834a4206..04db27e4e70 100644 --- a/rskj-core/src/main/java/co/rsk/peg/RepositoryBtcBlockStoreWithCache.java +++ b/rskj-core/src/main/java/co/rsk/peg/RepositoryBtcBlockStoreWithCache.java @@ -23,7 +23,7 @@ import co.rsk.bitcoinj.core.Sha256Hash; import co.rsk.bitcoinj.core.StoredBlock; import co.rsk.bitcoinj.store.BlockStoreException; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.core.RskAddress; import co.rsk.util.MaxSizeHashMap; import java.util.Optional; diff --git a/rskj-core/src/main/java/co/rsk/config/BridgeConstants.java b/rskj-core/src/main/java/co/rsk/peg/constants/BridgeConstants.java similarity index 91% rename from rskj-core/src/main/java/co/rsk/config/BridgeConstants.java rename to rskj-core/src/main/java/co/rsk/peg/constants/BridgeConstants.java index 554c6dbd268..579890fac06 100644 --- a/rskj-core/src/main/java/co/rsk/config/BridgeConstants.java +++ b/rskj-core/src/main/java/co/rsk/peg/constants/BridgeConstants.java @@ -16,23 +16,23 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package co.rsk.config; +package co.rsk.peg.constants; import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.Coin; import co.rsk.bitcoinj.core.NetworkParameters; import co.rsk.peg.vote.AddressBasedAuthorizer; -import co.rsk.peg.federation.Federation; import java.util.List; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ConsensusRule; +import java.time.Instant; + public abstract class BridgeConstants { protected String btcParamsString; - - protected Federation genesisFederation; - + protected List<BtcECKey> genesisFederationPublicKeys; + protected Instant genesisFederationCreationTime; protected int btc2RskMinimumAcceptableConfirmations; protected int btc2RskMinimumAcceptableConfirmationsOnRsk; protected int rsk2BtcMinimumAcceptableConfirmations; @@ -43,8 +43,8 @@ public abstract class BridgeConstants { protected Coin legacyMinimumPeginTxValue; protected Coin minimumPeginTxValue; - protected Coin legacyMinimumPegoutTxValueInSatoshis; - protected Coin minimumPegoutTxValueInSatoshis; + protected Coin legacyMinimumPegoutTxValue; + protected Coin minimumPegoutTxValue; protected long federationActivationAge; protected long federationActivationAgeLegacy; @@ -60,7 +60,6 @@ public abstract class BridgeConstants { protected AddressBasedAuthorizer feePerKbChangeAuthorizer; protected Coin genesisFeePerKb; - protected Coin maxFeePerKb; protected AddressBasedAuthorizer increaseLockingCapAuthorizer; @@ -76,7 +75,6 @@ public abstract class BridgeConstants { protected int maxDepthBlockchainAccepted; protected long erpFedActivationDelay; - protected List<BtcECKey> erpFedPubKeysList; protected String oldFederationAddress; @@ -98,7 +96,13 @@ public String getBtcParamsString() { return btcParamsString; } - public Federation getGenesisFederation() { return genesisFederation; } + public List<BtcECKey> getGenesisFederationPublicKeys() { + return genesisFederationPublicKeys; + } + + public Instant getGenesisFederationCreationTime() { + return genesisFederationCreationTime; + } public int getBtc2RskMinimumAcceptableConfirmations() { return btc2RskMinimumAcceptableConfirmations; @@ -120,9 +124,9 @@ public Coin getMinimumPeginTxValue(ActivationConfig.ForBlock activations) { return activations.isActive(ConsensusRule.RSKIP219) ? minimumPeginTxValue : legacyMinimumPeginTxValue; } - public Coin getLegacyMinimumPegoutTxValueInSatoshis() { return legacyMinimumPegoutTxValueInSatoshis; } + public Coin getLegacyMinimumPegoutTxValue() { return legacyMinimumPegoutTxValue; } - public Coin getMinimumPegoutTxValueInSatoshis() { return minimumPegoutTxValueInSatoshis; } + public Coin getMinimumPegoutTxValue() { return minimumPegoutTxValue; } public long getFederationActivationAge(ActivationConfig.ForBlock activations) { return activations.isActive(ConsensusRule.RSKIP383)? federationActivationAge: federationActivationAgeLegacy; diff --git a/rskj-core/src/main/java/co/rsk/config/BridgeDevNetConstants.java b/rskj-core/src/main/java/co/rsk/peg/constants/BridgeDevNetConstants.java similarity index 88% rename from rskj-core/src/main/java/co/rsk/config/BridgeDevNetConstants.java rename to rskj-core/src/main/java/co/rsk/peg/constants/BridgeDevNetConstants.java index f5843e8cded..34ef167cf1f 100644 --- a/rskj-core/src/main/java/co/rsk/config/BridgeDevNetConstants.java +++ b/rskj-core/src/main/java/co/rsk/peg/constants/BridgeDevNetConstants.java @@ -16,17 +16,15 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package co.rsk.config; +package co.rsk.peg.constants; import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.Coin; import co.rsk.bitcoinj.core.NetworkParameters; import co.rsk.peg.vote.AddressBasedAuthorizer; -import co.rsk.peg.federation.FederationArgs; -import co.rsk.peg.federation.FederationMember; -import co.rsk.peg.federation.FederationFactory; -import java.time.Instant; +import java.time.ZonedDateTime; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import org.bouncycastle.util.encoders.Hex; @@ -35,7 +33,7 @@ public class BridgeDevNetConstants extends BridgeConstants { // IMPORTANT: BTC, RSK and MST keys are the same. // Change upon implementation of the <INSERT FORK NAME HERE> fork. - public static final List<BtcECKey> DEVNET_FEDERATION_PUBLIC_KEYS = Arrays.asList( + public static final List<BtcECKey> DEVNET_FEDERATION_PUBLIC_KEYS = Collections.unmodifiableList(Arrays.asList( BtcECKey.fromPublicOnly( Hex.decode("03d68975ab0f6ab782febc37aaa486ae19cc5e72c6900e34e21317285c88915ed6") ), @@ -45,21 +43,14 @@ public class BridgeDevNetConstants extends BridgeConstants { BtcECKey.fromPublicOnly( Hex.decode("0309d9df35855aa45235a04e30d228889eb03e462874588e631359d5f9cdea6519") ) - ); + )); + private static final BridgeDevNetConstants instance = new BridgeDevNetConstants(DEVNET_FEDERATION_PUBLIC_KEYS); public BridgeDevNetConstants(List<BtcECKey> federationPublicKeys) { btcParamsString = NetworkParameters.ID_TESTNET; - List<FederationMember> federationMembers = FederationMember.getFederationMembersFromKeys(federationPublicKeys); - - // Currently set to: - // Monday, November 13, 2017 9:00:00 PM GMT-03:00 - Instant genesisFederationAddressCreatedAt = Instant.ofEpochMilli(1510617600l); - - // Expected federation address is: - // 2NCEo1RdmGDj6MqiipD6DUSerSxKv79FNWX - FederationArgs federationArgs = new FederationArgs(federationMembers, genesisFederationAddressCreatedAt, 1L, getBtcParams()); - genesisFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs); + genesisFederationPublicKeys = federationPublicKeys; + genesisFederationCreationTime = ZonedDateTime.parse("1970-01-18T11:36:57.600Z").toInstant(); btc2RskMinimumAcceptableConfirmations = 1; btc2RskMinimumAcceptableConfirmationsOnRsk = 10; @@ -70,9 +61,9 @@ public BridgeDevNetConstants(List<BtcECKey> federationPublicKeys) { maxBtcHeadersPerRskBlock = 500; legacyMinimumPeginTxValue = Coin.valueOf(1_000_000); - legacyMinimumPegoutTxValueInSatoshis = Coin.valueOf(500_000); + legacyMinimumPegoutTxValue = Coin.valueOf(500_000); minimumPeginTxValue = Coin.valueOf(500_000); - minimumPegoutTxValueInSatoshis = Coin.valueOf(250_000); + minimumPegoutTxValue = Coin.valueOf(250_000); // Keys generated with GenNodeKey using generators 'auth-a' through 'auth-e' List<ECKey> federationChangeAuthorizedKeys = Arrays.stream(new String[]{ @@ -118,7 +109,6 @@ public BridgeDevNetConstants(List<BtcECKey> federationPublicKeys) { ); genesisFeePerKb = Coin.MILLICOIN; - maxFeePerKb = Coin.valueOf(5_000_000L); // Key generated with GenNodeKey using generator 'auth-increase_locking_cap' @@ -168,4 +158,7 @@ public BridgeDevNetConstants(List<BtcECKey> federationPublicKeys) { btcHeightWhenPegoutTxIndexActivates = 1_000_000; pegoutTxIndexGracePeriodInBtcBlocks = 4_320; // 30 days in BTC blocks (considering 1 block every 10 minutes) } + public static BridgeDevNetConstants getInstance() { + return instance; + } } diff --git a/rskj-core/src/main/java/co/rsk/config/BridgeMainNetConstants.java b/rskj-core/src/main/java/co/rsk/peg/constants/BridgeMainNetConstants.java similarity index 88% rename from rskj-core/src/main/java/co/rsk/config/BridgeMainNetConstants.java rename to rskj-core/src/main/java/co/rsk/peg/constants/BridgeMainNetConstants.java index c8e90640141..23a929ca823 100644 --- a/rskj-core/src/main/java/co/rsk/config/BridgeMainNetConstants.java +++ b/rskj-core/src/main/java/co/rsk/peg/constants/BridgeMainNetConstants.java @@ -1,14 +1,11 @@ -package co.rsk.config; +package co.rsk.peg.constants; import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.Coin; import co.rsk.bitcoinj.core.NetworkParameters; import co.rsk.peg.vote.AddressBasedAuthorizer; -import co.rsk.peg.federation.FederationArgs; -import co.rsk.peg.federation.FederationMember; -import co.rsk.peg.federation.FederationFactory; import com.google.common.collect.Lists; -import java.time.Instant; +import java.time.ZonedDateTime; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -37,24 +34,14 @@ public class BridgeMainNetConstants extends BridgeConstants { BtcECKey federator13PublicKey = BtcECKey.fromPublicOnly(Hex.decode("02c6018fcbd3e89f3cf9c7f48b3232ea3638eb8bf217e59ee290f5f0cfb2fb9259")); BtcECKey federator14PublicKey = BtcECKey.fromPublicOnly(Hex.decode("03b65694ccccda83cbb1e56b31308acd08e993114c33f66a456b627c2c1c68bed6")); - List<BtcECKey> genesisFederationPublicKeys = Lists.newArrayList( + genesisFederationPublicKeys = Lists.newArrayList( federator0PublicKey, federator1PublicKey, federator2PublicKey, federator3PublicKey, federator4PublicKey, federator5PublicKey, federator6PublicKey, federator7PublicKey, federator8PublicKey, federator9PublicKey, federator10PublicKey, federator11PublicKey, federator12PublicKey, federator13PublicKey, federator14PublicKey ); - - // IMPORTANT: BTC, RSK and MST keys are the same. - // Change upon implementation of the <INSERT FORK NAME HERE> fork. - List<FederationMember> federationMembers = FederationMember.getFederationMembersFromKeys(genesisFederationPublicKeys); - - // Currently set to: - // Wednesday, January 3, 2018 12:00:00 AM GMT-03:00 - Instant genesisFederationAddressCreatedAt = Instant.ofEpochMilli(1514948400L); - - FederationArgs federationArgs = new FederationArgs(federationMembers, genesisFederationAddressCreatedAt, 1L, getBtcParams()); - genesisFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs); + genesisFederationCreationTime = ZonedDateTime.parse("1970-01-18T12:49:08.400Z").toInstant(); btc2RskMinimumAcceptableConfirmations = 100; btc2RskMinimumAcceptableConfirmationsOnRsk = 1000; @@ -65,9 +52,9 @@ public class BridgeMainNetConstants extends BridgeConstants { maxBtcHeadersPerRskBlock = 500; legacyMinimumPeginTxValue = Coin.valueOf(1_000_000); - legacyMinimumPegoutTxValueInSatoshis = Coin.valueOf(800_000); + legacyMinimumPegoutTxValue = Coin.valueOf(800_000); minimumPeginTxValue = Coin.valueOf(500_000); - minimumPegoutTxValueInSatoshis = Coin.valueOf(400_000); + minimumPegoutTxValue = Coin.valueOf(400_000); List<ECKey> federationChangeAuthorizedKeys = Arrays.stream(new String[]{ "04e593d4cde25137b13f19462bc4c02e97ba2ed5a3860813497abf9b4eeb9259e37e0384d12cfd2d9a7a0ba606b31ee34317a9d7f4a8591c6bcf5dfd5563248b2f", @@ -108,7 +95,6 @@ public class BridgeMainNetConstants extends BridgeConstants { ); genesisFeePerKb = Coin.MILLICOIN.multiply(5); - maxFeePerKb = Coin.valueOf(5_000_000L); List<ECKey> increaseLockingCapAuthorizedKeys = Arrays.stream(new String[]{ diff --git a/rskj-core/src/main/java/co/rsk/config/BridgeRegTestConstants.java b/rskj-core/src/main/java/co/rsk/peg/constants/BridgeRegTestConstants.java similarity index 89% rename from rskj-core/src/main/java/co/rsk/config/BridgeRegTestConstants.java rename to rskj-core/src/main/java/co/rsk/peg/constants/BridgeRegTestConstants.java index 43edf91c11f..489450bf6cb 100644 --- a/rskj-core/src/main/java/co/rsk/config/BridgeRegTestConstants.java +++ b/rskj-core/src/main/java/co/rsk/peg/constants/BridgeRegTestConstants.java @@ -16,19 +16,16 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package co.rsk.config; +package co.rsk.peg.constants; import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.Coin; import co.rsk.bitcoinj.core.NetworkParameters; import co.rsk.peg.vote.AddressBasedAuthorizer; -import co.rsk.peg.federation.FederationArgs; -import co.rsk.peg.federation.FederationMember; -import co.rsk.peg.federation.FederationFactory; import java.nio.charset.StandardCharsets; -import java.time.Instant; import java.time.ZonedDateTime; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import org.bouncycastle.util.encoders.Hex; @@ -38,26 +35,22 @@ public class BridgeRegTestConstants extends BridgeConstants { // IMPORTANT: BTC, RSK and MST keys are the same. // Change upon implementation of the <INSERT FORK NAME HERE> fork. - public static final List<BtcECKey> REGTEST_FEDERATION_PRIVATE_KEYS = Arrays.asList( + public static final List<BtcECKey> REGTEST_FEDERATION_PRIVATE_KEYS = Collections.unmodifiableList(Arrays.asList( BtcECKey.fromPrivate(HashUtil.keccak256("federator1".getBytes(StandardCharsets.UTF_8))), BtcECKey.fromPrivate(HashUtil.keccak256("federator2".getBytes(StandardCharsets.UTF_8))), BtcECKey.fromPrivate(HashUtil.keccak256("federator3".getBytes(StandardCharsets.UTF_8))) - ); - public static final List<BtcECKey> REGTEST_FEDERATION_PUBLIC_KEYS = REGTEST_FEDERATION_PRIVATE_KEYS.stream() + )); + public static final List<BtcECKey> REGTEST_FEDERATION_PUBLIC_KEYS = Collections.unmodifiableList(REGTEST_FEDERATION_PRIVATE_KEYS.stream() .map(key -> BtcECKey.fromPublicOnly(key.getPubKey())) - .collect(Collectors.toList()); + .collect(Collectors.toList())); private static final BridgeRegTestConstants instance = new BridgeRegTestConstants(REGTEST_FEDERATION_PUBLIC_KEYS); public BridgeRegTestConstants(List<BtcECKey> federationPublicKeys) { btcParamsString = NetworkParameters.ID_REGTEST; - List<FederationMember> federationMembers = FederationMember.getFederationMembersFromKeys(federationPublicKeys); - - Instant genesisFederationCreatedAt = ZonedDateTime.parse("2016-01-01T00:00:00Z").toInstant(); - - FederationArgs federationArgs = new FederationArgs(federationMembers, genesisFederationCreatedAt, 1L, getBtcParams()); - genesisFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs); + genesisFederationPublicKeys = federationPublicKeys; + genesisFederationCreationTime = ZonedDateTime.parse("2016-01-01T00:00:00Z").toInstant(); btc2RskMinimumAcceptableConfirmations = 3; btc2RskMinimumAcceptableConfirmationsOnRsk = 5; @@ -68,9 +61,9 @@ public BridgeRegTestConstants(List<BtcECKey> federationPublicKeys) { maxBtcHeadersPerRskBlock = 500; legacyMinimumPeginTxValue = Coin.COIN; - legacyMinimumPegoutTxValueInSatoshis = Coin.valueOf(500_000); + legacyMinimumPegoutTxValue = Coin.valueOf(500_000); minimumPeginTxValue = Coin.COIN.div(2); - minimumPegoutTxValueInSatoshis = Coin.valueOf(250_000); + minimumPegoutTxValue = Coin.valueOf(250_000); // Keys generated with GenNodeKey using generators 'auth-a' through 'auth-e' List<ECKey> federationChangeAuthorizedKeys = Arrays.stream(new String[]{ diff --git a/rskj-core/src/main/java/co/rsk/config/BridgeTestNetConstants.java b/rskj-core/src/main/java/co/rsk/peg/constants/BridgeTestNetConstants.java similarity index 87% rename from rskj-core/src/main/java/co/rsk/config/BridgeTestNetConstants.java rename to rskj-core/src/main/java/co/rsk/peg/constants/BridgeTestNetConstants.java index 86447a5cebf..9c66118bcca 100644 --- a/rskj-core/src/main/java/co/rsk/config/BridgeTestNetConstants.java +++ b/rskj-core/src/main/java/co/rsk/peg/constants/BridgeTestNetConstants.java @@ -16,16 +16,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package co.rsk.config; +package co.rsk.peg.constants; import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.Coin; import co.rsk.bitcoinj.core.NetworkParameters; import co.rsk.peg.vote.AddressBasedAuthorizer; -import co.rsk.peg.federation.FederationArgs; -import co.rsk.peg.federation.FederationMember; -import co.rsk.peg.federation.FederationFactory; -import java.time.Instant; +import java.time.ZonedDateTime; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -51,23 +48,14 @@ public class BridgeTestNetConstants extends BridgeConstants { Hex.decode("034844a99cd7028aa319476674cc381df006628be71bc5593b8b5fdb32bb42ef85") ); - List<BtcECKey> genesisFederationPublicKeys = Arrays.asList( + genesisFederationPublicKeys = Arrays.asList( federator0PublicKey, federator1PublicKey, federator2PublicKey, federator3PublicKey ); - // IMPORTANT: BTC, RSK and MST keys are the same. - // Change upon implementation of the <INSERT FORK NAME HERE> fork. - List<FederationMember> federationMembers = FederationMember.getFederationMembersFromKeys(genesisFederationPublicKeys); - - // Currently set to: - // Currently set to: Monday, October 8, 2018 12:00:00 AM GMT-03:00 - Instant genesisFederationAddressCreatedAt = Instant.ofEpochMilli(1538967600l); - - FederationArgs federationArgs = new FederationArgs(federationMembers, genesisFederationAddressCreatedAt, 1L, getBtcParams()); - genesisFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs); + genesisFederationCreationTime = ZonedDateTime.parse("1970-01-18T19:29:27.600Z").toInstant(); btc2RskMinimumAcceptableConfirmations = 10; btc2RskMinimumAcceptableConfirmationsOnRsk = 10; @@ -79,8 +67,8 @@ public class BridgeTestNetConstants extends BridgeConstants { legacyMinimumPeginTxValue = Coin.valueOf(1_000_000); minimumPeginTxValue = Coin.valueOf(500_000); - legacyMinimumPegoutTxValueInSatoshis = Coin.valueOf(500_000); - minimumPegoutTxValueInSatoshis = Coin.valueOf(250_000); + legacyMinimumPegoutTxValue = Coin.valueOf(500_000); + minimumPegoutTxValue = Coin.valueOf(250_000); // Passphrases are kept private List<ECKey> federationChangeAuthorizedKeys = Arrays.stream(new String[]{ @@ -123,7 +111,6 @@ public class BridgeTestNetConstants extends BridgeConstants { ); genesisFeePerKb = Coin.MILLICOIN; - maxFeePerKb = Coin.valueOf(5_000_000L); List<ECKey> increaseLockingCapAuthorizedKeys = Arrays.stream(new String[]{ @@ -173,5 +160,4 @@ public class BridgeTestNetConstants extends BridgeConstants { public static BridgeTestNetConstants getInstance() { return instance; } - } diff --git a/rskj-core/src/main/java/co/rsk/peg/federation/FederationMember.java b/rskj-core/src/main/java/co/rsk/peg/federation/FederationMember.java index 9b57a5fcf2d..bc42ea29c0f 100644 --- a/rskj-core/src/main/java/co/rsk/peg/federation/FederationMember.java +++ b/rskj-core/src/main/java/co/rsk/peg/federation/FederationMember.java @@ -60,7 +60,7 @@ public enum KeyType { RSK("rsk"), MST("mst"); - private String value; + private final String value; KeyType(String value) { this.value = value; diff --git a/rskj-core/src/main/java/co/rsk/peg/federation/PendingFederation.java b/rskj-core/src/main/java/co/rsk/peg/federation/PendingFederation.java index 301ba7010c3..9537312913c 100644 --- a/rskj-core/src/main/java/co/rsk/peg/federation/PendingFederation.java +++ b/rskj-core/src/main/java/co/rsk/peg/federation/PendingFederation.java @@ -20,7 +20,7 @@ import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.crypto.Keccak256; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ConsensusRule; diff --git a/rskj-core/src/main/java/co/rsk/peg/utils/BridgeEventLoggerImpl.java b/rskj-core/src/main/java/co/rsk/peg/utils/BridgeEventLoggerImpl.java index 7ecbd408971..13fce24bff6 100644 --- a/rskj-core/src/main/java/co/rsk/peg/utils/BridgeEventLoggerImpl.java +++ b/rskj-core/src/main/java/co/rsk/peg/utils/BridgeEventLoggerImpl.java @@ -18,7 +18,7 @@ package co.rsk.peg.utils; import co.rsk.bitcoinj.core.*; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.peg.BridgeEvents; diff --git a/rskj-core/src/main/java/co/rsk/peg/utils/BrigeEventLoggerLegacyImpl.java b/rskj-core/src/main/java/co/rsk/peg/utils/BrigeEventLoggerLegacyImpl.java index 1c9e520f53f..71211747f39 100644 --- a/rskj-core/src/main/java/co/rsk/peg/utils/BrigeEventLoggerLegacyImpl.java +++ b/rskj-core/src/main/java/co/rsk/peg/utils/BrigeEventLoggerLegacyImpl.java @@ -19,7 +19,7 @@ package co.rsk.peg.utils; import co.rsk.bitcoinj.core.*; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.peg.Bridge; import co.rsk.peg.DeprecatedMethodCallException; import co.rsk.peg.federation.Federation; diff --git a/rskj-core/src/main/java/co/rsk/remasc/Remasc.java b/rskj-core/src/main/java/co/rsk/remasc/Remasc.java index e59291f21d3..6b35b35eb67 100644 --- a/rskj-core/src/main/java/co/rsk/remasc/Remasc.java +++ b/rskj-core/src/main/java/co/rsk/remasc/Remasc.java @@ -18,7 +18,7 @@ package co.rsk.remasc; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.config.RemascConfig; import co.rsk.core.Coin; import co.rsk.core.RskAddress; diff --git a/rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java b/rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java index e7e0f978b0b..b7857351509 100644 --- a/rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java +++ b/rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java @@ -19,7 +19,7 @@ package co.rsk.rpc.modules.eth; import co.rsk.bitcoinj.store.BlockStoreException; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.core.ReversibleTransactionExecutor; import co.rsk.core.RskAddress; import co.rsk.core.bc.AccountInformationProvider; diff --git a/rskj-core/src/main/java/co/rsk/validators/ProofOfWorkRule.java b/rskj-core/src/main/java/co/rsk/validators/ProofOfWorkRule.java index f3e09465be9..fc8f4c5c5c4 100644 --- a/rskj-core/src/main/java/co/rsk/validators/ProofOfWorkRule.java +++ b/rskj-core/src/main/java/co/rsk/validators/ProofOfWorkRule.java @@ -21,7 +21,7 @@ import co.rsk.bitcoinj.core.BtcBlock; import co.rsk.bitcoinj.core.Sha256Hash; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.config.RskMiningConstants; import co.rsk.config.RskSystemProperties; import co.rsk.util.DifficultyUtils; diff --git a/rskj-core/src/main/java/org/ethereum/config/Constants.java b/rskj-core/src/main/java/org/ethereum/config/Constants.java index dd4fcab9bf3..e1d6da3dd3a 100644 --- a/rskj-core/src/main/java/org/ethereum/config/Constants.java +++ b/rskj-core/src/main/java/org/ethereum/config/Constants.java @@ -20,8 +20,8 @@ package org.ethereum.config; import co.rsk.bitcoinj.core.BtcECKey; -import co.rsk.config.*; import co.rsk.core.BlockDifficulty; +import co.rsk.peg.constants.*; import org.bouncycastle.util.encoders.Hex; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ConsensusRule; diff --git a/rskj-core/src/main/java/org/ethereum/config/SystemProperties.java b/rskj-core/src/main/java/org/ethereum/config/SystemProperties.java index f91d6c30296..cf1e49c79d6 100644 --- a/rskj-core/src/main/java/org/ethereum/config/SystemProperties.java +++ b/rskj-core/src/main/java/org/ethereum/config/SystemProperties.java @@ -20,8 +20,8 @@ package org.ethereum.config; import co.rsk.bitcoinj.core.BtcECKey; -import co.rsk.config.BridgeDevNetConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeDevNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.config.ConfigLoader; import com.typesafe.config.Config; import com.typesafe.config.ConfigObject; diff --git a/rskj-core/src/test/java/co/rsk/RskContextTest.java b/rskj-core/src/test/java/co/rsk/RskContextTest.java index c8279150283..0bb209782ab 100644 --- a/rskj-core/src/test/java/co/rsk/RskContextTest.java +++ b/rskj-core/src/test/java/co/rsk/RskContextTest.java @@ -22,6 +22,7 @@ import co.rsk.config.*; import co.rsk.net.AsyncNodeBlockProcessor; import co.rsk.net.NodeBlockProcessor; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.net.discovery.KnownPeersHandler; import co.rsk.trie.MultiTrieStore; import co.rsk.trie.TrieStore; diff --git a/rskj-core/src/test/java/co/rsk/net/handler/txvalidator/TxValidatorIntrinsicGasLimitValidatorTest.java b/rskj-core/src/test/java/co/rsk/net/handler/txvalidator/TxValidatorIntrinsicGasLimitValidatorTest.java index e3fbdfc2777..00fb4feb170 100644 --- a/rskj-core/src/test/java/co/rsk/net/handler/txvalidator/TxValidatorIntrinsicGasLimitValidatorTest.java +++ b/rskj-core/src/test/java/co/rsk/net/handler/txvalidator/TxValidatorIntrinsicGasLimitValidatorTest.java @@ -17,7 +17,7 @@ */ package co.rsk.net.handler.txvalidator; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import org.bouncycastle.util.encoders.Hex; import org.ethereum.config.Constants; import org.ethereum.config.blockchain.upgrades.ActivationConfig; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeCostsTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeCostsTest.java index be27fcc3620..0cfa6700fcd 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeCostsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeCostsTest.java @@ -1,7 +1,7 @@ package co.rsk.peg; import co.rsk.blockchain.utils.BlockGenerator; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.config.RskSystemProperties; import co.rsk.config.TestSystemProperties; import co.rsk.core.RskAddress; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSerializationUtilsTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSerializationUtilsTest.java index 345c0f70401..f6b256ccb4a 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSerializationUtilsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSerializationUtilsTest.java @@ -21,9 +21,9 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptBuilder; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeTestNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import co.rsk.core.RskAddress; import co.rsk.peg.vote.ABICallElection; import co.rsk.peg.vote.ABICallSpec; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeStateTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeStateTest.java index 00d4b25d9ff..1c4b2388a97 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeStateTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeStateTest.java @@ -18,7 +18,7 @@ package co.rsk.peg; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.config.TestSystemProperties; import co.rsk.db.MutableTrieImpl; import co.rsk.trie.Trie; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderFederationTests.java b/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderFederationTests.java index 1be609af42a..8c2dddb3d1e 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderFederationTests.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderFederationTests.java @@ -12,11 +12,11 @@ import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import java.io.IOException; import java.time.Instant; import java.util.List; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.peg.federation.*; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderPegoutTxIndexTests.java b/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderPegoutTxIndexTests.java index 668bc9427d5..ddc1ef526f0 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderPegoutTxIndexTests.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderPegoutTxIndexTests.java @@ -1,8 +1,8 @@ package co.rsk.peg; import co.rsk.bitcoinj.core.Sha256Hash; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; import co.rsk.core.RskAddress; import co.rsk.peg.bitcoin.BitcoinTestUtils; import org.ethereum.config.blockchain.upgrades.ActivationConfig; @@ -18,11 +18,9 @@ import org.mockito.Mockito; import java.io.IOException; -import java.util.Collections; import java.util.stream.Stream; import static co.rsk.peg.BridgeStorageIndexKey.PEGOUT_TX_SIG_HASH; -import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP134; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java index 072ebd8a2a7..6b83d9955fa 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java @@ -30,6 +30,10 @@ import co.rsk.peg.vote.ABICallElection; import co.rsk.peg.vote.ABICallSpec; import co.rsk.peg.bitcoin.*; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import co.rsk.peg.federation.*; import co.rsk.peg.flyover.FlyoverFederationInformation; import co.rsk.peg.vote.AddressBasedAuthorizer; @@ -91,6 +95,7 @@ class BridgeStorageProviderTest { private final ActivationConfig.ForBlock activationsBeforeFork = ActivationConfigsForTest.genesis().forBlock(0L); private final ActivationConfig.ForBlock activationsAllForks = ActivationConfigsForTest.all().forBlock(0); private final BridgeTestNetConstants bridgeTestnetInstance = BridgeTestNetConstants.getInstance(); + private final BridgeConstants bridgeMainNetConstants = BridgeMainNetConstants.getInstance(); private final NetworkParameters networkParameters = bridgeTestnetInstance.getBtcParams(); private int transactionOffset; @@ -276,9 +281,8 @@ void createSaveAndRecreateInstanceWithUTXOS() throws IOException { Repository repository = createRepository(); Repository track = repository.startTracking(); - BridgeConstants bridgeConstants = bridgeTestnetInstance; // Federation is the genesis federation ATM - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeMainNetConstants); BridgeStorageProvider provider0 = new BridgeStorageProvider( track, @@ -286,8 +290,8 @@ void createSaveAndRecreateInstanceWithUTXOS() throws IOException { bridgeTestnetInstance, activationsBeforeFork ); - provider0.getNewFederationBtcUTXOs().add(new UTXO(hash1, 1, Coin.COIN, 0, false, ScriptBuilder.createOutputScript(federation.getAddress()))); - provider0.getNewFederationBtcUTXOs().add(new UTXO(hash2, 2, Coin.FIFTY_COINS, 0, false, ScriptBuilder.createOutputScript(federation.getAddress()))); + provider0.getNewFederationBtcUTXOs().add(new UTXO(hash1, 1, Coin.COIN, 0, false, ScriptBuilder.createOutputScript(genesisFederation.getAddress()))); + provider0.getNewFederationBtcUTXOs().add(new UTXO(hash2, 2, Coin.FIFTY_COINS, 0, false, ScriptBuilder.createOutputScript(genesisFederation.getAddress()))); provider0.save(); track.commit(); diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportAddSignatureTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportAddSignatureTest.java index 1eb1abd5917..f1966ab576d 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportAddSignatureTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportAddSignatureTest.java @@ -5,8 +5,8 @@ import java.util.*; import java.util.stream.Stream; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; import co.rsk.peg.federation.*; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ConsensusRule; @@ -20,7 +20,7 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptChunk; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.crypto.Keccak256; import co.rsk.peg.btcLockSender.BtcLockSenderProvider; import co.rsk.peg.pegininstructions.PeginInstructionsProvider; @@ -58,8 +58,8 @@ class BridgeSupportAddSignatureTest { private static final RskAddress contractAddress = PrecompiledContracts.BRIDGE_ADDR; - private final BridgeConstants bridgeConstantsRegtest = BridgeRegTestConstants.getInstance(); - private final NetworkParameters btcRegTestParams = bridgeConstantsRegtest.getBtcParams(); + private final BridgeConstants bridgeRegTestConstants = BridgeRegTestConstants.getInstance(); + private final NetworkParameters btcRegTestParams = bridgeRegTestConstants.getBtcParams(); private final Instant creationTime = Instant.ofEpochMilli(1000L); private final long creationBlockNumber = 0L; @@ -97,14 +97,14 @@ void addSignature_fedPubKey_belongs_to_active_federation() throws Exception { BridgeStorageProvider provider = mock(BridgeStorageProvider.class); BridgeSupport bridgeSupport = new BridgeSupport( - bridgeConstantsRegtest, + bridgeRegTestConstants, provider, mock(BridgeEventLogger.class), new BtcLockSenderProvider(), new PeginInstructionsProvider(), mock(Repository.class), mock(Block.class), - new Context(bridgeConstantsRegtest.getBtcParams()), + new Context(bridgeRegTestConstants.getBtcParams()), mockFederationSupport, null, null, @@ -129,14 +129,14 @@ void addSignature_fedPubKey_belongs_to_retiring_federation() throws Exception { FederationSupport mockFederationSupport = mock(FederationSupport.class); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); BridgeSupport bridgeSupport = new BridgeSupport( - bridgeConstantsRegtest, + bridgeRegTestConstants, provider, mock(BridgeEventLogger.class), new BtcLockSenderProvider(), new PeginInstructionsProvider(), mock(Repository.class), mock(Block.class), - new Context(bridgeConstantsRegtest.getBtcParams()), + new Context(bridgeRegTestConstants.getBtcParams()), mockFederationSupport, null, null, @@ -192,14 +192,14 @@ void addSignature_fedPubKey_no_belong_to_retiring_or_active_federation() throws FederationSupport mockFederationSupport = mock(FederationSupport.class); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); BridgeSupport bridgeSupport = new BridgeSupport( - bridgeConstantsRegtest, + bridgeRegTestConstants, provider, mock(BridgeEventLogger.class), new BtcLockSenderProvider(), new PeginInstructionsProvider(), mock(Repository.class), mock(Block.class), - new Context(bridgeConstantsRegtest.getBtcParams()), + new Context(bridgeRegTestConstants.getBtcParams()), mockFederationSupport, null, null, @@ -254,7 +254,7 @@ void addSignature_fedPubKey_no_belong_to_active_federation_no_existing_retiring_ BridgeStorageProvider provider = mock(BridgeStorageProvider.class); BridgeSupport bridgeSupport = bridgeSupportBuilder - .withBridgeConstants(bridgeConstantsRegtest) + .withBridgeConstants(bridgeRegTestConstants) .withProvider(provider) .withEventLogger(mock(BridgeEventLogger.class)) .build(); @@ -271,24 +271,24 @@ void addSignature_fedPubKey_no_belong_to_active_federation_no_existing_retiring_ @Test void addSignatureToMissingTransaction() throws Exception { // Federation is the genesis federation ATM - Federation federation = bridgeConstantsRegtest.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeRegTestConstants); Repository repository = createRepository(); BridgeStorageProvider providerForSupport = new BridgeStorageProvider( repository, PrecompiledContracts.BRIDGE_ADDR, - bridgeConstantsRegtest, + bridgeRegTestConstants, activationsBeforeForks ); BridgeSupport bridgeSupport = bridgeSupportBuilder - .withBridgeConstants(bridgeConstantsRegtest) + .withBridgeConstants(bridgeRegTestConstants) .withProvider(providerForSupport) .withRepository(repository) .build(); bridgeSupport.addSignature( - federation.getBtcPublicKeys().get(0), + genesisFederation.getBtcPublicKeys().get(0), null, createHash().getBytes() ); @@ -297,7 +297,7 @@ void addSignatureToMissingTransaction() throws Exception { BridgeStorageProvider provider = new BridgeStorageProvider( repository, PrecompiledContracts.BRIDGE_ADDR, - bridgeConstantsRegtest, + bridgeRegTestConstants, activationsBeforeForks ); @@ -310,11 +310,11 @@ void addSignatureFromInvalidFederator() throws Exception { Repository repository = createRepository(); BridgeSupport bridgeSupport = bridgeSupportBuilder - .withBridgeConstants(bridgeConstantsRegtest) + .withBridgeConstants(bridgeRegTestConstants) .withProvider(new BridgeStorageProvider( repository, PrecompiledContracts.BRIDGE_ADDR, - bridgeConstantsRegtest, + bridgeRegTestConstants, activationsBeforeForks)) .withRepository(repository) .build(); @@ -323,7 +323,7 @@ void addSignatureFromInvalidFederator() throws Exception { bridgeSupport.save(); BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, - bridgeConstantsRegtest, activationsBeforeForks); + bridgeRegTestConstants, activationsBeforeForks); assertTrue(provider.getPegoutsWaitingForSignatures().isEmpty()); } @@ -355,18 +355,18 @@ void addSignatureNonCanonicalSignature() throws Exception { private void test_addSignature_EventEmitted(boolean rskip326Active, boolean useValidSignature, int wantedNumberOfInvocations, boolean shouldSignTwice) throws Exception { // Setup - Federation federation = bridgeConstantsRegtest.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeRegTestConstants); Repository track = createRepository().startTracking(); - BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeConstantsRegtest, activationsBeforeForks); + BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeRegTestConstants, activationsBeforeForks); // Build prev btc tx BtcTransaction prevTx = new BtcTransaction(btcRegTestParams); - TransactionOutput prevOut = new TransactionOutput(btcRegTestParams, prevTx, Coin.FIFTY_COINS, federation.getAddress()); + TransactionOutput prevOut = new TransactionOutput(btcRegTestParams, prevTx, Coin.FIFTY_COINS, genesisFederation.getAddress()); prevTx.addOutput(prevOut); // Build btc tx to be signed BtcTransaction btcTx = new BtcTransaction(btcRegTestParams); - btcTx.addInput(prevOut).setScriptSig(createBaseInputScriptThatSpendsFromTheFederation(federation)); + btcTx.addInput(prevOut).setScriptSig(createBaseInputScriptThatSpendsFromTheFederation(genesisFederation)); TransactionOutput output = new TransactionOutput(btcRegTestParams, btcTx, Coin.COIN, new BtcECKey().toAddress(btcRegTestParams)); btcTx.addOutput(output); @@ -385,7 +385,7 @@ private void test_addSignature_EventEmitted(boolean rskip326Active, boolean useV when(activations.isActive(ConsensusRule.RSKIP326)).thenReturn(rskip326Active); BridgeSupport bridgeSupport = bridgeSupportBuilder - .withBridgeConstants(bridgeConstantsRegtest) + .withBridgeConstants(bridgeRegTestConstants) .withProvider(provider) .withRepository(track) .withEventLogger(eventLogger) @@ -478,30 +478,30 @@ void addSignatureTwoSignatures() throws Exception { @Test void addSignatureMultipleInputsPartiallyValid() throws Exception { // Federation is the genesis federation ATM - Federation federation = bridgeConstantsRegtest.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeRegTestConstants); Repository repository = createRepository(); final Keccak256 keccak256 = createHash3(1); BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, - bridgeConstantsRegtest, activationsBeforeForks); + bridgeRegTestConstants, activationsBeforeForks); BtcTransaction prevTx1 = new BtcTransaction(btcRegTestParams); - TransactionOutput prevOut1 = new TransactionOutput(btcRegTestParams, prevTx1, Coin.FIFTY_COINS, federation.getAddress()); + TransactionOutput prevOut1 = new TransactionOutput(btcRegTestParams, prevTx1, Coin.FIFTY_COINS, genesisFederation.getAddress()); prevTx1.addOutput(prevOut1); BtcTransaction prevTx2 = new BtcTransaction(btcRegTestParams); - TransactionOutput prevOut2 = new TransactionOutput(btcRegTestParams, prevTx1, Coin.FIFTY_COINS, federation.getAddress()); + TransactionOutput prevOut2 = new TransactionOutput(btcRegTestParams, prevTx1, Coin.FIFTY_COINS, genesisFederation.getAddress()); prevTx2.addOutput(prevOut2); BtcTransaction prevTx3 = new BtcTransaction(btcRegTestParams); - TransactionOutput prevOut3 = new TransactionOutput(btcRegTestParams, prevTx1, Coin.FIFTY_COINS, federation.getAddress()); + TransactionOutput prevOut3 = new TransactionOutput(btcRegTestParams, prevTx1, Coin.FIFTY_COINS, genesisFederation.getAddress()); prevTx3.addOutput(prevOut3); BtcTransaction t = new BtcTransaction(btcRegTestParams); TransactionOutput output = new TransactionOutput(btcRegTestParams, t, Coin.COIN, new BtcECKey().toAddress(btcRegTestParams)); t.addOutput(output); - t.addInput(prevOut1).setScriptSig(createBaseInputScriptThatSpendsFromTheFederation(federation)); - t.addInput(prevOut2).setScriptSig(createBaseInputScriptThatSpendsFromTheFederation(federation)); - t.addInput(prevOut3).setScriptSig(createBaseInputScriptThatSpendsFromTheFederation(federation)); + t.addInput(prevOut1).setScriptSig(createBaseInputScriptThatSpendsFromTheFederation(genesisFederation)); + t.addInput(prevOut2).setScriptSig(createBaseInputScriptThatSpendsFromTheFederation(genesisFederation)); + t.addInput(prevOut3).setScriptSig(createBaseInputScriptThatSpendsFromTheFederation(genesisFederation)); provider.getPegoutsWaitingForSignatures().put(keccak256, t); provider.save(); @@ -509,10 +509,10 @@ void addSignatureMultipleInputsPartiallyValid() throws Exception { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); List<LogInfo> logs = new ArrayList<>(); - BridgeEventLogger eventLogger = new BrigeEventLoggerLegacyImpl(bridgeConstantsRegtest, activations, logs, signatureCache); + BridgeEventLogger eventLogger = new BrigeEventLoggerLegacyImpl(bridgeRegTestConstants, activations, logs, signatureCache); BridgeSupport bridgeSupport = bridgeSupportBuilder - .withBridgeConstants(bridgeConstantsRegtest) + .withBridgeConstants(bridgeRegTestConstants) .withProvider(provider) .withRepository(repository) .withEventLogger(eventLogger) @@ -544,7 +544,7 @@ void addSignatureMultipleInputsPartiallyValid() throws Exception { } // Sign with two valid signatures and one invalid signature - bridgeSupport.addSignature(findPublicKeySignedBy(federation.getBtcPublicKeys(), privateKeyOfFirstFed), derEncodedSigsFirstFed, keccak256.getBytes()); + bridgeSupport.addSignature(findPublicKeySignedBy(genesisFederation.getBtcPublicKeys(), privateKeyOfFirstFed), derEncodedSigsFirstFed, keccak256.getBytes()); bridgeSupport.save(); // Sign with two valid signatures and one malformed signature @@ -553,19 +553,19 @@ void addSignatureMultipleInputsPartiallyValid() throws Exception { malformedSignature[i] = (byte) i; } derEncodedSigsFirstFed.set(2, malformedSignature); - bridgeSupport.addSignature(findPublicKeySignedBy(federation.getBtcPublicKeys(), privateKeyOfFirstFed), derEncodedSigsFirstFed, keccak256.getBytes()); + bridgeSupport.addSignature(findPublicKeySignedBy(genesisFederation.getBtcPublicKeys(), privateKeyOfFirstFed), derEncodedSigsFirstFed, keccak256.getBytes()); bridgeSupport.save(); // Sign with fully valid signatures for same federator derEncodedSigsFirstFed.set(2, lastSig.encodeToDER()); - bridgeSupport.addSignature(findPublicKeySignedBy(federation.getBtcPublicKeys(), privateKeyOfFirstFed), derEncodedSigsFirstFed, keccak256.getBytes()); + bridgeSupport.addSignature(findPublicKeySignedBy(genesisFederation.getBtcPublicKeys(), privateKeyOfFirstFed), derEncodedSigsFirstFed, keccak256.getBytes()); bridgeSupport.save(); // Sign with second federation - bridgeSupport.addSignature(findPublicKeySignedBy(federation.getBtcPublicKeys(), privateKeyOfSecondFed), derEncodedSigsSecondFed, keccak256.getBytes()); + bridgeSupport.addSignature(findPublicKeySignedBy(genesisFederation.getBtcPublicKeys(), privateKeyOfSecondFed), derEncodedSigsSecondFed, keccak256.getBytes()); bridgeSupport.save(); - provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeConstantsRegtest, activationsBeforeForks); + provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeRegTestConstants, activationsBeforeForks); assertTrue(provider.getPegoutsWaitingForSignatures().isEmpty()); assertThat(logs, is(not(empty()))); @@ -716,22 +716,22 @@ private void commonAssertLogs(List<LogInfo> logs) { */ private void addSignatureFromValidFederator(List<BtcECKey> privateKeysToSignWith, int numberOfInputsToSign, boolean signatureCanonical, boolean signTwice, String expectedResult) throws Exception { // Federation is the genesis federation ATM - Federation federation = bridgeConstantsRegtest.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeRegTestConstants); Repository repository = createRepository(); final Keccak256 keccak256 = PegTestUtils.createHash3(); Repository track = repository.startTracking(); - BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeConstantsRegtest, activationsBeforeForks); + BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeRegTestConstants, activationsBeforeForks); BtcTransaction prevTx = new BtcTransaction(btcRegTestParams); - TransactionOutput prevOut = new TransactionOutput(btcRegTestParams, prevTx, Coin.FIFTY_COINS, federation.getAddress()); + TransactionOutput prevOut = new TransactionOutput(btcRegTestParams, prevTx, Coin.FIFTY_COINS, genesisFederation.getAddress()); prevTx.addOutput(prevOut); BtcTransaction t = new BtcTransaction(btcRegTestParams); TransactionOutput output = new TransactionOutput(btcRegTestParams, t, Coin.COIN, new BtcECKey().toAddress(btcRegTestParams)); t.addOutput(output); - t.addInput(prevOut).setScriptSig(createBaseInputScriptThatSpendsFromTheFederation(federation)); + t.addInput(prevOut).setScriptSig(createBaseInputScriptThatSpendsFromTheFederation(genesisFederation)); provider.getPegoutsWaitingForSignatures().put(keccak256, t); provider.save(); track.commit(); @@ -741,14 +741,14 @@ private void addSignatureFromValidFederator(List<BtcECKey> privateKeysToSignWith track = repository.startTracking(); ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); List<LogInfo> logs = new ArrayList<>(); - BridgeEventLogger eventLogger = new BrigeEventLoggerLegacyImpl(bridgeConstantsRegtest, activations, logs, signatureCache); + BridgeEventLogger eventLogger = new BrigeEventLoggerLegacyImpl(bridgeRegTestConstants, activations, logs, signatureCache); BridgeSupport bridgeSupport = bridgeSupportBuilder - .withBridgeConstants(bridgeConstantsRegtest) + .withBridgeConstants(bridgeRegTestConstants) .withProvider(new BridgeStorageProvider( track, contractAddress, - bridgeConstantsRegtest, + bridgeRegTestConstants, activationsAfterForks )) .withRepository(track) @@ -771,7 +771,7 @@ private void addSignatureFromValidFederator(List<BtcECKey> privateKeysToSignWith for (int i = 0; i < numberOfInputsToSign; i++) { derEncodedSigs.add(derEncodedSig); } - bridgeSupport.addSignature(findPublicKeySignedBy(federation.getBtcPublicKeys(), privateKeysToSignWith.get(0)), derEncodedSigs, keccak256.getBytes()); + bridgeSupport.addSignature(findPublicKeySignedBy(genesisFederation.getBtcPublicKeys(), privateKeysToSignWith.get(0)), derEncodedSigs, keccak256.getBytes()); if (signTwice) { // Create another valid signature with the same private key ECDSASigner signer = new ECDSASigner(); @@ -783,7 +783,7 @@ private void addSignatureFromValidFederator(List<BtcECKey> privateKeysToSignWith BtcECKey.ECDSASignature sig2 = new BtcECKey.ECDSASignature(components[0], components[1]).toCanonicalised(); List<byte[]> list = new ArrayList<>(); list.add(sig2.encodeToDER()); - bridgeSupport.addSignature(findPublicKeySignedBy(federation.getBtcPublicKeys(), privateKeysToSignWith.get(0)), list, keccak256.getBytes()); + bridgeSupport.addSignature(findPublicKeySignedBy(genesisFederation.getBtcPublicKeys(), privateKeysToSignWith.get(0)), list, keccak256.getBytes()); } if (privateKeysToSignWith.size() > 1) { BtcECKey.ECDSASignature sig2 = privateKeysToSignWith.get(1).sign(sighash); @@ -792,12 +792,12 @@ private void addSignatureFromValidFederator(List<BtcECKey> privateKeysToSignWith for (int i = 0; i < numberOfInputsToSign; i++) { derEncodedSigs2.add(derEncodedSig2); } - bridgeSupport.addSignature(findPublicKeySignedBy(federation.getBtcPublicKeys(), privateKeysToSignWith.get(1)), derEncodedSigs2, keccak256.getBytes()); + bridgeSupport.addSignature(findPublicKeySignedBy(genesisFederation.getBtcPublicKeys(), privateKeysToSignWith.get(1)), derEncodedSigs2, keccak256.getBytes()); } bridgeSupport.save(); track.commit(); - provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeConstantsRegtest, activationsBeforeForks); + provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeRegTestConstants, activationsBeforeForks); if ("FullySigned".equals(expectedResult)) { assertTrue(provider.getPegoutsWaitingForSignatures().isEmpty()); diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportFlyoverTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportFlyoverTest.java index a640d8b5773..3b771f6a7de 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportFlyoverTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportFlyoverTest.java @@ -33,15 +33,16 @@ import co.rsk.bitcoinj.script.ScriptBuilder; import co.rsk.bitcoinj.store.BlockStoreException; import co.rsk.bitcoinj.wallet.Wallet; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.peg.bitcoin.CoinbaseInformation; import co.rsk.peg.btcLockSender.BtcLockSender; import co.rsk.peg.btcLockSender.BtcLockSenderProvider; import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationTestUtils; import co.rsk.peg.flyover.FlyoverFederationInformation; import co.rsk.peg.flyover.FlyoverTxResponseCodes; import co.rsk.peg.pegininstructions.PeginInstructionsProvider; @@ -91,6 +92,7 @@ class BridgeSupportFlyoverTest { private final BridgeConstants bridgeConstantsRegtest = BridgeRegTestConstants.getInstance(); private final BridgeConstants bridgeConstantsMainnet = BridgeMainNetConstants.getInstance(); protected final NetworkParameters btcRegTestParams = bridgeConstantsRegtest.getBtcParams(); + protected final NetworkParameters btcMainnetParams = bridgeConstantsMainnet.getBtcParams(); private BridgeSupportBuilder bridgeSupportBuilder; private ActivationConfig.ForBlock activations; private SignatureCache signatureCache; @@ -2803,12 +2805,12 @@ void registerFlyoverBtcTransaction_amount_sent_is_0() when(activations.isActive(ConsensusRule.RSKIP176)).thenReturn(true); Context btcContext = mock(Context.class); - when(btcContext.getParams()).thenReturn(bridgeConstantsRegtest.getBtcParams()); + when(btcContext.getParams()).thenReturn(bridgeConstantsMainnet.getBtcParams()); RskAddress lbcAddress = PegTestUtils.createRandomRskAddress(); BridgeSupport bridgeSupport = spy(new BridgeSupport( - bridgeConstantsRegtest, + bridgeConstantsMainnet, mock(BridgeStorageProvider.class), mock(BridgeEventLogger.class), new BtcLockSenderProvider(), @@ -2822,7 +2824,9 @@ void registerFlyoverBtcTransaction_amount_sent_is_0() signatureCache )); - doReturn(bridgeConstantsRegtest.getGenesisFederation()).when(bridgeSupport).getActiveFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); + + doReturn(genesisFederation).when(bridgeSupport).getActiveFederation(); doReturn(true).when(bridgeSupport).validationsForRegisterBtcTransaction(any(), anyInt(), any(), any()); doReturn(PegTestUtils.createHash3(1)).when(bridgeSupport).getFlyoverDerivationHash( any(Keccak256.class), @@ -2831,7 +2835,7 @@ void registerFlyoverBtcTransaction_amount_sent_is_0() any(RskAddress.class) ); - BtcTransaction tx = createBtcTransactionWithOutputToAddress(Coin.COIN, new BtcECKey().toAddress(btcRegTestParams)); + BtcTransaction tx = createBtcTransactionWithOutputToAddress(Coin.COIN, new BtcECKey().toAddress(btcMainnetParams)); InternalTransaction rskTx = new InternalTransaction( Keccak256.ZERO_HASH.getBytes(), 0, @@ -2897,8 +2901,9 @@ void registerFlyoverBtcTransaction_surpasses_locking_cap_and_shouldTransfer_is_t activations, signatureCache )); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); - doReturn(bridgeConstantsRegtest.getGenesisFederation()).when(bridgeSupport).getActiveFederation(); + doReturn(genesisFederation).when(bridgeSupport).getActiveFederation(); doReturn(true).when(bridgeSupport).validationsForRegisterBtcTransaction(any(), anyInt(), any(), any()); doReturn(Coin.COIN).when(bridgeSupport).getLockingCap(); doReturn(PegTestUtils.createHash3(1)).when(bridgeSupport).getFlyoverDerivationHash( @@ -2985,7 +2990,9 @@ void registerFlyoverBtcTransaction_surpasses_locking_cap_and_shouldTransfer_is_f signatureCache )); - doReturn(bridgeConstantsRegtest.getGenesisFederation()).when(bridgeSupport).getActiveFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); + + doReturn(genesisFederation).when(bridgeSupport).getActiveFederation(); doReturn(true).when(bridgeSupport).validationsForRegisterBtcTransaction(any(), anyInt(), any(), any()); doReturn(Coin.COIN).when(bridgeSupport).getLockingCap(); doReturn(PegTestUtils.createHash3(1)).when(bridgeSupport).getFlyoverDerivationHash( @@ -3072,8 +3079,9 @@ void registerFlyoverBtcTransaction_surpasses_locking_cap_and_tries_to_register_a activations, signatureCache )); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); - doReturn(bridgeConstantsRegtest.getGenesisFederation()).when(bridgeSupport).getActiveFederation(); + doReturn(genesisFederation).when(bridgeSupport).getActiveFederation(); doReturn(true).when(bridgeSupport).validationsForRegisterBtcTransaction(any(), anyInt(), any(), any()); doReturn( Coin.COIN, // The first time we simulate a lower locking cap than the value to register, to force the reimburse @@ -3179,7 +3187,9 @@ void registerFlyoverBtcTransaction_OK() signatureCache )); - doReturn(bridgeConstantsRegtest.getGenesisFederation()).when(bridgeSupport).getActiveFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); + + doReturn(genesisFederation).when(bridgeSupport).getActiveFederation(); doReturn(true).when(bridgeSupport).validationsForRegisterBtcTransaction(any(), anyInt(), any(), any()); doReturn(PegTestUtils.createHash3(1)).when(bridgeSupport).getFlyoverDerivationHash( any(Keccak256.class), @@ -3266,9 +3276,9 @@ void createFlyoverFederationInformation_OK() { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); when(activations.isActive(ConsensusRule.RSKIP176)).thenReturn(true); - Federation fed = bridgeConstantsRegtest.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); FederationSupport federationSupport = mock(FederationSupport.class); - when(federationSupport.getActiveFederation()).thenReturn(fed); + when(federationSupport.getActiveFederation()).thenReturn(activeFederation); BridgeSupport bridgeSupport = new BridgeSupport( bridgeConstantsRegtest, @@ -3285,8 +3295,11 @@ void createFlyoverFederationInformation_OK() { signatureCache ); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); + Script federationRedeemScript = genesisFederation.getRedeemScript(); + Script flyoverRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript( - bridgeConstantsRegtest.getGenesisFederation().getRedeemScript(), + federationRedeemScript, PegTestUtils.createHash(1) ); @@ -3295,7 +3308,7 @@ void createFlyoverFederationInformation_OK() { FlyoverFederationInformation expectedFlyoverFederationInformation = new FlyoverFederationInformation(derivationHash, - fed.getP2SHScript().getPubKeyHash(), + activeFederation.getP2SHScript().getPubKeyHash(), flyoverP2SH.getPubKeyHash() ); @@ -3331,11 +3344,11 @@ void getFlyoverWallet_ok() { signatureCache ); - Federation fed = bridgeConstantsRegtest.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); Keccak256 derivationHash = PegTestUtils.createHash3(1); Script flyoverRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript( - fed.getRedeemScript(), + genesisFederation.getRedeemScript(), Sha256Hash.wrap(derivationHash.getBytes()) ); @@ -3344,7 +3357,7 @@ void getFlyoverWallet_ok() { FlyoverFederationInformation flyoverFederationInformation = new FlyoverFederationInformation( derivationHash, - fed.getP2SHScript().getPubKeyHash(), + genesisFederation.getP2SHScript().getPubKeyHash(), flyoverP2SH.getPubKeyHash() ); @@ -3447,8 +3460,11 @@ void saveFlyoverDataInStorage_OK() throws IOException { } private Address getFlyoverFederationAddress() { + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); + Script federationRedeemScript = genesisFederation.getRedeemScript(); + Script flyoverRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript( - bridgeConstantsRegtest.getGenesisFederation().getRedeemScript(), + federationRedeemScript, PegTestUtils.createHash(1) ); diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportProcessFundsMigrationTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportProcessFundsMigrationTest.java index b6d4563c41b..13f65527818 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportProcessFundsMigrationTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportProcessFundsMigrationTest.java @@ -4,9 +4,9 @@ import co.rsk.bitcoinj.core.Coin; import co.rsk.bitcoinj.core.UTXO; import co.rsk.blockchain.utils.BlockGenerator; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeTestNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import co.rsk.peg.federation.Federation; import co.rsk.peg.federation.FederationArgs; import co.rsk.peg.federation.FederationFactory; @@ -119,9 +119,9 @@ void test_processFundsMigration( ActivationConfig.ForBlock activations, boolean inMigrationAge ) throws IOException { - BridgeEventLogger bridgeEventLogger = mock(BridgeEventLogger.class); - Federation oldFederation = bridgeConstants.getGenesisFederation(); + BridgeEventLogger bridgeEventLogger = mock(BridgeEventLogger.class); + Federation oldFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); long federationActivationAge = bridgeConstants.getFederationActivationAge(activations); long federationCreationBlockNumber = 5L; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportRSKIP220NewMethodsTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportRSKIP220NewMethodsTest.java index aab6602d4d2..3384e932948 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportRSKIP220NewMethodsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportRSKIP220NewMethodsTest.java @@ -2,8 +2,8 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.store.BlockStoreException; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.test.builders.BridgeSupportBuilder; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportRegisterBtcTransactionTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportRegisterBtcTransactionTest.java index 38a2b0f0e80..c707ae8d41d 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportRegisterBtcTransactionTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportRegisterBtcTransactionTest.java @@ -1,29 +1,76 @@ package co.rsk.peg; -import co.rsk.bitcoinj.core.*; +import static co.rsk.peg.BridgeSupportTestUtil.mockChainOfStoredBlocks; +import static co.rsk.peg.PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation; +import static co.rsk.peg.PegTestUtils.createBech32Output; +import static co.rsk.peg.PegTestUtils.createFederation; +import static co.rsk.peg.pegin.RejectedPeginReason.INVALID_AMOUNT; +import static co.rsk.peg.pegin.RejectedPeginReason.LEGACY_PEGIN_MULTISIG_SENDER; +import static co.rsk.peg.pegin.RejectedPeginReason.PEGIN_V1_INVALID_PAYLOAD; +import static co.rsk.peg.utils.UnrefundablePeginReason.LEGACY_PEGIN_UNDETERMINED_SENDER; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import co.rsk.bitcoinj.core.Address; +import co.rsk.bitcoinj.core.BtcECKey; +import co.rsk.bitcoinj.core.BtcTransaction; +import co.rsk.bitcoinj.core.Coin; +import co.rsk.bitcoinj.core.Context; +import co.rsk.bitcoinj.core.NetworkParameters; +import co.rsk.bitcoinj.core.PartialMerkleTree; +import co.rsk.bitcoinj.core.Sha256Hash; +import co.rsk.bitcoinj.core.StoredBlock; +import co.rsk.bitcoinj.core.TransactionWitness; +import co.rsk.bitcoinj.core.UTXO; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptBuilder; import co.rsk.bitcoinj.store.BlockStoreException; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeRegTestConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.peg.bitcoin.BitcoinTestUtils; import co.rsk.peg.bitcoin.CoinbaseInformation; import co.rsk.peg.btcLockSender.BtcLockSenderProvider; -import co.rsk.peg.federation.*; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationArgs; +import co.rsk.peg.federation.FederationFactory; +import co.rsk.peg.federation.FederationMember; +import co.rsk.peg.federation.FederationTestUtils; import co.rsk.peg.pegin.RejectedPeginReason; import co.rsk.peg.pegininstructions.PeginInstructionsProvider; import co.rsk.peg.utils.BridgeEventLogger; import co.rsk.peg.utils.UnrefundablePeginReason; import co.rsk.peg.whitelist.LockWhitelist; import co.rsk.test.builders.BridgeSupportBuilder; +import java.io.IOException; +import java.math.BigInteger; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; import org.bouncycastle.util.encoders.Hex; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest; import org.ethereum.config.blockchain.upgrades.ConsensusRule; -import org.ethereum.core.*; +import org.ethereum.core.Block; +import org.ethereum.core.BlockTxSignatureCache; +import org.ethereum.core.ReceivedTxSignatureCache; +import org.ethereum.core.Repository; +import org.ethereum.core.SignatureCache; +import org.ethereum.core.Transaction; import org.ethereum.crypto.ECKey; import org.ethereum.vm.PrecompiledContracts; import org.junit.jupiter.api.Assertions; @@ -33,24 +80,10 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import java.io.IOException; -import java.math.BigInteger; -import java.time.Instant; -import java.util.*; -import java.util.stream.Stream; - -import static co.rsk.peg.BridgeSupportTestUtil.mockChainOfStoredBlocks; -import static co.rsk.peg.PegTestUtils.*; -import static co.rsk.peg.pegin.RejectedPeginReason.*; -import static co.rsk.peg.utils.UnrefundablePeginReason.LEGACY_PEGIN_UNDETERMINED_SENDER; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; - class BridgeSupportRegisterBtcTransactionTest { private static final BridgeConstants bridgeMainnetConstants = BridgeMainNetConstants.getInstance(); private static final NetworkParameters btcMainnetParams = bridgeMainnetConstants.getBtcParams(); - private static final ActivationConfig.ForBlock fingerrootActivations = ActivationConfigsForTest.fingerroot500().forBlock(0); private static final ActivationConfig.ForBlock arrowhead600Activations = ActivationConfigsForTest.arrowhead600().forBlock(0); @@ -1591,7 +1624,7 @@ void pegout_many_outputs_and_inputs_with_change_output( ); } - Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis(); + Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue(); Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4); for (int i = 0; i < 10; i++) { btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), BitcoinTestUtils.createP2PKHAddress(btcMainnetParams, "user" + i)); @@ -1672,7 +1705,7 @@ void pegout_many_outputs_and_one_input( ScriptBuilder.createP2SHMultiSigInputScript(null, activeFederation.getRedeemScript()) ); - Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis(); + Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue(); Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4); for (int i = 0; i < 10; i++) { btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), BitcoinTestUtils.createP2PKHAddress(btcMainnetParams, "user" + i)); @@ -1755,7 +1788,7 @@ void pegout_one_output_and_many_input( ); } - Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis(); + Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue(); btcTransaction.addOutput(minimumPegoutTxValue, userAddress); FederationTestUtils.addSignatures(activeFederation, activeFedSigners, btcTransaction); @@ -1913,7 +1946,7 @@ void migration_many_outputs_and_inputs( ); } - Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis(); + Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue(); Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4); for (int i = 0; i < 10; i++) { btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), activeFederation.getAddress()); @@ -1980,7 +2013,7 @@ void migration_many_outputs_and_one_input( ScriptBuilder.createP2SHMultiSigInputScript(null, retiringFederation.getRedeemScript()) ); - Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis(); + Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue(); Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4); for (int i = 0; i < 10; i++) { btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), activeFederation.getAddress()); @@ -2050,7 +2083,7 @@ void migration_one_outputs_and_many_input( ); } - Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis(); + Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue(); btcTransaction.addOutput(minimumPegoutTxValue, activeFederation.getAddress()); FederationTestUtils.addSignatures(retiringFederation, retiringFedSigners, btcTransaction); @@ -2422,7 +2455,7 @@ void old_fed_migration( when(provider.getPegoutsWaitingForConfirmations()).thenReturn(pegoutsWaitingForConfirmations); Federation oldFederation = createFederation(bridgeRegTestConstants, REGTEST_OLD_FEDERATION_PRIVATE_KEYS); - Federation activeFederation = bridgeRegTestConstants.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeRegTestConstants); BtcTransaction migrationTx = new BtcTransaction(btcRegTestsParams); migrationTx.addInput( diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportReleaseBtcTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportReleaseBtcTest.java index 5a0d41e0027..1ce3339998e 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportReleaseBtcTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportReleaseBtcTest.java @@ -18,8 +18,8 @@ package co.rsk.peg; import co.rsk.bitcoinj.core.*; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.db.MutableTrieCache; @@ -430,10 +430,10 @@ void release_after_rskip_219() throws IOException { bridgeSupport = initBridgeSupport(eventLogger, activationMock); // Get a value between old and new minimum pegout values - Coin middle = bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis().subtract(bridgeConstants.getMinimumPegoutTxValueInSatoshis()).div(2); - Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis().add(middle); - Assertions.assertTrue(value.isLessThan(bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis())); - Assertions.assertTrue(value.isGreaterThan(bridgeConstants.getMinimumPegoutTxValueInSatoshis())); + Coin middle = bridgeConstants.getLegacyMinimumPegoutTxValue().subtract(bridgeConstants.getMinimumPegoutTxValue()).div(2); + Coin value = bridgeConstants.getMinimumPegoutTxValue().add(middle); + Assertions.assertTrue(value.isLessThan(bridgeConstants.getLegacyMinimumPegoutTxValue())); + Assertions.assertTrue(value.isGreaterThan(bridgeConstants.getMinimumPegoutTxValue())); bridgeSupport.releaseBtc(buildReleaseRskTx(value)); Transaction rskTx = buildUpdateTx(); @@ -465,10 +465,10 @@ void release_after_rskip_219_326() throws IOException { bridgeSupport = initBridgeSupport(eventLogger, activationMock); // Get a value between old and new minimum pegout values - Coin middle = bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis().subtract(bridgeConstants.getMinimumPegoutTxValueInSatoshis()).div(2); - Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis().add(middle); - Assertions.assertTrue(value.isLessThan(bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis())); - Assertions.assertTrue(value.isGreaterThan(bridgeConstants.getMinimumPegoutTxValueInSatoshis())); + Coin middle = bridgeConstants.getLegacyMinimumPegoutTxValue().subtract(bridgeConstants.getMinimumPegoutTxValue()).div(2); + Coin value = bridgeConstants.getMinimumPegoutTxValue().add(middle); + Assertions.assertTrue(value.isLessThan(bridgeConstants.getLegacyMinimumPegoutTxValue())); + Assertions.assertTrue(value.isGreaterThan(bridgeConstants.getMinimumPegoutTxValue())); bridgeSupport.releaseBtc(buildReleaseRskTx(value)); Transaction rskTx = buildUpdateTx(); @@ -498,10 +498,10 @@ void release_before_rskip_219() throws IOException { bridgeSupport = initBridgeSupport(eventLogger, activationMock); // Get a value between old and new minimum pegout values - Coin middle = bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis().subtract(bridgeConstants.getMinimumPegoutTxValueInSatoshis()).div(2); - Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis().add(middle); - Assertions.assertTrue(value.isLessThan(bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis())); - Assertions.assertTrue(value.isGreaterThan(bridgeConstants.getMinimumPegoutTxValueInSatoshis())); + Coin middle = bridgeConstants.getLegacyMinimumPegoutTxValue().subtract(bridgeConstants.getMinimumPegoutTxValue()).div(2); + Coin value = bridgeConstants.getMinimumPegoutTxValue().add(middle); + Assertions.assertTrue(value.isLessThan(bridgeConstants.getLegacyMinimumPegoutTxValue())); + Assertions.assertTrue(value.isGreaterThan(bridgeConstants.getMinimumPegoutTxValue())); bridgeSupport.releaseBtc(buildReleaseRskTx(value)); Transaction rskTx = buildUpdateTx(); @@ -525,7 +525,7 @@ void release_before_rskip_219_minimum_exclusive() throws IOException { bridgeSupport = initBridgeSupport(eventLogger, activationMock); // Get a value exactly to legacy minimum - Coin value = bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis(); + Coin value = bridgeConstants.getLegacyMinimumPegoutTxValue(); bridgeSupport.releaseBtc(buildReleaseRskTx(value)); Transaction rskTx = buildUpdateTx(); @@ -549,7 +549,7 @@ void release_after_rskip_219_minimum_inclusive() throws IOException { bridgeSupport = initBridgeSupport(eventLogger, activationMock); // Get a value exactly to current minimum - Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis(); + Coin value = bridgeConstants.getMinimumPegoutTxValue(); bridgeSupport.releaseBtc(buildReleaseRskTx(value)); Transaction rskTx = buildUpdateTx(); @@ -580,7 +580,7 @@ void release_after_rskip_219_326_minimum_inclusive() throws IOException { bridgeSupport = initBridgeSupport(eventLogger, activationMock); // Get a value exactly to current minimum - Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis(); + Coin value = bridgeConstants.getMinimumPegoutTxValue(); bridgeSupport.releaseBtc(buildReleaseRskTx(value)); Transaction rskTx = buildUpdateTx(); @@ -602,7 +602,7 @@ void release_after_rskip_219_326_minimum_inclusive() throws IOException { @Test void release_verify_fee_below_fee_is_rejected() throws IOException { - Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis().add(Coin.SATOSHI); + Coin value = bridgeConstants.getMinimumPegoutTxValue().add(Coin.SATOSHI); testPegoutMinimumWithFeeVerification(Coin.COIN, value, false); } @@ -633,7 +633,7 @@ void release_verify_fee_above_fee_but_below_gap_is_rejected_after_rskip_271() th void release_verify_fee_above_fee_but_below_minimum_is_rejected() throws IOException { testPegoutMinimumWithFeeVerification( Coin.MILLICOIN, - bridgeConstants.getMinimumPegoutTxValueInSatoshis().minus(Coin.SATOSHI), + bridgeConstants.getMinimumPegoutTxValue().minus(Coin.SATOSHI), false ); } @@ -647,9 +647,9 @@ void release_verify_fee_above_fee_and_minimum_is_accepted() throws IOException { void test_processPegoutsIndividually_before_RSKIP271_activation() throws IOException { when(activationMock.isActive(ConsensusRule.RSKIP271)).thenReturn(false); - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); List<UTXO> utxos = new ArrayList<>(); - utxos.add(PegTestUtils.createUTXO(1, 0, Coin.COIN.multiply(3), federation.getAddress())); + utxos.add(PegTestUtils.createUTXO(1, 0, Coin.COIN.multiply(3), genesisFederation.getAddress())); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); when(provider.getNewFederationBtcUTXOs()).thenReturn(utxos); @@ -681,9 +681,9 @@ void test_processPegoutsInBatch_after_RSKIP271() throws IOException { when(activationMock.isActive(ConsensusRule.RSKIP271)).thenReturn(true); when(activationMock.isActive(ConsensusRule.RSKIP146)).thenReturn(true); - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); List<UTXO> utxos = new ArrayList<>(); - utxos.add(PegTestUtils.createUTXO(1, 0, Coin.COIN.multiply(4), federation.getAddress())); + utxos.add(PegTestUtils.createUTXO(1, 0, Coin.COIN.multiply(4), genesisFederation.getAddress())); ReleaseRequestQueue pegoutRequests = new ReleaseRequestQueue( Arrays.asList( @@ -797,9 +797,9 @@ void test_processPegoutsInBatch_after_RSKIP271_activation_no_requests_in_queue_u void test_processPegoutsInBatch_after_rskip_271_Insufficient_Money() throws IOException { when(activationMock.isActive(ConsensusRule.RSKIP271)).thenReturn(true); - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); List<UTXO> utxos = new ArrayList<>(); - utxos.add(PegTestUtils.createUTXO(2, 0, Coin.COIN.multiply(4), federation.getAddress())); + utxos.add(PegTestUtils.createUTXO(2, 0, Coin.COIN.multiply(4), genesisFederation.getAddress())); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); @@ -833,8 +833,8 @@ void test_processPegoutsInBatch_after_rskip_271_Insufficient_Money() throws IOEx void test_processPegoutsInBatch_after_rskip_271_divide_transaction_when_max_size_exceeded() throws IOException { when(activationMock.isActive(ConsensusRule.RSKIP271)).thenReturn(true); - Federation federation = bridgeConstants.getGenesisFederation(); - List<UTXO> utxos = PegTestUtils.createUTXOs(610, federation.getAddress()); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); + List<UTXO> utxos = PegTestUtils.createUTXOs(610, genesisFederation.getAddress()); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); @@ -867,8 +867,8 @@ void test_processPegoutsInBatch_after_rskip_271_divide_transaction_when_max_size void test_processPegoutsInBatch_after_rskip_271_when_max_size_exceeded_for_one_pegout() throws IOException { when(activationMock.isActive(ConsensusRule.RSKIP271)).thenReturn(true); - Federation federation = bridgeConstants.getGenesisFederation(); - List<UTXO> utxos = PegTestUtils.createUTXOs(700, federation.getAddress()); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); + List<UTXO> utxos = PegTestUtils.createUTXOs(700, genesisFederation.getAddress()); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); @@ -895,8 +895,8 @@ void test_processPegoutsInBatch_after_rskip_271_when_max_size_exceeded_for_one_p void test_processPegoutsInBatch_after_rskip_271_when_max_size_exceeded_for_two_pegout() throws IOException { when(activationMock.isActive(ConsensusRule.RSKIP271)).thenReturn(true); - Federation federation = bridgeConstants.getGenesisFederation(); - List<UTXO> utxos = PegTestUtils.createUTXOs(1400, federation.getAddress()); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); + List<UTXO> utxos = PegTestUtils.createUTXOs(1400, genesisFederation.getAddress()); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); @@ -923,10 +923,10 @@ void test_processPegoutsInBatch_after_rskip_271_when_max_size_exceeded_for_two_p void test_processPegoutsIndividually_before_rskip_271_no_funds_to_process_any_requests() throws IOException { when(activationMock.isActive(ConsensusRule.RSKIP271)).thenReturn(false); - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); List<UTXO> utxos = new ArrayList<>(); - utxos.add(PegTestUtils.createUTXO(1, 0, Coin.COIN, federation.getAddress())); - utxos.add(PegTestUtils.createUTXO(2, 1, Coin.COIN, federation.getAddress())); + utxos.add(PegTestUtils.createUTXO(1, 0, Coin.COIN, genesisFederation.getAddress())); + utxos.add(PegTestUtils.createUTXO(2, 1, Coin.COIN, genesisFederation.getAddress())); List<ReleaseRequestQueue.Entry> entries = Arrays.asList( new ReleaseRequestQueue.Entry(PegTestUtils.createRandomP2PKHBtcAddress(bridgeConstants.getBtcParams()), Coin.COIN.multiply(5)), @@ -960,10 +960,10 @@ void test_processPegoutsIndividually_before_rskip_271_no_funds_to_process_any_re void test_processPegoutsIndividually_before_rskip_271_no_funds_to_process_any_requests_order_changes_in_queue() throws IOException { when(activationMock.isActive(ConsensusRule.RSKIP271)).thenReturn(false); - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); List<UTXO> utxos = new ArrayList<>(); - utxos.add(PegTestUtils.createUTXO(1, 0, Coin.COIN, federation.getAddress())); - utxos.add(PegTestUtils.createUTXO(2, 1, Coin.COIN, federation.getAddress())); + utxos.add(PegTestUtils.createUTXO(1, 0, Coin.COIN, genesisFederation.getAddress())); + utxos.add(PegTestUtils.createUTXO(2, 1, Coin.COIN, genesisFederation.getAddress())); List<ReleaseRequestQueue.Entry> entries = new ArrayList<>(); int entriesSizeAboveMaxIterations = BridgeSupport.MAX_RELEASE_ITERATIONS + 10; @@ -1010,9 +1010,9 @@ void test_processPegoutsIndividually_before_rskip_271_no_funds_to_process_any_re void test_check_wallet_balance_before_rskip_271_process_at_least_one_request() throws IOException { when(activationMock.isActive(ConsensusRule.RSKIP271)).thenReturn(false); - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); List<UTXO> utxos = new ArrayList<>(); - utxos.add(PegTestUtils.createUTXO(1, 0, Coin.COIN.multiply(2), federation.getAddress())); + utxos.add(PegTestUtils.createUTXO(1, 0, Coin.COIN.multiply(2), genesisFederation.getAddress())); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); when(provider.getNewFederationBtcUTXOs()).thenReturn(utxos); @@ -1041,11 +1041,11 @@ void test_check_wallet_balance_before_rskip_271_process_at_least_one_request() t void test_check_wallet_balance_after_rskip_271_process_no_requests() throws IOException { when(activationMock.isActive(ConsensusRule.RSKIP271)).thenReturn(true); - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); List<UTXO> utxos = new ArrayList<>(); - utxos.add(PegTestUtils.createUTXO(1, 0, Coin.COIN.multiply(4), federation.getAddress())); - utxos.add(PegTestUtils.createUTXO(2, 1, Coin.COIN.multiply(4), federation.getAddress())); - utxos.add(PegTestUtils.createUTXO(3, 2, Coin.COIN.multiply(3), federation.getAddress())); + utxos.add(PegTestUtils.createUTXO(1, 0, Coin.COIN.multiply(4), genesisFederation.getAddress())); + utxos.add(PegTestUtils.createUTXO(2, 1, Coin.COIN.multiply(4), genesisFederation.getAddress())); + utxos.add(PegTestUtils.createUTXO(3, 2, Coin.COIN.multiply(3), genesisFederation.getAddress())); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); when(provider.getNewFederationBtcUTXOs()).thenReturn(utxos); @@ -1077,11 +1077,11 @@ void test_check_wallet_balance_after_rskip_271_process_no_requests() throws IOEx void test_check_wallet_balance_after_rskip_271_process_all_requests_when_utxos_available() throws IOException { when(activationMock.isActive(ConsensusRule.RSKIP271)).thenReturn(true); - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); List<UTXO> utxos = new ArrayList<>(); - utxos.add(PegTestUtils.createUTXO(1, 0, Coin.COIN.multiply(4), federation.getAddress())); - utxos.add(PegTestUtils.createUTXO(2, 1, Coin.COIN.multiply(4), federation.getAddress())); - utxos.add(PegTestUtils.createUTXO(3, 2, Coin.COIN.multiply(3), federation.getAddress())); + utxos.add(PegTestUtils.createUTXO(1, 0, Coin.COIN.multiply(4), genesisFederation.getAddress())); + utxos.add(PegTestUtils.createUTXO(2, 1, Coin.COIN.multiply(4), genesisFederation.getAddress())); + utxos.add(PegTestUtils.createUTXO(3, 2, Coin.COIN.multiply(3), genesisFederation.getAddress())); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); when(provider.getNewFederationBtcUTXOs()).thenReturn(utxos); @@ -1109,7 +1109,7 @@ void test_check_wallet_balance_after_rskip_271_process_all_requests_when_utxos_a verify(eventLogger, never()).logBatchPegoutCreated(any(), any()); verify(provider, never()).setNextPegoutHeight(any(Long.class)); - utxos.add(PegTestUtils.createUTXO(4, 3, Coin.COIN.multiply(1), federation.getAddress())); + utxos.add(PegTestUtils.createUTXO(4, 3, Coin.COIN.multiply(1), genesisFederation.getAddress())); when(provider.getNewFederationBtcUTXOs()).thenReturn(utxos); bridgeSupport = bridgeSupportBuilder .withBridgeConstants(bridgeConstants) @@ -1147,7 +1147,7 @@ private void testPegoutMinimumWithFeeVerification(Coin feePerKB, Coin value, boo // if shouldPegout true then value should be greater or equals than both required fee plus gap and min pegout value // if shouldPegout false then value should be smaller than any of those minimums Assertions.assertEquals(!shouldPegout, value.isLessThan(minValueWithGapAboveFee) || - value.isLessThan(bridgeConstants.getMinimumPegoutTxValueInSatoshis())); + value.isLessThan(bridgeConstants.getMinimumPegoutTxValue())); bridgeSupport.releaseBtc(buildReleaseRskTx(value)); diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSigHashTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSigHashTest.java index f2aa5fc235c..a0dfede33e9 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSigHashTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSigHashTest.java @@ -1,16 +1,11 @@ package co.rsk.peg; -import co.rsk.bitcoinj.core.Coin; -import co.rsk.bitcoinj.core.Context; -import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.bitcoinj.core.Sha256Hash; -import co.rsk.bitcoinj.core.TransactionOutput; -import co.rsk.bitcoinj.core.UTXO; +import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.wallet.Wallet; import co.rsk.blockchain.utils.BlockGenerator; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; import co.rsk.peg.bitcoin.BitcoinUtils; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; import co.rsk.peg.federation.Federation; import co.rsk.peg.federation.FederationArgs; import co.rsk.peg.federation.FederationFactory; @@ -27,23 +22,13 @@ import java.io.IOException; import java.time.Instant; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.TreeMap; +import java.util.*; import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; class BridgeSupportSigHashTest { @@ -75,10 +60,12 @@ private static Stream<Arguments> pegoutTxIndexArgsProvider() { @ParameterizedTest @MethodSource("pegoutTxIndexArgsProvider") void test_pegoutTxIndex_when_pegout_batch_is_created(ActivationConfig.ForBlock activations) throws IOException { + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); + Address federationAddress = genesisFederation.getAddress(); // Arrange List<UTXO> fedUTXOs = PegTestUtils.createUTXOs( 10, - bridgeMainnetConstants.getGenesisFederation().getAddress() + federationAddress ); when(provider.getNewFederationBtcUTXOs()) .thenReturn(fedUTXOs); @@ -123,7 +110,7 @@ void test_pegoutTxIndex_when_migration_tx_is_created(ActivationConfig.ForBlock a PegoutsWaitingForConfirmations pegoutsWaitingForConfirmations = provider.getPegoutsWaitingForConfirmations(); - Federation oldFederation = bridgeMainnetConstants.getGenesisFederation(); + Federation oldFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); long newFedCreationBlockNumber = 5L; FederationArgs newFederationArgs = new FederationArgs(FederationTestUtils.getFederationMembers(1), @@ -189,7 +176,7 @@ void test_pegoutTxIndex_when_migration_and_pegout_batch_tx_are_created(Activatio when(provider.getReleaseRequestQueue()) .thenReturn(new ReleaseRequestQueue(PegTestUtils.createReleaseRequestQueueEntries(3))); - Federation oldFederation = bridgeMainnetConstants.getGenesisFederation(); + Federation oldFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); long newFedCreationBlockNumber = 5L; FederationArgs newFederationArgs = new FederationArgs(FederationTestUtils.getFederationMembers(1), diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java index b0d30abd04b..956b39641b8 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java @@ -24,10 +24,10 @@ import co.rsk.bitcoinj.store.BlockStoreException; import co.rsk.bitcoinj.wallet.Wallet; import co.rsk.blockchain.utils.BlockGenerator; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeRegTestConstants; -import co.rsk.config.BridgeTestNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.peg.vote.ABICallElection; @@ -349,6 +349,7 @@ void getActivePowpegRedeemScript_before_RSKIP293_activation() { @Test void getActivePowpegRedeemScript_after_RSKIP293_activation() { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); when(activations.isActive(ConsensusRule.RSKIP293)).thenReturn(true); BridgeSupport bridgeSupport = bridgeSupportBuilder @@ -356,9 +357,11 @@ void getActivePowpegRedeemScript_after_RSKIP293_activation() { .withActivations(activations) .build(); + Script federationRedeemScript = genesisFederation.getRedeemScript(); + assertTrue(bridgeSupport.getActivePowpegRedeemScript().isPresent()); assertEquals( - bridgeConstantsRegtest.getGenesisFederation().getRedeemScript(), + federationRedeemScript, bridgeSupport.getActivePowpegRedeemScript().get() ); } @@ -575,16 +578,17 @@ void getBtcTxHashProcessedHeight() throws IOException { void eventLoggerLogLockBtc_before_rskip_146_activation() throws Exception { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(false); - BridgeEventLogger mockedEventLogger = mock(BridgeEventLogger.class); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); + BridgeStorageProvider mockBridgeStorageProvider = mock(BridgeStorageProvider.class); when(mockBridgeStorageProvider.getHeightIfBtcTxhashIsAlreadyProcessed(any(Sha256Hash.class))).thenReturn(Optional.empty()); LockWhitelist lockWhitelist = mock(LockWhitelist.class); when(lockWhitelist.isWhitelistedFor(any(Address.class), any(Coin.class), any(int.class))).thenReturn(true); when(mockBridgeStorageProvider.getLockWhitelist()).thenReturn(lockWhitelist); - when(mockBridgeStorageProvider.getNewFederation()).thenReturn(bridgeConstantsRegtest.getGenesisFederation()); + when(mockBridgeStorageProvider.getNewFederation()).thenReturn(genesisFederation); Block executionBlock = mock(Block.class); BtcBlockStoreWithCache.Factory btcBlockStoreFactory = mock(BtcBlockStoreWithCache.Factory.class); @@ -635,6 +639,8 @@ void eventLoggerLogLockBtc_after_rskip_146_activation() throws Exception { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(true); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); + BridgeEventLogger mockedEventLogger = mock(BridgeEventLogger.class); BridgeStorageProvider mockBridgeStorageProvider = mock(BridgeStorageProvider.class); @@ -643,7 +649,7 @@ void eventLoggerLogLockBtc_after_rskip_146_activation() throws Exception { LockWhitelist lockWhitelist = mock(LockWhitelist.class); when(lockWhitelist.isWhitelistedFor(any(Address.class), any(Coin.class), any(int.class))).thenReturn(true); when(mockBridgeStorageProvider.getLockWhitelist()).thenReturn(lockWhitelist); - when(mockBridgeStorageProvider.getNewFederation()).thenReturn(bridgeConstantsRegtest.getGenesisFederation()); + when(mockBridgeStorageProvider.getNewFederation()).thenReturn(genesisFederation); Block executionBlock = mock(Block.class); BtcBlockStoreWithCache.Factory btcBlockStoreFactory = mock(BtcBlockStoreWithCache.Factory.class); @@ -706,6 +712,7 @@ void eventLoggerLogPeginRejectionEvents_before_rskip_181_activation() throws Exc when(activations.isActive(ConsensusRule.RSKIP181)).thenReturn(false); BridgeEventLogger mockedEventLogger = mock(BridgeEventLogger.class); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); BridgeStorageProvider mockBridgeStorageProvider = mock(BridgeStorageProvider.class); when(mockBridgeStorageProvider.getHeightIfBtcTxhashIsAlreadyProcessed(any(Sha256Hash.class))).thenReturn(Optional.empty()); @@ -713,7 +720,7 @@ void eventLoggerLogPeginRejectionEvents_before_rskip_181_activation() throws Exc LockWhitelist lockWhitelist = mock(LockWhitelist.class); when(lockWhitelist.isWhitelistedFor(any(Address.class), any(Coin.class), any(int.class))).thenReturn(true); when(mockBridgeStorageProvider.getLockWhitelist()).thenReturn(lockWhitelist); - when(mockBridgeStorageProvider.getNewFederation()).thenReturn(bridgeConstantsRegtest.getGenesisFederation()); + when(mockBridgeStorageProvider.getNewFederation()).thenReturn(genesisFederation); Block executionBlock = mock(Block.class); BtcBlockStoreWithCache.Factory btcBlockStoreFactory = mock(BtcBlockStoreWithCache.Factory.class); @@ -773,6 +780,7 @@ void eventLoggerLogPeginRejectionEvents_after_rskip_181_activation() throws Exce when(activations.isActive(ConsensusRule.RSKIP181)).thenReturn(true); BridgeEventLogger mockedEventLogger = mock(BridgeEventLogger.class); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); BridgeStorageProvider mockBridgeStorageProvider = mock(BridgeStorageProvider.class); when(mockBridgeStorageProvider.getHeightIfBtcTxhashIsAlreadyProcessed(any(Sha256Hash.class))).thenReturn(Optional.empty()); @@ -780,7 +788,7 @@ void eventLoggerLogPeginRejectionEvents_after_rskip_181_activation() throws Exce LockWhitelist lockWhitelist = mock(LockWhitelist.class); when(lockWhitelist.isWhitelistedFor(any(Address.class), any(Coin.class), any(int.class))).thenReturn(true); when(mockBridgeStorageProvider.getLockWhitelist()).thenReturn(lockWhitelist); - when(mockBridgeStorageProvider.getNewFederation()).thenReturn(bridgeConstantsRegtest.getGenesisFederation()); + when(mockBridgeStorageProvider.getNewFederation()).thenReturn(genesisFederation); Block executionBlock = mock(Block.class); BtcBlockStoreWithCache.Factory btcBlockStoreFactory = mock(BtcBlockStoreWithCache.Factory.class); @@ -840,6 +848,7 @@ void eventLoggerLogPeginBtc_before_rskip_170_activation() throws Exception { when(activations.isActive(ConsensusRule.RSKIP170)).thenReturn(false); BridgeEventLogger mockedEventLogger = mock(BridgeEventLogger.class); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); BridgeStorageProvider mockBridgeStorageProvider = mock(BridgeStorageProvider.class); when(mockBridgeStorageProvider.getHeightIfBtcTxhashIsAlreadyProcessed(any(Sha256Hash.class))).thenReturn(Optional.empty()); @@ -847,7 +856,7 @@ void eventLoggerLogPeginBtc_before_rskip_170_activation() throws Exception { LockWhitelist lockWhitelist = mock(LockWhitelist.class); when(lockWhitelist.isWhitelistedFor(any(Address.class), any(Coin.class), any(int.class))).thenReturn(true); when(mockBridgeStorageProvider.getLockWhitelist()).thenReturn(lockWhitelist); - when(mockBridgeStorageProvider.getNewFederation()).thenReturn(bridgeConstantsRegtest.getGenesisFederation()); + when(mockBridgeStorageProvider.getNewFederation()).thenReturn(genesisFederation); Block executionBlock = mock(Block.class); BtcBlockStoreWithCache.Factory btcBlockStoreFactory = mock(BtcBlockStoreWithCache.Factory.class); @@ -901,6 +910,7 @@ void eventLoggerLogPeginBtc_after_rskip_170_activation() throws Exception { when(activations.isActive(ConsensusRule.RSKIP170)).thenReturn(true); BridgeEventLogger mockedEventLogger = mock(BridgeEventLogger.class); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); BridgeStorageProvider mockBridgeStorageProvider = mock(BridgeStorageProvider.class); when(mockBridgeStorageProvider.getHeightIfBtcTxhashIsAlreadyProcessed(any(Sha256Hash.class))).thenReturn(Optional.empty()); @@ -908,7 +918,7 @@ void eventLoggerLogPeginBtc_after_rskip_170_activation() throws Exception { LockWhitelist lockWhitelist = mock(LockWhitelist.class); when(lockWhitelist.isWhitelistedFor(any(Address.class), any(Coin.class), any(int.class))).thenReturn(true); when(mockBridgeStorageProvider.getLockWhitelist()).thenReturn(lockWhitelist); - when(mockBridgeStorageProvider.getNewFederation()).thenReturn(bridgeConstantsRegtest.getGenesisFederation()); + when(mockBridgeStorageProvider.getNewFederation()).thenReturn(genesisFederation); Block executionBlock = mock(Block.class); BtcBlockStoreWithCache.Factory btcBlockStoreFactory = mock(BtcBlockStoreWithCache.Factory.class); @@ -1428,7 +1438,7 @@ void callProcessFundsMigration_is_migrating_before_rskip_146_activation() throws BridgeEventLogger bridgeEventLogger = mock(BridgeEventLogger.class); - Federation oldFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation oldFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); FederationArgs newFederationArgs = new FederationArgs(FederationTestUtils.getFederationMembers(1), Instant.EPOCH, @@ -1493,7 +1503,7 @@ void callProcessFundsMigration_is_migrating_after_rskip_146_activation() throws BridgeEventLogger bridgeEventLogger = mock(BridgeEventLogger.class); - Federation oldFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation oldFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); FederationArgs newFederationArgs = new FederationArgs(FederationTestUtils.getFederationMembers(1), Instant.EPOCH, @@ -1560,7 +1570,7 @@ void callProcessFundsMigration_is_migrated_before_rskip_146_activation() throws BridgeEventLogger bridgeEventLogger = mock(BridgeEventLogger.class); - Federation oldFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation oldFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); FederationArgs newFederationArgs = new FederationArgs(FederationTestUtils.getFederationMembers(1), Instant.EPOCH, @@ -1625,7 +1635,7 @@ void callProcessFundsMigration_is_migrated_after_rskip_146_activation() throws I BridgeEventLogger bridgeEventLogger = mock(BridgeEventLogger.class); - Federation oldFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation oldFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); FederationArgs newFederationArgs = new FederationArgs(FederationTestUtils.getFederationMembers(1), Instant.EPOCH, @@ -1691,7 +1701,7 @@ void updateFederationCreationBlockHeights_before_rskip_186_activation() throws I BridgeEventLogger bridgeEventLogger = mock(BridgeEventLogger.class); - Federation oldFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation oldFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); FederationArgs newFederationArgs = new FederationArgs(FederationTestUtils.getFederationMembers(1), Instant.EPOCH, @@ -1756,7 +1766,7 @@ void updateFederationCreationBlockHeights_after_rskip_186_activation() throws IO BridgeEventLogger bridgeEventLogger = mock(BridgeEventLogger.class); - Federation oldFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation oldFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); FederationArgs newFederationArgs = new FederationArgs(FederationTestUtils.getFederationMembers(1), Instant.EPOCH, @@ -2140,7 +2150,7 @@ void rskTxWaitingForSignature_fail_adding_an_already_existing_key_after_rskip_37 ActivationConfig.ForBlock fingerrootActivations = ActivationConfigsForTest.fingerroot500().forBlock(0); // Set state to make concur a pegout migration tx and pegout batch creation on the same updateCollection - Federation oldFederation = bridgeConstants.getGenesisFederation(); + Federation oldFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); FederationArgs newFederationArgs = new FederationArgs(FederationTestUtils.getFederationMembers(1), Instant.EPOCH, 5L, @@ -5821,9 +5831,11 @@ void validationsForRegisterBtcTransaction_invalid_block_merkle_root() throws IOE @Test void validationsForRegisterBtcTransaction_successful() throws IOException, BlockStoreException, BridgeIllegalArgumentException { BridgeStorageProvider mockBridgeStorageProvider = mock(BridgeStorageProvider.class); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); + when(mockBridgeStorageProvider.getHeightIfBtcTxhashIsAlreadyProcessed(any(Sha256Hash.class))).thenReturn(Optional.empty()); - when(mockBridgeStorageProvider.getNewFederation()).thenReturn(bridgeConstantsRegtest.getGenesisFederation()); + when(mockBridgeStorageProvider.getNewFederation()).thenReturn(genesisFederation); BtcBlockStoreWithCache.Factory btcBlockStoreFactory = mock(BtcBlockStoreWithCache.Factory.class); @@ -5964,9 +5976,11 @@ void processPegIn_errorParsingPeginInstructions_beforeRskip170_dontRefundSender( when(activations.isActive(ConsensusRule.RSKIP170)).thenReturn(false); Repository repository = createRepository(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); + Address federationAddress = genesisFederation.getAddress(); BtcTransaction btcTx = new BtcTransaction(btcRegTestParams); - btcTx.addOutput(Coin.COIN.multiply(10), bridgeConstantsRegtest.getGenesisFederation().getAddress()); + btcTx.addOutput(Coin.COIN.multiply(10), federationAddress); btcTx.addInput(PegTestUtils.createHash(1), 0, new Script(new byte[]{})); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); @@ -6014,9 +6028,11 @@ void processPegIn_errorParsingPeginInstructions_afterRskip170_refundSender() ECKey key = ECKey.fromPublicOnly(srcKey1.getPubKey()); RskAddress rskAddress = new RskAddress(key.getAddress()); Address btcSenderAddress = srcKey1.toAddress(btcRegTestParams); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); + Address federationAddress = genesisFederation.getAddress(); BtcTransaction btcTx = new BtcTransaction(btcRegTestParams); - btcTx.addOutput(Coin.COIN.multiply(10), bridgeConstantsRegtest.getGenesisFederation().getAddress()); + btcTx.addOutput(Coin.COIN.multiply(10), federationAddress); btcTx.addInput(PegTestUtils.createHash(1), 0, new Script(new byte[]{})); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); @@ -6348,9 +6364,11 @@ private void assertRefundInProcessPegInVersionLegacy( ECKey key = ECKey.fromPublicOnly(srcKey1.getPubKey()); Address btcAddress = srcKey1.toAddress(btcRegTestParams); RskAddress rskAddress = new RskAddress(key.getAddress()); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); + Address federationAddress = genesisFederation.getAddress(); BtcTransaction btcTx = new BtcTransaction(btcRegTestParams); - btcTx.addOutput(Coin.COIN.multiply(10), bridgeConstantsRegtest.getGenesisFederation().getAddress()); + btcTx.addOutput(Coin.COIN.multiply(10), federationAddress); btcTx.addInput(PegTestUtils.createHash(1), 0, new Script(new byte[]{})); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); @@ -6589,7 +6607,7 @@ private static Stream<Arguments> getEstimatedFeesForNextPegOutEventArgsProvider_ PegTestUtils.createRandomBtcECKeys(7) ); - Federation standardFed = bridgeConstants.getGenesisFederation(); + Federation standardFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); ActivationConfig.ForBlock preRSKIP271_activations = mock(ActivationConfig.ForBlock.class); when(preRSKIP271_activations.isActive(ConsensusRule.RSKIP271)).thenReturn(false); @@ -6603,21 +6621,21 @@ private static Stream<Arguments> getEstimatedFeesForNextPegOutEventArgsProvider_ // active fed is standard and pegoutRequestsCount is equal to zero Arguments.of( preRSKIP271_activations, - standardFed, + standardFederation, 0, Coin.valueOf(0L) ), // active fed is standard and pegoutRequestsCount is equal to one Arguments.of( preRSKIP271_activations, - standardFed, + standardFederation, 1, Coin.valueOf(0L) ), // active fed is standard and there are many pegout requests Arguments.of( preRSKIP271_activations, - standardFed, + standardFederation, 150, Coin.valueOf(0L) ), @@ -6651,7 +6669,7 @@ private static Stream<Arguments> getEstimatedFeesForNextPegOutEventArgsProvider_ PegTestUtils.createRandomBtcECKeys(7) ); - Federation standardFed = bridgeConstants.getGenesisFederation(); + Federation standardFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); ActivationConfig.ForBlock preRSKIP385_activations = mock(ActivationConfig.ForBlock.class); when(preRSKIP385_activations.isActive(ConsensusRule.RSKIP271)).thenReturn(true); @@ -6669,21 +6687,21 @@ private static Stream<Arguments> getEstimatedFeesForNextPegOutEventArgsProvider_ // active fed is standard and pegoutRequestsCount is equal to zero Arguments.of( preRSKIP385_activations, - standardFed, + standardFederation, 0, Coin.valueOf(0L) ), // active fed is standard and pegoutRequestsCount is equal to one Arguments.of( preRSKIP385_activations, - standardFed, + standardFederation, 1, Coin.valueOf(bridgeConstants instanceof BridgeMainNetConstants? 237000L: 68600L) ), // active fed is standard and there are many pegout requests Arguments.of( preRSKIP385_activations, - standardFed, + standardFederation, 150, Coin.valueOf(bridgeConstants instanceof BridgeMainNetConstants? 713800L: 545400L) ), @@ -6717,7 +6735,7 @@ private static Stream<Arguments> getEstimatedFeesForNextPegOutEventArgsProvider_ when(postRSKIP385_activations.isActive(ConsensusRule.RSKIP271)).thenReturn(true); when(postRSKIP385_activations.isActive(ConsensusRule.RSKIP385)).thenReturn(true); - Federation standardFed = bridgeConstants.getGenesisFederation(); + Federation standardFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); List<FederationMember> members = FederationMember.getFederationMembersFromKeys( PegTestUtils.createRandomBtcECKeys(7) ); @@ -6734,21 +6752,21 @@ private static Stream<Arguments> getEstimatedFeesForNextPegOutEventArgsProvider_ // active fed is standard and pegoutRequestsCount is equal to zero Arguments.of( postRSKIP385_activations, - standardFed, + standardFederation, 0, Coin.valueOf(bridgeConstants instanceof BridgeMainNetConstants? 233800L: 65400L) ), // active fed is standard and pegoutRequestsCount is equal to one Arguments.of( postRSKIP385_activations, - standardFed, + standardFederation, 1, Coin.valueOf(bridgeConstants instanceof BridgeMainNetConstants? 237000L: 68600L) ), // active fed is standard and there are many pegout requests Arguments.of( postRSKIP385_activations, - standardFed, + standardFederation, 150, Coin.valueOf(bridgeConstants instanceof BridgeMainNetConstants? 713800L: 545400L) ), @@ -6834,6 +6852,9 @@ private void assertRefundInProcessPegInVersion1( List<ConsensusRule> consensusRules) throws IOException, RegisterBtcTransactionException, PeginInstructionsException { + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); + Address federationAddress = genesisFederation.getAddress(); + // Arrange ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); for (ConsensusRule consensusRule : consensusRules) { @@ -6851,7 +6872,7 @@ private void assertRefundInProcessPegInVersion1( } BtcTransaction btcTx = new BtcTransaction(btcRegTestParams); - btcTx.addOutput(Coin.COIN.multiply(10), bridgeConstantsRegtest.getGenesisFederation().getAddress()); + btcTx.addOutput(Coin.COIN.multiply(10), federationAddress); btcTx.addInput(PegTestUtils.createHash(1), 0, new Script(new byte[]{})); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java index 5f84e1f873b..8987ff2b210 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java @@ -47,9 +47,9 @@ import co.rsk.bitcoinj.store.BlockStoreException; import co.rsk.bitcoinj.wallet.Wallet; import co.rsk.blockchain.utils.BlockGenerator; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeRegTestConstants; -import co.rsk.config.BridgeTestNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import co.rsk.core.BlockDifficulty; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; @@ -386,7 +386,7 @@ void callUpdateCollectionsGenerateEventLog() throws IOException { @Test void callUpdateCollectionsFundsEnoughForJustTheSmallerTx() throws IOException { // Federation is the genesis federation ATM - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); Repository repository = createRepository(); Repository track = repository.startTracking(); @@ -404,7 +404,7 @@ void callUpdateCollectionsFundsEnoughForJustTheSmallerTx() throws IOException { Coin.valueOf(12, 0), 0, false, - ScriptBuilder.createOutputScript(federation.getAddress()) + ScriptBuilder.createOutputScript(genesisFederation.getAddress()) )); provider0.save(); @@ -458,7 +458,7 @@ void callUpdateCollectionsFundsEnoughForJustTheSmallerTx() throws IOException { @Test void callUpdateCollectionsThrowsCouldNotAdjustDownwards() throws IOException { // Federation is the genesis federation ATM - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); Repository repository = createRepository(); Repository track = repository.startTracking(); @@ -473,7 +473,7 @@ void callUpdateCollectionsThrowsCouldNotAdjustDownwards() throws IOException { Coin.valueOf(1000000), 0, false, - ScriptBuilder.createOutputScript(federation.getAddress()) + ScriptBuilder.createOutputScript(genesisFederation.getAddress()) )); provider0.save(); @@ -538,7 +538,7 @@ void callUpdateCollectionsThrowsCouldNotAdjustDownwards() throws IOException { @Test void callUpdateCollectionsThrowsExceededMaxTransactionSize() throws IOException { // Federation is the genesis federation ATM - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); Repository repository = createRepository(); Repository track = repository.startTracking(); @@ -553,7 +553,7 @@ void callUpdateCollectionsThrowsExceededMaxTransactionSize() throws IOException Coin.CENT, 0, false, - ScriptBuilder.createOutputScript(federation.getAddress()) + ScriptBuilder.createOutputScript(genesisFederation.getAddress()) )); } @@ -618,7 +618,7 @@ void callUpdateCollectionsThrowsExceededMaxTransactionSize() throws IOException @Test void minimumProcessFundsMigrationValue() throws IOException { - Federation oldFederation = bridgeConstants.getGenesisFederation(); + Federation oldFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); BtcECKey key = new BtcECKey(new SecureRandom()); FederationMember member = new FederationMember(key, new ECKey(), new ECKey()); FederationArgs newFederationArgs = new FederationArgs( @@ -712,7 +712,7 @@ void minimumProcessFundsMigrationValue() throws IOException { @Test void callUpdateCollectionsChangeGetsOutOfDust() throws IOException { // Federation is the genesis federation ATM - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); Map<byte[], BigInteger> preMineMap = new HashMap<>(); preMineMap.put(PrecompiledContracts.BRIDGE_ADDR.getBytes(), LIMIT_MONETARY_BASE.asBigInteger()); @@ -737,7 +737,7 @@ void callUpdateCollectionsChangeGetsOutOfDust() throws IOException { BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, activationsBeforeForks); provider0.getReleaseRequestQueue().add(new BtcECKey().toAddress(btcParams), Coin.COIN); - provider0.getNewFederationBtcUTXOs().add(new UTXO(PegTestUtils.createHash(), 1, Coin.COIN.add(Coin.valueOf(100)), 0, false, ScriptBuilder.createOutputScript(federation.getAddress()))); + provider0.getNewFederationBtcUTXOs().add(new UTXO(PegTestUtils.createHash(), 1, Coin.COIN.add(Coin.valueOf(100)), 0, false, ScriptBuilder.createOutputScript(genesisFederation.getAddress()))); provider0.save(); @@ -1276,7 +1276,7 @@ void registerBtcTransactionTxNotLockNorReleaseTx() throws BlockStoreException, A @Test void registerBtcTransactionReleaseTx() throws BlockStoreException, AddressFormatException, IOException, BridgeIllegalArgumentException { // Federation is the genesis federation ATM - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); Repository repository = createRepository(); repository.addBalance(PrecompiledContracts.BRIDGE_ADDR, LIMIT_MONETARY_BASE); Repository track = repository.startTracking(); @@ -1287,29 +1287,29 @@ void registerBtcTransactionReleaseTx() throws BlockStoreException, AddressFormat BtcTransaction tx = new BtcTransaction(this.btcParams); Address address = ScriptBuilder.createP2SHOutputScript(2, Lists.newArrayList(new BtcECKey(), new BtcECKey(), new BtcECKey())).getToAddress(btcParams); tx.addOutput(Coin.COIN, address); - Address address2 = federation.getAddress(); + Address address2 = genesisFederation.getAddress(); tx.addOutput(Coin.COIN, address2); // Create previous tx BtcTransaction prevTx = new BtcTransaction(btcParams); - TransactionOutput prevOut = new TransactionOutput(btcParams, prevTx, Coin.FIFTY_COINS, federation.getAddress()); + TransactionOutput prevOut = new TransactionOutput(btcParams, prevTx, Coin.FIFTY_COINS, genesisFederation.getAddress()); prevTx.addOutput(prevOut); // Create tx input tx.addInput(prevOut); // Create tx input base script sig - Script scriptSig = PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation(federation); + Script scriptSig = PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation(genesisFederation); // Create sighash - Script redeemScript = ScriptBuilder.createRedeemScript(federation.getNumberOfSignaturesRequired(), federation.getBtcPublicKeys()); + Script redeemScript = ScriptBuilder.createRedeemScript(genesisFederation.getNumberOfSignaturesRequired(), genesisFederation.getBtcPublicKeys()); Sha256Hash sighash = tx.hashForSignature(0, redeemScript, BtcTransaction.SigHash.ALL, false); // Sign by federator 0 BtcECKey.ECDSASignature sig0 = BridgeRegTestConstants.REGTEST_FEDERATION_PRIVATE_KEYS.get(0).sign(sighash); TransactionSignature txSig0 = new TransactionSignature(sig0, BtcTransaction.SigHash.ALL, false); - int sigIndex0 = scriptSig.getSigInsertionIndex(sighash, federation.getBtcPublicKeys().get(0)); + int sigIndex0 = scriptSig.getSigInsertionIndex(sighash, genesisFederation.getBtcPublicKeys().get(0)); scriptSig = ScriptBuilder.updateScriptWithSignature(scriptSig, txSig0.encodeToBitcoin(), sigIndex0, 1, 1); // Sign by federator 1 BtcECKey.ECDSASignature sig1 = BridgeRegTestConstants.REGTEST_FEDERATION_PRIVATE_KEYS.get(1).sign(sighash); TransactionSignature txSig1 = new TransactionSignature(sig1, BtcTransaction.SigHash.ALL, false); - int sigIndex1 = scriptSig.getSigInsertionIndex(sighash, federation.getBtcPublicKeys().get(1)); + int sigIndex1 = scriptSig.getSigInsertionIndex(sighash, genesisFederation.getBtcPublicKeys().get(1)); scriptSig = ScriptBuilder.updateScriptWithSignature(scriptSig, txSig1.encodeToBitcoin(), sigIndex1, 1, 1); // Set scipt sign to tx input tx.getInput(0).setScriptSig(scriptSig); @@ -1794,10 +1794,13 @@ void getFederationMethods_genesis() throws IOException { NetworkParameters.fromID(NetworkParameters.ID_REGTEST) ); Federation activeFederation = FederationFactory.buildStandardMultiSigFederation( - activeFedArgs + activeFedArgs ); - - FederationArgs genesisFedArgs = new FederationArgs(FederationTestUtils.getFederationMembers(6), + FederationArgs genesisFedArgs = new FederationArgs(FederationTestUtils.getFederationMembersWithKeys( + Stream.iterate(1, i -> i + 1) + .limit(6) + .map(i -> BtcECKey.fromPrivate(BigInteger.valueOf((i) * 100))) + .collect(Collectors.toList())), Instant.ofEpochMilli(1000), 0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST) @@ -1810,7 +1813,8 @@ void getFederationMethods_genesis() throws IOException { Assertions.assertEquals(6, bridgeSupport.getFederationSize().intValue()); Assertions.assertEquals(4, bridgeSupport.getFederationThreshold().intValue()); Assertions.assertEquals(genesisFederation.getAddress().toString(), bridgeSupport.getFederationAddress().toString()); - List<FederationMember> members = FederationTestUtils.getFederationMembers(6); + + List<FederationMember> members = genesisFederation.getMembers(); for (int i = 0; i < 6; i++) { Assertions.assertTrue(Arrays.equals(members.get(i).getBtcPublicKey().getPubKey(), bridgeSupport.getFederatorPublicKey(i))); Assertions.assertTrue(Arrays.equals(members.get(i).getBtcPublicKey().getPubKey(), bridgeSupport.getFederatorPublicKeyOfType(i, FederationMember.KeyType.BTC))); @@ -3909,7 +3913,10 @@ private BridgeSupport getBridgeSupportWithMocksForFederationTests( BridgeEventLogger eventLogger) throws IOException { BridgeConstants constantsMock = mock(BridgeConstants.class); - when(constantsMock.getGenesisFederation()).thenReturn((StandardMultisigFederation) mockedGenesisFederation); + if (mockedGenesisFederation != null) { + when(constantsMock.getGenesisFederationCreationTime()).thenReturn(mockedGenesisFederation.getCreationTime()); + when(constantsMock.getGenesisFederationPublicKeys()).thenReturn(mockedGenesisFederation.getBtcPublicKeys()); + } when(constantsMock.getBtcParams()).thenReturn(NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); when(constantsMock.getFederationChangeAuthorizer()).thenReturn(bridgeConstants.getFederationChangeAuthorizer()); diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeTest.java index 6b5e92d3693..2538fd550d8 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeTest.java @@ -9,10 +9,9 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.store.BlockStoreException; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeRegTestConstants; -import co.rsk.config.BridgeTestNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.peg.bitcoin.BitcoinTestUtils; @@ -50,6 +49,7 @@ class BridgeTest { private NetworkParameters networkParameters; private BridgeBuilder bridgeBuilder; + private final BridgeConstants bridgeMainNetConstants = BridgeMainNetConstants.getInstance(); @BeforeEach void resetConfigToMainnet() { @@ -76,7 +76,8 @@ void getActivePowpegRedeemScript_after_RSKIP293_activation() throws VMException CallTransaction.Function getActivePowpegRedeemScriptFunction = BridgeMethods.GET_ACTIVE_POWPEG_REDEEM_SCRIPT.getFunction(); BridgeSupport bridgeSupportMock = mock(BridgeSupport.class); - Script activePowpegRedeemScript = BridgeRegTestConstants.getInstance().getGenesisFederation().getRedeemScript(); + Script activePowpegRedeemScript = FederationTestUtils.getGenesisFederation( + bridgeMainNetConstants).getRedeemScript(); when(bridgeSupportMock.getActivePowpegRedeemScript()).thenReturn( Optional.of(activePowpegRedeemScript) ); @@ -762,10 +763,12 @@ void receiveHeader_bridgeSupport_Exception() throws IOException, BlockStoreExcep @Test void receiveHeaders_after_RSKIP200_notFederation() { ActivationConfig activationConfig = ActivationConfigsForTest.iris300(); - BridgeSupport bridgeSupportMock = mock(BridgeSupport.class); + Federation genesisFederation = FederationTestUtils.getGenesisFederation( + bridgeMainNetConstants); + when(bridgeSupportMock.getRetiringFederation()).thenReturn(null); - when(bridgeSupportMock.getActiveFederation()).thenReturn(BridgeRegTestConstants.getInstance().getGenesisFederation()); + when(bridgeSupportMock.getActiveFederation()).thenReturn(genesisFederation); Transaction txMock = mock(Transaction.class); RskAddress txSender = new RskAddress(new ECKey().getAddress()); diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeTestIntegration.java b/rskj-core/src/test/java/co/rsk/peg/BridgeTestIntegration.java index 2a06c2cd3f5..69a0ba40040 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeTestIntegration.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeTestIntegration.java @@ -53,6 +53,7 @@ import co.rsk.peg.vote.ABICallSpec; import co.rsk.peg.federation.Federation; import co.rsk.peg.federation.FederationMember; +import co.rsk.peg.federation.FederationTestUtils; import co.rsk.test.builders.BlockChainBuilder; import org.bouncycastle.util.encoders.Hex; import org.ethereum.TestUtils; @@ -105,8 +106,8 @@ import co.rsk.bitcoinj.script.ScriptBuilder; import co.rsk.bitcoinj.store.BlockStoreException; import co.rsk.blockchain.utils.BlockGenerator; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.config.RskSystemProperties; import co.rsk.config.TestSystemProperties; import co.rsk.core.BlockDifficulty; @@ -133,7 +134,7 @@ @MockitoSettings(strictness = Strictness.LENIENT) public class BridgeTestIntegration { private static NetworkParameters networkParameters; - private static BridgeRegTestConstants bridgeConstants; + private static BridgeConstants bridgeRegTestConstants; private static final BigInteger AMOUNT = new BigInteger("1000000000000000000"); private static final BigInteger NONCE = new BigInteger("0"); @@ -152,8 +153,8 @@ public class BridgeTestIntegration { @BeforeAll static void setUpBeforeClass() { - bridgeConstants = BridgeRegTestConstants.getInstance(); - networkParameters = bridgeConstants.getBtcParams(); + bridgeRegTestConstants = BridgeRegTestConstants.getInstance(); + networkParameters = bridgeRegTestConstants.getBtcParams(); BtcECKey fedBTCPrivateKey = BridgeRegTestConstants.REGTEST_FEDERATION_PRIVATE_KEYS.get(0); fedECPrivateKey = ECKey.fromPrivate(fedBTCPrivateKey.getPrivKey()); } @@ -177,7 +178,7 @@ void callUpdateCollectionsWithSignatureNotFromFederation() throws IOException { Repository repository = createRepository(); Repository track = repository.startTracking(); - BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, activationConfigAll); + BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeRegTestConstants, activationConfigAll); provider0.getPegoutsWaitingForConfirmations().add(tx1, 1L, PegTestUtils.createHash3(0)); provider0.save(); @@ -199,8 +200,8 @@ void callUpdateCollectionsWithSignatureNotFromFederation() throws IOException { rskTx.sign(new ECKey().getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -218,14 +219,14 @@ void callUpdateCollectionsWithSignatureNotFromFederation() throws IOException { @Test void callUpdateCollectionsWithTransactionsWaitingForConfirmation() throws IOException, VMException { - BtcTransaction tx1 = createTransaction(2, bridgeConstants.getMinimumPegoutTxValueInSatoshis()); - BtcTransaction tx2 = createTransaction(3, bridgeConstants.getMinimumPegoutTxValueInSatoshis().add(Coin.MILLICOIN)); - BtcTransaction tx3 = createTransaction(4, bridgeConstants.getMinimumPegoutTxValueInSatoshis().add(Coin.MILLICOIN).add(Coin.MILLICOIN)); + BtcTransaction tx1 = createTransaction(2, bridgeRegTestConstants.getMinimumPegoutTxValue()); + BtcTransaction tx2 = createTransaction(3, bridgeRegTestConstants.getMinimumPegoutTxValue().add(Coin.MILLICOIN)); + BtcTransaction tx3 = createTransaction(4, bridgeRegTestConstants.getMinimumPegoutTxValue().add(Coin.MILLICOIN).add(Coin.MILLICOIN)); Repository repository = createRepository(); Repository track = repository.startTracking(); - BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, activationConfig.forBlock(0)); + BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeRegTestConstants, activationConfig.forBlock(0)); provider0.getPegoutsWaitingForConfirmations().add(tx1, 1L); provider0.getPegoutsWaitingForConfirmations().add(tx2, 2L); @@ -249,8 +250,8 @@ void callUpdateCollectionsWithTransactionsWaitingForConfirmation() throws IOExce rskTx.sign(fedECPrivateKey.getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); @@ -266,7 +267,7 @@ void callUpdateCollectionsWithTransactionsWaitingForConfirmation() throws IOExce track.commit(); //Reusing same storage configuration as the height doesn't affect storage configurations for releases. - BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, activationConfigAll); + BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeRegTestConstants, activationConfigAll); Assertions.assertEquals(3, provider.getPegoutsWaitingForConfirmations().getEntries().size()); Assertions.assertEquals(0, provider.getPegoutsWaitingForSignatures().size()); @@ -274,14 +275,14 @@ void callUpdateCollectionsWithTransactionsWaitingForConfirmation() throws IOExce @Test void callUpdateCollectionsWithTransactionsWaitingForConfirmationWithEnoughConfirmations() throws IOException, VMException { - BtcTransaction tx1 = createTransaction(2, bridgeConstants.getMinimumPegoutTxValueInSatoshis()); - BtcTransaction tx2 = createTransaction(3, bridgeConstants.getMinimumPegoutTxValueInSatoshis().add(Coin.MILLICOIN)); - BtcTransaction tx3 = createTransaction(4, bridgeConstants.getMinimumPegoutTxValueInSatoshis().add(Coin.MILLICOIN).add(Coin.MILLICOIN)); + BtcTransaction tx1 = createTransaction(2, bridgeRegTestConstants.getMinimumPegoutTxValue()); + BtcTransaction tx2 = createTransaction(3, bridgeRegTestConstants.getMinimumPegoutTxValue().add(Coin.MILLICOIN)); + BtcTransaction tx3 = createTransaction(4, bridgeRegTestConstants.getMinimumPegoutTxValue().add(Coin.MILLICOIN).add(Coin.MILLICOIN)); Repository repository = createRepository(); Repository track = repository.startTracking(); - BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, activationConfig.forBlock(0)); + BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeRegTestConstants, activationConfig.forBlock(0)); provider0.getPegoutsWaitingForConfirmations().add(tx1, 1L); provider0.getPegoutsWaitingForConfirmations().add(tx2, 2L); @@ -312,8 +313,8 @@ void callUpdateCollectionsWithTransactionsWaitingForConfirmationWithEnoughConfir world.getBlockStore().saveBlock(blocks.get(1), new BlockDifficulty(BigInteger.ONE), true); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -325,7 +326,7 @@ void callUpdateCollectionsWithTransactionsWaitingForConfirmationWithEnoughConfir track.commit(); // reusing same storage configuration as the height doesn't affect storage configurations for releases. - BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, activationConfigAll); + BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeRegTestConstants, activationConfigAll); Assertions.assertEquals(2, provider.getPegoutsWaitingForConfirmations().getEntries().size()); Assertions.assertEquals(1, provider.getPegoutsWaitingForSignatures().size()); @@ -337,8 +338,8 @@ void sendNoRskTx() throws IOException { Repository track = repository.startTracking(); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -374,7 +375,7 @@ void sendNoBlockHeader() throws BlockStoreException, IOException, VMException { BridgeSupportFactory bridgeSupportFactory = mock(BridgeSupportFactory.class); BridgeSupport bridgeSupport = mock(BridgeSupport.class); when(bridgeSupportFactory.newInstance(any(), any(), any(), any())).thenReturn(bridgeSupport); - when(bridgeSupport.getActiveFederation()).thenReturn(bridgeConstants.getGenesisFederation()); + when(bridgeSupport.getActiveFederation()).thenReturn(FederationTestUtils.getGenesisFederation(bridgeRegTestConstants)); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactory, signatureCache); bridge.init(rskTx, getGenesisBlock(), track, null, null, null); @@ -406,8 +407,8 @@ void sendOrphanBlockHeader() throws VMException { rskTx.sign(fedECPrivateKey.getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactory, signatureCache); @@ -437,8 +438,8 @@ void sendOrphanBlockHeader() throws VMException { @Test void executeWithFunctionSignatureLengthTooShortBeforeRskip88() throws VMException { BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactory, signatureCache); @@ -452,8 +453,8 @@ void executeWithFunctionSignatureLengthTooShortAfterRskip88() { doReturn(true).when(activationConfig).isActive(eq(RSKIP88), anyLong()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache ); @@ -478,8 +479,8 @@ void executeWithFunctionSignatureLengthTooShortAfterRskip88() { @Test void executeWithInexistentFunctionBeforeRskip88() throws VMException { BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -494,8 +495,8 @@ void executeWithInexistentFunctionAfterRskip88() { doReturn(true).when(activationConfig).isActive(eq(RSKIP88), anyLong()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -526,8 +527,8 @@ void receiveHeadersNotFromTheFederation() { rskTx.sign(new ECKey().getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -561,8 +562,8 @@ void receiveHeadersWithNonParseableHeader() throws VMException { rskTx.sign(fedECPrivateKey.getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -621,7 +622,7 @@ void receiveHeadersWithCorrectSizeHeaders() throws Exception { try (MockedStatic<BridgeUtils> bridgeUtilsMocked = mockStatic(BridgeUtils.class)) { bridgeUtilsMocked.when(() -> BridgeUtils.isFromFederateMember(any(), any(), any())).thenReturn(true); - MessageSerializer serializer = bridgeConstants.getBtcParams().getDefaultSerializer(); + MessageSerializer serializer = bridgeRegTestConstants.getBtcParams().getDefaultSerializer(); MessageSerializer spySerializer = Mockito.spy(serializer); NetworkParameters btcParamsMock = mock(NetworkParameters.class); @@ -783,8 +784,8 @@ void receiveHeadersWithHugeDeclaredTransactionsSize() throws VMException { rskTx.sign(fedECPrivateKey.getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactory, signatureCache); @@ -842,8 +843,8 @@ void registerBtcTransactionWithNonParseableTx() throws VMException { rskTx.sign(fedECPrivateKey.getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactory, signatureCache); @@ -901,8 +902,8 @@ void registerBtcTransactionWithNonParseableMerkleeProof1() throws Exception { rskTx.sign(fedECPrivateKey.getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -937,8 +938,8 @@ void registerBtcTransactionWithNonParseableMerkleeProof2() throws VMException { rskTx.sign(fedECPrivateKey.getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -973,8 +974,8 @@ void registerBtcTransactionWithHugeDeclaredSizeMerkleeProof() throws VMException rskTx.sign(fedECPrivateKey.getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1016,13 +1017,13 @@ public void bitcoinSerializeToStream(OutputStream stream) throws IOException { @Test void getFederationAddress() throws Exception { // Case with genesis federation - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeRegTestConstants); Repository repository = createRepository(); Repository track = repository.startTracking(); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1032,7 +1033,7 @@ void getFederationAddress() throws Exception { byte[] data = Bridge.GET_FEDERATION_ADDRESS.encode(); - Assertions.assertArrayEquals(Bridge.GET_FEDERATION_ADDRESS.encodeOutputs(federation.getAddress().toString()), bridge.execute(data)); + Assertions.assertArrayEquals(Bridge.GET_FEDERATION_ADDRESS.encodeOutputs(genesisFederation.getAddress().toString()), bridge.execute(data)); } @Test @@ -1041,8 +1042,8 @@ void getMinimumLockTxValue() throws Exception { Repository track = repository.startTracking(); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1052,7 +1053,7 @@ void getMinimumLockTxValue() throws Exception { byte[] data = Bridge.GET_MINIMUM_LOCK_TX_VALUE.encode(); - Assertions.assertArrayEquals(Bridge.GET_MINIMUM_LOCK_TX_VALUE.encodeOutputs(bridgeConstants.getMinimumPeginTxValue(activationConfig.forBlock(0)).value), bridge.execute(data)); + Assertions.assertArrayEquals(Bridge.GET_MINIMUM_LOCK_TX_VALUE.encodeOutputs(bridgeRegTestConstants.getMinimumPeginTxValue(activationConfig.forBlock(0)).value), bridge.execute(data)); } @Test @@ -1073,8 +1074,8 @@ void addSignatureNotFromFederation() throws Exception { rskTx.sign(new ECKey().getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1112,8 +1113,8 @@ void addSignatureWithNonParseablePublicKey() throws Exception { rskTx.sign(fedECPrivateKey.getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1146,8 +1147,8 @@ void addSignatureWithEmptySignatureArray() throws Exception { rskTx.sign(fedECPrivateKey.getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1180,8 +1181,8 @@ void addSignatureWithNonParseableSignature() throws Exception { rskTx.sign(fedECPrivateKey.getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1214,8 +1215,8 @@ void addSignatureWithNonParseableRskTx() throws Exception { rskTx.sign(fedECPrivateKey.getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1338,8 +1339,8 @@ void getBtcBlockchainBlockLocatorAfterRskip88And89Fork() { Repository track = repository.startTracking(); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1361,8 +1362,8 @@ void getGasForDataFreeTx() { activationConfig = ActivationConfigsForTest.bridgeUnitTest(); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1449,8 +1450,8 @@ void getGasForDataGetMinimumLockTxValue() { @Test void isBtcTxHashAlreadyProcessed_normalFlow() throws IOException, VMException { BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1477,8 +1478,8 @@ void isBtcTxHashAlreadyProcessed_normalFlow() throws IOException, VMException { @Test void isBtcTxHashAlreadyProcessed_exception() throws IOException { BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1498,8 +1499,8 @@ void isBtcTxHashAlreadyProcessed_exception() throws IOException { @Test void getBtcTxHashProcessedHeight_normalFlow() throws IOException, VMException { BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1525,8 +1526,8 @@ void getBtcTxHashProcessedHeight_normalFlow() throws IOException, VMException { @Test void getBtcTxHashProcessedHeight_exception() throws IOException { BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1546,8 +1547,8 @@ void getBtcTxHashProcessedHeight_exception() throws IOException { @Test void getFederationSize() { BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1581,8 +1582,8 @@ void getFederationThreshold() { @Test void getFederationCreationTime() { BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1708,8 +1709,8 @@ void getFederatorPublicKeyOfType_afterMultikey() throws Exception { @Test void getRetiringFederationSize() { BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -1743,8 +1744,8 @@ void getRetiringFederationThreshold() { @Test void getRetiringFederationCreationTime() { BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -2111,8 +2112,8 @@ void addFederatorPublicKeyMultikey_afterMultikey() throws Exception { void commitFederation_ok() throws BridgeIllegalArgumentException { Transaction txMock = mock(Transaction.class); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -2129,8 +2130,8 @@ void commitFederation_ok() throws BridgeIllegalArgumentException { @Test void commitFederation_wrongParameterType() throws BridgeIllegalArgumentException { BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -2165,8 +2166,8 @@ void rollbackFederation() throws BridgeIllegalArgumentException { @Test void getLockWhitelistSize() { BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -2286,8 +2287,8 @@ void addLockWhitelistAddressBeforeRskip87Fork() throws VMException { when(mockedTransaction.getSender(any(SignatureCache.class))).thenReturn(sender); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -2314,8 +2315,8 @@ void addLockWhitelistAddressAfterRskip87And88Fork() { Transaction mockedTransaction = mock(Transaction.class); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -2368,8 +2369,8 @@ void addOneOffLockWhitelistAddressAfterRskip87Fork() throws VMException { when(mockedTransaction.getSender(any(SignatureCache.class))).thenReturn(sender); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -2396,8 +2397,8 @@ void addUnlimitedLockWhitelistAddressBeforeRskip87And88Fork() throws VMException Transaction mockedTransaction = mock(Transaction.class); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -2421,8 +2422,8 @@ void addUnlimitedLockWhitelistAddressAfterRskip87Fork() throws VMException { when(mockedTransaction.getSender(any(SignatureCache.class))).thenReturn(sender); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -2445,8 +2446,8 @@ void addUnlimitedLockWhitelistAddressAfterRskip87Fork() throws VMException { void removeLockWhitelistAddress() { Transaction mockedTransaction = mock(Transaction.class); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -2541,8 +2542,8 @@ void testBlock457BridgeCall() throws Exception { // Setup bridge BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -2726,8 +2727,8 @@ void getBtcTransactionConfirmationsAfterWasabi_ok() throws Exception { void getBtcTransactionConfirmationsAfterWasabi_errorInBridgeSupport() throws Exception { Transaction txMock = mock(Transaction.class); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); @@ -2795,8 +2796,8 @@ void getBtcTransactionConfirmationsAfterWasabi_errorInBridgeSupport() throws Exc void getBtcTransactionConfirmationsAfterWasabi_merkleBranchConstructionError() throws Exception { Transaction txMock = mock(Transaction.class); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); @@ -2892,8 +2893,8 @@ void getBtcTransactionConfirmations_gasCost() { @Test void getBtcBlockchainBlockHashAtDepth() throws BlockStoreException, IOException, VMException { BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -2940,12 +2941,11 @@ void testCallFromContract_beforeOrchid() { // Run the program on the VM Program program = new Program(config.getVmConfig(), precompiledContracts, blockFactory, mock(ActivationConfig.ForBlock.class), code, invoke, tx, new HashSet<>(), new BlockTxSignatureCache(new ReceivedTxSignatureCache())); - Exception ex = Assertions.assertThrows(NullPointerException.class, () -> { + Assertions.assertThrows(NullPointerException.class, () -> { for (int i = 0; i < numOps; i++) { vm.step(program); } }); - Assertions.assertNull(ex.getMessage()); } @Test @@ -3142,7 +3142,7 @@ void receiveHeadersAccess_beforePublic_noAccessIfNotFromFederationMember() throw BridgeSupport bridgeSupportMock = mock(BridgeSupport.class); when(bridgeSupportMock.getRetiringFederation()).thenReturn(null); - when(bridgeSupportMock.getActiveFederation()).thenReturn(BridgeRegTestConstants.getInstance().getGenesisFederation()); + when(bridgeSupportMock.getActiveFederation()).thenReturn(FederationTestUtils.getGenesisFederation(bridgeRegTestConstants)); BridgeSupportFactory bridgeSupportFactoryMock = mock(BridgeSupportFactory.class); @@ -3177,7 +3177,7 @@ void receiveHeadersAccess_beforePublic_accessIfFromFederationMember() throws Exc BridgeSupport bridgeSupportMock = mock(BridgeSupport.class); when(bridgeSupportMock.getRetiringFederation()).thenReturn(null); - when(bridgeSupportMock.getActiveFederation()).thenReturn(BridgeRegTestConstants.getInstance().getGenesisFederation()); + when(bridgeSupportMock.getActiveFederation()).thenReturn(FederationTestUtils.getGenesisFederation(bridgeRegTestConstants)); BridgeSupportFactory bridgeSupportFactoryMock = mock(BridgeSupportFactory.class); @@ -3273,8 +3273,8 @@ private void executeAndCheckMethodWithAnyCallsAllowed(boolean localCall) throws @Test void getBtcBlockchainInitialBlockHeight() throws IOException, VMException { BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -3322,8 +3322,8 @@ private void getGasForDataPaidTx(int expected, CallTransaction.Function function activationConfig = ActivationConfigsForTest.bridgeUnitTest(); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, @@ -3383,8 +3383,8 @@ private void registerBtcTransactionWithHugeDeclaredSize(BtcTransaction tx) throw rskTx.sign(fedECPrivateKey.getPrivKeyBytes()); BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory( - new RepositoryBtcBlockStoreWithCache.Factory(bridgeConstants.getBtcParams()), - bridgeConstants, + new RepositoryBtcBlockStoreWithCache.Factory(bridgeRegTestConstants.getBtcParams()), + bridgeRegTestConstants, activationConfig, signatureCache); Bridge bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeUtilsLegacyTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeUtilsLegacyTest.java index b3afe72db5f..1765378275f 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeUtilsLegacyTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeUtilsLegacyTest.java @@ -1,9 +1,9 @@ package co.rsk.peg; import co.rsk.bitcoinj.core.*; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import java.time.Instant; import java.util.List; import co.rsk.peg.federation.Federation; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeUtilsTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeUtilsTest.java index 95adee50229..35e74dd78e7 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeUtilsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeUtilsTest.java @@ -25,9 +25,9 @@ import co.rsk.bitcoinj.wallet.RedeemData; import co.rsk.bitcoinj.wallet.Wallet; import co.rsk.blockchain.utils.BlockGenerator; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.core.RskAddress; import co.rsk.core.genesis.TestGenesisLoader; import co.rsk.crypto.Keccak256; @@ -1339,7 +1339,7 @@ void getAmountSentToAddresses_ok() { } private void getAmountSentToAddresses_no_output_for_address_by_network(BridgeConstants bridgeConstants) { - Federation genesisFederation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); Address receiver = genesisFederation.getAddress(); BtcTransaction btcTx = new BtcTransaction(bridgeConstants.getBtcParams()); @@ -1363,7 +1363,7 @@ void getAmountSentToAddresses_no_output_for_address() { } private void getAmountSentToAddresses_output_value_is_0_by_network(BridgeConstants bridgeConstants) { - Federation genesisFederation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); Address receiver = genesisFederation.getAddress(); Coin valueToTransfer = Coin.ZERO; @@ -1465,7 +1465,7 @@ private Genesis getGenesisInstance(TrieStore trieStore) { } private ErpFederation createNonStandardErpFederation() { - Federation genesisFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); FederationArgs genesisFederationArgs = genesisFederation.getArgs(); List<BtcECKey> erpPubKeys = bridgeConstantsRegtest.getErpFedPubKeysList(); long activationDelay = bridgeConstantsRegtest.getErpFedActivationDelay(); @@ -1484,7 +1484,7 @@ private BtcTransaction createPegOutTx( byte[] program; if (federation == null) { - federation = BridgeRegTestConstants.getInstance().getGenesisFederation(); + federation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); } if (isFlyover) { @@ -1681,15 +1681,6 @@ private Script signWithOneKey( return inputScript; } - private Federation getGenesisFederationForTest(BridgeConstants bridgeConstants, Context btcContext){ - Federation federation = bridgeConstants.getGenesisFederation(); - Wallet wallet = new BridgeBtcWallet(btcContext, Collections.singletonList(federation)); - Address federationAddress = federation.getAddress(); - wallet.addWatchedAddress(federationAddress, federation.getCreationTime().toEpochMilli()); - - return federation; - } - @Test void testValidateFlyoverPeginValue_sent_zero_amount_before_RSKIP293() { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); diff --git a/rskj-core/src/test/java/co/rsk/peg/ErpRedeemScriptBuilderUtilsTest.java b/rskj-core/src/test/java/co/rsk/peg/ErpRedeemScriptBuilderUtilsTest.java index cd12c50da2c..fc89f2a5728 100644 --- a/rskj-core/src/test/java/co/rsk/peg/ErpRedeemScriptBuilderUtilsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/ErpRedeemScriptBuilderUtilsTest.java @@ -4,8 +4,8 @@ import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptBuilder; import co.rsk.bitcoinj.script.ScriptChunk; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; import co.rsk.peg.bitcoin.ErpRedeemScriptBuilderUtils; import co.rsk.peg.bitcoin.RedeemScriptCreationException; import org.bouncycastle.util.encoders.Hex; diff --git a/rskj-core/src/test/java/co/rsk/peg/FederationSupportTest.java b/rskj-core/src/test/java/co/rsk/peg/FederationSupportTest.java index 74a00696666..b55cbada875 100644 --- a/rskj-core/src/test/java/co/rsk/peg/FederationSupportTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/FederationSupportTest.java @@ -17,13 +17,26 @@ */ package co.rsk.peg; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeTestNetConstants; import co.rsk.peg.bitcoin.BitcoinTestUtils; -import co.rsk.peg.federation.*; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationArgs; +import co.rsk.peg.federation.FederationFactory; +import co.rsk.peg.federation.FederationMember; +import co.rsk.peg.federation.FederationTestUtils; +import java.time.Instant; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; import org.bouncycastle.util.encoders.Hex; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest; @@ -36,16 +49,6 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import java.time.Instant; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Stream; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - class FederationSupportTest { private FederationSupport federationSupport; @@ -62,7 +65,7 @@ void setUp() { activations = mock(ActivationConfig.ForBlock.class); federationSupport = new FederationSupport( - bridgeConstants, + bridgeConstants, provider, executionBlock, activations @@ -71,11 +74,13 @@ void setUp() { @Test void whenNewFederationIsNullThenActiveFederationIsGenesisFederation() { - Federation genesisFederation = getNewFakeFederation(0); - when(provider.getNewFederation()) - .thenReturn(null); - when(bridgeConstants.getGenesisFederation()) - .thenReturn(genesisFederation); + final BridgeConstants bridgeMainNetConstants = BridgeMainNetConstants.getInstance(); + final Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeMainNetConstants); + + when(provider.getNewFederation()).thenReturn(null); + when(bridgeConstants.getGenesisFederationCreationTime()).thenReturn(genesisFederation.getCreationTime()); + when(bridgeConstants.getGenesisFederationPublicKeys()).thenReturn(genesisFederation.getBtcPublicKeys()); + when(bridgeConstants.getBtcParams()).thenReturn(genesisFederation.getBtcParams()); assertThat(federationSupport.getActiveFederation(), is(genesisFederation)); } diff --git a/rskj-core/src/test/java/co/rsk/peg/PegTestUtils.java b/rskj-core/src/test/java/co/rsk/peg/PegTestUtils.java index 8f44a68744b..079224bbc6e 100644 --- a/rskj-core/src/test/java/co/rsk/peg/PegTestUtils.java +++ b/rskj-core/src/test/java/co/rsk/peg/PegTestUtils.java @@ -23,7 +23,7 @@ import co.rsk.bitcoinj.script.FastBridgeRedeemScriptParser; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptBuilder; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.peg.federation.*; diff --git a/rskj-core/src/test/java/co/rsk/peg/PegUtilsAllUTXOsToFedAreAboveMinimumPeginValueTest.java b/rskj-core/src/test/java/co/rsk/peg/PegUtilsAllUTXOsToFedAreAboveMinimumPeginValueTest.java index 3d73b1e2ec8..9a6498903a3 100644 --- a/rskj-core/src/test/java/co/rsk/peg/PegUtilsAllUTXOsToFedAreAboveMinimumPeginValueTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/PegUtilsAllUTXOsToFedAreAboveMinimumPeginValueTest.java @@ -12,8 +12,8 @@ import co.rsk.bitcoinj.core.Context; import co.rsk.bitcoinj.core.NetworkParameters; import co.rsk.bitcoinj.wallet.Wallet; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; import co.rsk.peg.bitcoin.BitcoinTestUtils; import java.util.Arrays; import java.util.Collections; diff --git a/rskj-core/src/test/java/co/rsk/peg/PegUtilsEvaluatePeginTest.java b/rskj-core/src/test/java/co/rsk/peg/PegUtilsEvaluatePeginTest.java index 74b59f1b0ed..ea2e79af3f7 100644 --- a/rskj-core/src/test/java/co/rsk/peg/PegUtilsEvaluatePeginTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/PegUtilsEvaluatePeginTest.java @@ -11,8 +11,8 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.script.ScriptBuilder; import co.rsk.bitcoinj.wallet.Wallet; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; import co.rsk.peg.bitcoin.BitcoinTestUtils; import co.rsk.peg.btcLockSender.BtcLockSender; import co.rsk.peg.federation.Federation; diff --git a/rskj-core/src/test/java/co/rsk/peg/PegUtilsGetTransactionTypeTest.java b/rskj-core/src/test/java/co/rsk/peg/PegUtilsGetTransactionTypeTest.java index fa2ee1f9ea2..54c16db432b 100644 --- a/rskj-core/src/test/java/co/rsk/peg/PegUtilsGetTransactionTypeTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/PegUtilsGetTransactionTypeTest.java @@ -20,9 +20,9 @@ import co.rsk.bitcoinj.core.TransactionWitness; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptBuilder; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.peg.bitcoin.BitcoinTestUtils; @@ -725,7 +725,7 @@ void anyAddressToAnyAddress_pegin_before_RSKIP379() { anyToAnyTx.addInput(BitcoinTestUtils.createHash(1), 0, new Script(new byte[]{})); anyToAnyTx.addOutput(minimumPeginTxValue, new Script(new byte[]{}) ); - Federation activeFederation = bridgeMainnetConstants.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); // Act PegTxType transactionType = PegUtils.getTransactionType( @@ -753,7 +753,7 @@ void pegin_anyAddressToAnyAddress_below_minimum_pegin_before_RSIP379() { anyToAnyTx.addInput(BitcoinTestUtils.createHash(1), 0, new Script(new byte[]{})); anyToAnyTx.addOutput(belowMinimum, new Script(new byte[]{})); - Federation activeFederation = bridgeMainnetConstants.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); // Act PegTxType transactionType = PegUtils.getTransactionType( @@ -781,7 +781,7 @@ void unknown_anyAddressToAnyAddress_unknown_after_RSIP379_and_using_pegout_tx_in anyToAnyTx.addInput(BitcoinTestUtils.createHash(1), 0, new Script(new byte[]{})); anyToAnyTx.addOutput(minimumPeginTxValue, new Script(new byte[]{}) ); - Federation activeFederation = bridgeMainnetConstants.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); // Act PegTxType transactionType = PegUtils.getTransactionType( @@ -809,7 +809,7 @@ void unknown_anyAddressToAnyAddress_below_minimum_unknown_after_RSIP379_and_usin anyToAnyTx.addInput(BitcoinTestUtils.createHash(1), 0, new Script(new byte[]{})); anyToAnyTx.addOutput(belowMinimum, new Script(new byte[]{})); - Federation activeFederation = bridgeMainnetConstants.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); // Act PegTxType transactionType = PegUtils.getTransactionType( @@ -860,7 +860,7 @@ void sending_funds_below_minimum_active_fed( BridgeStorageProvider provider = mock(BridgeStorageProvider.class); Coin belowMinimumPeginTxValue = bridgeMainnetConstants.getMinimumPeginTxValue(activations).div(10); - Federation activeFederation = bridgeMainnetConstants.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); BtcTransaction peginTx = new BtcTransaction(btcMainnetParams); peginTx.addInput(BitcoinTestUtils.createHash(1), 0, new Script(new byte[]{})); @@ -895,7 +895,7 @@ void sending_funds_below_and_above_minimum_active_fed( BridgeStorageProvider provider = mock(BridgeStorageProvider.class); Coin belowMinimumPeginTxValue = bridgeMainnetConstants.getMinimumPeginTxValue(activations).div(10); - Federation activeFederation = bridgeMainnetConstants.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); BtcTransaction peginTx = new BtcTransaction(btcMainnetParams); peginTx.addInput(BitcoinTestUtils.createHash(1), 0, new Script(new byte[]{})); @@ -951,7 +951,7 @@ void sending_funds_equal_to_minimum_active_fed( BridgeStorageProvider provider = mock(BridgeStorageProvider.class); Coin minimumPeginTxValue = bridgeMainnetConstants.getMinimumPeginTxValue(activations); - Federation activeFederation = bridgeMainnetConstants.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); BtcTransaction peginTx = new BtcTransaction(btcMainnetParams); peginTx.addInput(BitcoinTestUtils.createHash(1), 0, new Script(new byte[]{})); @@ -982,7 +982,7 @@ void sending_funds_above_minimum_active_fed( BridgeStorageProvider provider = mock(BridgeStorageProvider.class); Coin minimumPeginTxValue = bridgeMainnetConstants.getMinimumPeginTxValue(activations).add(Coin.CENT); - Federation activeFederation = bridgeMainnetConstants.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); BtcTransaction peginTx = new BtcTransaction(btcMainnetParams); peginTx.addInput(BitcoinTestUtils.createHash(1), 0, new Script(new byte[]{})); @@ -1111,7 +1111,7 @@ void many_outputs_and_inputs_pegout( ); } - Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis(); + Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue(); Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4); for (int i = 0; i < 10; i++) { btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), BitcoinTestUtils.createP2PKHAddress(btcMainnetParams, "user" + i )); @@ -1170,7 +1170,7 @@ void many_outputs_and_one_input_pegout( ScriptBuilder.createP2SHMultiSigInputScript(null, activeFederation.getRedeemScript()) ); - Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis(); + Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue(); Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4); for (int i = 0; i < 10; i++) { btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), BitcoinTestUtils.createP2PKHAddress(btcMainnetParams, "user" + i )); @@ -1231,7 +1231,7 @@ void one_outputs_and_many_input_pegout( ); } - Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis(); + Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue(); btcTransaction.addOutput(minimumPegoutTxValue, userAddress); FederationTestUtils.addSignatures(activeFederation, activeFedSigners, btcTransaction); @@ -1434,7 +1434,7 @@ void many_outputs_and_inputs_migration( ); } - Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis(); + Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue(); Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4); for (int i = 0; i < 10; i++) { btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), activeFederation.getAddress()); @@ -1495,7 +1495,7 @@ void many_outputs_and_one_input_migration( ScriptBuilder.createP2SHMultiSigInputScript(null, retiringFederation.getRedeemScript()) ); - Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis(); + Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue(); Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4); for (int i = 0; i < 10; i++) { btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), activeFederation.getAddress()); @@ -1557,7 +1557,7 @@ void one_outputs_and_many_input_migration( ); } - Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis(); + Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue(); btcTransaction.addOutput(minimumPegoutTxValue, activeFederation.getAddress()); FederationTestUtils.addSignatures(retiringFederation, retiringFedSigners, btcTransaction); @@ -2104,7 +2104,7 @@ void old_fed_to_live_fed( BridgeStorageProvider provider = mock(BridgeStorageProvider.class); Federation oldFederation = createFederation(bridgeRegTestConstants, REGTEST_OLD_FEDERATION_PRIVATE_KEYS); - Federation activeFederation = bridgeRegTestConstants.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeRegTestConstants); Assertions.assertEquals(oldFederation.getAddress().toString(), bridgeRegTestConstants.getOldFederationAddress()); @@ -2245,21 +2245,19 @@ void retired_fed_no_existing_in_the_storage_to_live_fed( PegTxType expectedType ) { // Arrange - BridgeConstants bridgeRegTestConstants = BridgeRegTestConstants.getInstance(); - NetworkParameters btcRegTestsParams = bridgeRegTestConstants.getBtcParams(); - Context.propagate(new Context(btcRegTestsParams)); + Context.propagate(new Context(btcMainnetParams)); BridgeStorageProvider provider = mock(BridgeStorageProvider.class); List<BtcECKey> fedKeys = BitcoinTestUtils.getBtcEcKeysFromSeeds( new String[]{"fa01", "fa02", "fa03"}, true ); - Federation retiredFederation = createFederation(bridgeRegTestConstants, fedKeys); - Federation activeFederation = bridgeRegTestConstants.getGenesisFederation(); + Federation retiredFederation = createFederation(bridgeMainnetConstants, fedKeys); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); when(provider.getLastRetiredFederationP2SHScript()).thenReturn(Optional.empty()); - BtcTransaction migrationTx = new BtcTransaction(btcRegTestsParams); + BtcTransaction migrationTx = new BtcTransaction(btcMainnetParams); migrationTx.addInput( BitcoinTestUtils.createHash(1), @@ -2279,7 +2277,7 @@ void retired_fed_no_existing_in_the_storage_to_live_fed( PegTxType transactionType = PegUtils.getTransactionType( activations, provider, - bridgeRegTestConstants, + bridgeMainnetConstants, activeFederation, null, migrationTx, diff --git a/rskj-core/src/test/java/co/rsk/peg/PegUtilsLegacyGetTransactionTypeTest.java b/rskj-core/src/test/java/co/rsk/peg/PegUtilsLegacyGetTransactionTypeTest.java index eefb4d10e28..b6d8c651ca7 100644 --- a/rskj-core/src/test/java/co/rsk/peg/PegUtilsLegacyGetTransactionTypeTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/PegUtilsLegacyGetTransactionTypeTest.java @@ -3,10 +3,10 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptBuilder; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeRegTestConstants; import co.rsk.peg.bitcoin.BitcoinTestUtils; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.peg.federation.*; import org.bouncycastle.util.encoders.Hex; import org.ethereum.config.blockchain.upgrades.ActivationConfig; @@ -65,7 +65,7 @@ void test_sentFromP2SHErpFed() { ); List<FederationMember> federationMembers = FederationTestUtils.getFederationMembersWithBtcKeys(standardKeys); - Federation genesisFederation = bridgeMainnetConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); List<BtcECKey> erpPubKeys = bridgeMainnetConstants.getErpFedPubKeysList(); long activationDelay = bridgeMainnetConstants.getErpFedActivationDelay(); FederationArgs activeFedArgs = @@ -131,12 +131,17 @@ void test_sentFromOldFed(ActivationConfig.ForBlock activations, PegTxType expect BtcECKey.fromPrivate(Hex.decode("e1b17fcd0ef1942465eee61b20561b16750191143d365e71de08b33dd84a9788")) ); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeRegTestConstants); + List<FederationMember> federationMembers = genesisFederation.getMembers(); + Instant federationCreationTime = genesisFederation.getCreationTime(); + NetworkParameters networkParameters = genesisFederation.getBtcParams(); + // Arrange FederationArgs federationArgs = new FederationArgs( - bridgeRegTestConstants.getGenesisFederation().getMembers(), - bridgeRegTestConstants.getGenesisFederation().getCreationTime(), + federationMembers, + federationCreationTime, 5L, - bridgeRegTestConstants.getGenesisFederation().getBtcParams() + networkParameters ); Federation activeFederation = FederationFactory.buildStandardMultiSigFederation( federationArgs @@ -153,14 +158,14 @@ void test_sentFromOldFed(ActivationConfig.ForBlock activations, PegTxType expect // Act PegTxType transactionType = PegUtilsLegacy.getTransactionType( - migrationTx, - activeFederation, - null, - activations.isActive(RSKIP186)? retiredFederation.getP2SHScript(): null, - oldFederationAddress, - activations, - bridgeRegTestConstants.getMinimumPeginTxValue(activations), - new BridgeBtcWallet(btcContext, Collections.singletonList(activeFederation)) + migrationTx, + activeFederation, + null, + activations.isActive(RSKIP186) ? retiredFederation.getP2SHScript() : null, + oldFederationAddress, + activations, + bridgeRegTestConstants.getMinimumPeginTxValue(activations), + new BridgeBtcWallet(btcContext, Collections.singletonList(activeFederation)) ); // Assert @@ -173,7 +178,7 @@ void test_sentFromP2SH_pegin() { // Arrange ActivationConfig.ForBlock activations = ActivationConfigsForTest.hop400().forBlock(0); - Federation activeFederation = bridgeMainnetConstants.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); List<BtcECKey> unknownFedSigners = BitcoinTestUtils.getBtcEcKeysFromSeeds( new String[]{"key1", "key2", "key3"}, true @@ -539,7 +544,7 @@ void test_migration_from_and_to_p2shFed_tx() { @Test void test_unknown_tx() { // Arrange - Federation activeFederation = bridgeMainnetConstants.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); diff --git a/rskj-core/src/test/java/co/rsk/peg/PegUtilsLegacyTest.java b/rskj-core/src/test/java/co/rsk/peg/PegUtilsLegacyTest.java index 18f06e2bf24..e0bbeb8d56b 100644 --- a/rskj-core/src/test/java/co/rsk/peg/PegUtilsLegacyTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/PegUtilsLegacyTest.java @@ -5,9 +5,9 @@ import co.rsk.bitcoinj.script.*; import co.rsk.bitcoinj.wallet.RedeemData; import co.rsk.bitcoinj.wallet.Wallet; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.peg.btcLockSender.BtcLockSender; import co.rsk.peg.federation.*; import org.bouncycastle.util.encoders.Hex; @@ -51,11 +51,10 @@ void setupConfig() { void testIsValidPegInTx() { // Peg-in is for the genesis federation ATM Context btcContext = new Context(networkParameters); - - Federation federation = bridgeConstantsRegtest.getGenesisFederation(); - Wallet wallet = new BridgeBtcWallet(btcContext, Collections.singletonList(federation)); - Address federationAddress = federation.getAddress(); - wallet.addWatchedAddress(federationAddress, federation.getCreationTime().toEpochMilli()); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); + Wallet wallet = new BridgeBtcWallet(btcContext, Collections.singletonList(genesisFederation)); + Address federationAddress = genesisFederation.getAddress(); + wallet.addWatchedAddress(federationAddress, genesisFederation.getCreationTime().toEpochMilli()); when(activations.isActive(any(ConsensusRule.class))).thenReturn(false); // Tx sending less than the minimum allowed, not a peg-in tx @@ -63,7 +62,7 @@ void testIsValidPegInTx() { BtcTransaction tx = new BtcTransaction(networkParameters); tx.addOutput(minimumLockValue.subtract(Coin.CENT), federationAddress); tx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); - assertFalse(isValidPegInTx(tx, federation, wallet, bridgeConstantsRegtest, activations)); + assertFalse(isValidPegInTx(tx, genesisFederation, wallet, bridgeConstantsRegtest, activations)); // Tx sending 1 btc to the federation, but also spending from the federation address, // the typical peg-out tx, not a peg-in tx. @@ -76,38 +75,38 @@ void testIsValidPegInTx() { new TransactionOutPoint(networkParameters, 0, Sha256Hash.ZERO_HASH) ); tx2.addInput(txIn); - signWithNecessaryKeys(bridgeConstantsRegtest.getGenesisFederation(), BridgeRegTestConstants.REGTEST_FEDERATION_PRIVATE_KEYS, txIn, tx2); - assertFalse(isValidPegInTx(tx2, federation, wallet, bridgeConstantsRegtest, activations)); + signWithNecessaryKeys(genesisFederation, BridgeRegTestConstants.REGTEST_FEDERATION_PRIVATE_KEYS, txIn, tx2); + assertFalse(isValidPegInTx(tx2, genesisFederation, wallet, bridgeConstantsRegtest, activations)); // Tx sending 1 btc to the federation, is a peg-in tx BtcTransaction tx3 = new BtcTransaction(networkParameters); tx3.addOutput(Coin.COIN, federationAddress); tx3.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); - assertTrue(isValidPegInTx(tx3, federation, wallet, bridgeConstantsRegtest, activations)); + assertTrue(isValidPegInTx(tx3, genesisFederation, wallet, bridgeConstantsRegtest, activations)); // Tx sending 50 btc to the federation, is a peg-in tx BtcTransaction tx4 = new BtcTransaction(networkParameters); tx4.addOutput(Coin.FIFTY_COINS, federationAddress); tx4.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); - assertTrue(isValidPegInTx(tx4, federation, wallet, bridgeConstantsRegtest, activations)); + assertTrue(isValidPegInTx(tx4, genesisFederation, wallet, bridgeConstantsRegtest, activations)); } @Test void testIsValidPegInTx_less_than_minimum_not_pegin_after_iris() { // Tx sending less than the minimum allowed, not a peg-in tx Context btcContext = new Context(networkParameters); - Federation federation = this.getGenesisFederationForTest(bridgeConstantsRegtest, btcContext); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); when(activations.isActive(ConsensusRule.RSKIP219)).thenReturn(true); Coin minimumPegInValueAfterIris = bridgeConstantsRegtest.getMinimumPeginTxValue(activations); // Tx sending less than the minimum allowed, not a peg-in tx BtcTransaction tx = new BtcTransaction(networkParameters); - tx.addOutput(minimumPegInValueAfterIris.subtract(Coin.CENT), federation.getAddress()); + tx.addOutput(minimumPegInValueAfterIris.subtract(Coin.CENT), genesisFederation.getAddress()); tx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); - Wallet federationWallet = new BridgeBtcWallet(btcContext, Collections.singletonList(federation)); - assertFalse(isValidPegInTx(tx, federation, federationWallet, bridgeConstantsRegtest, activations)); + Wallet federationWallet = new BridgeBtcWallet(btcContext, Collections.singletonList(genesisFederation)); + assertFalse(isValidPegInTx(tx, genesisFederation, federationWallet, bridgeConstantsRegtest, activations)); } @Test @@ -115,12 +114,12 @@ void testIsValidPegInTx_spending_from_federation_is_pegout_after_iris() { // Tx sending 1 btc to the federation, but also spending from the federation address, // the typical peg-out tx, not a peg-in tx. Context btcContext = new Context(networkParameters); - Federation federation = this.getGenesisFederationForTest(bridgeConstantsRegtest, btcContext); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); when(activations.isActive(ConsensusRule.RSKIP219)).thenReturn(true); BtcTransaction tx = new BtcTransaction(networkParameters); - tx.addOutput(Coin.COIN, federation.getAddress()); + tx.addOutput(Coin.COIN, genesisFederation.getAddress()); TransactionInput txIn = new TransactionInput( networkParameters, tx, @@ -128,74 +127,73 @@ void testIsValidPegInTx_spending_from_federation_is_pegout_after_iris() { new TransactionOutPoint(networkParameters, 0, Sha256Hash.ZERO_HASH) ); tx.addInput(txIn); - signWithNecessaryKeys(bridgeConstantsRegtest.getGenesisFederation(), BridgeRegTestConstants.REGTEST_FEDERATION_PRIVATE_KEYS, txIn, tx); + signWithNecessaryKeys(genesisFederation, BridgeRegTestConstants.REGTEST_FEDERATION_PRIVATE_KEYS, txIn, tx); - Wallet federationWallet = new BridgeBtcWallet(btcContext, Collections.singletonList(federation)); - assertFalse(isValidPegInTx(tx, federation, federationWallet, bridgeConstantsRegtest, activations)); + Wallet federationWallet = new BridgeBtcWallet(btcContext, Collections.singletonList(genesisFederation)); + assertFalse(isValidPegInTx(tx, genesisFederation, federationWallet, bridgeConstantsRegtest, activations)); } @Test void testIsValidPegInTx_sending_50_btc_after_iris() { // Tx sending 50 btc to the federation, is a peg-in tx - Context btcContext = new Context(networkParameters); - Federation federation = this.getGenesisFederationForTest(bridgeConstantsRegtest, btcContext); + Context btcContext = new Context(bridgeConstantsMainnet.getBtcParams()); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); when(activations.isActive(ConsensusRule.RSKIP219)).thenReturn(true); - BtcTransaction tx = new BtcTransaction(networkParameters); - tx.addOutput(Coin.FIFTY_COINS, federation.getAddress()); + BtcTransaction tx = new BtcTransaction(bridgeConstantsMainnet.getBtcParams()); + tx.addOutput(Coin.FIFTY_COINS, genesisFederation.getAddress()); tx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); - Wallet federationWallet = new BridgeBtcWallet(btcContext, Collections.singletonList(federation)); - assertTrue(isValidPegInTx(tx, federation, federationWallet, bridgeConstantsRegtest, activations)); + Wallet federationWallet = new BridgeBtcWallet(btcContext, Collections.singletonList(genesisFederation)); + assertTrue(isValidPegInTx(tx, genesisFederation, federationWallet, bridgeConstantsMainnet, activations)); } @Test void testIsValidPegInTx_value_between_old_and_new_before_iris() { // Tx sending btc between old and new value, it is not a peg-in before iris - Context btcContext = new Context(networkParameters); - Federation federation = this.getGenesisFederationForTest(bridgeConstantsRegtest, btcContext); + Context btcContext = new Context(bridgeConstantsMainnet.getBtcParams()); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); when(activations.isActive(ConsensusRule.RSKIP219)).thenReturn(false); - BtcTransaction tx = new BtcTransaction(networkParameters); + BtcTransaction tx = new BtcTransaction(bridgeConstantsMainnet.getBtcParams()); // Get a value in between pre and post iris minimum - Coin minimumPegInValueBeforeIris = bridgeConstantsRegtest.getMinimumPeginTxValue(ActivationConfigsForTest.papyrus200().forBlock(0)); - Coin minimumPegInValueAfterIris = bridgeConstantsRegtest.getMinimumPeginTxValue(ActivationConfigsForTest.iris300().forBlock(0)); + Coin minimumPegInValueBeforeIris = bridgeConstantsMainnet.getMinimumPeginTxValue(ActivationConfigsForTest.papyrus200().forBlock(0)); + Coin minimumPegInValueAfterIris = bridgeConstantsMainnet.getMinimumPeginTxValue(ActivationConfigsForTest.iris300().forBlock(0)); Coin valueLock = minimumPegInValueAfterIris.plus((minimumPegInValueBeforeIris.subtract(minimumPegInValueAfterIris)).div(2)); assertTrue(valueLock.isLessThan(minimumPegInValueBeforeIris)); assertTrue(valueLock.isGreaterThan(minimumPegInValueAfterIris)); - tx.addOutput(valueLock, federation.getAddress()); + tx.addOutput(valueLock, genesisFederation.getAddress()); tx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); - Wallet federationWallet = new BridgeBtcWallet(btcContext, Collections.singletonList(federation)); - assertFalse(isValidPegInTx(tx, federation, federationWallet, bridgeConstantsRegtest, activations)); + Wallet federationWallet = new BridgeBtcWallet(btcContext, Collections.singletonList(genesisFederation)); + assertFalse(isValidPegInTx(tx, genesisFederation, federationWallet, bridgeConstantsMainnet, activations)); } @Test void testIsValidPegInTx_value_between_old_and_new_after_iris() { // Tx sending btc between old and new value, it is a peg-in after iris - Context btcContext = new Context(networkParameters); - Federation federation = this.getGenesisFederationForTest(bridgeConstantsRegtest, btcContext); - + Context btcContext = new Context(bridgeConstantsMainnet.getBtcParams()); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); when(activations.isActive(ConsensusRule.RSKIP219)).thenReturn(true); - BtcTransaction tx = new BtcTransaction(networkParameters); + BtcTransaction tx = new BtcTransaction(bridgeConstantsMainnet.getBtcParams()); // Get a value in between pre and post iris minimum - Coin minimumPegInValueBeforeIris = bridgeConstantsRegtest.getMinimumPeginTxValue(ActivationConfigsForTest.papyrus200().forBlock(0)); - Coin minimumPegInValueAfterIris = bridgeConstantsRegtest.getMinimumPeginTxValue(ActivationConfigsForTest.iris300().forBlock(0)); + Coin minimumPegInValueBeforeIris = bridgeConstantsMainnet.getMinimumPeginTxValue(ActivationConfigsForTest.papyrus200().forBlock(0)); + Coin minimumPegInValueAfterIris = bridgeConstantsMainnet.getMinimumPeginTxValue(ActivationConfigsForTest.iris300().forBlock(0)); Coin valueLock = minimumPegInValueAfterIris.plus((minimumPegInValueBeforeIris.subtract(minimumPegInValueAfterIris)).div(2)); assertTrue(valueLock.isGreaterThan(minimumPegInValueAfterIris)); assertTrue(valueLock.isLessThan(minimumPegInValueBeforeIris)); - tx.addOutput(valueLock, federation.getAddress()); + tx.addOutput(valueLock, genesisFederation.getAddress()); tx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); - Wallet federationWallet = new BridgeBtcWallet(btcContext, Collections.singletonList(federation)); - assertTrue(isValidPegInTx(tx, federation, federationWallet, bridgeConstantsRegtest, activations)); + Wallet federationWallet = new BridgeBtcWallet(btcContext, Collections.singletonList(genesisFederation)); + assertTrue(isValidPegInTx(tx, genesisFederation, federationWallet, bridgeConstantsMainnet, activations)); } @Test @@ -482,45 +480,45 @@ void testIsValidPegInTxForTwoFederations() { @Test void testIsValidPegInTx_hasChangeUtxoFromFlyoverFederation_beforeRskip201_isPegin() { - Context btcContext = new Context(networkParameters); + Context btcContext = new Context(bridgeConstantsMainnet.getBtcParams()); when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(false); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); Script flyoverRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript( activeFederation.getRedeemScript(), Sha256Hash.of(PegTestUtils.createHash(1).getBytes()) ); // Create a tx from the fast bridge fed to the active fed - BtcTransaction tx = new BtcTransaction(networkParameters); + BtcTransaction tx = new BtcTransaction(bridgeConstantsMainnet.getBtcParams()); tx.addOutput(Coin.COIN, activeFederation.getAddress()); tx.addInput(Sha256Hash.ZERO_HASH, 0, flyoverRedeemScript); Wallet federationWallet = new BridgeBtcWallet(btcContext, Collections.singletonList(activeFederation)); Assertions.assertTrue(isValidPegInTx(tx, activeFederation, federationWallet, - bridgeConstantsRegtest, activations)); + bridgeConstantsMainnet, activations)); } @Test void testIsValidPegInTx_hasChangeUtxoFromFlyoverFederation_afterRskip201_notPegin() { - Context btcContext = new Context(networkParameters); + Context btcContext = new Context(bridgeConstantsMainnet.getBtcParams()); when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); Script flyoverRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript( activeFederation.getRedeemScript(), Sha256Hash.of(PegTestUtils.createHash(1).getBytes()) ); // Create a tx from the fast bridge fed to the active fed - BtcTransaction tx = new BtcTransaction(networkParameters); + BtcTransaction tx = new BtcTransaction(bridgeConstantsMainnet.getBtcParams()); tx.addOutput(Coin.COIN, activeFederation.getAddress()); tx.addInput(Sha256Hash.ZERO_HASH, 0, flyoverRedeemScript); Wallet federationWallet = new BridgeBtcWallet(btcContext, Collections.singletonList(activeFederation)); Assertions.assertFalse(isValidPegInTx(tx, activeFederation, federationWallet, - bridgeConstantsRegtest, activations)); + bridgeConstantsMainnet, activations)); } @Test @@ -529,7 +527,7 @@ void testIsValidPegInTx_hasChangeUtxoFromFlyoverErpFederation_beforeRskip201_isP Context btcContext = new Context(networkParameters); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); FederationArgs federationArgs = activeFederation.getArgs(); List<BtcECKey> erpPubKeys = Arrays.asList( @@ -568,7 +566,7 @@ void testIsValidPegInTx_hasChangeUtxoFromFlyoverErpFederation_afterRskip201_notP Context btcContext = new Context(networkParameters); when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); List<BtcECKey> erpFederationKeys = Arrays.asList( BtcECKey.fromPrivate(Hex.decode("fa01")), BtcECKey.fromPrivate(Hex.decode("fa02")) @@ -610,7 +608,7 @@ void testIsValidPegInTx_hasChangeUtxoFromErpFederation_beforeRskip201_isPegin() Context btcContext = new Context(networkParameters); when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(false); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); List<BtcECKey> erpFederationKeys = Arrays.asList( BtcECKey.fromPrivate(Hex.decode("fa01")), BtcECKey.fromPrivate(Hex.decode("fa02")) @@ -648,7 +646,7 @@ void testIsValidPegInTx_hasChangeUtxoFromErpFederation_afterRskip201_notPegin() Context btcContext = new Context(networkParameters); when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); List<BtcECKey> erpFederationKeys = Arrays.asList( BtcECKey.fromPrivate(Hex.decode("fa01")), BtcECKey.fromPrivate(Hex.decode("fa02")) @@ -684,7 +682,7 @@ void testIsValidPegInTx_hasChangeUtxoFromErpFederation_afterRskip201_notPegin() @Test void testIsValidPegInTx_hasChangeUtxoFromFlyoverRetiredFederation_beforeRskip201_isPegin() { Context btcContext = new Context(networkParameters); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(false); List<BtcECKey> retiredFederationKeys = Arrays.asList( @@ -734,7 +732,7 @@ void testIsValidPegInTx_hasChangeUtxoFromFlyoverRetiredFederation_beforeRskip201 @Test void testIsValidPegInTx_hasChangeUtxoFromFlyoverRetiredFederation_afterRskip201_notPegin() { Context btcContext = new Context(networkParameters); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true); List<BtcECKey> retiredFederationKeys = Arrays.asList( @@ -784,7 +782,7 @@ void testIsValidPegInTx_hasChangeUtxoFromFlyoverRetiredFederation_afterRskip201_ @Test void testIsValidPegInTx_hasChangeUtxoFromFlyoverErpRetiredFederation_beforeRskip201_isPegin() { Context btcContext = new Context(networkParameters); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(false); List<BtcECKey> retiredFederationKeys = Arrays.asList( @@ -838,7 +836,7 @@ void testIsValidPegInTx_hasChangeUtxoFromFlyoverErpRetiredFederation_beforeRskip @Test void testIsValidPegInTx_hasChangeUtxoFromFlyoverErpRetiredFederation_afterRskip201_notPegin() { Context btcContext = new Context(networkParameters); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true); List<BtcECKey> retiredFederationKeys = Arrays.asList( @@ -892,7 +890,7 @@ void testIsValidPegInTx_hasChangeUtxoFromFlyoverErpRetiredFederation_afterRskip2 @Test void testIsValidPegInTx_hasChangeUtxoFromErpRetiredFederation_beforeRskip201_isPegin() { Context btcContext = new Context(networkParameters); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); List<BtcECKey> retiredFederationKeys = Arrays.asList( BtcECKey.fromPrivate(Hex.decode("fa01")), @@ -940,7 +938,7 @@ void testIsValidPegInTx_hasChangeUtxoFromErpRetiredFederation_beforeRskip201_isP @Test void testIsValidPegInTx_hasChangeUtxoFromErpRetiredFederation_afterRskip201_notPegin() { Context btcContext = new Context(networkParameters); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true); List<BtcECKey> retiredFederationKeys = Arrays.asList( @@ -988,14 +986,14 @@ void testIsValidPegInTx_hasChangeUtxoFromErpRetiredFederation_afterRskip201_notP @Test void testIsValidPegInTx_has_multiple_utxos_below_minimum_but_total_amount_is_ok_before_RSKIP293() { - Context btcContext = new Context(networkParameters); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Context btcContext = new Context(bridgeConstantsMainnet.getBtcParams()); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true); when(activations.isActive(ConsensusRule.RSKIP293)).thenReturn(false); - Coin minimumPeginValue = bridgeConstantsRegtest.getMinimumPeginTxValue(activations); + Coin minimumPeginValue = bridgeConstantsMainnet.getMinimumPeginTxValue(activations); // Create a tx with multiple utxos below the minimum but the sum of each utxos is equal to the minimum - BtcTransaction tx = new BtcTransaction(networkParameters); + BtcTransaction tx = new BtcTransaction(bridgeConstantsMainnet.getBtcParams()); tx.addOutput(minimumPeginValue.div(4), activeFederation.getAddress()); tx.addOutput(minimumPeginValue.div(4), activeFederation.getAddress()); tx.addOutput(minimumPeginValue.div(4), activeFederation.getAddress()); @@ -1015,14 +1013,14 @@ void testIsValidPegInTx_has_multiple_utxos_below_minimum_but_total_amount_is_ok_ @Test void testIsValidPegInTx_has_utxos_below_minimum_and_total_amount_as_well_before_RSKIP293() { - Context btcContext = new Context(networkParameters); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Context btcContext = new Context(bridgeConstantsMainnet.getBtcParams()); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true); when(activations.isActive(ConsensusRule.RSKIP293)).thenReturn(false); - Coin minimumPeginValue = bridgeConstantsRegtest.getMinimumPeginTxValue(activations); + Coin minimumPeginValue = bridgeConstantsMainnet.getMinimumPeginTxValue(activations); // Create a tx with multiple utxos below the minimum, and the sum of each utxos as well is below the minimum - BtcTransaction tx = new BtcTransaction(networkParameters); + BtcTransaction tx = new BtcTransaction(bridgeConstantsMainnet.getBtcParams()); tx.addOutput(minimumPeginValue.div(4), activeFederation.getAddress()); tx.addOutput(minimumPeginValue.div(4), activeFederation.getAddress()); tx.addOutput(minimumPeginValue.div(4), activeFederation.getAddress()); @@ -1035,24 +1033,24 @@ void testIsValidPegInTx_has_utxos_below_minimum_and_total_amount_as_well_before_ Collections.singletonList(activeFederation), null, federationWallet, - bridgeConstantsRegtest.getMinimumPeginTxValue(activations), + bridgeConstantsMainnet.getMinimumPeginTxValue(activations), activations )); } @Test void testIsValidPegInTx_has_utxos_below_minimum_after_RSKIP293() { - Context btcContext = new Context(networkParameters); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Context btcContext = new Context(bridgeConstantsMainnet.getBtcParams()); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true); when(activations.isActive(ConsensusRule.RSKIP293)).thenReturn(true); - Coin minimumPeginValue = bridgeConstantsRegtest.getMinimumPeginTxValue(activations); + Coin minimumPeginValue = bridgeConstantsMainnet.getMinimumPeginTxValue(activations); Coin belowMinimumPeginValue = minimumPeginValue.divide(2); Coin aboveMinimumPeginValue = minimumPeginValue.add(Coin.COIN); // Create a tx with multiple utxos below, one equal to, and one above, the minimum. - BtcTransaction tx = new BtcTransaction(networkParameters); + BtcTransaction tx = new BtcTransaction(bridgeConstantsMainnet.getBtcParams()); tx.addOutput(belowMinimumPeginValue, activeFederation.getAddress()); tx.addOutput(belowMinimumPeginValue, activeFederation.getAddress()); tx.addOutput(belowMinimumPeginValue, activeFederation.getAddress()); @@ -1073,14 +1071,14 @@ void testIsValidPegInTx_has_utxos_below_minimum_after_RSKIP293() { @Test void testIsValidPegInTx_utxo_equal_to_minimum_after_RSKIP293() { - Context btcContext = new Context(networkParameters); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Context btcContext = new Context(bridgeConstantsMainnet.getBtcParams()); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true); when(activations.isActive(ConsensusRule.RSKIP293)).thenReturn(true); - Coin minimumPeginValue = bridgeConstantsRegtest.getMinimumPeginTxValue(activations); + Coin minimumPeginValue = bridgeConstantsMainnet.getMinimumPeginTxValue(activations); - BtcTransaction tx = new BtcTransaction(networkParameters); + BtcTransaction tx = new BtcTransaction(bridgeConstantsMainnet.getBtcParams()); tx.addOutput(minimumPeginValue, activeFederation.getAddress()); Wallet federationWallet = new BridgeBtcWallet(btcContext, Collections.singletonList(activeFederation)); @@ -1097,7 +1095,8 @@ void testIsValidPegInTx_utxo_equal_to_minimum_after_RSKIP293() { @Test void testIsValidPegInTx_p2shErpScript_sends_funds_to_federation_address_before_RSKIP353() { - Address activeFederationAddress = bridgeConstantsRegtest.getGenesisFederation().getAddress(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); + Address activeFederationAddress = genesisFederation.getAddress(); testIsValidPegInTx_fromP2shErpScriptSender( false, false, @@ -1120,7 +1119,8 @@ void testIsValidPegInTx_p2shErpScript_sends_funds_to_random_address_before_RSKIP @Test void testIsValidPegInTx_p2shErpScript_sends_funds_to_federation_address_after_RSKIP353() { - Address activeFederationAddress = bridgeConstantsRegtest.getGenesisFederation().getAddress(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); + Address activeFederationAddress = genesisFederation.getAddress(); testIsValidPegInTx_fromP2shErpScriptSender( true, false, @@ -1142,7 +1142,8 @@ void testIsValidPegInTx_p2shErpScript_sends_funds_to_random_address_after_RSKIP3 @Test void testIsValidPegInTx_flyoverP2shErpScript_sends_funds_to_federation_address_before_RSKIP353() { - Address activeFederationAddress = bridgeConstantsRegtest.getGenesisFederation().getAddress(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); + Address activeFederationAddress = genesisFederation.getAddress(); testIsValidPegInTx_fromP2shErpScriptSender( false, true, @@ -1165,7 +1166,8 @@ void testIsValidPegInTx_flyoverP2shErpScript_sends_funds_to_random_address_befor @Test void testIsValidPegInTx_flyoverpP2shErpScript_sends_funds_to_federation_address_after_RSKIP353() { - Address activeFederationAddress = bridgeConstantsRegtest.getGenesisFederation().getAddress(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); + Address activeFederationAddress = activeFederation.getAddress(); testIsValidPegInTx_fromP2shErpScriptSender( true, true, @@ -1196,7 +1198,7 @@ private void testIsValidPegInTx_fromP2shErpScriptSender( when(activations.isActive(ConsensusRule.RSKIP353)).thenReturn(isRskip353Active); Context btcContext = new Context(networkParameters); - Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); FederationArgs activeFederationArgs = activeFederation.getArgs(); List<BtcECKey> emergencyKeys = PegTestUtils.createRandomBtcECKeys(3); @@ -1791,7 +1793,7 @@ void testIsMigrationTx() { @Test void testIsPegOutTx() { - Federation federation = bridgeConstantsRegtest.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); List<BtcECKey> activeFederationKeys = Stream.of( BtcECKey.fromPrivate(Hex.decode("fa01")), BtcECKey.fromPrivate(Hex.decode("fa02")), @@ -1817,14 +1819,14 @@ void testIsPegOutTx() { new TransactionOutPoint(networkParameters, 0, Sha256Hash.ZERO_HASH) ); pegOutTx1.addInput(pegOutInput1); - signWithNecessaryKeys(federation, federationPrivateKeys, pegOutInput1, pegOutTx1); + signWithNecessaryKeys(genesisFederation, federationPrivateKeys, pegOutInput1, pegOutTx1); - assertTrue(isPegOutTx(pegOutTx1, Collections.singletonList(federation), activations)); - assertTrue(isPegOutTx(pegOutTx1, Arrays.asList(federation, federation2), activations)); + assertTrue(isPegOutTx(pegOutTx1, Collections.singletonList(genesisFederation), activations)); + assertTrue(isPegOutTx(pegOutTx1, Arrays.asList(genesisFederation, federation2), activations)); assertFalse(isPegOutTx(pegOutTx1, Collections.singletonList(federation2), activations)); - assertTrue(isPegOutTx(pegOutTx1, activations, federation.getP2SHScript())); - assertTrue(isPegOutTx(pegOutTx1, activations, federation.getP2SHScript(), federation2.getP2SHScript())); + assertTrue(isPegOutTx(pegOutTx1, activations, genesisFederation.getP2SHScript())); + assertTrue(isPegOutTx(pegOutTx1, activations, genesisFederation.getP2SHScript(), federation2.getP2SHScript())); assertFalse(isPegOutTx(pegOutTx1, activations, federation2.getP2SHScript())); } @@ -1845,7 +1847,7 @@ void testIsPegOutTx_fromFlyoverFederation() { args ); - Federation standardFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation standardFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); // Create a tx from the fast bridge fed to a random address Address randomAddress = PegTestUtils.createRandomP2PKHBtcAddress(networkParameters); @@ -1909,7 +1911,7 @@ void testIsPegOutTx_fromErpFederation() { erpFederationPublicKeys.sort(BtcECKey.PUBKEY_COMPARATOR); ErpFederation nonStandardErpFederation = FederationFactory.buildNonStandardErpFederation(federationArgs, erpFederationPublicKeys, 500L, activations); - Federation standardFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation standardFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); // Create a tx from the erp fed to a random address Address randomAddress = PegTestUtils.createRandomP2PKHBtcAddress(networkParameters); @@ -1975,7 +1977,7 @@ void testIsPegOutTx_fromFlyoverErpFederation() { ErpFederation nonStandardErpFederation = FederationFactory.buildNonStandardErpFederation(federationArgs, erpFederationPublicKeys, 500L, activations); - Federation standardFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation standardFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); // Create a tx from the fast bridge erp fed to a random address Address randomAddress = PegTestUtils.createRandomP2PKHBtcAddress(networkParameters); @@ -2020,39 +2022,39 @@ void testIsPegOutTx_fromFlyoverErpFederation() { @Test void testIsPegOutTx_noRedeemScript() { - Federation federation = bridgeConstantsRegtest.getGenesisFederation(); - Address randomAddress = PegTestUtils.createRandomP2PKHBtcAddress(networkParameters); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); + Address randomAddress = PegTestUtils.createRandomP2PKHBtcAddress(bridgeConstantsMainnet.getBtcParams()); - BtcTransaction pegOutTx1 = new BtcTransaction(networkParameters); + BtcTransaction pegOutTx1 = new BtcTransaction(bridgeConstantsMainnet.getBtcParams()); pegOutTx1.addOutput(Coin.COIN, randomAddress); TransactionInput pegOutInput1 = new TransactionInput( - networkParameters, + bridgeConstantsMainnet.getBtcParams(), pegOutTx1, new byte[]{}, - new TransactionOutPoint(networkParameters, 0, Sha256Hash.ZERO_HASH) + new TransactionOutPoint(bridgeConstantsMainnet.getBtcParams(), 0, Sha256Hash.ZERO_HASH) ); pegOutTx1.addInput(pegOutInput1); - assertFalse(isPegOutTx(pegOutTx1, Collections.singletonList(federation), activations)); + assertFalse(isPegOutTx(pegOutTx1, Collections.singletonList(genesisFederation), activations)); } @Test void testIsPegOutTx_invalidRedeemScript() { - Federation federation = bridgeConstantsRegtest.getGenesisFederation(); - Address randomAddress = PegTestUtils.createRandomP2PKHBtcAddress(networkParameters); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsMainnet); + Address randomAddress = PegTestUtils.createRandomP2PKHBtcAddress(bridgeConstantsMainnet.getBtcParams()); Script invalidRedeemScript = ScriptBuilder.createRedeemScript(2, Arrays.asList(new BtcECKey(), new BtcECKey())); - BtcTransaction pegOutTx1 = new BtcTransaction(networkParameters); + BtcTransaction pegOutTx1 = new BtcTransaction(bridgeConstantsMainnet.getBtcParams()); pegOutTx1.addOutput(Coin.COIN, randomAddress); TransactionInput pegOutInput1 = new TransactionInput( - networkParameters, + bridgeConstantsMainnet.getBtcParams(), pegOutTx1, invalidRedeemScript.getProgram(), - new TransactionOutPoint(networkParameters, 0, Sha256Hash.ZERO_HASH) + new TransactionOutPoint(bridgeConstantsMainnet.getBtcParams(), 0, Sha256Hash.ZERO_HASH) ); pegOutTx1.addInput(pegOutInput1); - assertFalse(isPegOutTx(pegOutTx1, Collections.singletonList(federation), activations)); + assertFalse(isPegOutTx(pegOutTx1, Collections.singletonList(genesisFederation), activations)); } @Test @@ -2233,7 +2235,7 @@ void testIsAnyUTXOAmountBelowMinimum_has_utxos_below_minimum() { @Test void scriptCorrectlySpends_fromGenesisFederation_ok() { - Federation genesisFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); Address destinationAddress = PegTestUtils.createRandomP2PKHBtcAddress(networkParameters); BtcTransaction tx = new BtcTransaction(networkParameters); @@ -2252,7 +2254,7 @@ void scriptCorrectlySpends_fromGenesisFederation_ok() { @Test void scriptCorrectlySpends_invalidScript() { - Federation genesisFederation = bridgeConstantsRegtest.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstantsRegtest); Address destinationAddress = PegTestUtils.createRandomP2PKHBtcAddress(networkParameters); BtcTransaction tx = new BtcTransaction(networkParameters); @@ -2365,13 +2367,4 @@ private Script signWithOneKey( return inputScript; } - - private Federation getGenesisFederationForTest(BridgeConstants bridgeConstants, Context btcContext){ - Federation federation = bridgeConstants.getGenesisFederation(); - Wallet wallet = new BridgeBtcWallet(btcContext, Collections.singletonList(federation)); - Address federationAddress = federation.getAddress(); - wallet.addWatchedAddress(federationAddress, federation.getCreationTime().toEpochMilli()); - - return federation; - } } diff --git a/rskj-core/src/test/java/co/rsk/peg/PegUtilsTest.java b/rskj-core/src/test/java/co/rsk/peg/PegUtilsTest.java index 1b41abee10b..efef866186a 100644 --- a/rskj-core/src/test/java/co/rsk/peg/PegUtilsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/PegUtilsTest.java @@ -4,9 +4,9 @@ import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptBuilder; import co.rsk.bitcoinj.wallet.Wallet; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeTestNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.peg.bitcoin.BitcoinTestUtils; @@ -40,8 +40,6 @@ class PegUtilsTest { private BridgeStorageProvider provider; private Address userAddress; - - private Federation retiredFed; private List<BtcECKey> retiringFedSigners; private Federation retiringFederation; private List<BtcECKey> activeFedSigners; @@ -52,9 +50,6 @@ class PegUtilsTest { void init() { provider = mock(BridgeStorageProvider.class); userAddress = BitcoinTestUtils.createP2PKHAddress(btcMainnetParams, "userAddress"); - - retiredFed = bridgeMainnetConstants.getGenesisFederation(); - retiringFedSigners = BitcoinTestUtils.getBtcEcKeysFromSeeds( new String[]{"fa01", "fa02", "fa03"}, true ); @@ -107,7 +102,7 @@ void test_getTransactionType_tx_sending_funds_to_unknown_address() { @Test void test_getTransactionType_pegin_below_minimum_active_fed() { // Arrange - Federation activeFederation = bridgeMainnetConstants.getGenesisFederation(); + Federation activeFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); Wallet liveFederationWallet = new BridgeBtcWallet(context, Collections.singletonList(activeFederation)); Coin minimumPeginTxValue = bridgeMainnetConstants.getMinimumPeginTxValue(activations); @@ -199,7 +194,7 @@ void test_getTransactionType_pegin_multiple_outputs_to_active_fed() { @Test void test_getTransactionType_pegin_output_to_retiring_fed_and_other_addresses() { // Arrange - Federation retiringFed = bridgeMainnetConstants.getGenesisFederation(); + Federation retiringFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); List<BtcECKey> signers = BitcoinTestUtils.getBtcEcKeysFromSeeds( new String[]{"fa01", "fa02", "fa03"}, true @@ -211,12 +206,12 @@ void test_getTransactionType_pegin_output_to_retiring_fed_and_other_addresses() FederationArgs federationArgs = new FederationArgs(fedMembers, creationTime, 0L, btcMainnetParams); ErpFederation activeFed = FederationFactory.buildP2shErpFederation(federationArgs, erpPubKeys, activationDelay); - Wallet liveFederationWallet = new BridgeBtcWallet(context, Arrays.asList(retiringFed, activeFed)); + Wallet liveFederationWallet = new BridgeBtcWallet(context, Arrays.asList(retiringFederation, activeFed)); BtcTransaction btcTransaction = new BtcTransaction(btcMainnetParams); btcTransaction.addInput(BitcoinTestUtils.createHash(1), FIRST_OUTPUT_INDEX, new Script(new byte[]{})); btcTransaction.addOutput(Coin.COIN, userAddress); - btcTransaction.addOutput(Coin.COIN, retiringFed.getAddress()); + btcTransaction.addOutput(Coin.COIN, retiringFederation.getAddress()); btcTransaction.addOutput(Coin.COIN, BitcoinTestUtils.createP2PKHAddress(btcMainnetParams, "unknown2")); // Act @@ -518,19 +513,20 @@ void test_getTransactionType_migration_sighash_no_exists_in_provider() { void test_getTransactionType_migration_from_retired_fed() { // Arrange Wallet liveFederationWallet = new BridgeBtcWallet(context, Collections.singletonList(activeFederation)); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); BtcTransaction btcTransaction = new BtcTransaction(btcMainnetParams); - btcTransaction.addInput(BitcoinTestUtils.createHash(1), FIRST_OUTPUT_INDEX, retiredFed.getP2SHScript()); + btcTransaction.addInput(BitcoinTestUtils.createHash(1), FIRST_OUTPUT_INDEX, genesisFederation.getP2SHScript()); btcTransaction.addOutput(Coin.COIN, activeFederation.getAddress()); - Script p2SHScript = ScriptBuilder.createP2SHOutputScript(retiredFed.getRedeemScript()); - Script inputScript = p2SHScript.createEmptyInputScript(null, retiredFed.getRedeemScript()); + Script p2SHScript = ScriptBuilder.createP2SHOutputScript(genesisFederation.getRedeemScript()); + Script inputScript = p2SHScript.createEmptyInputScript(null, genesisFederation.getRedeemScript()); btcTransaction.getInput(FIRST_INPUT_INDEX).setScriptSig(inputScript); Sha256Hash firstInputSigHash = btcTransaction.hashForSignature( FIRST_INPUT_INDEX, - retiredFed.getRedeemScript(), + genesisFederation.getRedeemScript(), BtcTransaction.SigHash.ALL, false ); @@ -600,7 +596,7 @@ void test_getTransactionType_flyover_segwit() { NetworkParameters btcTestNetParams = bridgeTestNetConstants.getBtcParams(); Context context = new Context(bridgeTestNetConstants.getBtcParams()); - Federation retiringFed = bridgeTestNetConstants.getGenesisFederation(); + Federation retiringFederation = FederationTestUtils.getGenesisFederation(bridgeMainnetConstants); List<BtcECKey> signers = BitcoinTestUtils.getBtcEcKeysFromSeeds( new String[]{"fa01", "fa02", "fa03"}, true @@ -613,7 +609,7 @@ void test_getTransactionType_flyover_segwit() { FederationArgs federationArgs = new FederationArgs(fedMembers, creationTime, 0L, btcTestNetParams); ErpFederation activeFed = FederationFactory.buildP2shErpFederation(federationArgs, erpPubKeys, activationDelay); - Wallet liveFederationWallet = new BridgeBtcWallet(context, Arrays.asList(retiringFed, activeFed)); + Wallet liveFederationWallet = new BridgeBtcWallet(context, Arrays.asList(retiringFederation, activeFed)); String segwitTxHex = "020000000001011f668117f2ca3314806ade1d99ae400f5413d7e9d4bfcbd11d52645e060e22fb0100000000fdffffff0300000000000000001b6a1952534b5401a27c6f697954357247e78f9900023cfe01a9d49c0412030000000000160014b413f59a7ee6e34321140e83ea661e0484a79bc2988708000000000017a9145e6cf80958803e9b3c81cd90422152520d2a505c870247304402203fce49b39f79581d93720f462b5f33f9174e66dc6efb635d4f41aacb33b08d0302201221aec5db31e269454fcc7a4df2936ccedd566ccf48828d4f97050954f196540121021831c5ba44b739521d635e521560525672087e4d5db053801f4aeb60e782f6d6d0f02400"; BtcTransaction btcTransaction = new BtcTransaction(btcTestNetParams, Hex.decode(segwitTxHex)); diff --git a/rskj-core/src/test/java/co/rsk/peg/PeginInformationTest.java b/rskj-core/src/test/java/co/rsk/peg/PeginInformationTest.java index 18016878eba..9dac753de38 100644 --- a/rskj-core/src/test/java/co/rsk/peg/PeginInformationTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/PeginInformationTest.java @@ -7,9 +7,9 @@ import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.BtcTransaction; import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeRegTestConstants; -import co.rsk.config.BridgeTestNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import co.rsk.core.RskAddress; import co.rsk.peg.btcLockSender.BtcLockSender; import co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType; diff --git a/rskj-core/src/test/java/co/rsk/peg/PocSighashTest.java b/rskj-core/src/test/java/co/rsk/peg/PocSighashTest.java index ac85c504401..1b7c94610e9 100644 --- a/rskj-core/src/test/java/co/rsk/peg/PocSighashTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/PocSighashTest.java @@ -6,8 +6,8 @@ import co.rsk.bitcoinj.script.ScriptBuilder; import co.rsk.bitcoinj.script.ScriptChunk; import co.rsk.bitcoinj.wallet.RedeemData; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeTestNetConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import co.rsk.peg.bitcoin.BitcoinTestUtils; import co.rsk.peg.federation.*; import org.bouncycastle.util.encoders.Hex; diff --git a/rskj-core/src/test/java/co/rsk/peg/PowpegMigrationTest.java b/rskj-core/src/test/java/co/rsk/peg/PowpegMigrationTest.java index 66750a928a0..5594d4eb3e7 100644 --- a/rskj-core/src/test/java/co/rsk/peg/PowpegMigrationTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/PowpegMigrationTest.java @@ -4,8 +4,8 @@ import co.rsk.bitcoinj.script.*; import co.rsk.bitcoinj.store.BlockStoreException; import co.rsk.bitcoinj.store.BtcBlockStore; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.db.MutableTrieCache; diff --git a/rskj-core/src/test/java/co/rsk/peg/ReleaseTransactionBuilderTest.java b/rskj-core/src/test/java/co/rsk/peg/ReleaseTransactionBuilderTest.java index 600531d0da4..47ff749a227 100644 --- a/rskj-core/src/test/java/co/rsk/peg/ReleaseTransactionBuilderTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/ReleaseTransactionBuilderTest.java @@ -41,9 +41,9 @@ import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.wallet.SendRequest; import co.rsk.bitcoinj.wallet.Wallet; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.peg.bitcoin.BitcoinTestUtils; import java.math.BigInteger; import java.nio.charset.StandardCharsets; @@ -69,7 +69,7 @@ class ReleaseTransactionBuilderTest { private ActivationConfig.ForBlock activations; private Context btcContext; private NetworkParameters networkParameters; - private BridgeConstants bridgeConstants; + private BridgeConstants bridgeRegTestConstants; private Federation federation; @BeforeEach @@ -77,10 +77,10 @@ void setup() { wallet = mock(Wallet.class); changeAddress = mockAddress(1000); activations = mock(ActivationConfig.ForBlock.class); - bridgeConstants = BridgeRegTestConstants.getInstance(); - networkParameters = bridgeConstants.getBtcParams(); + bridgeRegTestConstants = BridgeRegTestConstants.getInstance(); + networkParameters = bridgeRegTestConstants.getBtcParams(); btcContext = new Context(networkParameters); - federation = bridgeConstants.getGenesisFederation(); + federation = FederationTestUtils.getGenesisFederation(bridgeRegTestConstants); builder = new ReleaseTransactionBuilder( networkParameters, wallet, diff --git a/rskj-core/src/test/java/co/rsk/peg/RepositoryBtcBlockStoreWithCacheTest.java b/rskj-core/src/test/java/co/rsk/peg/RepositoryBtcBlockStoreWithCacheTest.java index 32f6e7069c9..afbbc6fdad4 100644 --- a/rskj-core/src/test/java/co/rsk/peg/RepositoryBtcBlockStoreWithCacheTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/RepositoryBtcBlockStoreWithCacheTest.java @@ -24,8 +24,8 @@ import co.rsk.bitcoinj.core.StoredBlock; import co.rsk.bitcoinj.params.RegTestParams; import co.rsk.bitcoinj.store.BlockStoreException; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.db.MutableTrieCache; import co.rsk.db.MutableTrieImpl; import co.rsk.trie.Trie; diff --git a/rskj-core/src/test/java/co/rsk/peg/RskForksBridgeTest.java b/rskj-core/src/test/java/co/rsk/peg/RskForksBridgeTest.java index f5203aedc96..5c3adefa9f3 100644 --- a/rskj-core/src/test/java/co/rsk/peg/RskForksBridgeTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/RskForksBridgeTest.java @@ -20,7 +20,7 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.params.RegTestParams; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.config.TestSystemProperties; import co.rsk.core.RskAddress; import co.rsk.core.TransactionExecutorFactory; diff --git a/rskj-core/src/test/java/co/rsk/peg/StateForFederatorTest.java b/rskj-core/src/test/java/co/rsk/peg/StateForFederatorTest.java index 256550965fc..2c3e171dff6 100644 --- a/rskj-core/src/test/java/co/rsk/peg/StateForFederatorTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/StateForFederatorTest.java @@ -20,7 +20,7 @@ import co.rsk.bitcoinj.core.BtcTransaction; import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.crypto.Keccak256; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.Assertions; diff --git a/rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinUtilsTest.java b/rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinUtilsTest.java index 9d34d288bcb..b46ed5b58ed 100644 --- a/rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinUtilsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinUtilsTest.java @@ -11,8 +11,8 @@ import co.rsk.bitcoinj.script.RedeemScriptParserFactory; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptChunk; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; diff --git a/rskj-core/src/test/java/co/rsk/peg/btcLockSender/BtcLockSenderProviderTest.java b/rskj-core/src/test/java/co/rsk/peg/btcLockSender/BtcLockSenderProviderTest.java index 4243129d14a..982329f8957 100644 --- a/rskj-core/src/test/java/co/rsk/peg/btcLockSender/BtcLockSenderProviderTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/btcLockSender/BtcLockSenderProviderTest.java @@ -4,8 +4,8 @@ import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.BtcTransaction; import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.config.BridgeRegTestConstants; -import co.rsk.config.BridgeTestNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import co.rsk.core.RskAddress; import co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType; import org.bouncycastle.util.encoders.Hex; diff --git a/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2PkhBtcLockSenderTest.java b/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2PkhBtcLockSenderTest.java index c295dbb595b..910d4ea185a 100644 --- a/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2PkhBtcLockSenderTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2PkhBtcLockSenderTest.java @@ -5,8 +5,8 @@ import co.rsk.bitcoinj.core.NetworkParameters; import co.rsk.bitcoinj.core.TransactionInput; import co.rsk.bitcoinj.script.ScriptBuilder; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.core.RskAddress; import co.rsk.peg.PegTestUtils; import co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType; diff --git a/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2shMultisigBtcLockSenderTest.java b/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2shMultisigBtcLockSenderTest.java index d4b756c0c8d..ea11b828271 100644 --- a/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2shMultisigBtcLockSenderTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2shMultisigBtcLockSenderTest.java @@ -1,8 +1,8 @@ package co.rsk.peg.btcLockSender; import co.rsk.bitcoinj.core.*; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType; import org.bouncycastle.util.encoders.Hex; import org.ethereum.crypto.HashUtil; diff --git a/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2shP2wpkhBtcLockSenderTest.java b/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2shP2wpkhBtcLockSenderTest.java index a8c150da08f..d404731ec75 100644 --- a/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2shP2wpkhBtcLockSenderTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2shP2wpkhBtcLockSenderTest.java @@ -3,8 +3,8 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptBuilder; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.core.RskAddress; import co.rsk.peg.PegTestUtils; import co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType; diff --git a/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2shP2wshBtcLockSenderTest.java b/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2shP2wshBtcLockSenderTest.java index 83646648ddd..46f5ba3264e 100644 --- a/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2shP2wshBtcLockSenderTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/btcLockSender/P2shP2wshBtcLockSenderTest.java @@ -2,8 +2,8 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.script.ScriptBuilder; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.peg.PegTestUtils; import co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType; import org.bouncycastle.util.encoders.Hex; diff --git a/rskj-core/src/test/java/co/rsk/config/BridgeConstantsTest.java b/rskj-core/src/test/java/co/rsk/peg/constants/BridgeConstantsTest.java similarity index 88% rename from rskj-core/src/test/java/co/rsk/config/BridgeConstantsTest.java rename to rskj-core/src/test/java/co/rsk/peg/constants/BridgeConstantsTest.java index 0a47296d80c..7ed06c1ceca 100644 --- a/rskj-core/src/test/java/co/rsk/config/BridgeConstantsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/constants/BridgeConstantsTest.java @@ -1,10 +1,11 @@ -package co.rsk.config; +package co.rsk.peg.constants; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import co.rsk.bitcoinj.core.Coin; +import java.time.Instant; import java.util.stream.Stream; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ConsensusRule; @@ -157,4 +158,20 @@ void getPegoutTxIndexGracePeriodInBtcBlocks(BridgeConstants bridgeConstants, int // assert assertEquals(expectedValue, pegoutTxIndexGracePeriodInBtcBlocks); } + + private static Stream<Arguments> getGenesisFederationCreationTimeTestProvider() { + return Stream.of( + Arguments.of(BridgeMainNetConstants.getInstance(), Instant.ofEpochMilli(1514948400L)), + Arguments.of(BridgeTestNetConstants.getInstance(), Instant.ofEpochMilli(1538967600L)), + Arguments.of(BridgeRegTestConstants.getInstance(), Instant.ofEpochSecond(1451606400L)), + Arguments.of(BridgeDevNetConstants.getInstance(), Instant.ofEpochMilli(1510617600L)) + ); + } + + @ParameterizedTest + @MethodSource("getGenesisFederationCreationTimeTestProvider") + void getGenesisFederationCreationTimeTest(BridgeConstants bridgeConstants, Instant expectedGenesisFederationCreationTime){ + Instant actualGenesisFederationCreationTime = bridgeConstants.getGenesisFederationCreationTime(); + assertEquals(expectedGenesisFederationCreationTime, actualGenesisFederationCreationTime); + } } diff --git a/rskj-core/src/test/java/co/rsk/peg/federation/FederationFactoryTest.java b/rskj-core/src/test/java/co/rsk/peg/federation/FederationFactoryTest.java index c893c158d45..4dc36bca092 100644 --- a/rskj-core/src/test/java/co/rsk/peg/federation/FederationFactoryTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/federation/FederationFactoryTest.java @@ -2,9 +2,9 @@ import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeTestNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import org.bouncycastle.util.encoders.Hex; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ConsensusRule; diff --git a/rskj-core/src/test/java/co/rsk/peg/federation/FederationTestUtils.java b/rskj-core/src/test/java/co/rsk/peg/federation/FederationTestUtils.java index 2b42e4391a2..1a84a6510f1 100644 --- a/rskj-core/src/test/java/co/rsk/peg/federation/FederationTestUtils.java +++ b/rskj-core/src/test/java/co/rsk/peg/federation/FederationTestUtils.java @@ -31,14 +31,20 @@ import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptBuilder; import java.math.BigInteger; +import java.time.Instant; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; + +import co.rsk.peg.constants.BridgeConstants; import org.ethereum.crypto.ECKey; -public class FederationTestUtils { +public final class FederationTestUtils { + + private FederationTestUtils() { + } public static Federation getFederation(Integer... federationMemberPks) { FederationArgs federationArgs = new FederationArgs( @@ -52,6 +58,15 @@ public static Federation getFederation(Integer... federationMemberPks) { ); } + public static Federation getGenesisFederation(BridgeConstants bridgeConstants) { + final long GENESIS_FEDERATION_CREATION_BLOCK_NUMBER = 1L; + final List<BtcECKey> genesisFederationPublicKeys = bridgeConstants.getGenesisFederationPublicKeys(); + final List<FederationMember> federationMembers = FederationMember.getFederationMembersFromKeys(genesisFederationPublicKeys); + final Instant genesisFederationCreationTime = bridgeConstants.getGenesisFederationCreationTime(); + final FederationArgs federationArgs = new FederationArgs(federationMembers, genesisFederationCreationTime, GENESIS_FEDERATION_CREATION_BLOCK_NUMBER, bridgeConstants.getBtcParams()); + return FederationFactory.buildStandardMultiSigFederation(federationArgs); + } + public static List<FederationMember> getFederationMembers(int memberCount) { List<FederationMember> result = new ArrayList<>(); for (int i = 1; i <= memberCount; i++) { diff --git a/rskj-core/src/test/java/co/rsk/peg/federation/NonStandardErpFederationsTest.java b/rskj-core/src/test/java/co/rsk/peg/federation/NonStandardErpFederationsTest.java index f97d4b8c103..7fd99e8c8a3 100644 --- a/rskj-core/src/test/java/co/rsk/peg/federation/NonStandardErpFederationsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/federation/NonStandardErpFederationsTest.java @@ -18,9 +18,9 @@ import co.rsk.bitcoinj.core.Utils; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptOpCodes; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeTestNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import co.rsk.peg.bitcoin.*; import co.rsk.peg.resources.TestConstants; import com.fasterxml.jackson.annotation.JsonCreator; diff --git a/rskj-core/src/test/java/co/rsk/peg/federation/P2shErpFederationTest.java b/rskj-core/src/test/java/co/rsk/peg/federation/P2shErpFederationTest.java index 5fcace9599d..227d70aeccc 100644 --- a/rskj-core/src/test/java/co/rsk/peg/federation/P2shErpFederationTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/federation/P2shErpFederationTest.java @@ -10,8 +10,11 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptOpCodes; -import co.rsk.config.*; import co.rsk.peg.bitcoin.*; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; @@ -335,7 +338,7 @@ void getRedeemScript(BridgeConstants bridgeConstants) { // should add this case because adding erp to mainnet genesis federation // throws a validation error, so in that case we use the one set up before each test. // if using testnet constants, we can add them with no errors - defaultKeys = bridgeConstants.getGenesisFederation().getBtcPublicKeys(); + defaultKeys = bridgeConstants.getGenesisFederationPublicKeys(); } emergencyKeys = bridgeConstants.getErpFedPubKeysList(); diff --git a/rskj-core/src/test/java/co/rsk/peg/federation/PendingFederationTest.java b/rskj-core/src/test/java/co/rsk/peg/federation/PendingFederationTest.java index 49f7756198e..0fdbfaab254 100644 --- a/rskj-core/src/test/java/co/rsk/peg/federation/PendingFederationTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/federation/PendingFederationTest.java @@ -20,16 +20,15 @@ import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeTestNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import co.rsk.crypto.Keccak256; import co.rsk.peg.resources.TestConstants; import org.ethereum.TestUtils; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ConsensusRule; import org.ethereum.crypto.ECKey; -import org.ethereum.crypto.HashUtil; import org.ethereum.util.ByteUtil; import org.ethereum.util.RLP; import org.ethereum.util.RLPList; diff --git a/rskj-core/src/test/java/co/rsk/peg/federation/StandardMultisigFederationTest.java b/rskj-core/src/test/java/co/rsk/peg/federation/StandardMultisigFederationTest.java index 3b2529961bd..7ba21181c30 100644 --- a/rskj-core/src/test/java/co/rsk/peg/federation/StandardMultisigFederationTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/federation/StandardMultisigFederationTest.java @@ -33,8 +33,8 @@ import java.util.Optional; import java.util.stream.Collectors; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; import co.rsk.peg.bitcoin.ScriptCreationException; import org.bouncycastle.util.encoders.Hex; import org.ethereum.TestUtils; @@ -51,13 +51,12 @@ class StandardMultisigFederationTest { private List<BtcECKey> keys; private List<BtcECKey> sortedPublicKeys; private List<byte[]> rskAddresses; + private final BridgeConstants bridgeMainNetConstants = BridgeMainNetConstants.getInstance(); @BeforeEach void setUp() { - BridgeConstants bridgeConstants = BridgeMainNetConstants.getInstance(); - - networkParameters = bridgeConstants.getBtcParams(); - federation = bridgeConstants.getGenesisFederation(); + networkParameters = bridgeMainNetConstants.getBtcParams(); + federation = FederationTestUtils.getGenesisFederation(bridgeMainNetConstants); keys = federation.getBtcPublicKeys(); sortedPublicKeys = keys.stream() diff --git a/rskj-core/src/test/java/co/rsk/peg/pegininstructions/PeginInstructionsProviderTest.java b/rskj-core/src/test/java/co/rsk/peg/pegininstructions/PeginInstructionsProviderTest.java index 041c8c283d3..026b8808de3 100644 --- a/rskj-core/src/test/java/co/rsk/peg/pegininstructions/PeginInstructionsProviderTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/pegininstructions/PeginInstructionsProviderTest.java @@ -8,8 +8,8 @@ import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptBuilder; import co.rsk.bitcoinj.script.ScriptOpCodes; -import co.rsk.config.BridgeRegTestConstants; -import co.rsk.config.BridgeTestNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeTestNetConstants; import co.rsk.core.RskAddress; import co.rsk.peg.PegTestUtils; import java.util.Optional; diff --git a/rskj-core/src/test/java/co/rsk/peg/pegininstructions/PeginInstructionsVersion1Test.java b/rskj-core/src/test/java/co/rsk/peg/pegininstructions/PeginInstructionsVersion1Test.java index b74071747ac..e528d455217 100644 --- a/rskj-core/src/test/java/co/rsk/peg/pegininstructions/PeginInstructionsVersion1Test.java +++ b/rskj-core/src/test/java/co/rsk/peg/pegininstructions/PeginInstructionsVersion1Test.java @@ -5,7 +5,7 @@ import co.rsk.bitcoinj.core.NetworkParameters; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.script.ScriptBuilder; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.core.RskAddress; import co.rsk.peg.PegTestUtils; import java.util.Arrays; diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/ActiveFederationTest.java b/rskj-core/src/test/java/co/rsk/peg/performance/ActiveFederationTest.java index 8a675d8fd31..b5e190176eb 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/ActiveFederationTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/ActiveFederationTest.java @@ -21,10 +21,7 @@ import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.store.BtcBlockStore; import co.rsk.peg.*; -import co.rsk.peg.federation.Federation; -import co.rsk.peg.federation.FederationArgs; -import co.rsk.peg.federation.FederationFactory; -import co.rsk.peg.federation.FederationMember; +import co.rsk.peg.federation.*; import org.ethereum.TestUtils; import org.ethereum.core.CallTransaction; import org.ethereum.core.Repository; @@ -129,7 +126,7 @@ private BridgeStorageProviderInitializer buildInitializer(boolean genesis) { ); provider.setNewFederation(federation); } else { - federation = bridgeConstants.getGenesisFederation(); + federation = FederationTestUtils.getGenesisFederation(bridgeConstants); } }; } diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/AddSignatureTest.java b/rskj-core/src/test/java/co/rsk/peg/performance/AddSignatureTest.java index c127ba7c6f9..f47e8b3f172 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/AddSignatureTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/AddSignatureTest.java @@ -34,6 +34,7 @@ import co.rsk.peg.BridgeStorageProvider; import co.rsk.peg.federation.Federation; import co.rsk.peg.PegTestUtils; +import co.rsk.peg.federation.FederationTestUtils; import org.ethereum.TestUtils; import org.ethereum.core.Repository; import org.ethereum.crypto.HashUtil; @@ -86,11 +87,13 @@ private void addSignature_nonFullySigned(int times, ExecutionStats stats) throws } private void addSignature_fullySigned(int times, ExecutionStats stats) throws VMException { + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); + int numberOfSignaturesRequired = genesisFederation.getNumberOfSignaturesRequired(); executeAndAverage( "addSignature-fullySigned", times, getABIEncoder(), - getInitializerFor(bridgeConstants.getGenesisFederation().getNumberOfSignaturesRequired()-1), + getInitializerFor(numberOfSignaturesRequired-1), Helper.getZeroValueValueTxBuilderFromFedMember(), Helper.getRandomHeightProvider(10), stats @@ -112,7 +115,7 @@ private BridgeStorageProviderInitializer getInitializerFor(int numSignatures) { return (BridgeStorageProvider provider, Repository repository, int executionIndex, BtcBlockStore blockStore) -> { releaseTx = new BtcTransaction(networkParameters); - Federation federation = bridgeConstants.getGenesisFederation(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); // Receiver and amounts BtcECKey to = new BtcECKey(); @@ -126,10 +129,10 @@ private BridgeStorageProviderInitializer getInitializerFor(int numSignatures) { for (int i = 0; i < numInputs; i++) { Coin inputAmount = releaseAmount.divide(numInputs); BtcTransaction inputTx = new BtcTransaction(networkParameters); - inputTx.addOutput(inputAmount, federation.getAddress()); + inputTx.addOutput(inputAmount, genesisFederation.getAddress()); releaseTx .addInput(inputTx.getOutput(0)) - .setScriptSig(PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation(federation)); + .setScriptSig(PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation(genesisFederation)); } // Partial signing according to numSignatures asked for diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/BridgePerformanceTestCase.java b/rskj-core/src/test/java/co/rsk/peg/performance/BridgePerformanceTestCase.java index 5fe98f66f2c..7c8c0a3d682 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/BridgePerformanceTestCase.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/BridgePerformanceTestCase.java @@ -19,8 +19,8 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.store.BtcBlockStore; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.core.RskAddress; import co.rsk.db.BenchmarkedRepository; import co.rsk.db.RepositoryTrackWithBenchmarking; diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/GetFeePerKbTest.java b/rskj-core/src/test/java/co/rsk/peg/performance/GetFeePerKbTest.java index 2e102d078ea..7cbe359f5a5 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/GetFeePerKbTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/GetFeePerKbTest.java @@ -23,6 +23,7 @@ import co.rsk.peg.Bridge; import co.rsk.peg.BridgeStorageProvider; import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationTestUtils; import org.ethereum.core.Repository; import org.ethereum.vm.exception.VMException; import org.junit.jupiter.api.Assertions; @@ -31,7 +32,7 @@ @Disabled class GetFeePerKbTest extends BridgePerformanceTestCase { - private Federation federation; + private Federation genesisFederation; @Test void getFeePerKb() throws VMException { @@ -59,7 +60,7 @@ private BridgeStorageProviderInitializer buildInitializer(boolean genesis) { if (!genesis) { provider.setFeePerKb(Helper.randomCoin(Coin.MILLICOIN, 1, 100)); } else { - federation = bridgeConstants.getGenesisFederation(); + genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); } }; } diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/LockingCapTest.java b/rskj-core/src/test/java/co/rsk/peg/performance/LockingCapTest.java index b044ff319c1..7405540d7d7 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/LockingCapTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/LockingCapTest.java @@ -3,7 +3,7 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.store.BlockStoreException; import co.rsk.bitcoinj.store.BtcBlockStore; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.peg.Bridge; import co.rsk.peg.BridgeStorageProvider; import co.rsk.peg.RepositoryBtcBlockStoreWithCache; diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/PowpegRedeemScriptTest.java b/rskj-core/src/test/java/co/rsk/peg/performance/PowpegRedeemScriptTest.java index 51ddb49c26f..89cfbbb5087 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/PowpegRedeemScriptTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/PowpegRedeemScriptTest.java @@ -1,7 +1,10 @@ package co.rsk.peg.performance; +import co.rsk.bitcoinj.script.Script; import co.rsk.peg.Bridge; import co.rsk.peg.BridgeMethods; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationTestUtils; import org.ethereum.config.Constants; import org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest; import org.ethereum.vm.exception.VMException; @@ -24,6 +27,12 @@ static void setupA() { void getActivePowpegRedeemScriptTest() throws VMException { ExecutionStats stats = new ExecutionStats("getActivePowpegRedeemScript"); ABIEncoder abiEncoder = (int executionIndex) -> BridgeMethods.GET_ACTIVE_POWPEG_REDEEM_SCRIPT.getFunction().encode(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); + Script federationRedeemScript= genesisFederation.getRedeemScript(); + byte[] federationRedeemScriptProgram = federationRedeemScript.getProgram(); + + + executeAndAverage( "getActivePowpegRedeemScriptTest", 10, @@ -32,12 +41,10 @@ void getActivePowpegRedeemScriptTest() throws VMException { Helper.getZeroValueRandomSenderTxBuilder(), Helper.getRandomHeightProvider(10), stats, - (environment, executionResult) -> { - assertArrayEquals( - constants.getBridgeConstants().getGenesisFederation().getRedeemScript().getProgram(), - getByteFromResult(executionResult) - ); - } + (environment, executionResult) -> assertArrayEquals( + federationRedeemScriptProgram, + getByteFromResult(executionResult) + ) ); BridgePerformanceTest.addStats(stats); } diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/ReceiveHeadersTest.java b/rskj-core/src/test/java/co/rsk/peg/performance/ReceiveHeadersTest.java index dfd594b28aa..f6979dbdea1 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/ReceiveHeadersTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/ReceiveHeadersTest.java @@ -24,7 +24,7 @@ import co.rsk.bitcoinj.core.Sha256Hash; import co.rsk.bitcoinj.store.BlockStoreException; import co.rsk.bitcoinj.store.BtcBlockStore; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.peg.Bridge; import co.rsk.peg.BridgeStorageProvider; import co.rsk.peg.RepositoryBtcBlockStoreWithCache; diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/RegisterBtcTransactionTest.java b/rskj-core/src/test/java/co/rsk/peg/performance/RegisterBtcTransactionTest.java index 2a99f9b68f8..94c04bbbf52 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/RegisterBtcTransactionTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/RegisterBtcTransactionTest.java @@ -25,6 +25,8 @@ import co.rsk.core.RskAddress; import co.rsk.peg.*; import co.rsk.peg.PegTestUtils; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationTestUtils; import org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest; import org.ethereum.core.Repository; import org.ethereum.crypto.ECKey; @@ -240,10 +242,13 @@ private BridgeStorageProviderInitializer generateInitializerForLock( BtcTransaction inputTx = new BtcTransaction(networkParameters); inputTx.addOutput(fromAmount, fromAddress); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); + Address federationAddress = genesisFederation.getAddress(); + // Lock tx that uses the input tx txToLock = new BtcTransaction(networkParameters); txToLock.addInput(inputTx.getOutput(0)); - txToLock.addOutput(lockAmount, bridgeConstants.getGenesisFederation().getAddress()); + txToLock.addOutput(lockAmount, federationAddress); txToLock.addOutput(changeAmount, fromAddress); ECKey ecKey = new ECKey(); diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/RegisterFlyoverBtcTransactionTest.java b/rskj-core/src/test/java/co/rsk/peg/performance/RegisterFlyoverBtcTransactionTest.java index b8721aac45c..7c98a738967 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/RegisterFlyoverBtcTransactionTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/RegisterFlyoverBtcTransactionTest.java @@ -10,6 +10,8 @@ import co.rsk.crypto.Keccak256; import co.rsk.peg.*; import co.rsk.peg.PegTestUtils; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationTestUtils; import org.ethereum.config.Constants; import org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest; import org.ethereum.core.Repository; @@ -149,9 +151,12 @@ private BridgeStorageProviderInitializer generateInitializerForTest( int blocksToGenerate = Helper.randomInRange(minBtcBlocks, maxBtcBlocks); BtcBlock lastBlock = Helper.generateAndAddBlocks(btcBlockChain, blocksToGenerate); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); + Script federationRedeemScript= genesisFederation.getRedeemScript(); - Script flyoverRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript( - bridgeConstants.getGenesisFederation().getRedeemScript(), + + Script flyoverRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript( + federationRedeemScript, Sha256Hash.wrap( getFLyoverDerivationHash( PegTestUtils.createHash3(1), diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/RetiringFederationTest.java b/rskj-core/src/test/java/co/rsk/peg/performance/RetiringFederationTest.java index 139d9bd7ae4..16b77292c38 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/RetiringFederationTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/RetiringFederationTest.java @@ -24,6 +24,7 @@ import co.rsk.peg.federation.Federation; import co.rsk.peg.federation.FederationArgs; import co.rsk.peg.federation.FederationFactory; +import co.rsk.peg.federation.FederationTestUtils; import org.ethereum.core.CallTransaction; import org.ethereum.core.Repository; import org.ethereum.vm.exception.VMException; @@ -102,6 +103,7 @@ private BridgeStorageProviderInitializer buildInitializer(boolean present) { final int minFederators = 10; final int maxFederators = 16; Random random = new Random(RetiringFederationTest.class.hashCode()); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); return (BridgeStorageProvider provider, Repository repository, int executionIndex, BtcBlockStore blockStore) -> { if (present) { int numFederators = Helper.randomInRange(minFederators, maxFederators); @@ -114,7 +116,7 @@ private BridgeStorageProviderInitializer buildInitializer(boolean present) { retiringFederation = FederationFactory.buildStandardMultiSigFederation( federationArgs ); - provider.setNewFederation(bridgeConstants.getGenesisFederation()); + provider.setNewFederation(genesisFederation); provider.setOldFederation(retiringFederation); } else { retiringFederation = null; diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/StateForBtcReleaseClientTest.java b/rskj-core/src/test/java/co/rsk/peg/performance/StateForBtcReleaseClientTest.java index 0abfa48fbc2..d033011327a 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/StateForBtcReleaseClientTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/StateForBtcReleaseClientTest.java @@ -28,6 +28,7 @@ import co.rsk.peg.BridgeStorageProvider; import co.rsk.peg.federation.Federation; import co.rsk.peg.PegTestUtils; +import co.rsk.peg.federation.FederationTestUtils; import org.ethereum.TestUtils; import org.ethereum.core.Repository; import org.ethereum.vm.exception.VMException; @@ -73,11 +74,10 @@ private BridgeStorageProviderInitializer getInitializer() { } int numTxs = Helper.randomInRange(minNumTxs, maxNumTxs); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeConstants); for (int i = 0; i < numTxs; i++) { BtcTransaction releaseTx = new BtcTransaction(networkParameters); - Federation federation = bridgeConstants.getGenesisFederation(); - // Receiver and amounts Address toAddress = new BtcECKey().toAddress(networkParameters); Coin releaseAmount = Coin.CENT.multiply(Helper.randomInRange(10, 100)); @@ -89,10 +89,10 @@ private BridgeStorageProviderInitializer getInitializer() { for (int j = 0; j < numInputs; j++) { Coin inputAmount = releaseAmount.divide(numInputs); BtcTransaction inputTx = new BtcTransaction(networkParameters); - inputTx.addOutput(inputAmount, federation.getAddress()); + inputTx.addOutput(inputAmount, genesisFederation.getAddress()); releaseTx .addInput(inputTx.getOutput(0)) - .setScriptSig(PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation(federation)); + .setScriptSig(PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation(genesisFederation)); } diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/UpdateCollectionsTest.java b/rskj-core/src/test/java/co/rsk/peg/performance/UpdateCollectionsTest.java index bdd12c2844d..c859fef26b4 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/UpdateCollectionsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/UpdateCollectionsTest.java @@ -18,21 +18,19 @@ package co.rsk.peg.performance; -import co.rsk.bitcoinj.core.BtcECKey; -import co.rsk.bitcoinj.core.BtcTransaction; -import co.rsk.bitcoinj.core.Coin; -import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.bitcoinj.core.Sha256Hash; -import co.rsk.bitcoinj.core.UTXO; +import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.script.Script; import co.rsk.bitcoinj.store.BtcBlockStore; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.crypto.Keccak256; import co.rsk.peg.Bridge; import co.rsk.peg.BridgeStorageProvider; import co.rsk.peg.PegTestUtils; import co.rsk.peg.ReleaseRequestQueue; import co.rsk.peg.PegoutsWaitingForConfirmations; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationTestUtils; import org.ethereum.config.Constants; import org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest; import org.ethereum.core.Repository; @@ -70,6 +68,8 @@ class UpdateCollectionsTest extends BridgePerformanceTestCase { private int maxHeight = 150; private int minCentOutput = 1; private int maxCentOutput = 100; + private final BridgeConstants bridgeRegTestConstants = BridgeRegTestConstants.getInstance(); + @Test void updateCollections() throws IOException, VMException { @@ -188,13 +188,13 @@ private void updateCollections_buildPegoutsWaitingForConfirmations(ExecutionStat // Generate some utxos int numUTXOs = Helper.randomInRange(minUTXOs, maxUTXOs); - - Script federationScript = BridgeRegTestConstants.getInstance().getGenesisFederation().getP2SHScript(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeRegTestConstants); + Script federationP2SHScript = genesisFederation.getP2SHScript(); for (int i = 0; i < numUTXOs; i++) { Sha256Hash hash = Sha256Hash.wrap(HashUtil.sha256(BigInteger.valueOf(rnd.nextLong()).toByteArray())); Coin value = Coin.MILLICOIN.multiply(Helper.randomInRange(minMilliBtc, maxMilliBtc)); - utxos.add(new UTXO(hash, 0, value, 1, false, federationScript)); + utxos.add(new UTXO(hash, 0, value, 1, false, federationP2SHScript)); } // Generate some release requests to process @@ -247,8 +247,10 @@ private void updateCollections_confirmTxs(ExecutionStats stats, int numCases) th throw new RuntimeException("Unable to gather release tx set"); } + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeRegTestConstants); + // Generate some txs waiting for signatures - Script genesisFederationScript = bridgeConstants.getGenesisFederation().getP2SHScript(); + Script genesisFederationScript = genesisFederation.getP2SHScript(); for (int i = 0; i < Helper.randomInRange(minTxsWaitingForSigs, maxTxsWaitingForSigs); i++) { Keccak256 rskHash = new Keccak256(HashUtil.keccak256(BigInteger.valueOf(rnd.nextLong()).toByteArray())); BtcTransaction btcTx = new BtcTransaction(networkParameters); @@ -305,13 +307,13 @@ private void updateCollections_buildPegoutWaitingForConfirmationsForBatchingPego // Generate some utxos int numUTXOs = Helper.randomInRange(minUTXOs, maxUTXOs); - - Script federationScript = BridgeRegTestConstants.getInstance().getGenesisFederation().getP2SHScript(); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeRegTestConstants); + Script federationP2SHScript = genesisFederation.getP2SHScript(); for (int i = 0; i < numUTXOs; i++) { Sha256Hash hash = Sha256Hash.wrap(HashUtil.sha256(BigInteger.valueOf(rnd.nextLong()).toByteArray())); Coin value = Coin.MILLICOIN.multiply(Helper.randomInRange(minMilliBtc, maxMilliBtc)); - utxos.add(new UTXO(hash, 0, value, 1, false, federationScript)); + utxos.add(new UTXO(hash, 0, value, 1, false, federationP2SHScript)); } // Generate some release requests to process diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/VoteFeePerKbChangeTest.java b/rskj-core/src/test/java/co/rsk/peg/performance/VoteFeePerKbChangeTest.java index 3c42bb20b22..7d8e18649fa 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/VoteFeePerKbChangeTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/VoteFeePerKbChangeTest.java @@ -19,7 +19,7 @@ package co.rsk.peg.performance; import co.rsk.bitcoinj.core.Coin; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.peg.Bridge; import org.ethereum.crypto.ECKey; import org.ethereum.crypto.HashUtil; diff --git a/rskj-core/src/test/java/co/rsk/peg/utils/BridgeEventLoggerImplTest.java b/rskj-core/src/test/java/co/rsk/peg/utils/BridgeEventLoggerImplTest.java index d666f35c50b..52d6befc0da 100644 --- a/rskj-core/src/test/java/co/rsk/peg/utils/BridgeEventLoggerImplTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/utils/BridgeEventLoggerImplTest.java @@ -19,8 +19,8 @@ import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.script.ScriptBuilder; -import co.rsk.config.BridgeMainNetConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.peg.*; diff --git a/rskj-core/src/test/java/co/rsk/peg/utils/BridgeEventLoggerLegacyImplTest.java b/rskj-core/src/test/java/co/rsk/peg/utils/BridgeEventLoggerLegacyImplTest.java index 23e9ad54133..33c7a6c6c43 100644 --- a/rskj-core/src/test/java/co/rsk/peg/utils/BridgeEventLoggerLegacyImplTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/utils/BridgeEventLoggerLegacyImplTest.java @@ -19,8 +19,8 @@ package co.rsk.peg.utils; import co.rsk.bitcoinj.core.*; -import co.rsk.config.BridgeConstants; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.peg.*; diff --git a/rskj-core/src/test/java/co/rsk/peg/utils/BtcTransactionFormatUtilsTest.java b/rskj-core/src/test/java/co/rsk/peg/utils/BtcTransactionFormatUtilsTest.java index 7673ecac5f8..d77f756825d 100644 --- a/rskj-core/src/test/java/co/rsk/peg/utils/BtcTransactionFormatUtilsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/utils/BtcTransactionFormatUtilsTest.java @@ -27,7 +27,7 @@ import co.rsk.bitcoinj.core.Sha256Hash; import co.rsk.bitcoinj.core.TransactionWitness; import co.rsk.bitcoinj.script.Script; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import org.bouncycastle.util.encoders.Hex; import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; diff --git a/rskj-core/src/test/java/co/rsk/remasc/RemascFederationProviderTest.java b/rskj-core/src/test/java/co/rsk/remasc/RemascFederationProviderTest.java index ec8e4b6df22..ad381e9c74f 100644 --- a/rskj-core/src/test/java/co/rsk/remasc/RemascFederationProviderTest.java +++ b/rskj-core/src/test/java/co/rsk/remasc/RemascFederationProviderTest.java @@ -3,7 +3,7 @@ import static org.mockito.Mockito.*; import co.rsk.blockchain.utils.BlockGenerator; -import co.rsk.config.BridgeMainNetConstants; +import co.rsk.peg.constants.BridgeMainNetConstants; import co.rsk.core.RskAddress; import co.rsk.peg.BridgeStorageProvider; import co.rsk.peg.FederationSupport; diff --git a/rskj-core/src/test/java/co/rsk/rpc/modules/eth/EthModuleTest.java b/rskj-core/src/test/java/co/rsk/rpc/modules/eth/EthModuleTest.java index a4bcbf608cc..77c4f73a2d2 100644 --- a/rskj-core/src/test/java/co/rsk/rpc/modules/eth/EthModuleTest.java +++ b/rskj-core/src/test/java/co/rsk/rpc/modules/eth/EthModuleTest.java @@ -17,7 +17,7 @@ */ package co.rsk.rpc.modules.eth; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.config.TestSystemProperties; import co.rsk.core.Coin; import co.rsk.core.ReversibleTransactionExecutor; diff --git a/rskj-core/src/test/java/co/rsk/test/builders/BridgeSupportBuilder.java b/rskj-core/src/test/java/co/rsk/test/builders/BridgeSupportBuilder.java index 0bc09cb56a7..ae7d38e3062 100644 --- a/rskj-core/src/test/java/co/rsk/test/builders/BridgeSupportBuilder.java +++ b/rskj-core/src/test/java/co/rsk/test/builders/BridgeSupportBuilder.java @@ -3,7 +3,7 @@ import static org.mockito.Mockito.mock; import co.rsk.bitcoinj.core.Context; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.peg.BridgeStorageProvider; import co.rsk.peg.BridgeSupport; import co.rsk.peg.BtcBlockStoreWithCache.Factory; diff --git a/rskj-core/src/test/java/org/ethereum/config/ConstantsTest.java b/rskj-core/src/test/java/org/ethereum/config/ConstantsTest.java index e08b2514786..bd86ad68a72 100644 --- a/rskj-core/src/test/java/org/ethereum/config/ConstantsTest.java +++ b/rskj-core/src/test/java/org/ethereum/config/ConstantsTest.java @@ -28,6 +28,11 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; + +import co.rsk.peg.constants.BridgeConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationTestUtils; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ConsensusRule; import org.ethereum.crypto.HashUtil; @@ -46,6 +51,8 @@ class ConstantsTest { private final ActivationConfig activationConfig = mock(ActivationConfig.class); private final ActivationConfig.ForBlock preRskip297Config = mock(ActivationConfig.ForBlock.class); private final ActivationConfig.ForBlock postRskip297Config = mock(ActivationConfig.ForBlock.class); + private final BridgeConstants bridgeRegTestConstants = BridgeRegTestConstants.getInstance(); + @BeforeEach void setUp() { @@ -55,11 +62,12 @@ void setUp() { @Test void devnetWithFederationTest() { - Constants constants = Constants.devnetWithFederation(TEST_FED_KEYS.subList(0, 3)); - assertThat(constants.getBridgeConstants().getGenesisFederation().hasBtcPublicKey(TEST_FED_KEYS.get(0)), is(true)); - assertThat(constants.getBridgeConstants().getGenesisFederation().hasBtcPublicKey(TEST_FED_KEYS.get(1)), is(true)); - assertThat(constants.getBridgeConstants().getGenesisFederation().hasBtcPublicKey(TEST_FED_KEYS.get(2)), is(true)); - assertThat(constants.getBridgeConstants().getGenesisFederation().hasBtcPublicKey(TEST_FED_KEYS.get(3)), is(false)); + Federation genesisFederation = FederationTestUtils.getGenesisFederation(bridgeRegTestConstants); + + assertThat(genesisFederation.hasBtcPublicKey(TEST_FED_KEYS.get(0)), is(true)); + assertThat(genesisFederation.hasBtcPublicKey(TEST_FED_KEYS.get(1)), is(true)); + assertThat(genesisFederation.hasBtcPublicKey(TEST_FED_KEYS.get(2)), is(true)); + assertThat(genesisFederation.hasBtcPublicKey(TEST_FED_KEYS.get(3)), is(false)); } @Test diff --git a/rskj-core/src/test/java/org/ethereum/jsontestsuite/runners/StateTestRunner.java b/rskj-core/src/test/java/org/ethereum/jsontestsuite/runners/StateTestRunner.java index ac3d4704afb..480e759517c 100644 --- a/rskj-core/src/test/java/org/ethereum/jsontestsuite/runners/StateTestRunner.java +++ b/rskj-core/src/test/java/org/ethereum/jsontestsuite/runners/StateTestRunner.java @@ -18,7 +18,7 @@ */ package org.ethereum.jsontestsuite.runners; -import co.rsk.config.BridgeRegTestConstants; +import co.rsk.peg.constants.BridgeRegTestConstants; import co.rsk.config.TestSystemProperties; import co.rsk.core.RskAddress; import co.rsk.core.TransactionExecutorFactory; diff --git a/rskj-core/src/test/java/org/ethereum/util/EthModuleTestUtils.java b/rskj-core/src/test/java/org/ethereum/util/EthModuleTestUtils.java index d3fedfc3618..1a80bcbff50 100644 --- a/rskj-core/src/test/java/org/ethereum/util/EthModuleTestUtils.java +++ b/rskj-core/src/test/java/org/ethereum/util/EthModuleTestUtils.java @@ -19,7 +19,7 @@ package org.ethereum.util; -import co.rsk.config.BridgeConstants; +import co.rsk.peg.constants.BridgeConstants; import co.rsk.config.TestSystemProperties; import co.rsk.core.ReversibleTransactionExecutor; import co.rsk.core.TransactionExecutorFactory;