Search in sources :

Example 6 with NetworkParamsRegtest

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

the class ShardUtilTest method testBlockRewardNoShard.

@Test
public void testBlockRewardNoShard() {
    NetworkParams params = new NetworkParamsRegtest();
    long reward = ShardUtil.getBlockReward(params, BlockHeader.newBuilder().build());
    Assert.assertEquals(PowUtil.getBlockReward(params, 0), reward);
}
Also used : NetworkParamsRegtest(snowblossom.lib.NetworkParamsRegtest) NetworkParams(snowblossom.lib.NetworkParams) Test(org.junit.Test)

Example 7 with NetworkParamsRegtest

use of snowblossom.lib.NetworkParamsRegtest 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 8 with NetworkParamsRegtest

use of snowblossom.lib.NetworkParamsRegtest 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 9 with NetworkParamsRegtest

use of snowblossom.lib.NetworkParamsRegtest 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 10 with NetworkParamsRegtest

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

the class SpoonTest method genWallet.

public static WalletDatabase genWallet() {
    TreeMap<String, String> config_map = new TreeMap<>();
    config_map.put("key_count", "20");
    WalletDatabase db = WalletUtil.makeNewDatabase(new ConfigMem(config_map), new NetworkParamsRegtest());
    return db;
}
Also used : NetworkParamsRegtest(snowblossom.lib.NetworkParamsRegtest) ByteString(com.google.protobuf.ByteString) ConfigMem(duckutil.ConfigMem)

Aggregations

NetworkParamsRegtest (snowblossom.lib.NetworkParamsRegtest)10 Test (org.junit.Test)9 NetworkParams (snowblossom.lib.NetworkParams)8 BigInteger (java.math.BigInteger)5 ByteString (com.google.protobuf.ByteString)3 ConfigMem (duckutil.ConfigMem)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Random (java.util.Random)1 AddressSpecHash (snowblossom.lib.AddressSpecHash)1 NetworkParamsProd (snowblossom.lib.NetworkParamsProd)1 NetworkParamsTestnet (snowblossom.lib.NetworkParamsTestnet)1 BlockHeader (snowblossom.proto.BlockHeader)1 BlockImportList (snowblossom.proto.BlockImportList)1