use of com.icodici.universa.Decimal in project universa by UniversaBlockchain.
the class ContractTestBase method createCoinWithAmount.
protected Contract createCoinWithAmount(String amount, String fieldName) throws Exception {
Contract contract = createCoin();
contract.getStateData().set(fieldName, new Decimal(amount));
contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(contract, true);
return contract;
}
use of com.icodici.universa.Decimal in project universa by UniversaBlockchain.
the class ContractsServiceTest method goodShare.
@Test
public void goodShare() 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.createShareContract(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"), 1);
assertEquals(splitJoinParams.get("min_unit"), 1);
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.universa.Decimal in project universa by UniversaBlockchain.
the class SplitJoinPermissionTest method shouldSplitWithChangedOwnerAndNewValueSerialize.
@Test
public void shouldSplitWithChangedOwnerAndNewValueSerialize() throws Exception {
int defaultValue = 1000000;
int valueForSplit = 85;
Contract c = createCoin();
c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
Binder d = c.getStateData();
sealCheckTrace(c, true);
Contract c2 = c.splitValue(FIELD_NAME, new Decimal(valueForSplit));
c2.addSignerKey(ownerKey2);
Binder d2 = c2.getStateData();
sealCheckTrace(c2, true);
assertEquals(defaultValue - valueForSplit, d.getIntOrThrow(FIELD_NAME));
assertEquals(valueForSplit, d2.getIntOrThrow(FIELD_NAME));
}
use of com.icodici.universa.Decimal in project universa by UniversaBlockchain.
the class SplitJoinPermissionTest method shouldNotJoinWithWrongParent.
@Test
public void shouldNotJoinWithWrongParent() throws Exception {
Contract c = createCoin();
c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
Contract c1 = c.splitValue(FIELD_NAME, new Decimal(1));
Contract.ContractDev dev = c1.new ContractDev(c1);
// Check after split.
sealCheckTrace(c, true);
// Set wrong parent
HashId parent = HashId.withDigest(Do.randomNegativeBytes(64));
HashId origin = HashId.withDigest(Do.randomNegativeBytes(64));
dev.setParent(parent);
dev.setOrigin(origin);
c.getRevokingItems().add(dev.getContract());
sealCheckTrace(c, false);
}
use of com.icodici.universa.Decimal in project universa by UniversaBlockchain.
the class SplitJoinPermissionTest method splitJoinHasNotEnoughSumRevoking.
@Test
public void splitJoinHasNotEnoughSumRevoking() throws Exception {
Contract root = createCoinWithAmount("200", FIELD_NAME);
Contract c1 = root.splitValue(FIELD_NAME, new Decimal(100));
sealCheckTrace(c1, true);
// c1 split 50 50
c1 = c1.createRevision(ownerKey2);
c1.seal();
Contract c50_1 = c1.splitValue(FIELD_NAME, new Decimal(50));
sealCheckTrace(c50_1, true);
// set wrong revoking with the same amount
root = root.createRevision(ownerKey2);
root.seal();
// c1 split 45 5
c1 = c50_1.createRevision(ownerKey2);
c1.seal();
Contract c5 = c1.splitValue(FIELD_NAME, new Decimal(5));
sealCheckTrace(c5, true);
// coin amount: 200 (revoking: 100 and 50 and 5)
root.getStateData().set(FIELD_NAME, new Decimal(200));
root.addRevokingItems(c50_1);
root.addRevokingItems(c5);
sealCheckTrace(root, false);
}
Aggregations