use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class PeginInstructionsProviderTest method buildPeginInstructions_v1_dataLengthSmallerThanExpected.
@Test(expected = PeginInstructionsException.class)
public void buildPeginInstructions_v1_dataLengthSmallerThanExpected() throws Exception {
// Arrange
int protocolVersion = 1;
BtcTransaction btcTransaction = new BtcTransaction(params);
Script opReturnScript = PegTestUtils.createOpReturnScriptForRskWithCustomPayload(protocolVersion, new byte[5]);
btcTransaction.addOutput(Coin.ZERO, opReturnScript);
// Act
PeginInstructionsProvider peginInstructionsProvider = new PeginInstructionsProvider();
peginInstructionsProvider.buildPeginInstructions(btcTransaction);
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class PeginInstructionsProviderTest method extractOpReturnData_twoOpReturnOutputsForRsk.
@Test(expected = PeginInstructionsException.class)
public void extractOpReturnData_twoOpReturnOutputsForRsk() throws PeginInstructionsException {
// Arrange
Script opReturnScript = PegTestUtils.createOpReturnScriptForRsk(1, new RskAddress(new byte[20]), Optional.empty());
BtcTransaction btcTransaction = new BtcTransaction(params);
btcTransaction.addOutput(Coin.ZERO, opReturnScript);
btcTransaction.addOutput(Coin.ZERO, opReturnScript);
// Act
PeginInstructionsProvider.extractOpReturnData(btcTransaction);
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class PeginInstructionsProviderTest method buildPeginInstructions_invalidProtocolVersion.
@Test(expected = PeginInstructionsException.class)
public void buildPeginInstructions_invalidProtocolVersion() throws Exception {
// Arrange
int invalidProtocolVersion = 0;
BtcTransaction btcTransaction = new BtcTransaction(params);
Script opReturnScript = PegTestUtils.createOpReturnScriptForRsk(invalidProtocolVersion, new RskAddress(new byte[20]), Optional.empty());
btcTransaction.addOutput(Coin.ZERO, opReturnScript);
// Act
PeginInstructionsProvider peginInstructionsProvider = new PeginInstructionsProvider();
peginInstructionsProvider.buildPeginInstructions(btcTransaction);
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeUtilsTest method testIsValidPegInTx_hasChangeUtxoFromFastBridgeErpFederation_beforeRskip201_isPegin.
@Test
public void testIsValidPegInTx_hasChangeUtxoFromFastBridgeErpFederation_beforeRskip201_isPegin() {
Context btcContext = new Context(networkParameters);
when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(false);
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 fastBridgeErpRedeemScript = FastBridgeErpRedeemScriptParser.createFastBridgeErpRedeemScript(activeFederation.getRedeemScript(), erpFederation.getRedeemScript(), 500L, Sha256Hash.of(PegTestUtils.createHash(1).getBytes()));
// Create a tx from the fast bridge erp fed to the active fed
BtcTransaction tx = new BtcTransaction(networkParameters);
tx.addOutput(Coin.COIN, activeFederation.getAddress());
tx.addInput(Sha256Hash.ZERO_HASH, 0, fastBridgeErpRedeemScript);
Assert.assertTrue(BridgeUtils.isValidPegInTx(tx, activeFederation, btcContext, bridgeConstantsRegtest, activations));
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeUtilsTest method testIsValidPegInTx_hasChangeUtxoFromFastBridgeFederation_afterRskip201_notPegin.
@Test
public void testIsValidPegInTx_hasChangeUtxoFromFastBridgeFederation_afterRskip201_notPegin() {
Context btcContext = new Context(networkParameters);
when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true);
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.assertFalse(BridgeUtils.isValidPegInTx(tx, activeFederation, btcContext, bridgeConstantsRegtest, activations));
}
Aggregations