[More Detail] [Collapse All]
Feature: A contract constructors creates an other contract
features/100-constructors/200-contract-constructs.feature
- Background: Create configuration with two source files
link
features/100-constructors/200-contract-constructs.feature:3
Given I create initial sbuilder context with:
Directory
solidity demo1
setup setup1
And a file named "solidity/demo1.sol" with:
pragma solidity >0.4.4;

contract Demo1 {

    uint storedData1;


    function set(uint x) {
        storedData1 = x;
    }

    function get() constant returns (uint retVal) {
        return storedData1;
    }

}

//  Demo2 constructor creates also Demo1 constructor.

contract Demo2 { 

      Demo1 demo1;

       function Demo2() {
          demo1 = new Demo1();
       }

       function setInDemo1() {
            demo1.set( 5 );
       }

}
# Content of setup 'setup1'
And a file named "cnf/setup1.yaml" with:
 - domain-extension:

     - domain: eth_address
       values:
          - acc1
          - acc2
          - acc3

       # Ethre value range, could be also int
     - domain: eth_value
       range: [0,7]


     - domain: Demo1_storedData1
       values: 
           - store1_1
           - store1_2
           - store1_3


  #  Three steps:
  #  - step 1: create account 
  #  - step 2: mine 6 units ether
  #  - step 3: constract Demo2 contract (and "under the hood" 
  #    also Demo1 contract

 - step-extension:
        - interface: personal_newAccount()
        - interface: geth_mine()
          bindExact: true
          input:
              _default: 1
              value: 6

        - interface: Demo2()
          bindExact: true
          input:
              _default: 0
              value: 1
              sender: 1

        - interface: Demo2(setInDemo1)
          bindExact: true
          input:
              _default: 0
              value: 0
              recipient: 2
              sender: 1
- Scenario: Construct 'Demo1' which creates 'Demo2'
link

In this scenario:

- step 1: creates new account 'acc1'
- step 2: mines 6 units to beneficiary address 'acc1'
- step 3: account 'acc1' creates 'Demo2' (with address 'acc2')
          and 'acc2' further creates 'Demo1' with address 'acc3')


Expect
          
step         called                     balances       acc1.storedData1
                                       acc1    acc2  
step 1:   personal_newAccount()         -      -          -
step 2:   geth_mine()                   6      -          - 
step 3:   Demo2()                       5      1          0
step 4:   Demo2(setInDemo1)             5      1          5    



Account "types" codeHash
acc1  - Nil
acc2  - Demo2
acc3  - Demo1
features/100-constructors/200-contract-constructs.feature:107
Given I generate, translate, and model check setup `setup1`
Then State space extract `gen/setup1/tla/state.dump` contains
Tick Variable Key Field Value
1 step p_personal_newAccount__
2 step p_geth_mine__
3 step p_Demo2__
4 step p_Demo2_setInDemo1_
And State space extract `gen/setup1/tla/state.dump` contains
Tick Variable Key Field Value
3 eth_accounts acc1 codeHash Nil
3 eth_accounts acc2 codeHash Demo2
3 eth_accounts acc3 codeHash Demo1
And State space extract `gen/setup1/tla/state.dump` contains
Tick Variable Key Field Value
2 eth_accounts acc1 balance 6
3 eth_accounts acc1 balance 5
3 eth_accounts acc2 balance 1
3 eth_accounts acc3 balance 0
And State space extract `gen/setup1/tla/state.dump` contains
Tick Variable Key Field Value
3 eth_storageRoot acc3 storedData1 0
4 eth_storageRoot acc3 storedData1 5