Search in sources :

Example 1 with JSApiRole

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)));
}
Also used : KeyAddress(com.icodici.crypto.KeyAddress) JSApiRole(com.icodici.universa.contract.jsapi.roles.JSApiRole) 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 JSApiRole

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)));
}
Also used : KeyAddress(com.icodici.crypto.KeyAddress) JSApiRole(com.icodici.universa.contract.jsapi.roles.JSApiRole) 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)2 Contract (com.icodici.universa.contract.Contract)2 JSApiRole (com.icodici.universa.contract.jsapi.roles.JSApiRole)2 NSmartContract (com.icodici.universa.contract.services.NSmartContract)2 SlotContract (com.icodici.universa.contract.services.SlotContract)2 Test (org.junit.Test)2