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