Search in sources :

Example 16 with NetworkParams

use of snowblossom.lib.NetworkParams 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

NetworkParams (snowblossom.lib.NetworkParams)16 Test (org.junit.Test)11 NetworkParamsRegtest (snowblossom.lib.NetworkParamsRegtest)8 ByteString (com.google.protobuf.ByteString)6 BigInteger (java.math.BigInteger)6 ConfigMem (duckutil.ConfigMem)5 LinkedList (java.util.LinkedList)3 NetworkParamsTestnet (snowblossom.lib.NetworkParamsTestnet)3 BlockHeader (snowblossom.proto.BlockHeader)3 NetworkParamsProd (snowblossom.lib.NetworkParamsProd)2 PoolMiner (snowblossom.miner.PoolMiner)2 BlockSummary (snowblossom.proto.BlockSummary)2 ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 AddressSpecHash (snowblossom.lib.AddressSpecHash)1 SnowFall (snowblossom.lib.SnowFall)1 SnowFieldInfo (snowblossom.lib.SnowFieldInfo)1