Search in sources :

Example 1 with World

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());
}
Also used : SimpleBtcTransaction(co.rsk.peg.bitcoin.SimpleBtcTransaction) SimpleBtcTransaction(co.rsk.peg.bitcoin.SimpleBtcTransaction) RepositoryImpl(co.rsk.db.RepositoryImpl) ECKey(org.ethereum.crypto.ECKey) World(co.rsk.test.World) Test(org.junit.Test)

Example 2 with World

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());
}
Also used : Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) Test(org.junit.Test)

Example 3 with World

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());
}
Also used : Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) Test(org.junit.Test)

Example 4 with World

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();
    }
}
Also used : Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) Test(org.junit.Test)

Example 5 with World

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());
}
Also used : Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) Test(org.junit.Test)

Aggregations

World (co.rsk.test.World)198 Test (org.junit.Test)169 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)55 DslParser (co.rsk.test.dsl.DslParser)52 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)46 HashMapDB (org.ethereum.datasource.HashMapDB)45 AccountBuilder (co.rsk.test.builders.AccountBuilder)36 Block (org.ethereum.core.Block)36 ReceiptStore (org.ethereum.db.ReceiptStore)34 BlockBuilder (co.rsk.test.builders.BlockBuilder)31 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)31 Blockchain (org.ethereum.core.Blockchain)30 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)24 Transaction (org.ethereum.core.Transaction)23 BigInteger (java.math.BigInteger)17 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)15 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Account (org.ethereum.core.Account)15 TestSystemProperties (co.rsk.config.TestSystemProperties)14