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);
}
}
}
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);
}
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);
}
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));
}
}
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;
}
Aggregations