use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeSupportTest method assertRefundInProcessPegInVersionLegacy.
private void assertRefundInProcessPegInVersionLegacy(boolean isWhitelisted, boolean mockLockingCap, TxSenderAddressType lockSenderAddressType, @Nullable ConsensusRule consensusRule) throws IOException, RegisterBtcTransactionException {
// Arrange
ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
if (consensusRule != null) {
when(activations.isActive(consensusRule)).thenReturn(true);
}
Repository repository = createRepository();
BtcECKey srcKey1 = new BtcECKey();
ECKey key = ECKey.fromPublicOnly(srcKey1.getPubKey());
Address btcAddress = srcKey1.toAddress(btcParams);
RskAddress rskAddress = new RskAddress(key.getAddress());
BtcTransaction btcTx = new BtcTransaction(btcParams);
btcTx.addOutput(Coin.COIN.multiply(10), bridgeConstants.getGenesisFederation().getAddress());
btcTx.addInput(PegTestUtils.createHash(1), 0, new Script(new byte[] {}));
BridgeStorageProvider provider = mock(BridgeStorageProvider.class);
LockWhitelist lockWhitelist = mock(LockWhitelist.class);
when(lockWhitelist.isWhitelistedFor(eq(btcAddress), any(Coin.class), any(int.class))).thenReturn(isWhitelisted);
when(provider.getLockWhitelist()).thenReturn(lockWhitelist);
ReleaseTransactionSet releaseTransactionSet = new ReleaseTransactionSet(new HashSet<>());
when(provider.getReleaseTransactionSet()).thenReturn(releaseTransactionSet);
if (mockLockingCap) {
when(provider.getLockingCap()).thenReturn(Coin.COIN.multiply(1));
}
BtcLockSenderProvider btcLockSenderProvider = getBtcLockSenderProvider(lockSenderAddressType, btcAddress, rskAddress);
BridgeSupport bridgeSupport = getBridgeSupport(bridgeConstants, provider, repository, btcLockSenderProvider, new PeginInstructionsProvider(), mock(Block.class), mock(BtcBlockStoreWithCache.Factory.class), activations);
// Act
bridgeSupport.processPegIn(btcTx, mock(Transaction.class), 0, mock(Sha256Hash.class));
// Assert
Assert.assertEquals(1, releaseTransactionSet.getEntries().size());
// Check rejection tx input was created from btc tx
boolean successfulRejection = false;
for (ReleaseTransactionSet.Entry e : releaseTransactionSet.getEntries()) {
if (e.getTransaction().getInput(0).getOutpoint().getHash() == btcTx.getHash()) {
successfulRejection = true;
break;
}
}
Assert.assertTrue(successfulRejection);
// Check tx was not marked as processed
Assert.assertFalse(provider.getHeightIfBtcTxhashIsAlreadyProcessed(btcTx.getHash()).isPresent());
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeStorageProviderTest method saveLastRetiredFederationP2SHScript_after_RSKIP186.
@Test
public void saveLastRetiredFederationP2SHScript_after_RSKIP186() {
Repository repository = mock(Repository.class);
BridgeStorageProvider provider0 = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsAllForks);
Script script = new Script(new byte[] {});
provider0.setLastRetiredFederationP2SHScript(script);
provider0.saveLastRetiredFederationP2SHScript();
// Once the network upgrade is active, we will store it in the repository
verify(repository, times(1)).addStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromString("lastRetiredFedP2SHScript"), BridgeSerializationUtils.serializeScript(script));
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeSerializationUtilsTest method deserializeScript.
@Test
public void deserializeScript() {
Script expectedScript = ScriptBuilder.createP2SHOutputScript(2, Lists.newArrayList(new BtcECKey(), new BtcECKey(), new BtcECKey()));
byte[] data = RLP.encodeList(RLP.encodeElement(expectedScript.getProgram()));
Script actualScript = BridgeSerializationUtils.deserializeScript(data);
Assert.assertEquals(expectedScript, actualScript);
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeStorageProviderTest method setLastRetiredFederationP2SHScriptAndGetLastRetiredFederationP2SHScript.
@Test
public void setLastRetiredFederationP2SHScriptAndGetLastRetiredFederationP2SHScript() {
Repository repository = createRepository();
Repository track = repository.startTracking();
Script script = new Script(new byte[] {});
BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsAllForks);
// We store the value
provider0.setLastRetiredFederationP2SHScript(script);
provider0.saveLastRetiredFederationP2SHScript();
track.commit();
track = repository.startTracking();
BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsAllForks);
// And then we get it back
assertThat(provider.getLastRetiredFederationP2SHScript(), is(Optional.of(script)));
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeUtilsTest method testIsValidPegInTx_value_between_old_and_new_before_iris.
@Test
public void testIsValidPegInTx_value_between_old_and_new_before_iris() {
// Tx sending btc between old and new value, it is not a peg-in before iris
Context btcContext = new Context(networkParameters);
Federation federation = this.getGenesisFederationForTest(bridgeConstantsRegtest, btcContext);
when(activations.isActive(ConsensusRule.RSKIP219)).thenReturn(false);
BtcTransaction tx = new BtcTransaction(networkParameters);
// Get a value in between pre and post iris minimum
Coin minimumPegInValueBeforeIris = bridgeConstantsRegtest.getLegacyMinimumPeginTxValueInSatoshis();
Coin minimumPegInValueAfterIris = bridgeConstantsRegtest.getMinimumPeginTxValueInSatoshis();
Coin valueLock = minimumPegInValueAfterIris.plus((minimumPegInValueBeforeIris.subtract(minimumPegInValueAfterIris)).div(2));
assertTrue(valueLock.isLessThan(minimumPegInValueBeforeIris));
assertTrue(valueLock.isGreaterThan(minimumPegInValueAfterIris));
tx.addOutput(valueLock, federation.getAddress());
tx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[] {}));
assertFalse(BridgeUtils.isValidPegInTx(tx, federation, btcContext, bridgeConstantsRegtest, activations));
}
Aggregations