use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class MainTest method testContractCheck.
@Test
public void testContractCheck() throws Exception {
PrivateKey key = TestKeys.privateKey(3);
testSomeWork(() -> {
try {
Contract c = new Contract(key);
for (int k = 0; k < 500; k++) {
Contract nc = new Contract(key);
nc.seal();
c.addNewItems(nc);
}
c.seal();
c.check();
} catch (Quantiser.QuantiserException e) {
e.printStackTrace();
}
});
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class MainTest method testNewContractSeal.
@Test
public void testNewContractSeal() throws Exception {
testSomeWork(() -> {
for (int i = 0; i < 10; ++i) {
PrivateKey myKey = null;
try {
myKey = TestKeys.privateKey(3);
} catch (Exception e) {
}
Contract testContract = new Contract(myKey);
for (int iContract = 0; iContract < 10; ++iContract) {
Contract nc = new Contract(myKey);
nc.seal();
testContract.addNewItems(nc);
}
testContract.seal();
}
});
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class MainTest method registerContractWithAnonymousId.
@Test
public void registerContractWithAnonymousId() throws Exception {
TestSpace ts = prepareTestSpace();
PrivateKey myPrivKey = TestKeys.privateKey(1);
PublicKey myPubKey = myPrivKey.getPublicKey();
byte[] myAnonId = myPrivKey.createAnonymousId();
Contract contract = new Contract();
contract.setExpiresAt(ZonedDateTime.now().plusDays(90));
Role r = contract.setIssuerKeys(AnonymousId.fromBytes(myAnonId));
contract.registerRole(new RoleLink("owner", "issuer"));
contract.registerRole(new RoleLink("creator", "issuer"));
contract.addPermission(new ChangeOwnerPermission(r));
contract.addSignerKey(myPrivKey);
contract.seal();
System.out.println("contract.check(): " + contract.check());
contract.traceErrors();
// ItemResult itemResult = ts.client.register(contract.getPackedTransaction(), 5000);
ItemResult itemResult0 = ts.node.node.registerItem(contract);
// Thread.sleep(1000000000);
ItemResult itemResult = ts.node.node.waitItem(contract.getId(), 100);
assertEquals(ItemState.APPROVED, itemResult.state);
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class MainTest method registerContractWithAnonymousId_bak.
@Test
public void registerContractWithAnonymousId_bak() throws Exception {
TestSpace ts = prepareTestSpace();
PrivateKey myPrivKey = TestKeys.privateKey(1);
PublicKey myPubKey = myPrivKey.getPublicKey();
byte[] myAnonId = myPrivKey.createAnonymousId();
Contract contract = new Contract();
contract.setExpiresAt(ZonedDateTime.now().plusDays(90));
Role r = contract.setIssuerKeys(myPubKey);
contract.registerRole(new RoleLink("owner", "issuer"));
contract.registerRole(new RoleLink("creator", "issuer"));
contract.addPermission(new ChangeOwnerPermission(r));
contract.addSignerKey(myPrivKey);
contract.seal();
ItemResult itemResult = ts.client.register(contract.getPackedTransaction(), 5000);
assertEquals(ItemState.APPROVED, itemResult.state);
}
use of com.icodici.crypto.PrivateKey in project universa by UniversaBlockchain.
the class MainTest method checkShutdown.
@Test
public void checkShutdown() throws Exception {
List<Main> mm = new ArrayList<>();
for (int i = 0; i < 3; i++) {
mm.add(createMain("node" + (i + 1), false));
}
Main main = mm.get(0);
PrivateKey myKey = TestKeys.privateKey(3);
Client client = null;
try {
client = new Client(myKey, main.myInfo, null);
} catch (Exception e) {
System.out.println("prepareClient exception: " + e.toString());
}
Contract testContract = new Contract(myKey);
for (int i = 0; i < 10; i++) {
Contract nc = new Contract(myKey);
testContract.addNewItems(nc);
}
testContract.seal();
assertTrue(testContract.isOk());
Parcel parcel = createParcelWithFreshTU(client, testContract, Do.listOf(myKey));
client.registerParcel(parcel.pack());
System.out.println(">> before shutdown state: " + client.getState(parcel.getPayloadContract().getId()));
System.out.println(">> before shutdown state: " + client.getState(parcel.getPayloadContract().getNew().get(0).getId()));
main.shutdown();
mm.remove(main);
main = createMain("node1", false);
mm.add(main);
try {
client = new Client(myKey, main.myInfo, null);
} catch (Exception e) {
System.out.println("prepareClient exception: " + e.toString());
}
ItemResult itemResult = client.getState(parcel.getPayloadContract().getId());
ItemResult itemResult2 = client.getState(parcel.getPayloadContract().getNew().get(0).getId());
System.out.println(">> after shutdown state: " + itemResult + " and new " + itemResult2);
assertEquals(ItemState.UNDEFINED, itemResult.state);
assertEquals(ItemState.UNDEFINED, itemResult2.state);
mm.forEach(x -> x.shutdown());
}
Aggregations