use of co.rsk.test.World in project rskj by rsksmart.
the class BridgeTest method callUpdateCollectionsWithTransactionsWaitingForConfirmation.
@Test
public void callUpdateCollectionsWithTransactionsWaitingForConfirmation() 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();
Transaction rskTx = Transaction.create(config, PrecompiledContracts.BRIDGE_ADDR_STR, AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA);
rskTx.sign(new ECKey().getPrivKeyBytes());
Bridge bridge = new Bridge(config, PrecompiledContracts.BRIDGE_ADDR);
World world = new World();
bridge.init(rskTx, world.getBlockChain().getBestBlock(), 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(3, provider.getReleaseTransactionSet().getEntries().size());
Assert.assertEquals(0, provider.getRskTxsWaitingForSignatures().size());
}
use of co.rsk.test.World in project rskj by rsksmart.
the class MinerManagerTest method mineBlockWhilePlayingBlocks.
@Test
public void mineBlockWhilePlayingBlocks() {
World world = new World();
Blockchain blockchain = world.getBlockChain();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
RskImplForTest rsk = new RskImplForTest() {
@Override
public boolean hasBetterBlockToSync() {
return false;
}
@Override
public boolean isPlayingBlocks() {
return true;
}
};
MinerServerImpl minerServer = getMinerServer(blockchain);
MinerClientImpl minerClient = getMinerClient(rsk, minerServer);
minerServer.buildBlockToMine(blockchain.getBestBlock(), false);
Assert.assertFalse(minerClient.mineBlock());
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
}
use of co.rsk.test.World in project rskj by rsksmart.
the class MinerManagerTest method doWork.
@Test
public void doWork() {
World world = new World();
Blockchain blockchain = world.getBlockChain();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
MinerServerImpl minerServer = getMinerServer(blockchain);
MinerClientImpl minerClient = getMinerClient(minerServer);
minerServer.buildBlockToMine(blockchain.getBestBlock(), false);
minerClient.doWork();
Assert.assertEquals(1, blockchain.getBestBlock().getNumber());
}
use of co.rsk.test.World in project rskj by rsksmart.
the class MinerManagerTest method doWorkInThread.
@Test
public void doWorkInThread() throws Exception {
World world = new World();
Blockchain blockchain = world.getBlockChain();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
MinerServerImpl minerServer = getMinerServer(blockchain);
MinerClientImpl minerClient = getMinerClient(minerServer);
minerServer.buildBlockToMine(blockchain.getBestBlock(), false);
Thread thread = minerClient.createDoWorkThread();
thread.start();
try {
Awaitility.await().timeout(Duration.FIVE_SECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return minerClient.isMining();
}
});
Assert.assertTrue(minerClient.isMining());
} finally {
// enought ?
thread.interrupt();
minerClient.stop();
}
}
use of co.rsk.test.World in project rskj by rsksmart.
the class MinerManagerTest method doWorkEvenWithoutMinerServer.
@Test
public void doWorkEvenWithoutMinerServer() {
World world = new World();
Blockchain blockchain = world.getBlockChain();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
MinerServerImpl minerServer = getMinerServer(blockchain);
MinerClientImpl minerClient = getMinerClient(null);
minerServer.buildBlockToMine(blockchain.getBestBlock(), false);
minerClient.doWork();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
}
Aggregations