use of co.rsk.bitcoinj.core.TransactionOutPoint in project rskj by rsksmart.
the class BridgeUtilsTest method scriptCorrectlySpends_fromGenesisFederation_ok.
@Test
public void scriptCorrectlySpends_fromGenesisFederation_ok() {
Federation genesisFederation = bridgeConstantsRegtest.getGenesisFederation();
Address destinationAddress = PegTestUtils.createRandomBtcAddress();
BtcTransaction tx = new BtcTransaction(networkParameters);
tx.addOutput(Coin.COIN, destinationAddress);
TransactionInput txIn = new TransactionInput(networkParameters, tx, new byte[] {}, new TransactionOutPoint(networkParameters, 0, Sha256Hash.ZERO_HASH));
tx.addInput(txIn);
signWithNecessaryKeys(genesisFederation, BridgeRegTestConstants.REGTEST_FEDERATION_PRIVATE_KEYS, txIn, tx);
assertTrue(BridgeUtils.scriptCorrectlySpendsTx(tx, 0, genesisFederation.getP2SHScript()));
}
use of co.rsk.bitcoinj.core.TransactionOutPoint in project rskj by rsksmart.
the class BridgeUtilsTest method testIsValidPegInTx_hasChangeUtxoFromFastBridgeRetiredFederation_afterRskip201_notPegin.
@Test
public void testIsValidPegInTx_hasChangeUtxoFromFastBridgeRetiredFederation_afterRskip201_notPegin() {
Context btcContext = new Context(networkParameters);
Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation();
when(activations.isActive(ConsensusRule.RSKIP201)).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);
// 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 fastBridgeRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript(retiredFederation.getRedeemScript(), PegTestUtils.createHash(2));
signWithNecessaryKeys(retiredFederation, fastBridgeRedeemScript, retiredFederationKeys, txInput, tx);
assertFalse(BridgeUtils.isValidPegInTx(tx, Collections.singletonList(activeFederation), retiredFederation.getP2SHScript(), btcContext, bridgeConstantsRegtest, activations));
}
use of co.rsk.bitcoinj.core.TransactionOutPoint in project rskj by rsksmart.
the class BridgeUtilsTest method isInputSignedByThisFederator_notSigned.
@Test
public void isInputSignedByThisFederator_notSigned() {
// Arrange
BtcECKey federator1Key = new BtcECKey();
BtcECKey federator2Key = new BtcECKey();
Federation federation = new Federation(FederationMember.getFederationMembersFromKeys(Arrays.asList(federator1Key, federator2Key)), Instant.now(), 0, networkParameters);
// Create a tx from the Fed to a random btc address
BtcTransaction tx = new BtcTransaction(networkParameters);
TransactionInput txInput = new TransactionInput(networkParameters, tx, new byte[] {}, new TransactionOutPoint(networkParameters, 0, Sha256Hash.ZERO_HASH));
// Create script to be signed by federation members
Script inputScript = PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation(federation);
txInput.setScriptSig(inputScript);
tx.addInput(txInput);
List<ScriptChunk> chunks = inputScript.getChunks();
byte[] program = chunks.get(chunks.size() - 1).data;
Script redeemScript = new Script(program);
Sha256Hash sighash = tx.hashForSignature(0, redeemScript, BtcTransaction.SigHash.ALL, false);
// Act
boolean isSigned = BridgeUtils.isInputSignedByThisFederator(federator1Key, sighash, txInput);
// Assert
Assert.assertFalse(isSigned);
}
use of co.rsk.bitcoinj.core.TransactionOutPoint in project rskj by rsksmart.
the class BridgeUtilsTest method testIsPegOutTx.
@Test
public void testIsPegOutTx() {
Federation federation = bridgeConstantsRegtest.getGenesisFederation();
List<BtcECKey> activeFederationKeys = Stream.of(BtcECKey.fromPrivate(Hex.decode("fa01")), BtcECKey.fromPrivate(Hex.decode("fa02")), BtcECKey.fromPrivate(Hex.decode("fa03"))).sorted(BtcECKey.PUBKEY_COMPARATOR).collect(Collectors.toList());
Federation federation2 = new Federation(FederationTestUtils.getFederationMembersWithBtcKeys(activeFederationKeys), Instant.ofEpochMilli(2000L), 2L, bridgeConstantsRegtest.getBtcParams());
List<BtcECKey> federationPrivateKeys = BridgeRegTestConstants.REGTEST_FEDERATION_PRIVATE_KEYS;
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);
signWithNecessaryKeys(federation, federationPrivateKeys, pegOutInput1, pegOutTx1);
assertTrue(BridgeUtils.isPegOutTx(pegOutTx1, Collections.singletonList(federation), activations));
assertTrue(BridgeUtils.isPegOutTx(pegOutTx1, Arrays.asList(federation, federation2), activations));
assertFalse(BridgeUtils.isPegOutTx(pegOutTx1, Collections.singletonList(federation2), activations));
assertTrue(BridgeUtils.isPegOutTx(pegOutTx1, activations, federation.getP2SHScript()));
assertTrue(BridgeUtils.isPegOutTx(pegOutTx1, activations, federation.getP2SHScript(), federation2.getP2SHScript()));
assertFalse(BridgeUtils.isPegOutTx(pegOutTx1, activations, federation2.getP2SHScript()));
}
use of co.rsk.bitcoinj.core.TransactionOutPoint 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()));
}
Aggregations