Search in sources :

Example 1 with NetworkParamsTestnet

use of snowblossom.lib.NetworkParamsTestnet in project snowblossom by snowblossomcoin.

the class BlockIngestorTest method testFirstBlockSummary.

@Test
public void testFirstBlockSummary() {
    NetworkParams params = new NetworkParamsTestnet();
    BlockHeader header = BlockHeader.newBuilder().setTarget(BlockchainUtil.targetBigIntegerToBytes(params.getMaxTarget())).setTimestamp(System.currentTimeMillis()).build();
    BlockSummary prev_summary;
    prev_summary = BlockSummary.newBuilder().build();
    System.out.println(prev_summary);
    BlockSummary s = BlockchainUtil.getNewSummary(header, prev_summary, params, 1L, 600L, new LinkedList());
    Assert.assertNotNull(s.getHeader());
    Assert.assertEquals("1024", s.getWorkSum());
    Assert.assertEquals(params.getMaxTarget().toString(), s.getTargetAverage());
    Assert.assertEquals(params.getBlockTimeTarget(), s.getBlocktimeAverageMs());
}
Also used : NetworkParamsTestnet(snowblossom.lib.NetworkParamsTestnet) NetworkParams(snowblossom.lib.NetworkParams) BlockHeader(snowblossom.proto.BlockHeader) BlockSummary(snowblossom.proto.BlockSummary) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with NetworkParamsTestnet

use of snowblossom.lib.NetworkParamsTestnet in project snowblossom by snowblossomcoin.

the class AddressUtilTest method testAddressConversions.

@Test
public void testAddressConversions() throws ValidationException {
    ArrayList<NetworkParams> plist = new ArrayList<NetworkParams>();
    plist.add(new NetworkParamsProd());
    plist.add(new NetworkParamsTestnet());
    plist.add(new NetworkParamsRegtest());
    byte[] buff = new byte[Globals.ADDRESS_SPEC_HASH_LEN];
    Random rnd = new Random();
    HashSet<String> addresses = new HashSet<>();
    for (int i = 0; i < 1000; i++) {
        if (i > 0) {
            rnd.nextBytes(buff);
        }
        AddressSpecHash spec = new AddressSpecHash(buff);
        for (NetworkParams p : plist) {
            String addr = spec.toAddressString(p);
            Assert.assertFalse(addresses.contains(addr));
            addresses.add(addr);
            System.out.println("Address: " + addr);
            AddressSpecHash dec = new AddressSpecHash(addr, p);
            Assert.assertEquals(spec, dec);
            int colon = addr.indexOf(":");
            String without = addr.substring(colon + 1);
            AddressSpecHash dec2 = new AddressSpecHash(without, p);
            Assert.assertEquals(spec, dec2);
        }
    }
}
Also used : NetworkParamsRegtest(snowblossom.lib.NetworkParamsRegtest) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) NetworkParamsTestnet(snowblossom.lib.NetworkParamsTestnet) Random(java.util.Random) NetworkParams(snowblossom.lib.NetworkParams) NetworkParamsProd(snowblossom.lib.NetworkParamsProd) AddressSpecHash(snowblossom.lib.AddressSpecHash) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with NetworkParamsTestnet

use of snowblossom.lib.NetworkParamsTestnet in project snowblossom by snowblossomcoin.

the class IceLeafTestnet method main.

public static void main(String[] args) throws Exception {
    Globals.addCryptoProvider();
    Preferences ice_leaf_prefs = Preferences.userNodeForPackage(new NetworkParamsTestnet().getClass());
    new IceLeaf(new NetworkParamsTestnet(), ice_leaf_prefs);
}
Also used : NetworkParamsTestnet(snowblossom.lib.NetworkParamsTestnet) Preferences(java.util.prefs.Preferences)

Example 4 with NetworkParamsTestnet

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

NetworkParamsTestnet (snowblossom.lib.NetworkParamsTestnet)4 Test (org.junit.Test)3 NetworkParams (snowblossom.lib.NetworkParams)3 LinkedList (java.util.LinkedList)2 BlockHeader (snowblossom.proto.BlockHeader)2 BlockSummary (snowblossom.proto.BlockSummary)2 ByteString (com.google.protobuf.ByteString)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 Preferences (java.util.prefs.Preferences)1 AddressSpecHash (snowblossom.lib.AddressSpecHash)1 NetworkParamsProd (snowblossom.lib.NetworkParamsProd)1 NetworkParamsRegtest (snowblossom.lib.NetworkParamsRegtest)1