use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class ContractsServiceTest method createTestTU.
@Test
public void createTestTU() throws Exception {
PrivateKey privateKey = TestKeys.privateKey(3);
Set<PublicKey> keys = new HashSet();
keys.add(privateKey.getPublicKey());
Contract tu = InnerContractsService.createFreshTU(100, keys, true);
tu.check();
tu.traceErrors();
assertEquals(true, tu.getRole("owner").isAllowedForKeys(keys));
assertEquals(100, tu.getStateData().getIntOrThrow("transaction_units"));
assertEquals(10000, tu.getStateData().getIntOrThrow("test_transaction_units"));
PrivateKey manufacturePrivateKey = new PrivateKey(Do.read("./src/test_contracts/keys/tu_key.private.unikey"));
Set<PublicKey> badKeys = new HashSet();
badKeys.add(manufacturePrivateKey.getPublicKey());
assertEquals(false, tu.getRole("owner").isAllowedForKeys(badKeys));
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class ContractsServiceTest method goodToken.
@Test
public void goodToken() throws Exception {
Set<PrivateKey> martyPrivateKeys = new HashSet<>();
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
Set<PublicKey> martyPublicKeys = new HashSet<>();
Set<PublicKey> stepaPublicKeys = new HashSet<>();
martyPrivateKeys.add(new PrivateKey(Do.read(rootPath + "keys/marty_mcfly.private.unikey")));
stepaPrivateKeys.add(new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey")));
for (PrivateKey pk : stepaPrivateKeys) stepaPublicKeys.add(pk.getPublicKey());
for (PrivateKey pk : martyPrivateKeys) martyPublicKeys.add(pk.getPublicKey());
Contract notaryContract = ContractsService.createTokenContract(martyPrivateKeys, stepaPublicKeys, "100");
notaryContract.check();
notaryContract.traceErrors();
assertTrue(notaryContract.isOk());
assertTrue(notaryContract.getOwner().isAllowedForKeys(stepaPublicKeys));
assertTrue(notaryContract.getIssuer().isAllowedForKeys(martyPrivateKeys));
assertTrue(notaryContract.getCreator().isAllowedForKeys(martyPrivateKeys));
assertFalse(notaryContract.getOwner().isAllowedForKeys(martyPrivateKeys));
assertFalse(notaryContract.getIssuer().isAllowedForKeys(stepaPublicKeys));
assertFalse(notaryContract.getCreator().isAllowedForKeys(stepaPublicKeys));
assertTrue(notaryContract.getExpiresAt().isAfter(ZonedDateTime.now().plusMonths(3)));
assertTrue(notaryContract.getCreatedAt().isBefore(ZonedDateTime.now()));
assertEquals(InnerContractsService.getDecimalField(notaryContract, "amount"), new Decimal(100));
assertEquals(notaryContract.getPermissions().get("split_join").size(), 1);
Binder splitJoinParams = notaryContract.getPermissions().get("split_join").iterator().next().getParams();
assertEquals(splitJoinParams.get("min_value"), 0.01);
assertEquals(splitJoinParams.get("min_unit"), 0.01);
assertEquals(splitJoinParams.get("field_name"), "amount");
assertTrue(splitJoinParams.get("join_match_fields") instanceof List);
assertEquals(((List) splitJoinParams.get("join_match_fields")).get(0), "state.origin");
assertTrue(notaryContract.isPermitted("revoke", stepaPublicKeys));
assertTrue(notaryContract.isPermitted("revoke", martyPublicKeys));
assertTrue(notaryContract.isPermitted("change_owner", stepaPublicKeys));
assertFalse(notaryContract.isPermitted("change_owner", martyPublicKeys));
assertTrue(notaryContract.isPermitted("split_join", stepaPublicKeys));
assertFalse(notaryContract.isPermitted("split_join", martyPublicKeys));
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class ContractsServiceTest method goodNotary.
@Test
public void goodNotary() throws Exception {
Set<PrivateKey> martyPrivateKeys = new HashSet<>();
Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
Set<PublicKey> martyPublicKeys = new HashSet<>();
Set<PublicKey> stepaPublicKeys = new HashSet<>();
martyPrivateKeys.add(new PrivateKey(Do.read(rootPath + "keys/marty_mcfly.private.unikey")));
stepaPrivateKeys.add(new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey")));
for (PrivateKey pk : stepaPrivateKeys) stepaPublicKeys.add(pk.getPublicKey());
for (PrivateKey pk : martyPrivateKeys) martyPublicKeys.add(pk.getPublicKey());
Contract notaryContract = ContractsService.createNotaryContract(martyPrivateKeys, stepaPublicKeys);
notaryContract.check();
notaryContract.traceErrors();
assertTrue(notaryContract.isOk());
assertTrue(notaryContract.getOwner().isAllowedForKeys(stepaPublicKeys));
assertTrue(notaryContract.getIssuer().isAllowedForKeys(martyPrivateKeys));
assertTrue(notaryContract.getCreator().isAllowedForKeys(martyPrivateKeys));
assertFalse(notaryContract.getOwner().isAllowedForKeys(martyPrivateKeys));
assertFalse(notaryContract.getIssuer().isAllowedForKeys(stepaPublicKeys));
assertFalse(notaryContract.getCreator().isAllowedForKeys(stepaPublicKeys));
assertTrue(notaryContract.getExpiresAt().isAfter(ZonedDateTime.now().plusMonths(3)));
assertTrue(notaryContract.getCreatedAt().isBefore(ZonedDateTime.now()));
assertTrue(notaryContract.isPermitted("revoke", stepaPublicKeys));
assertTrue(notaryContract.isPermitted("revoke", martyPublicKeys));
assertTrue(notaryContract.isPermitted("change_owner", stepaPublicKeys));
assertFalse(notaryContract.isPermitted("change_owner", martyPublicKeys));
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class ExtendedSignatureTest method extractPublicKey.
@Test
public void extractPublicKey() throws Exception {
byte[] data = "Hello world".getBytes();
PrivateKey k = TestKeys.privateKey(3);
byte[] signature = ExtendedSignature.sign(k, data, true);
PublicKey pubKey = k.getPublicKey();
ExtendedSignature es = ExtendedSignature.verify(pubKey, signature, data);
assertNotNull(es);
assertAlmostSame(es.getCreatedAt(), ZonedDateTime.now());
assertEquals(ExtendedSignature.keyId(k), ExtendedSignature.keyId(pubKey));
assertEquals(ExtendedSignature.keyId(k), ExtendedSignature.extractKeyId(signature));
assertNotNull(es.getPublicKey());
assertEquals(pubKey, es.getPublicKey());
}
use of com.icodici.crypto.PublicKey in project universa by UniversaBlockchain.
the class ExtendedSignatureTest method sign.
@Test
public void sign() throws Exception {
byte[] data = "Hello world".getBytes();
PrivateKey k = TestKeys.privateKey(3);
byte[] signature = ExtendedSignature.sign(k, data);
PublicKey pubKey = k.getPublicKey();
ExtendedSignature es = ExtendedSignature.verify(pubKey, signature, data);
assertNotNull(es);
assertAlmostSame(es.getCreatedAt(), ZonedDateTime.now());
assertEquals(ExtendedSignature.keyId(k), ExtendedSignature.keyId(pubKey));
assertEquals(ExtendedSignature.keyId(k), ExtendedSignature.extractKeyId(signature));
}
Aggregations