use of com.icodici.universa.contract.jsapi.roles.JSApiRole in project universa by UniversaBlockchain.
the class ScriptEngineTest method testListRole.
@Test
public void testListRole() throws Exception {
KeyAddress k0 = TestKeys.publicKey(0).getShortAddress();
KeyAddress k1 = TestKeys.publicKey(1).getShortAddress();
KeyAddress k2 = TestKeys.publicKey(2).getShortAddress();
KeyAddress k3 = TestKeys.publicKey(3).getShortAddress();
Contract contract = new Contract(TestKeys.privateKey(0));
String js = "";
js += "print('testListRole');";
js += "var simpleRole0 = jsApi.getRoleBuilder().createSimpleRole('owner', '" + k0.toString() + "');";
js += "var simpleRole1 = jsApi.getRoleBuilder().createSimpleRole('owner', '" + k1.toString() + "');";
js += "var simpleRole2 = jsApi.getRoleBuilder().createSimpleRole('owner', '" + k2.toString() + "');";
js += "var listRole = jsApi.getRoleBuilder().createListRole('listRole', 'all', simpleRole0, simpleRole1, simpleRole2);";
js += "result = listRole;";
JSApiScriptParameters scriptParameters = new JSApiScriptParameters();
contract.getDefinition().setJS(js.getBytes(), "client script.js", scriptParameters);
contract.seal();
JSApiRole res = (JSApiRole) contract.execJS(js.getBytes());
assertTrue(res.isAllowedForKeys(TestKeys.publicKey(0), TestKeys.publicKey(1), TestKeys.publicKey(2)));
assertFalse(res.isAllowedForKeys(TestKeys.publicKey(0)));
assertFalse(res.isAllowedForKeys(TestKeys.publicKey(1)));
assertFalse(res.isAllowedForKeys(TestKeys.publicKey(2)));
assertFalse(res.isAllowedForKeys(TestKeys.publicKey(3)));
}
use of com.icodici.universa.contract.jsapi.roles.JSApiRole in project universa by UniversaBlockchain.
the class ScriptEngineTest method testSimpleRole.
@Test
public void testSimpleRole() throws Exception {
KeyAddress k0 = TestKeys.publicKey(0).getShortAddress();
KeyAddress k1 = TestKeys.publicKey(1).getShortAddress();
KeyAddress k2 = TestKeys.publicKey(2).getShortAddress();
KeyAddress k3 = TestKeys.publicKey(3).getShortAddress();
Contract contract = new Contract(TestKeys.privateKey(0));
String js = "";
js += "print('testSimpleRole');";
js += "var simpleRole = jsApi.getRoleBuilder().createSimpleRole('owner', '" + k0.toString() + "', '" + k1.toString() + "', '" + k2.toString() + "');";
js += "result = simpleRole;";
JSApiScriptParameters scriptParameters = new JSApiScriptParameters();
contract.getDefinition().setJS(js.getBytes(), "client script.js", scriptParameters);
contract.seal();
JSApiRole res = (JSApiRole) contract.execJS(js.getBytes());
assertTrue(res.isAllowedForKeys(TestKeys.publicKey(0), TestKeys.publicKey(1), TestKeys.publicKey(2)));
assertFalse(res.isAllowedForKeys(TestKeys.publicKey(0)));
assertFalse(res.isAllowedForKeys(TestKeys.publicKey(1)));
assertFalse(res.isAllowedForKeys(TestKeys.publicKey(2)));
assertFalse(res.isAllowedForKeys(TestKeys.publicKey(3)));
}
Aggregations