Search in sources :

Example 6 with NSmartContract

use of com.icodici.universa.contract.services.NSmartContract in project universa by UniversaBlockchain.

the class SmartContractTest method serializeSmartContract.

@Test
public void serializeSmartContract() throws Exception {
    final PrivateKey key = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey"));
    Contract smartContract = new NSmartContract(key);
    smartContract.seal();
    smartContract.check();
    smartContract.traceErrors();
    assertTrue(smartContract.isOk());
    Binder b = BossBiMapper.serialize(smartContract);
    Contract desContract = DefaultBiMapper.deserialize(b);
    assertSameContracts(smartContract, desContract);
    assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), desContract.getDefinition().getExtendedType());
    assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), desContract.get("definition.extended_type"));
    assertTrue(desContract instanceof NSmartContract);
    assertTrue(desContract instanceof NContract);
    Contract copiedContract = smartContract.copy();
    assertSameContracts(smartContract, copiedContract);
    assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), copiedContract.getDefinition().getExtendedType());
    assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), copiedContract.get("definition.extended_type"));
    assertTrue(copiedContract instanceof NSmartContract);
    assertTrue(copiedContract instanceof NContract);
}
Also used : Binder(net.sergeych.tools.Binder) NSmartContract(com.icodici.universa.contract.services.NSmartContract) PrivateKey(com.icodici.crypto.PrivateKey) NContract(com.icodici.universa.contract.services.NContract) NContract(com.icodici.universa.contract.services.NContract) NSmartContract(com.icodici.universa.contract.services.NSmartContract) Test(org.junit.Test)

Example 7 with NSmartContract

use of com.icodici.universa.contract.services.NSmartContract in project universa by UniversaBlockchain.

the class SmartContractTest method goodSmartContract.

@Test
public void goodSmartContract() throws Exception {
    final PrivateKey key = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey"));
    Contract smartContract = new NSmartContract(key);
    smartContract.seal();
    smartContract.check();
    smartContract.traceErrors();
    assertTrue(smartContract.isOk());
    assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.getDefinition().getExtendedType());
    assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.get("definition.extended_type"));
    assertTrue(smartContract instanceof NSmartContract);
    assertTrue(smartContract instanceof NContract);
}
Also used : NSmartContract(com.icodici.universa.contract.services.NSmartContract) PrivateKey(com.icodici.crypto.PrivateKey) NContract(com.icodici.universa.contract.services.NContract) NContract(com.icodici.universa.contract.services.NContract) NSmartContract(com.icodici.universa.contract.services.NSmartContract) Test(org.junit.Test)

Example 8 with NSmartContract

use of com.icodici.universa.contract.services.NSmartContract in project universa by UniversaBlockchain.

the class NSmartContractTest method serializeNSmartContract.

@Test
public void serializeNSmartContract() throws Exception {
    final PrivateKey key = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey"));
    Contract smartContract = new NSmartContract(key);
    smartContract.seal();
    smartContract.check();
    smartContract.traceErrors();
    assertTrue(smartContract.isOk());
    Binder b = BossBiMapper.serialize(smartContract);
    Contract desContract = DefaultBiMapper.deserialize(b);
    assertSameContracts(smartContract, desContract);
    assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), desContract.getDefinition().getExtendedType());
    assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), desContract.get("definition.extended_type"));
    assertTrue(desContract instanceof NSmartContract);
    assertTrue(smartContract instanceof NContract);
    Contract copiedContract = smartContract.copy();
    assertSameContracts(smartContract, copiedContract);
    assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), copiedContract.getDefinition().getExtendedType());
    assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), copiedContract.get("definition.extended_type"));
    assertTrue(copiedContract instanceof NSmartContract);
    assertTrue(smartContract instanceof NContract);
}
Also used : Binder(net.sergeych.tools.Binder) NSmartContract(com.icodici.universa.contract.services.NSmartContract) PrivateKey(com.icodici.crypto.PrivateKey) NContract(com.icodici.universa.contract.services.NContract) NContract(com.icodici.universa.contract.services.NContract) NSmartContract(com.icodici.universa.contract.services.NSmartContract) Test(org.junit.Test)

Example 9 with NSmartContract

use of com.icodici.universa.contract.services.NSmartContract in project universa by UniversaBlockchain.

the class NSmartContractTest method goodNSmartContract.

@Test
public void goodNSmartContract() throws Exception {
    final PrivateKey key = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey"));
    Contract smartContract = new NSmartContract(key);
    smartContract.seal();
    smartContract.check();
    smartContract.traceErrors();
    assertTrue(smartContract.isOk());
    assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.getDefinition().getExtendedType());
    assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.get("definition.extended_type"));
    assertTrue(smartContract instanceof NSmartContract);
    assertTrue(smartContract instanceof NContract);
}
Also used : NSmartContract(com.icodici.universa.contract.services.NSmartContract) PrivateKey(com.icodici.crypto.PrivateKey) NContract(com.icodici.universa.contract.services.NContract) NContract(com.icodici.universa.contract.services.NContract) NSmartContract(com.icodici.universa.contract.services.NSmartContract) Test(org.junit.Test)

Example 10 with NSmartContract

use of com.icodici.universa.contract.services.NSmartContract in project universa by UniversaBlockchain.

the class NSmartContractTest method goodNSmartContractFromDSL.

@Test
public void goodNSmartContractFromDSL() throws Exception {
    Contract smartContract = NSmartContract.fromDslFile(rootPath + "NotaryNSmartDSLTemplate.yml");
    smartContract.addSignerKeyFromFile(rootPath + "_xer0yfe2nn1xthc.private.unikey");
    smartContract.seal();
    smartContract.check();
    smartContract.traceErrors();
    assertTrue(smartContract.isOk());
    assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.getDefinition().getExtendedType());
    assertEquals(NSmartContract.SmartContractType.N_SMART_CONTRACT.name(), smartContract.get("definition.extended_type"));
    assertTrue(smartContract instanceof NSmartContract);
    assertTrue(smartContract instanceof NContract);
}
Also used : NSmartContract(com.icodici.universa.contract.services.NSmartContract) NContract(com.icodici.universa.contract.services.NContract) NContract(com.icodici.universa.contract.services.NContract) NSmartContract(com.icodici.universa.contract.services.NSmartContract) Test(org.junit.Test)

Aggregations

NSmartContract (com.icodici.universa.contract.services.NSmartContract)10 PrivateKey (com.icodici.crypto.PrivateKey)6 NContract (com.icodici.universa.contract.services.NContract)6 Test (org.junit.Test)6 Binder (net.sergeych.tools.Binder)4 PublicKey (com.icodici.crypto.PublicKey)1 HashId (com.icodici.universa.HashId)1 HashIdentifiable (com.icodici.universa.HashIdentifiable)1 Contract (com.icodici.universa.contract.Contract)1 Parcel (com.icodici.universa.contract.Parcel)1 FollowerContract (com.icodici.universa.contract.services.FollowerContract)1 NImmutableEnvironment (com.icodici.universa.contract.services.NImmutableEnvironment)1 NMutableEnvironment (com.icodici.universa.contract.services.NMutableEnvironment)1 SlotContract (com.icodici.universa.contract.services.SlotContract)1 UnsContract (com.icodici.universa.contract.services.UnsContract)1 Quantiser (com.icodici.universa.node2.Quantiser)1 IOException (java.io.IOException)1 java.util (java.util)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1