use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class PermissionsTest method shouldNotModifyDescEmptyStateDataValues.
@Test
public void shouldNotModifyDescEmptyStateDataValues() throws Exception {
PrivateKey ownerKey2 = TestKeys.privateKey(1);
Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2);
Binder d = c.getStateData();
Contract c1 = c.createRevision(ownerKey2);
Binder d1 = c1.getStateData();
final String oldValue = "An example of smart contract.";
final String newValue = "wrong value.";
final String field = "description";
setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
sealCheckTrace(c1, false);
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class PermissionsTest method shouldModifySeveralStateDataValues.
@Test
public void shouldModifySeveralStateDataValues() throws Exception {
PrivateKey ownerKey2 = TestKeys.privateKey(1);
Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2);
Binder d = c.getStateData();
Contract c1 = c.createRevision(ownerKey2);
Binder d1 = c1.getStateData();
String oldValue = "An example of smart contract.";
String newValue = "UniversaSmartContract";
String field = "description";
setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
oldValue = "blockchain-partnership.";
newValue = "blockchain-universa.";
field = "partner_name";
setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
d1.addToInt("direction", 3);
sealCheckTrace(c1, true);
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class SplitJoinPermissionTest method shouldNotSplitWithWrongCreatedBySerialize.
@Test
public void shouldNotSplitWithWrongCreatedBySerialize() throws Exception {
Contract c = createCoin();
c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(c, true);
Contract c2 = c.split(1)[0];
sealCheckTrace(c2, true);
Binder sd2 = DefaultBiMapper.serialize(c2);
Binder state = (Binder) sd2.get("state");
assertNotNull(state);
assertTrue(state.size() > 0);
state.set("createdBy", "other");
Contract dc2 = DefaultBiMapper.deserialize(sd2);
sealCheckTrace(dc2, false);
state.set("createdBy", "owner");
Contract dc3 = DefaultBiMapper.deserialize(sd2);
sealCheckTrace(dc3, false);
state.remove("createdBy");
Contract dc4 = DefaultBiMapper.deserialize(sd2);
sealCheckTrace(dc4, false);
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class SplitJoinPermissionTest method cheatCreateValue2.
@Test
public void cheatCreateValue2() throws Exception {
Contract c = createCoin();
c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
Binder d = c.getStateData();
int a = 1000000;
assertEquals(a, d.getIntOrThrow(FIELD_NAME));
c.seal();
assertTrue(c.check());
Contract c1 = c.createRevision(ownerKey2);
c1.getStateData().set(FIELD_NAME, "500.00000001");
sealCheckTrace(c1, false);
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class SplitJoinPermissionTest method testProperSum.
@Test
public void testProperSum() throws Exception {
Contract c = createCoin();
c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
Binder d = c.getStateData();
int a = 1000000;
assertEquals(a, d.getIntOrThrow(FIELD_NAME));
sealCheckTrace(c, true);
// bad split: no changes
Contract c1 = c.createRevision(ownerKey2);
sealCheckTrace(c1, false);
// Good split
Contract c2 = c1.splitValue(FIELD_NAME, new Decimal(500));
assertEquals(a - 500, c1.getStateData().getIntOrThrow(FIELD_NAME));
assertEquals(500, c2.getStateData().getIntOrThrow(FIELD_NAME));
c1.getErrors().clear();
sealCheckTrace(c1, true);
// and it should be the same after seriazling to the transaction pack
TransactionPack tp = new TransactionPack(c1);
// tp.trace();
TransactionPack tp2 = TransactionPack.unpack(new TransactionPack(c1).pack());
// tp2.trace();
Contract restored = tp2.getContract();
restored.check();
restored.traceErrors();
assertTrue(restored.isOk());
// TODO: check that value can't be just changed
// TODO: check that the sum must be equal
// TODO: check children have different branches
// TODO: check smae branch spoofing
}
Aggregations