Package org.ethereum.core

Examples of org.ethereum.core.Block


   
    @Test
    public void testCalcDifficulty() {

        Blockchain blockchain = worldManager.getBlockchain();
        Block genesis = Genesis.getInstance();
        BigInteger difficulty = new BigInteger(1, genesis.calcDifficulty());
        logger.info("Genesis difficulty: [{}]", difficulty.toString());
        assertEquals(new BigInteger(1, Genesis.DIFFICULTY), difficulty);

        // Storing genesis because the parent needs to be in the DB for calculation.
        blockchain.add(genesis);

        Block block1 = new Block(Hex.decode(PoC7_GENESIS_HEX_RLP_ENCODED));
        BigInteger calcDifficulty = new BigInteger(1, block1.calcDifficulty());
        BigInteger actualDifficulty = new BigInteger(1, block1.getDifficulty());
        logger.info("Block#1 actual difficulty: [{}] ", actualDifficulty.toString());
        logger.info("Block#1 calculated difficulty: [{}] ", calcDifficulty.toString());
        assertEquals(actualDifficulty, calcDifficulty);
    }
View Full Code Here


    }
   
    @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

        BlocksMessage blocksMessage = new BlocksMessage(payload);
        List<Block> list = blocksMessage.getBlocks();
        logger.info(blocksMessage.toString());

        Block block = list.get(0);
        assertEquals(1, block.getTransactionsList().size());
        assertEquals(3911, block.getNumber());
        assertEquals("140446b9f55bbbe9bad9fe963157cf0fc6ab2d068433eb95e161847f197362b2",
               Hex.toHexString(block.getHash()));
        assertEquals("396d2ff722ae3811cb5deb69270933c8016f2397a5189aac429bc6fc466607bb",
                Hex.toHexString(block.getStateRoot()));
    }
View Full Code Here

        BlocksMessage blocksMessage = new BlocksMessage(payload);
        List<Block> list = blocksMessage.getBlocks();
        logger.info(blocksMessage.toString());

        Block block = list.get(0);

        assertEquals(2, block.getTransactionsList().size());
        assertEquals(3822, block.getNumber());
        assertEquals("faced238a53a0bf1cd13c93e9fe1329e165e6d90d1c19aa1babd7d851cebad8f",
                Hex.toHexString(block.getHash()));
        assertEquals("14fd76260a37d307936e721ed7999c61e58dfc42b2680a6de01de2aa80fece52",
                Hex.toHexString(block.getStateRoot()));

    }
View Full Code Here

        BlocksMessage blocksMessage = new BlocksMessage(data);

        int size = blocksMessage.getBlocks().size();
        for (int i = 0; i < size; ++i){

            Block block = blocksMessage.getBlocks().get(i);

            int unclesSize = block.getUncleList().size();
            for (int j = 0; j < unclesSize; ++j) {
                System.out.println("*** uncle: " + Hex.toHexString(block.getUncleList().get(j).getCoinbase()));
            }

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

  }

    @Test
    public void test_2(){

        Block block = new Block(
                Hex.decode("f90277f8cfa0887ef3904d3c464cbb3ce2a7e2ce02c57b1a38caaa5013ad1202ead0fc1077baa0a962ba850109a5112e7bd3109db477014057b478772825173cc3da54cfc3264e94407d73d8a49eeb85d32cf465507dd71d507100c180a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b42180830200000380830f42408086014997893f1080a000000000000000000000000000000000000000000000000000000000000018e9c0f901a2f8cfa0955f36d073ccb026b78ab3424c15cf966a7563aa270413859f78702b9e8e22cba01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347942bd26d8f796719923ff13d295644f9b45db1f73080a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b42180830200000180830f4240808601499789326680a00000000000000000000000000000000000000000000000000000000000010da5f8cfa0717e058643634a0f80b9cf33da423d304dabaa826c586f50a783ba6c70cfd60da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794f92c0f3e4825f09490ca264dc0cdacffeb566f0680a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b42180830200000280830f424080860149978936fe80a0000000000000000000000000000000000000000000000000000000000001d01f"));
        byte[] diff = new byte[] {0};

        NewBlockMessage nbm = new NewBlockMessage(block, diff);
View Full Code Here

    if (blockReceivedQueue.isEmpty())
      return;
   
    logger.info("BlockQueue size: {}", blockReceivedQueue.size());
        while(!blockReceivedQueue.isEmpty()){
            Block block = blockReceivedQueue.poll();

            logger.info("Processing block index: {}", block.getNumber());
            blockchain.add(block);
        }

  }
View Full Code Here

TOP

Related Classes of org.ethereum.core.Block

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.