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