use of co.rsk.bitcoinj.wallet.Wallet in project rskj by rsksmart.
the class BridgeSupportTest method getRetiringFederationWallet_nonEmpty.
@Test
public void getRetiringFederationWallet_nonEmpty() throws IOException {
Federation mockedNewFederation = new Federation(getTestFederationPublicKeys(2), Instant.ofEpochMilli(2000), 10L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST));
Federation expectedFederation = new Federation(Arrays.asList(new BtcECKey[] { BtcECKey.fromPublicOnly(Hex.decode("036bb9eab797eadc8b697f0e82a01d01cabbfaaca37e5bafc06fdc6fdd38af894a")), BtcECKey.fromPublicOnly(Hex.decode("031da807c71c2f303b7f409dd2605b297ac494a563be3b9ca5f52d95a43d183cc5")) }), Instant.ofEpochMilli(5005L), 0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST));
Block mockedBlock = mock(Block.class);
when(mockedBlock.getNumber()).thenReturn(25L);
BridgeSupport bridgeSupport = getBridgeSupportWithMocksForFederationTests(false, mockedNewFederation, null, expectedFederation, null, null, mockedBlock);
Context expectedContext = mock(Context.class);
Whitebox.setInternalState(bridgeSupport, "btcContext", expectedContext);
BridgeStorageProvider provider = (BridgeStorageProvider) Whitebox.getInternalState(bridgeSupport, "provider");
Object expectedUtxos = provider.getOldFederationBtcUTXOs();
final Wallet expectedWallet = mock(Wallet.class);
PowerMockito.mockStatic(BridgeUtils.class);
PowerMockito.when(BridgeUtils.getFederationSpendWallet(any(), any(), any())).then((InvocationOnMock m) -> {
Assert.assertEquals(m.getArgumentAt(0, Context.class), expectedContext);
Assert.assertEquals(m.getArgumentAt(1, Federation.class), expectedFederation);
Assert.assertEquals(m.getArgumentAt(2, Object.class), expectedUtxos);
return expectedWallet;
});
Assert.assertSame(expectedWallet, bridgeSupport.getRetiringFederationWallet());
}
use of co.rsk.bitcoinj.wallet.Wallet in project rskj by rsksmart.
the class BridgeUtilsTest method getFederationNoSpendWallet.
@Test
public void getFederationNoSpendWallet() {
NetworkParameters regTestParameters = NetworkParameters.fromID(NetworkParameters.ID_REGTEST);
Federation federation = new Federation(Arrays.asList(new BtcECKey[] { BtcECKey.fromPublicOnly(Hex.decode("036bb9eab797eadc8b697f0e82a01d01cabbfaaca37e5bafc06fdc6fdd38af894a")), BtcECKey.fromPublicOnly(Hex.decode("031da807c71c2f303b7f409dd2605b297ac494a563be3b9ca5f52d95a43d183cc5")) }), Instant.ofEpochMilli(5005L), 0L, regTestParameters);
Context mockedBtcContext = mock(Context.class);
when(mockedBtcContext.getParams()).thenReturn(regTestParameters);
Wallet wallet = BridgeUtils.getFederationNoSpendWallet(mockedBtcContext, federation);
Assert.assertEquals(BridgeBtcWallet.class, wallet.getClass());
assertIsWatching(federation.getAddress(), wallet, regTestParameters);
}
use of co.rsk.bitcoinj.wallet.Wallet in project rskj by rsksmart.
the class BridgeUtilsTest method testIsLock.
@Test
public void testIsLock() throws Exception {
// Lock is for the genesis federation ATM
NetworkParameters params = RegTestParams.get();
Context btcContext = new Context(params);
BridgeRegTestConstants bridgeConstants = BridgeRegTestConstants.getInstance();
Federation federation = bridgeConstants.getGenesisFederation();
Wallet wallet = new BridgeBtcWallet(btcContext, Arrays.asList(federation));
wallet.addWatchedAddress(federation.getAddress(), federation.getCreationTime().toEpochMilli());
Address address = federation.getAddress();
// Tx sending less than 1 btc to the federation, not a lock tx
BtcTransaction tx = new BtcTransaction(params);
tx.addOutput(Coin.CENT, address);
tx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[] {}));
assertFalse(BridgeUtils.isLockTx(tx, federation, btcContext, bridgeConstants));
// Tx sending 1 btc to the federation, but also spending from the federation addres, the typical release tx, not a lock tx.
BtcTransaction tx2 = new BtcTransaction(params);
tx2.addOutput(Coin.COIN, address);
TransactionInput txIn = new TransactionInput(params, tx2, new byte[] {}, new TransactionOutPoint(params, 0, Sha256Hash.ZERO_HASH));
tx2.addInput(txIn);
signWithNecessaryKeys(bridgeConstants.getGenesisFederation(), bridgeConstants.getFederatorPrivateKeys(), txIn, tx2, bridgeConstants);
assertFalse(BridgeUtils.isLockTx(tx2, federation, btcContext, bridgeConstants));
// Tx sending 1 btc to the federation, is a lock tx
BtcTransaction tx3 = new BtcTransaction(params);
tx3.addOutput(Coin.COIN, address);
tx3.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[] {}));
assertTrue(BridgeUtils.isLockTx(tx3, federation, btcContext, bridgeConstants));
// Tx sending 50 btc to the federation, is a lock tx
BtcTransaction tx4 = new BtcTransaction(params);
tx4.addOutput(Coin.FIFTY_COINS, address);
tx4.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[] {}));
assertTrue(BridgeUtils.isLockTx(tx4, federation, btcContext, bridgeConstants));
}
use of co.rsk.bitcoinj.wallet.Wallet in project rskj by rsksmart.
the class BridgeUtils method isLockTx.
public static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants) {
// optionally sending some change to any of the federation addresses)
for (int i = 0; i < tx.getInputs().size(); i++) {
final int index = i;
if (federations.stream().anyMatch(federation -> scriptCorrectlySpendsTx(tx, index, federation.getP2SHScript()))) {
return false;
}
}
Wallet federationsWallet = BridgeUtils.getFederationsNoSpendWallet(btcContext, federations);
Coin valueSentToMe = tx.getValueSentToMe(federationsWallet);
int valueSentToMeSignum = valueSentToMe.signum();
if (valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())) {
logger.warn("Someone sent to the federation less than {} satoshis", bridgeConstants.getMinimumLockTxValue());
}
return (valueSentToMeSignum > 0 && !valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue()));
}
use of co.rsk.bitcoinj.wallet.Wallet in project rskj by rsksmart.
the class BridgeUtils method getFederationsNoSpendWallet.
public static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations) {
Wallet wallet = new BridgeBtcWallet(btcContext, federations);
federations.forEach(federation -> wallet.addWatchedAddress(federation.getAddress(), federation.getCreationTime().toEpochMilli()));
return wallet;
}
Aggregations