use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeUtilsTest method testIsValidPegInTx_hasChangeUtxoFromErpFederation_afterRskip201_notPegin.
@Test
public void testIsValidPegInTx_hasChangeUtxoFromErpFederation_afterRskip201_notPegin() {
Context btcContext = new Context(networkParameters);
when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true);
Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation();
List<BtcECKey> erpFederationKeys = Arrays.asList(BtcECKey.fromPrivate(Hex.decode("fa01")), BtcECKey.fromPrivate(Hex.decode("fa02")));
erpFederationKeys.sort(BtcECKey.PUBKEY_COMPARATOR);
Federation erpFederation = new Federation(FederationTestUtils.getFederationMembersWithBtcKeys(erpFederationKeys), Instant.ofEpochMilli(1000L), 0L, networkParameters);
Script erpRedeemScript = ErpFederationRedeemScriptParser.createErpRedeemScript(activeFederation.getRedeemScript(), erpFederation.getRedeemScript(), 500L);
// Create a tx from the erp fed to the active fed
BtcTransaction tx = new BtcTransaction(networkParameters);
tx.addOutput(Coin.COIN, activeFederation.getAddress());
tx.addInput(Sha256Hash.ZERO_HASH, 0, erpRedeemScript);
Assert.assertFalse(BridgeUtils.isValidPegInTx(tx, activeFederation, btcContext, bridgeConstantsRegtest, activations));
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeUtilsTest method testIsValidPegInTx_hasChangeUtxoFromFastBridgeErpRetiredFederation_afterRskip201_notPegin.
@Test
public void testIsValidPegInTx_hasChangeUtxoFromFastBridgeErpRetiredFederation_afterRskip201_notPegin() {
Context btcContext = new Context(networkParameters);
Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation();
when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true);
when(activations.isActive(ConsensusRule.RSKIP284)).thenReturn(true);
List<BtcECKey> retiredFederationKeys = Arrays.asList(BtcECKey.fromPrivate(Hex.decode("fa01")), BtcECKey.fromPrivate(Hex.decode("fa02")));
retiredFederationKeys.sort(BtcECKey.PUBKEY_COMPARATOR);
Federation retiredFederation = new Federation(FederationTestUtils.getFederationMembersWithBtcKeys(retiredFederationKeys), Instant.ofEpochMilli(1000L), 0L, networkParameters);
List<BtcECKey> erpFederationPublicKeys = Arrays.asList(BtcECKey.fromPrivate(Hex.decode("fa03")), BtcECKey.fromPrivate(Hex.decode("fa04")));
erpFederationPublicKeys.sort(BtcECKey.PUBKEY_COMPARATOR);
Federation erpFederation = new ErpFederation(FederationTestUtils.getFederationMembersWithBtcKeys(retiredFederationKeys), Instant.ofEpochMilli(1000L), 0L, networkParameters, erpFederationPublicKeys, 500L, activations);
// Create a tx from the retired fast bridge fed to the active fed
BtcTransaction tx = new BtcTransaction(networkParameters);
tx.addOutput(Coin.COIN, activeFederation.getAddress());
TransactionInput txInput = new TransactionInput(networkParameters, tx, new byte[0], new TransactionOutPoint(networkParameters, 0, Sha256Hash.ZERO_HASH));
tx.addInput(txInput);
Script fastBridgeErpRedeemScript = FastBridgeErpRedeemScriptParser.createFastBridgeErpRedeemScript(erpFederation.getRedeemScript(), PegTestUtils.createHash(2));
signWithNecessaryKeys(erpFederation, fastBridgeErpRedeemScript, retiredFederationKeys, txInput, tx);
assertFalse(BridgeUtils.isValidPegInTx(tx, Collections.singletonList(activeFederation), retiredFederation.getP2SHScript(), btcContext, bridgeConstantsRegtest, activations));
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class FastBridgeCompatibleBtcWalletWithSingleScriptTest method findRedeemDataFromScriptHash_with_fastBridgeInformation.
@Test
public void findRedeemDataFromScriptHash_with_fastBridgeInformation() {
byte[] fastBridgeScriptHash = new byte[] { (byte) 0x22 };
FastBridgeFederationInformation fastBridgeFederationInformation = new FastBridgeFederationInformation(PegTestUtils.createHash3(2), federation.getP2SHScript().getPubKeyHash(), fastBridgeScriptHash);
FastBridgeCompatibleBtcWalletWithSingleScript fastBridgeCompatibleBtcWalletWithSingleScript = new FastBridgeCompatibleBtcWalletWithSingleScript(mock(Context.class), federationList, fastBridgeFederationInformation);
RedeemData redeemData = fastBridgeCompatibleBtcWalletWithSingleScript.findRedeemDataFromScriptHash(federation.getP2SHScript().getPubKeyHash());
Script fastBridgeRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript(federation.getRedeemScript(), Sha256Hash.wrap(fastBridgeFederationInformation.getDerivationHash().getBytes()));
Assert.assertNotNull(redeemData);
Assert.assertEquals(fastBridgeRedeemScript, redeemData.redeemScript);
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeUtilsTest method testIsPegOutTx_fromFastBridgeFederation.
@Test
public void testIsPegOutTx_fromFastBridgeFederation() {
List<BtcECKey> fastBridgeFederationKeys = Arrays.asList(BtcECKey.fromPrivate(Hex.decode("fa01")), BtcECKey.fromPrivate(Hex.decode("fa02")), BtcECKey.fromPrivate(Hex.decode("fa03")));
fastBridgeFederationKeys.sort(BtcECKey.PUBKEY_COMPARATOR);
Federation fastBridgeFederation = new Federation(FederationTestUtils.getFederationMembersWithBtcKeys(fastBridgeFederationKeys), Instant.ofEpochMilli(1000L), 0L, networkParameters);
Federation standardFederation = bridgeConstantsRegtest.getGenesisFederation();
// Create a tx from the fast bridge fed to a random address
Address randomAddress = PegTestUtils.createRandomBtcAddress();
BtcTransaction pegOutTx1 = new BtcTransaction(networkParameters);
pegOutTx1.addOutput(Coin.COIN, randomAddress);
TransactionInput pegOutInput1 = new TransactionInput(networkParameters, pegOutTx1, new byte[] {}, new TransactionOutPoint(networkParameters, 0, Sha256Hash.ZERO_HASH));
pegOutTx1.addInput(pegOutInput1);
Script fastBridgeRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript(fastBridgeFederation.getRedeemScript(), PegTestUtils.createHash(2));
signWithNecessaryKeys(fastBridgeFederation, fastBridgeRedeemScript, fastBridgeFederationKeys, pegOutInput1, pegOutTx1);
// Before RSKIP 201 activation
when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(false);
assertFalse(BridgeUtils.isPegOutTx(pegOutTx1, Collections.singletonList(fastBridgeFederation), activations));
assertFalse(BridgeUtils.isPegOutTx(pegOutTx1, Arrays.asList(fastBridgeFederation, standardFederation), activations));
assertFalse(BridgeUtils.isPegOutTx(pegOutTx1, Collections.singletonList(standardFederation), activations));
assertFalse(BridgeUtils.isPegOutTx(pegOutTx1, activations, fastBridgeFederation.getP2SHScript()));
assertFalse(BridgeUtils.isPegOutTx(pegOutTx1, activations, fastBridgeFederation.getP2SHScript(), standardFederation.getP2SHScript()));
assertFalse(BridgeUtils.isPegOutTx(pegOutTx1, activations, standardFederation.getP2SHScript()));
// After RSKIP 201 activation
when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true);
assertTrue(BridgeUtils.isPegOutTx(pegOutTx1, Collections.singletonList(fastBridgeFederation), activations));
assertTrue(BridgeUtils.isPegOutTx(pegOutTx1, Arrays.asList(fastBridgeFederation, standardFederation), activations));
assertFalse(BridgeUtils.isPegOutTx(pegOutTx1, Collections.singletonList(standardFederation), activations));
assertTrue(BridgeUtils.isPegOutTx(pegOutTx1, activations, fastBridgeFederation.getP2SHScript()));
assertTrue(BridgeUtils.isPegOutTx(pegOutTx1, activations, fastBridgeFederation.getP2SHScript(), standardFederation.getP2SHScript()));
assertFalse(BridgeUtils.isPegOutTx(pegOutTx1, activations, standardFederation.getP2SHScript()));
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeUtilsTest method testIsValidPegInTx_hasChangeUtxoFromFastBridgeFederation_beforeRskip201_isPegin.
@Test
public void testIsValidPegInTx_hasChangeUtxoFromFastBridgeFederation_beforeRskip201_isPegin() {
Context btcContext = new Context(networkParameters);
when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(false);
Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation();
Script fastBridgeRedeemScript = 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);
tx.addOutput(Coin.COIN, activeFederation.getAddress());
tx.addInput(Sha256Hash.ZERO_HASH, 0, fastBridgeRedeemScript);
Assert.assertTrue(BridgeUtils.isValidPegInTx(tx, activeFederation, btcContext, bridgeConstantsRegtest, activations));
}
Aggregations