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