Package org.ethereum.core

Examples of org.ethereum.core.BlockchainImpl



    @Test
    public void fork1() throws URISyntaxException, IOException {

        BlockchainImpl blockchain = (BlockchainImpl)worldManager.getBlockchain();

        URL massiveUpload_1 = ClassLoader
                .getSystemResource("fork/scenario1.dmp");

        File file = new File(massiveUpload_1.toURI());
        List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);

        for(String blockRLP : strData){
            Block block = new Block(
                    Hex.decode(blockRLP));
            logger.info("sending block.hash: {}", Hex.toHexString( block.getHash() ));
            blockchain.tryToConnect(block);
        }

        List<Chain> altChains = blockchain.getAltChains();
        List<Block> garbage   = blockchain.getGarbage();

        assertEquals(1,  altChains.size());
        assertEquals(13, altChains.get(0).getSize());
        assertEquals(20, blockchain.getSize());
        assertEquals(0,  garbage.size());
    }
View Full Code Here


    }

    @Test
    public void fork2() throws URISyntaxException, IOException {

        BlockchainImpl blockchain = (BlockchainImpl) worldManager.getBlockchain();


        URL massiveUpload_1 = ClassLoader
                .getSystemResource("fork/scenario2.dmp");

        File file = new File(massiveUpload_1.toURI());
        List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);

        for(String blockRLP : strData){
            Block block = new Block(
                    Hex.decode(blockRLP));
            logger.info("sending block.hash: {}", Hex.toHexString( block.getHash() ));
            blockchain.tryToConnect(block);
        }

        List<Chain> altChains = blockchain.getAltChains();
        List<Block> garbage   = blockchain.getGarbage();

        assertEquals(2,  altChains.size());
//        assertEquals(13, altChains.get(0).getSize());
        assertEquals(new BigInteger("13238272"), altChains.get(0).getTotalDifficulty());
        assertEquals(new BigInteger("13369344"), altChains.get(1).getTotalDifficulty());

        assertEquals(new BigInteger("13238272"), blockchain.getTotalDifficulty() );
        assertEquals(100, blockchain.getSize());
        assertEquals(0,  garbage.size());

        System.out.println();
    }
View Full Code Here

        assertEquals(actualDifficulty, calcDifficulty);
    }
   
    @Test
    public void testCalcGasLimit() {
        BlockchainImpl blockchain =  (BlockchainImpl)worldManager.getBlockchain();
      Block genesis = Genesis.getInstance();
      long gasLimit = blockchain.calcGasLimit(genesis.getHeader());
        logger.info("Genesis gasLimit: [{}] ", gasLimit);
      assertEquals(Genesis.GAS_LIMIT, gasLimit);

      // Test with block
      Block block1 = new Block(Hex.decode(PoC7_GENESIS_HEX_RLP_ENCODED));
      long calcGasLimit = blockchain.calcGasLimit(block1.getHeader());
      long actualGasLimit = block1.getGasLimit();
        blockchain.tryToConnect(block1);
      logger.info("Block#1 actual gasLimit [{}] ", actualGasLimit);
        logger.info("Block#1 calculated gasLimit [{}] ", calcGasLimit);
      assertEquals(actualGasLimit, calcGasLimit);
    }
View Full Code Here

TOP

Related Classes of org.ethereum.core.BlockchainImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.