Search in sources :

Example 6 with PrivateKey

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();
        }
    });
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) Test(org.junit.Test)

Example 7 with PrivateKey

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();
        }
    });
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) SQLException(java.sql.SQLException) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with PrivateKey

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);
}
Also used : SimpleRole(com.icodici.universa.contract.roles.SimpleRole) Role(com.icodici.universa.contract.roles.Role) ListRole(com.icodici.universa.contract.roles.ListRole) RoleLink(com.icodici.universa.contract.roles.RoleLink) PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) ChangeOwnerPermission(com.icodici.universa.contract.permissions.ChangeOwnerPermission) Test(org.junit.Test)

Example 9 with PrivateKey

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);
}
Also used : SimpleRole(com.icodici.universa.contract.roles.SimpleRole) Role(com.icodici.universa.contract.roles.Role) ListRole(com.icodici.universa.contract.roles.ListRole) RoleLink(com.icodici.universa.contract.roles.RoleLink) PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) ChangeOwnerPermission(com.icodici.universa.contract.permissions.ChangeOwnerPermission) Test(org.junit.Test)

Example 10 with PrivateKey

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());
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) SQLException(java.sql.SQLException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

PrivateKey (com.icodici.crypto.PrivateKey)168 Test (org.junit.Test)122 PublicKey (com.icodici.crypto.PublicKey)76 SimpleRole (com.icodici.universa.contract.roles.SimpleRole)29 Contract (com.icodici.universa.contract.Contract)24 Binder (net.sergeych.tools.Binder)22 IOException (java.io.IOException)16 HashSet (java.util.HashSet)14 ListRole (com.icodici.universa.contract.roles.ListRole)12 SQLException (java.sql.SQLException)11 Ignore (org.junit.Ignore)9 File (java.io.File)8 KeyAddress (com.icodici.crypto.KeyAddress)7 KeyRecord (com.icodici.universa.contract.KeyRecord)7 Role (com.icodici.universa.contract.roles.Role)7 Semaphore (java.util.concurrent.Semaphore)7 RoleLink (com.icodici.universa.contract.roles.RoleLink)5 TimeoutException (java.util.concurrent.TimeoutException)5 Decimal (com.icodici.universa.Decimal)4 HashId (com.icodici.universa.HashId)4