Search in sources :

Example 6 with BlockChainStatus

use of co.rsk.core.bc.BlockChainStatus in project rskj by rsksmart.

the class SnapshotManagerTest method revertToSnapshot.

@Test
public void revertToSnapshot() {
    Blockchain blockchain = createBlockchain();
    addBlocks(blockchain, 10);
    BlockChainStatus status = blockchain.getStatus();
    SnapshotManager manager = new SnapshotManager();
    int snapshotId = manager.takeSnapshot(blockchain);
    addBlocks(blockchain, 20);
    Assert.assertEquals(30, blockchain.getStatus().getBestBlockNumber());
    Assert.assertTrue(manager.revertToSnapshot(blockchain, snapshotId));
    BlockChainStatus newStatus = blockchain.getStatus();
    Assert.assertEquals(status.getBestBlockNumber(), newStatus.getBestBlockNumber());
    Assert.assertEquals(status.getTotalDifficulty(), newStatus.getTotalDifficulty());
    Assert.assertEquals(status.getBestBlock().getHash(), newStatus.getBestBlock().getHash());
    for (int k = 11; k <= 30; k++) Assert.assertTrue(blockchain.getBlocksByNumber(k).isEmpty());
}
Also used : BlockChainStatus(co.rsk.core.bc.BlockChainStatus) Test(org.junit.Test)

Example 7 with BlockChainStatus

use of co.rsk.core.bc.BlockChainStatus in project rskj by rsksmart.

the class Web3ImplSnapshotTest method revertToSnapshot.

@Test
public void revertToSnapshot() {
    World world = new World();
    Web3Impl web3 = createWeb3(world);
    Blockchain blockchain = world.getBlockChain();
    addBlocks(blockchain, 10);
    Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
    BlockChainStatus status = blockchain.getStatus();
    String snapshotId = web3.evm_snapshot();
    addBlocks(blockchain, 10);
    Assert.assertEquals(20, blockchain.getBestBlock().getNumber());
    Assert.assertTrue(web3.evm_revert(snapshotId));
    Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
    BlockChainStatus newStatus = blockchain.getStatus();
    Assert.assertEquals(status.getBestBlock().getHash(), newStatus.getBestBlock().getHash());
    Assert.assertEquals(status.getTotalDifficulty(), newStatus.getTotalDifficulty());
}
Also used : Blockchain(org.ethereum.core.Blockchain) BlockChainStatus(co.rsk.core.bc.BlockChainStatus) World(co.rsk.test.World) Test(org.junit.Test)

Example 8 with BlockChainStatus

use of co.rsk.core.bc.BlockChainStatus in project rskj by rsksmart.

the class Web3ImplSnapshotTest method resetSnapshots.

@Test
public void resetSnapshots() {
    World world = new World();
    Web3Impl web3 = createWeb3(world);
    Blockchain blockchain = world.getBlockChain();
    BlockChainStatus status = blockchain.getStatus();
    addBlocks(blockchain, 10);
    Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
    web3.evm_reset();
    Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
    BlockChainStatus newStatus = blockchain.getStatus();
    Assert.assertEquals(status.getBestBlock().getHash(), newStatus.getBestBlock().getHash());
    Assert.assertEquals(status.getTotalDifficulty(), newStatus.getTotalDifficulty());
}
Also used : Blockchain(org.ethereum.core.Blockchain) BlockChainStatus(co.rsk.core.bc.BlockChainStatus) World(co.rsk.test.World) Test(org.junit.Test)

Aggregations

BlockChainStatus (co.rsk.core.bc.BlockChainStatus)8 Test (org.junit.Test)6 BlockDifficulty (co.rsk.core.BlockDifficulty)2 World (co.rsk.test.World)2 ArrayList (java.util.ArrayList)2 Block (org.ethereum.core.Block)2 Blockchain (org.ethereum.core.Blockchain)2 co.rsk.net (co.rsk.net)1 StatusMessage (co.rsk.net.messages.StatusMessage)1 DslParser (co.rsk.test.dsl.DslParser)1 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)1 TransactionInfo (org.ethereum.db.TransactionInfo)1 DataWord (org.ethereum.vm.DataWord)1