Search in sources :

Example 1 with JSApiPermission

use of com.icodici.universa.contract.jsapi.permissions.JSApiPermission in project universa by UniversaBlockchain.

the class ScriptEngineTest method testRevokePermission.

@Test
public void testRevokePermission() throws Exception {
    KeyAddress k0 = TestKeys.publicKey(0).getShortAddress();
    Contract contract = new Contract(TestKeys.privateKey(0));
    String js = "";
    js += "print('testRevokePermission');";
    js += "var simpleRole = jsApi.getRoleBuilder().createSimpleRole('owner', '" + k0.toString() + "');";
    js += "var revokePermission = jsApi.getPermissionBuilder().createRevokePermission(simpleRole);";
    js += "result = revokePermission;";
    contract.getDefinition().setJS(js.getBytes(), "client script.js", new JSApiScriptParameters());
    contract.seal();
    JSApiPermission res = (JSApiPermission) contract.execJS(js.getBytes());
    RevokePermission revokePermission = (RevokePermission) res.extractPermission(new JSApiAccessor());
    RevokePermission sample = new RevokePermission(new SimpleRole("test"));
    Field field = Permission.class.getDeclaredField("name");
    field.setAccessible(true);
    assertEquals(field.get(sample), field.get(revokePermission));
}
Also used : Field(java.lang.reflect.Field) SimpleRole(com.icodici.universa.contract.roles.SimpleRole) KeyAddress(com.icodici.crypto.KeyAddress) JSApiPermission(com.icodici.universa.contract.jsapi.permissions.JSApiPermission) Contract(com.icodici.universa.contract.Contract) NSmartContract(com.icodici.universa.contract.services.NSmartContract) SlotContract(com.icodici.universa.contract.services.SlotContract) Test(org.junit.Test)

Example 2 with JSApiPermission

use of com.icodici.universa.contract.jsapi.permissions.JSApiPermission in project universa by UniversaBlockchain.

the class ScriptEngineTest method testChangeOwnerPermission.

@Test
public void testChangeOwnerPermission() throws Exception {
    KeyAddress k0 = TestKeys.publicKey(0).getShortAddress();
    Contract contract = new Contract(TestKeys.privateKey(0));
    String js = "";
    js += "print('testChangeOwnerPermission');";
    js += "var simpleRole = jsApi.getRoleBuilder().createSimpleRole('owner', '" + k0.toString() + "');";
    js += "var changeOwnerPermission = jsApi.getPermissionBuilder().createChangeOwnerPermission(simpleRole);";
    js += "result = changeOwnerPermission;";
    contract.getDefinition().setJS(js.getBytes(), "client script.js", new JSApiScriptParameters());
    contract.seal();
    JSApiPermission res = (JSApiPermission) contract.execJS(js.getBytes());
    ChangeOwnerPermission changeOwnerPermission = (ChangeOwnerPermission) res.extractPermission(new JSApiAccessor());
    ChangeOwnerPermission sample = new ChangeOwnerPermission(new SimpleRole("test"));
    Field field = Permission.class.getDeclaredField("name");
    field.setAccessible(true);
    assertEquals(field.get(sample), field.get(changeOwnerPermission));
}
Also used : Field(java.lang.reflect.Field) SimpleRole(com.icodici.universa.contract.roles.SimpleRole) KeyAddress(com.icodici.crypto.KeyAddress) JSApiPermission(com.icodici.universa.contract.jsapi.permissions.JSApiPermission) Contract(com.icodici.universa.contract.Contract) NSmartContract(com.icodici.universa.contract.services.NSmartContract) SlotContract(com.icodici.universa.contract.services.SlotContract) Test(org.junit.Test)

Example 3 with JSApiPermission

use of com.icodici.universa.contract.jsapi.permissions.JSApiPermission in project universa by UniversaBlockchain.

the class ScriptEngineTest method testModifyDataPermission.

@Test
public void testModifyDataPermission() throws Exception {
    KeyAddress k0 = TestKeys.publicKey(0).getShortAddress();
    Contract contract = new Contract(TestKeys.privateKey(0));
    String js = "";
    js += "print('testModifyDataPermission');";
    js += "var simpleRole = jsApi.getRoleBuilder().createSimpleRole('owner', '" + k0.toString() + "');";
    js += "var modifyDataPermission = jsApi.getPermissionBuilder().createModifyDataPermission(simpleRole, " + "{some_field: [1, 2, 3]});";
    js += "result = modifyDataPermission;";
    contract.getDefinition().setJS(js.getBytes(), "client script.js", new JSApiScriptParameters());
    contract.seal();
    JSApiPermission res = (JSApiPermission) contract.execJS(js.getBytes());
    ModifyDataPermission changeOwnerPermission = (ModifyDataPermission) res.extractPermission(new JSApiAccessor());
    ModifyDataPermission sample = new ModifyDataPermission(new SimpleRole("test"), Binder.of("fields", Binder.of("some_field", Arrays.asList(1, 2, 3))));
    Field field = Permission.class.getDeclaredField("name");
    field.setAccessible(true);
    assertEquals(field.get(sample), field.get(changeOwnerPermission));
    field = ModifyDataPermission.class.getDeclaredField("fields");
    field.setAccessible(true);
    assertEquals(field.get(sample), field.get(changeOwnerPermission));
}
Also used : Field(java.lang.reflect.Field) SimpleRole(com.icodici.universa.contract.roles.SimpleRole) KeyAddress(com.icodici.crypto.KeyAddress) JSApiPermission(com.icodici.universa.contract.jsapi.permissions.JSApiPermission) Contract(com.icodici.universa.contract.Contract) NSmartContract(com.icodici.universa.contract.services.NSmartContract) SlotContract(com.icodici.universa.contract.services.SlotContract) Test(org.junit.Test)

Aggregations

KeyAddress (com.icodici.crypto.KeyAddress)3 Contract (com.icodici.universa.contract.Contract)3 JSApiPermission (com.icodici.universa.contract.jsapi.permissions.JSApiPermission)3 SimpleRole (com.icodici.universa.contract.roles.SimpleRole)3 NSmartContract (com.icodici.universa.contract.services.NSmartContract)3 SlotContract (com.icodici.universa.contract.services.SlotContract)3 Field (java.lang.reflect.Field)3 Test (org.junit.Test)3