Search in sources :

Example 76 with Script

use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.

the class PegTestUtils method createBaseInputScriptThatSpendsFromTheFederation.

public static Script createBaseInputScriptThatSpendsFromTheFederation(Federation federation) {
    Script scriptPubKey = federation.getP2SHScript();
    Script redeemScript = createBaseRedeemScriptThatSpendsFromTheFederation(federation);
    RedeemData redeemData = RedeemData.of(federation.getBtcPublicKeys(), redeemScript);
    Script inputScript = scriptPubKey.createEmptyInputScript(redeemData.keys.get(0), redeemData.redeemScript);
    return inputScript;
}
Also used : Script(co.rsk.bitcoinj.script.Script) RedeemData(co.rsk.bitcoinj.wallet.RedeemData)

Example 77 with Script

use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.

the class P2shP2wpkhBtcLockSenderTest method doesnt_parse_if_transaction_witness_doesnt_have_two_pushes.

@Test
public void doesnt_parse_if_transaction_witness_doesnt_have_two_pushes() {
    BtcTransaction btcTx = new BtcTransaction(networkParameters);
    btcTx.addInput(PegTestUtils.createHash(1), 0, new Script(new byte[] {}));
    TransactionWitness witness = new TransactionWitness(1);
    witness.setPush(0, new byte[] {});
    btcTx.setWitness(0, witness);
    BtcLockSender btcLockSender = new P2shP2wpkhBtcLockSender();
    Assert.assertFalse(btcLockSender.tryParse(btcTx));
}
Also used : Script(co.rsk.bitcoinj.script.Script) Test(org.junit.Test)

Example 78 with Script

use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.

the class PeginInstructionsProviderTest method extractOpReturnData_nullOpReturnData.

@Test(expected = NoOpReturnException.class)
public void extractOpReturnData_nullOpReturnData() throws PeginInstructionsException {
    // Arrange
    BtcTransaction btcTransaction = new BtcTransaction(params);
    // Add OP_RETURN output with empty data
    btcTransaction.addOutput(Coin.ZERO, new Script(new byte[] { ScriptOpCodes.OP_RETURN }));
    // Act
    PeginInstructionsProvider.extractOpReturnData(btcTransaction);
}
Also used : Script(co.rsk.bitcoinj.script.Script) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) Test(org.junit.Test)

Example 79 with Script

use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.

the class PeginInstructionsProviderTest method buildPeginInstructions_v1_noBtcRefundAddress.

@Test
public void buildPeginInstructions_v1_noBtcRefundAddress() throws Exception {
    // Arrange
    int protocolVersion = 1;
    BtcECKey key = new BtcECKey();
    RskAddress rskDestinationAddress = new RskAddress(ECKey.fromPublicOnly(key.getPubKey()).getAddress());
    Script opReturnScript = PegTestUtils.createOpReturnScriptForRsk(protocolVersion, rskDestinationAddress, Optional.empty());
    BtcTransaction btcTransaction = new BtcTransaction(params);
    btcTransaction.addOutput(Coin.ZERO, opReturnScript);
    // Act
    PeginInstructionsProvider peginInstructionsProvider = new PeginInstructionsProvider();
    Optional<PeginInstructions> peginInstructions = peginInstructionsProvider.buildPeginInstructions(btcTransaction);
    // Assert
    Assert.assertTrue(peginInstructions.isPresent());
    Assert.assertEquals(protocolVersion, peginInstructions.get().getProtocolVersion());
    Assert.assertEquals(rskDestinationAddress, peginInstructions.get().getRskDestinationAddress());
}
Also used : Script(co.rsk.bitcoinj.script.Script) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) RskAddress(co.rsk.core.RskAddress) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) Test(org.junit.Test)

Example 80 with Script

use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.

the class PeginInstructionsVersion1Test method parseAdditionalData_noBtcRefundAddress.

@Test
public void parseAdditionalData_noBtcRefundAddress() throws PeginInstructionsException {
    // Arrange
    Script opReturnScript = PegTestUtils.createOpReturnScriptForRsk(1, new RskAddress(new byte[20]), Optional.empty());
    // Act
    PeginInstructionsVersion1 peginInstructionsVersion1 = new PeginInstructionsVersion1(params);
    peginInstructionsVersion1.parseAdditionalData(opReturnScript.getChunks().get(1).data);
    // Assert
    Optional<Address> obtainedBtcAddress = peginInstructionsVersion1.getBtcRefundAddress();
    Assert.assertFalse(obtainedBtcAddress.isPresent());
}
Also used : Script(co.rsk.bitcoinj.script.Script) Address(co.rsk.bitcoinj.core.Address) RskAddress(co.rsk.core.RskAddress) RskAddress(co.rsk.core.RskAddress) 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