Search in sources :

Example 1 with PublicKey

use of com.icodici.crypto.PublicKey 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 2 with PublicKey

use of com.icodici.crypto.PublicKey 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 3 with PublicKey

use of com.icodici.crypto.PublicKey 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);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Contract(com.icodici.universa.contract.Contract) HashSet(java.util.HashSet)

Example 4 with PublicKey

use of com.icodici.crypto.PublicKey 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);
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Contract(com.icodici.universa.contract.Contract) HashSet(java.util.HashSet)

Example 5 with PublicKey

use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.

the class ContractsServiceTest method checkCreateParcelFotTestNet.

private void checkCreateParcelFotTestNet(String contract_file_payload, String contract_file_payment) throws Exception {
    final String ROOT_PATH = "./src/test_contracts/contractService/";
    PrivateKey privateKey = TestKeys.privateKey(3);
    Set<PrivateKey> privateKeys = new HashSet<>();
    privateKeys.add(privateKey);
    Set<PublicKey> publicKeys = new HashSet<>();
    publicKeys.add(privateKey.getPublicKey());
    Contract payload = Contract.fromDslFile(ROOT_PATH + contract_file_payload);
    payload.addSignerKey(privateKey);
    payload.seal();
    Contract payment = InnerContractsService.createFreshTU(100, publicKeys, true);
    Parcel parcel = ContractsService.createParcel(payload, payment, 20, privateKeys, true);
    assertEquals(parcel.getPayloadContract().getState().getBranchId(), payload.getState().getBranchId());
    assertEquals(parcel.getPaymentContract().getState().getBranchId(), payment.getState().getBranchId());
    assertEquals(parcel.getPayloadContract().getStateData(), payload.getStateData());
    assertEquals(parcel.getPaymentContract().getDefinition().getData(), payment.getDefinition().getData());
    assertEquals(100, parcel.getPaymentContract().getStateData().getIntOrThrow("transaction_units"));
    assertEquals(10000 - 20, parcel.getPaymentContract().getStateData().getIntOrThrow("test_transaction_units"));
    System.out.println("OK");
}
Also used : PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) HashSet(java.util.HashSet)

Aggregations

PublicKey (com.icodici.crypto.PublicKey)84 PrivateKey (com.icodici.crypto.PrivateKey)75 Test (org.junit.Test)57 SimpleRole (com.icodici.universa.contract.roles.SimpleRole)17 HashSet (java.util.HashSet)14 Binder (net.sergeych.tools.Binder)13 ListRole (com.icodici.universa.contract.roles.ListRole)11 Role (com.icodici.universa.contract.roles.Role)7 Contract (com.icodici.universa.contract.Contract)6 KeyAddress (com.icodici.crypto.KeyAddress)4 RoleLink (com.icodici.universa.contract.roles.RoleLink)4 KeyRecord (com.icodici.universa.contract.KeyRecord)3 ChangeOwnerPermission (com.icodici.universa.contract.permissions.ChangeOwnerPermission)3 Permission (com.icodici.universa.contract.permissions.Permission)3 TimeoutException (java.util.concurrent.TimeoutException)3 Decimal (com.icodici.universa.Decimal)2 ErrorRecord (com.icodici.universa.ErrorRecord)2 HashId (com.icodici.universa.HashId)2 Quantiser (com.icodici.universa.node2.Quantiser)2 List (java.util.List)2