use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class ResearchTest method registerSimpleContract_recreateNodeClient.
@Test
public void registerSimpleContract_recreateNodeClient() throws Exception {
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
Set<PublicKey> stepaPublicKeys = new HashSet<>();
stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey")));
for (PrivateKey pk : stepaPrivateKeys) {
stepaPublicKeys.add(pk.getPublicKey());
}
Contract stepaCoins = Contract.fromDslFile(ROOT_PATH + "stepaCoins.yml");
stepaCoins.addSignerKey(stepaPrivateKeys.iterator().next());
stepaCoins.seal();
System.out.println("nodeClient.register(stepaCoins)...");
ItemResult itemResult = nodeClient.register(stepaCoins.getLastSealedBinary(), 1000);
System.out.println("nodeClient.register(stepaCoins)... done! itemResult: " + itemResult.state);
reCreateNodeClient();
itemResult = nodeClient.getState(stepaCoins.getId());
System.out.println("nodeClient.getState(stepaCoins): " + itemResult.state);
assertEquals(ItemState.APPROVED, itemResult.state);
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class ResearchTest method registerSimpleContract_getStateOnly.
@Test
public void registerSimpleContract_getStateOnly() throws Exception {
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
Set<PublicKey> stepaPublicKeys = new HashSet<>();
stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey")));
for (PrivateKey pk : stepaPrivateKeys) {
stepaPublicKeys.add(pk.getPublicKey());
}
Contract stepaCoins = Contract.fromDslFile(ROOT_PATH + "stepaCoins.yml");
stepaCoins.addSignerKey(stepaPrivateKeys.iterator().next());
stepaCoins.seal();
ItemResult itemResult = nodeClient.getState(stepaCoins.getId());
System.out.println("nodeClient.getState(stepaCoins): " + itemResult.state);
assertEquals(ItemState.APPROVED, itemResult.state);
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class ContractTest method checkTestnetKeyStrengthCriteria.
@Test
public void checkTestnetKeyStrengthCriteria() throws Exception {
PrivateKey key = new PrivateKey(Do.read(PRIVATE_KEY_PATH));
Contract contract = createCoin100apiv3();
contract.setExpiresAt(ZonedDateTime.now().plusMonths(1));
contract.addSignerKey(key);
sealCheckTrace(contract, true);
assertFalse(contract.isSuitableForTestnet());
// now set contract limited for testnet
contract.setLimitedForTestnet(true);
sealCheckTrace(contract, false);
assertFalse(contract.isSuitableForTestnet());
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class ContractTest method checkParallelCreation.
@Ignore("parallel test")
@Test
public void checkParallelCreation() throws Exception {
final PrivateKey key = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey"));
int N = 100;
int M = Runtime.getRuntime().availableProcessors();
int K = 10;
float threshold = 1.2f;
float ratio = 0;
System.out.println("available processors: " + M);
for (int i = 0; i < N; i++) {
long ts1;
long ts2;
Semaphore semaphore = new Semaphore(-(M - 1));
ts1 = new Date().getTime();
for (int j = 0; j < M; j++) {
new Thread(() -> {
for (int x = 0; x < K; x++) {
try {
Contract c = new Contract(key);
for (int k = 0; k < 10; k++) {
Contract nc = new Contract(key);
nc.seal();
c.addNewItems(nc);
}
c.seal();
c.check();
} catch (Quantiser.QuantiserException e) {
e.printStackTrace();
}
}
semaphore.release();
}).start();
}
semaphore.acquire();
ts2 = new Date().getTime();
long time2 = ts2 - ts1;
ts1 = new Date().getTime();
new Thread(() -> {
for (int x = 0; x < K; x++) {
try {
Contract c = new Contract(key);
for (int k = 0; k < 10; k++) {
Contract nc = new Contract(key);
nc.seal();
c.addNewItems(nc);
}
c.seal();
c.check();
} catch (Quantiser.QuantiserException e) {
e.printStackTrace();
}
}
semaphore.release();
}).start();
semaphore.acquire();
ts2 = new Date().getTime();
long time3 = ts2 - ts1;
System.out.println(time2 * 1.0f / time3);
ratio += time2 * 1.0f / time3;
}
ratio /= N;
System.out.println("average " + ratio);
assertFalse(ratio > threshold);
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class ContractTest method checkFitTestnetCriteria.
@Test
public void checkFitTestnetCriteria() throws Exception {
PrivateKey key = new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey"));
Contract contract = Contract.fromDslFile(rootPath + "LamborghiniTestDrive.yml");
contract.setExpiresAt(ZonedDateTime.now().plusMonths(1));
contract.addSignerKey(key);
sealCheckTrace(contract, true);
System.out.println("Processing cost is " + contract.getProcessedCostTU());
assertTrue(contract.isSuitableForTestnet());
// now set contract limited for testnet
contract.setLimitedForTestnet(true);
sealCheckTrace(contract, true);
assertTrue(contract.isSuitableForTestnet());
}
Aggregations