Search in sources :

Example 1 with BiSerializationException

use of net.sergeych.biserializer.BiSerializationException in project universa by UniversaBlockchain.

the class ContractTest method calculateSplitProcessingCostbreakWhileUnpacking.

@Test
public void calculateSplitProcessingCostbreakWhileUnpacking() throws Exception {
    // Should create contract, sign and seal it, then create revision and split.
    // Then while calculating cost should break while unpacking contract (signs verifying).
    // should repeat contract processing procedure on the Node
    // (Contract.fromPackedTransaction() -> Contract(byte[], TransactionPack) -> Contract.check())
    Contract contract = createCoin100apiv3();
    contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
    sealCheckTrace(contract, true);
    System.out.println("Split");
    Contract forSplit = contract.createRevision();
    Contract splitted = forSplit.splitValue(FIELD_NAME, new Decimal(20));
    splitted.addSignerKeyFromFile(PRIVATE_KEY_PATH);
    sealCheckTrace(splitted, true);
    sealCheckTrace(forSplit, true);
    assertEquals(new Decimal(80), forSplit.getStateData().get("amount"));
    assertEquals(new Decimal(20), new Decimal(Long.valueOf(splitted.getStateData().get("amount").toString())));
    System.out.println("Calculated processing cost (forSplit): " + forSplit.getProcessedCost() + " (UTN)");
    System.out.println("Calculated processing cost (splitted): " + splitted.getProcessedCost() + " (UTN)");
    // Check 4096 bits signature own (8) +
    // Check 4096 bits signature new item (8) +
    // Check 4096 bits signature revoking item (8) +
    // Register a self version (20) +
    // Register new item a version (20) +
    // Register revoking item a version (20) +
    // Check self change owner permission (1) +
    // Check self change split join permission (1+2) +
    // Check self change revoke permission (1) +
    // Check new item change owner permission (1) +
    // Check new item change split join permission (1+2) +
    // Check new item change revoke permission (1)
    int costShouldBeForSplit = 94;
    boolean exceptionThrown = false;
    try {
        processContractAsItWillBeOnTheNode(forSplit, 20);
    } catch (Quantiser.QuantiserException e) {
        System.out.println("Thrown correct exception: " + e.getMessage());
        exceptionThrown = true;
    } catch (BiSerializationException e) {
        System.out.println("Thrown correct exception: " + e.getMessage());
        exceptionThrown = true;
    }
    assertEquals(true, exceptionThrown);
}
Also used : Decimal(com.icodici.universa.Decimal) Quantiser(com.icodici.universa.node2.Quantiser) BiSerializationException(net.sergeych.biserializer.BiSerializationException) Test(org.junit.Test)

Aggregations

Decimal (com.icodici.universa.Decimal)1 Quantiser (com.icodici.universa.node2.Quantiser)1 BiSerializationException (net.sergeych.biserializer.BiSerializationException)1 Test (org.junit.Test)1