Search in sources :

Example 11 with NetworkParams

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

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

the class PowUtilTest method testCalcNextTargetIncreasingFromAvg.

@Test
public void testCalcNextTargetIncreasingFromAvg() {
    NetworkParams params = new NetworkParamsRegtest();
    long time = System.currentTimeMillis();
    // block solved slow
    BlockHeader prev_header = BlockHeader.newBuilder().setTimestamp(time - params.getBlockTimeTarget() * 2).build();
    BigInteger average_target = params.getMaxTarget().divide(BigInteger.valueOf(100));
    BlockSummary bs = BlockSummary.newBuilder().setHeader(prev_header).setTargetAverage(average_target.toString()).setBlocktimeAverageMs(params.getBlockTimeTarget()).build();
    BigInteger target = PowUtil.calcNextTarget(bs, params, System.currentTimeMillis());
    System.out.println("Old: " + average_target + " new: " + target);
    Assert.assertTrue(target.compareTo(average_target) > 0);
}
Also used : NetworkParamsRegtest(snowblossom.lib.NetworkParamsRegtest) NetworkParams(snowblossom.lib.NetworkParams) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 13 with NetworkParams

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

the class PowUtilTest method testCalcNextTargetDecreasing.

@Test
public void testCalcNextTargetDecreasing() {
    NetworkParams params = new NetworkParamsRegtest();
    long time = System.currentTimeMillis();
    BlockHeader prev_header = BlockHeader.newBuilder().setTimestamp(time - params.getBlockTimeTarget() / 2).build();
    BlockSummary bs = BlockSummary.newBuilder().setHeader(prev_header).setTargetAverage(params.getMaxTarget().toString()).setBlocktimeAverageMs(params.getBlockTimeTarget()).build();
    BigInteger target = PowUtil.calcNextTarget(bs, params, System.currentTimeMillis());
    Assert.assertTrue(target.compareTo(params.getMaxTarget()) < 0);
}
Also used : NetworkParamsRegtest(snowblossom.lib.NetworkParamsRegtest) NetworkParams(snowblossom.lib.NetworkParams) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 14 with NetworkParams

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

the class PowUtilTest method testReward.

@Test
public void testReward() {
    NetworkParams params = new NetworkParamsProd();
    int n = 4 * 365 * 144;
    long reward = 50000000;
    for (int b = 1; b < 10; b++) {
        Assert.assertEquals(reward, PowUtil.getBlockReward(params, n * b - 1));
        reward /= 2;
        Assert.assertEquals(reward, PowUtil.getBlockReward(params, n * b));
    }
}
Also used : NetworkParams(snowblossom.lib.NetworkParams) NetworkParamsProd(snowblossom.lib.NetworkParamsProd) Test(org.junit.Test)

Example 15 with NetworkParams

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

the class SpoonTest method setupSnow.

protected File setupSnow(String network) throws Exception {
    TreeMap<String, String> config_map = new TreeMap<>();
    config_map.put("network", network);
    NetworkParams params = NetworkParams.loadFromConfig(new ConfigMem(config_map));
    String test_folder_base = test_folder.newFolder().getPath();
    File snow_path = new File(test_folder.newFolder(), "snow");
    for (int i = 0; i < 4; i++) {
        SnowFieldInfo info = params.getSnowFieldInfo(i);
        String name = network + "." + i;
        File field_path = new File(snow_path, name);
        field_path.mkdirs();
        File field = new File(field_path, name + ".snow");
        new SnowFall(field.getPath(), name, info.getLength());
        ByteString root_hash = new SnowMerkle(field_path, name, true).getRootHash();
        Assert.assertEquals(info.getMerkleRootHash(), root_hash);
    }
    return snow_path;
}
Also used : SnowMerkle(snowblossom.lib.SnowMerkle) SnowFieldInfo(snowblossom.lib.SnowFieldInfo) ByteString(com.google.protobuf.ByteString) NetworkParams(snowblossom.lib.NetworkParams) SnowFall(snowblossom.lib.SnowFall) ByteString(com.google.protobuf.ByteString) ConfigMem(duckutil.ConfigMem) File(java.io.File)

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