Search in sources :

Example 31 with Script

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));
}
Also used : Context(co.rsk.bitcoinj.core.Context) Script(co.rsk.bitcoinj.script.Script) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Example 32 with Script

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));
}
Also used : Context(co.rsk.bitcoinj.core.Context) Script(co.rsk.bitcoinj.script.Script) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) TransactionInput(co.rsk.bitcoinj.core.TransactionInput) TransactionOutPoint(co.rsk.bitcoinj.core.TransactionOutPoint) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Example 33 with Script

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);
}
Also used : Context(co.rsk.bitcoinj.core.Context) Script(co.rsk.bitcoinj.script.Script) RedeemData(co.rsk.bitcoinj.wallet.RedeemData) FastBridgeFederationInformation(co.rsk.peg.fastbridge.FastBridgeFederationInformation) Test(org.junit.Test)

Example 34 with Script

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()));
}
Also used : Script(co.rsk.bitcoinj.script.Script) Address(co.rsk.bitcoinj.core.Address) RskAddress(co.rsk.core.RskAddress) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) TransactionInput(co.rsk.bitcoinj.core.TransactionInput) TransactionOutPoint(co.rsk.bitcoinj.core.TransactionOutPoint) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Example 35 with Script

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));
}
Also used : Context(co.rsk.bitcoinj.core.Context) Script(co.rsk.bitcoinj.script.Script) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Aggregations

Script (co.rsk.bitcoinj.script.Script)123 Test (org.junit.Test)91 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)60 RskAddress (co.rsk.core.RskAddress)47 BtcTransaction (co.rsk.bitcoinj.core.BtcTransaction)40 Repository (org.ethereum.core.Repository)34 MutableRepository (org.ethereum.db.MutableRepository)33 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)29 BtcECKey (co.rsk.bitcoinj.core.BtcECKey)26 Block (org.ethereum.core.Block)24 Context (co.rsk.bitcoinj.core.Context)21 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)20 PeginInstructionsProvider (co.rsk.peg.pegininstructions.PeginInstructionsProvider)20 Address (co.rsk.bitcoinj.core.Address)17 TransactionOutPoint (co.rsk.bitcoinj.core.TransactionOutPoint)17 PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation (co.rsk.peg.PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation)17 PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation (co.rsk.peg.PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation)17 BtcLockSenderProvider (co.rsk.peg.btcLockSender.BtcLockSenderProvider)17 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)17 InternalTransaction (org.ethereum.vm.program.InternalTransaction)17