use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.
the class BridgeSupportTest method minimumProcessFundsMigrationValue.
@Test
public void minimumProcessFundsMigrationValue() throws IOException, BlockStoreException {
BridgeConstants bridgeConstants = BridgeRegTestConstants.getInstance();
Federation oldFederation = bridgeConstants.getGenesisFederation();
Federation newFederation = new Federation(Collections.singletonList(new BtcECKey(new SecureRandom())), Instant.EPOCH, 5L, bridgeConstants.getBtcParams());
BridgeStorageProvider provider = mock(BridgeStorageProvider.class);
when(provider.getFeePerKb()).thenReturn(Coin.MILLICOIN);
when(provider.getReleaseRequestQueue()).thenReturn(new ReleaseRequestQueue(Collections.emptyList()));
when(provider.getReleaseTransactionSet()).thenReturn(new ReleaseTransactionSet(Collections.emptySet()));
when(provider.getOldFederation()).thenReturn(oldFederation);
when(provider.getNewFederation()).thenReturn(newFederation);
BlockGenerator blockGenerator = new BlockGenerator();
// Old federation will be in migration age at block 35
org.ethereum.core.Block rskCurrentBlock = blockGenerator.createBlock(35, 1);
Transaction tx = Transaction.create(config, TO_ADDRESS, DUST_AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA);
Repository repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
BridgeSupport bridgeSupport = new BridgeSupport(config, track, mock(BridgeEventLogger.class), provider, rskCurrentBlock);
// One MICROCOIN is less than half the fee per kb, which is the minimum funds to migrate,
// and so it won't be removed from the old federation UTXOs list for migration.
List<UTXO> unsufficientUTXOsForMigration1 = new ArrayList<>();
unsufficientUTXOsForMigration1.add(createUTXO(Coin.MICROCOIN, oldFederation.getAddress()));
when(provider.getOldFederationBtcUTXOs()).thenReturn(unsufficientUTXOsForMigration1);
bridgeSupport.updateCollections(tx);
assertThat(unsufficientUTXOsForMigration1.size(), is(1));
// MILLICOIN is greater than half the fee per kb,
// and it will be removed from the old federation UTXOs list for migration.
List<UTXO> sufficientUTXOsForMigration1 = new ArrayList<>();
sufficientUTXOsForMigration1.add(createUTXO(Coin.MILLICOIN, oldFederation.getAddress()));
when(provider.getOldFederationBtcUTXOs()).thenReturn(sufficientUTXOsForMigration1);
bridgeSupport.updateCollections(tx);
assertThat(sufficientUTXOsForMigration1.size(), is(0));
// 2 smaller coins should work exactly like 1 MILLICOIN
List<UTXO> sufficientUTXOsForMigration2 = new ArrayList<>();
sufficientUTXOsForMigration2.add(createUTXO(Coin.MILLICOIN.divide(2), oldFederation.getAddress()));
sufficientUTXOsForMigration2.add(createUTXO(Coin.MILLICOIN.divide(2), oldFederation.getAddress()));
when(provider.getOldFederationBtcUTXOs()).thenReturn(sufficientUTXOsForMigration2);
bridgeSupport.updateCollections(tx);
assertThat(sufficientUTXOsForMigration2.size(), is(0));
// higher fee per kb prevents funds migration
List<UTXO> unsufficientUTXOsForMigration2 = new ArrayList<>();
unsufficientUTXOsForMigration2.add(createUTXO(Coin.MILLICOIN, oldFederation.getAddress()));
when(provider.getOldFederationBtcUTXOs()).thenReturn(unsufficientUTXOsForMigration2);
when(provider.getFeePerKb()).thenReturn(Coin.COIN);
bridgeSupport.updateCollections(tx);
assertThat(unsufficientUTXOsForMigration2.size(), is(1));
}
use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.
the class BridgeTest method callUpdateCollectionsWithTransactionsWaitingForConfirmationWithEnoughConfirmations.
@Test
public void callUpdateCollectionsWithTransactionsWaitingForConfirmationWithEnoughConfirmations() throws IOException {
BtcTransaction tx1 = createTransaction();
BtcTransaction tx2 = createTransaction();
BtcTransaction tx3 = createTransaction();
Repository repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
provider0.getReleaseTransactionSet().add(tx1, 1L);
provider0.getReleaseTransactionSet().add(tx2, 2L);
provider0.getReleaseTransactionSet().add(tx3, 3L);
provider0.save();
track.commit();
track = repository.startTracking();
World world = new World();
List<Block> blocks = new BlockGenerator().getSimpleBlockChain(world.getBlockChain().getBestBlock(), 10);
Transaction rskTx = Transaction.create(config, PrecompiledContracts.BRIDGE_ADDR_STR, AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA);
rskTx.sign(new ECKey().getPrivKeyBytes());
world.getBlockChain().getBlockStore().saveBlock(blocks.get(1), new BlockDifficulty(BigInteger.ONE), true);
Bridge bridge = new Bridge(config, PrecompiledContracts.BRIDGE_ADDR);
bridge.init(rskTx, blocks.get(9), track, world.getBlockChain().getBlockStore(), null, new LinkedList<>());
bridge.execute(Bridge.UPDATE_COLLECTIONS.encode());
track.commit();
BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
Assert.assertEquals(2, provider.getReleaseTransactionSet().getEntries().size());
Assert.assertEquals(1, provider.getRskTxsWaitingForSignatures().size());
}
use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.
the class SamplePrecompiledContractTest method samplePrecompiledContractGetBalanceInitialBalance.
@Test
public void samplePrecompiledContractGetBalanceInitialBalance() {
int balance = this.GetBalance(new RepositoryImpl(config));
assertEquals(0, balance);
}
use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.
the class SamplePrecompiledContractTest method samplePrecompiledContractGetResultInitialValue.
@Test
public void samplePrecompiledContractGetResultInitialValue() {
int result = this.GetResult(new RepositoryImpl(config));
assertEquals(0, result);
}
use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.
the class SamplePrecompiledContractTest method samplePrecompiledContractMethod1WrongData.
@Test
public void samplePrecompiledContractMethod1WrongData() {
DataWord addr = new DataWord(PrecompiledContracts.SAMPLE_ADDR.getBytes());
SamplePrecompiledContract contract = (SamplePrecompiledContract) precompiledContracts.getContractForAddress(addr);
String funcJson = "{\n" + " 'constant':false, \n" + " 'inputs':[{'name':'param0','type':'int'}, \n" + " {'name':'param1','type':'bytes'}, \n" + " {'name':'param2','type':'int'}], \n" + " 'name':'Method1', \n" + " 'outputs':[{'name':'output0','type':'int'}], \n" + " 'type':'function' \n" + "}\n";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
byte[] data = new byte[] { (byte) 0xab, (byte) 0xcd, (byte) 0xef };
contract.init(null, null, new RepositoryImpl(config), null, null, new ArrayList<LogInfo>());
byte[] result = contract.execute(data);
assertNull(result);
}
Aggregations