Search in sources :

Example 6 with BlockHeader

use of snowblossom.proto.BlockHeader in project snowblossom by snowblossomcoin.

the class BlockIngestorTest method testMagicBlockSummary.

@Test
public void testMagicBlockSummary() {
    NetworkParams params = new NetworkParamsTestnet();
    long time = System.currentTimeMillis();
    BigInteger using_target = params.getMaxTarget().divide(BigInteger.valueOf(2L));
    BlockHeader header = BlockHeader.newBuilder().setTarget(BlockchainUtil.targetBigIntegerToBytes(using_target)).setTimestamp(time).build();
    long using_time = params.getBlockTimeTarget() / 2;
    BlockHeader prev_header = BlockHeader.newBuilder().setTimestamp(time - using_time).build();
    BlockSummary prev_summary;
    prev_summary = BlockSummary.newBuilder().setWorkSum("1000").setBlocktimeAverageMs(params.getBlockTimeTarget()).setTargetAverage(params.getMaxTarget().toString()).setHeader(prev_header).build();
    System.out.println(prev_summary);
    BlockSummary s = BlockchainUtil.getNewSummary(header, prev_summary, params, 1L, 600L, new LinkedList());
    BigInteger expected_target = params.getMaxTarget().multiply(BigInteger.valueOf(990L)).add(using_target.multiply(BigInteger.valueOf(10L))).divide(BigInteger.valueOf(1000L));
    long expected_time = (params.getBlockTimeTarget() * 990L + using_time * 10L) / 1000L;
    Assert.assertNotNull(s.getHeader());
    int work = 1000 + 1024 * 2;
    Assert.assertEquals("" + work, s.getWorkSum());
    Assert.assertEquals(expected_target.toString(), s.getTargetAverage());
    Assert.assertEquals(expected_time, s.getBlocktimeAverageMs());
}
Also used : NetworkParamsTestnet(snowblossom.lib.NetworkParamsTestnet) NetworkParams(snowblossom.lib.NetworkParams) BigInteger(java.math.BigInteger) BlockHeader(snowblossom.proto.BlockHeader) BlockSummary(snowblossom.proto.BlockSummary) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

BlockHeader (snowblossom.proto.BlockHeader)6 ByteString (com.google.protobuf.ByteString)3 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 NetworkParams (snowblossom.lib.NetworkParams)2 NetworkParamsTestnet (snowblossom.lib.NetworkParamsTestnet)2 BlockSummary (snowblossom.proto.BlockSummary)2 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1 JSONArray (net.minidev.json.JSONArray)1 JSONObject (net.minidev.json.JSONObject)1 ChainHash (snowblossom.lib.ChainHash)1 BlockImportList (snowblossom.proto.BlockImportList)1 Transaction (snowblossom.proto.Transaction)1 TransactionInner (snowblossom.proto.TransactionInner)1 TransactionInput (snowblossom.proto.TransactionInput)1 TransactionOutput (snowblossom.proto.TransactionOutput)1