Search in sources :

Example 1 with Approvable

use of com.icodici.universa.Approvable in project universa by UniversaBlockchain.

the class MainTest method registerContract500approvedHalf_pack.

@Test
public void registerContract500approvedHalf_pack() throws Exception {
    TestSpace ts = prepareTestSpace();
    Contract contract = createContract500(ts.myKey);
    int i = 0;
    for (Approvable sub : contract.getNewItems()) {
        ++i;
        Contract subContract = (Contract) sub;
        if (i % 2 == 0) {
            ItemResult subItemResult = ts.client.register(subContract.getLastSealedBinary(), 1000);
            assertEquals(ItemState.APPROVED, subItemResult.state);
        } else {
            ItemResult subItemResult = ts.client.getState(subContract.getId());
            assertEquals(ItemState.UNDEFINED, subItemResult.state);
        }
        if (i % 10 == 0)
            System.out.println("register subContract: " + i);
    }
    System.out.println("register parent contract...");
    ItemResult itemResult = ts.client.register(contract.getPackedTransaction(), 30000);
    assertEquals(ItemState.DECLINED, itemResult.state);
    Thread.sleep(5000);
    i = 0;
    for (Approvable sub : contract.getNewItems()) {
        ++i;
        ItemResult subItemResult = ts.client.getState(sub);
        System.out.println("" + i + " - " + subItemResult.state);
        if (i % 2 == 0)
            assertEquals(ItemState.APPROVED, subItemResult.state);
        else
            assertEquals(ItemState.UNDEFINED, subItemResult.state);
    }
    ts.nodes.forEach(n -> n.shutdown());
}
Also used : Approvable(com.icodici.universa.Approvable) Test(org.junit.Test)

Example 2 with Approvable

use of com.icodici.universa.Approvable in project universa by UniversaBlockchain.

the class MainTest method registerContract500_pack.

@Test
public void registerContract500_pack() throws Exception {
    TestSpace ts = prepareTestSpace();
    Contract contract = createContract500(ts.myKey);
    ItemResult itemResult = ts.client.register(contract.getPackedTransaction(), 30000);
    assertEquals(ItemState.APPROVED, itemResult.state);
    Thread.sleep(5000);
    int i = 0;
    for (Approvable sub : contract.getNewItems()) {
        ItemResult subItemResult = ts.client.getState(sub);
        System.out.println("" + (i++) + " - " + subItemResult.state);
        assertEquals(ItemState.APPROVED, subItemResult.state);
    }
    ts.nodes.forEach(n -> n.shutdown());
}
Also used : Approvable(com.icodici.universa.Approvable) Test(org.junit.Test)

Example 3 with Approvable

use of com.icodici.universa.Approvable in project universa by UniversaBlockchain.

the class Node2EmulatedNetworkTest method unexpectedStrangeCaseWithConcurrent.

// @Test
public void unexpectedStrangeCaseWithConcurrent() throws Exception {
    String FIELD_NAME = "amount";
    PrivateKey ownerKey2 = TestKeys.privateKey(1);
    String PRIVATE_KEY = "_xer0yfe2nn1xthc.private.unikey";
    Contract root = Contract.fromDslFile("./src/test_contracts/coin.yml");
    root.getStateData().set(FIELD_NAME, new Decimal(200));
    root.addSignerKeyFromFile("./src/test_contracts/" + PRIVATE_KEY);
    root.setOwnerKey(ownerKey2);
    root.seal();
    assertTrue(root.check());
    Contract c1 = root.splitValue(FIELD_NAME, new Decimal(100));
    c1.seal();
    assertTrue(root.check());
    assertTrue(c1.isOk());
    // c1 split 50 50
    c1 = c1.createRevision(ownerKey2);
    c1.seal();
    Contract c50_1 = c1.splitValue(FIELD_NAME, new Decimal(50));
    c50_1.seal();
    assertTrue(c50_1.isOk());
    // good join
    Contract finalC = c50_1.createRevision(ownerKey2);
    finalC.addSignerKeyFromFile(Config.tuKeyPath);
    finalC.seal();
    finalC.getStateData().set(FIELD_NAME, new Decimal(100));
    finalC.addRevokingItems(c50_1);
    finalC.addRevokingItems(c1);
    for (int j = 0; j < 500; j++) {
        HashId id;
        StateRecord orCreate;
        int p = 0;
        for (Approvable c : finalC.getRevokingItems()) {
            id = c.getId();
            for (int i = 0; i < nodes.size(); i++) {
                if (i == nodes.size() - 1 && p == 1)
                    break;
                Node nodeS = nodes.get(i);
                orCreate = nodeS.getLedger().findOrCreate(id);
                orCreate.setState(ItemState.APPROVED).save();
            }
            ++p;
        }
        destroyFromAllNodesExistingNew(finalC);
        destroyCurrentFromAllNodesIfExists(finalC);
        node.registerItem(finalC);
        ItemResult itemResult = node.waitItem(finalC.getId(), 1500);
        System.out.println(itemResult.state);
    // if (ItemState.APPROVED != itemResult.state)
    // System.out.println("\r\nWrong state on repetition " + j + ": " + itemResult + ", " + itemResult.errors +
    // " \r\ncontract_errors: " + finalC.getErrors());
    // else
    // System.out.println("\r\nGood. repetition: " + j + " ledger:" + node.getLedger().toString());
    // fail("Wrong state on repetition " + j + ": " + itemResult + ", " + itemResult.errors +
    // " \r\ncontract_errors: " + finalC.getErrors());
    // assertEquals(ItemState.APPROVED, itemResult.state);
    }
}
Also used : HashId(com.icodici.universa.HashId) PrivateKey(com.icodici.crypto.PrivateKey) Decimal(com.icodici.universa.Decimal) Approvable(com.icodici.universa.Approvable) Contract(com.icodici.universa.contract.Contract)

Example 4 with Approvable

use of com.icodici.universa.Approvable in project universa by UniversaBlockchain.

the class TestEmulatedNetwork method getItem.

@Override
public Approvable getItem(HashId itemId, NodeInfo nodeInfo, Duration maxTimeout) throws InterruptedException {
    Node node = nodes.get(nodeInfo);
    Approvable item = node.getItem(itemId);
    return item;
}
Also used : Approvable(com.icodici.universa.Approvable)

Example 5 with Approvable

use of com.icodici.universa.Approvable in project universa by UniversaBlockchain.

the class TestLocalNetwork method getItem.

@Override
public Approvable getItem(HashId itemId, NodeInfo nodeInfo, Duration maxTimeout) throws InterruptedException {
    Node node = nodes.get(nodeInfo);
    Approvable item = node.getItem(itemId);
    return item;
}
Also used : Approvable(com.icodici.universa.Approvable)

Aggregations

Approvable (com.icodici.universa.Approvable)11 Test (org.junit.Test)6 Decimal (com.icodici.universa.Decimal)3 Contract (com.icodici.universa.contract.Contract)3 PrivateKey (com.icodici.crypto.PrivateKey)1 HashId (com.icodici.universa.HashId)1