[More Detail] [Collapse All]
Feature: A contract constructors creates an other contract
features/100-contructors/200-contract-constructs.feature
- Background: Create configuration with two source files
link
features/100-contructors/200-contract-constructs.feature:3
Given I create initial sbuilder context with:
Directory
solidity demo1
setup setup1
# Content of solidity 'demo1'
#
# Two contracts, where contract Demo2 constructor
# creates also Demo1 constructor.
And a file named "solidity/demo1.sol" with:
pragma solidity ^0.3.5;

contract Demo1 {

    uint storedData1;


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

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

}

contract Demo2 { 

      address demo1;

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

}
# 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]

       # TODO: should be created automatically
     - domain: eth_code_hash
       values:
          - Demo1
          - Demo2


     - 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
- Scenario: Construct 'Demo1' which creates 'Demo2'
link

Observe state changes:

Step 1: creates non-contract account 'acc1'

eth_accounts@1={[address |-> "acc1", codeHash |-> Nil, balance |-> 0]}

Step mined:
eth_accounts@2={[address |-> "acc1", codeHash |-> Nil, balance |-> 6]}


Step 3: creates two contract accounts 'acc2' & 'acc3', where acc2.demo1 is
pointing to 'acc3' type 'Demo1'

eth_accounts@3={ [address |-> "acc1", codeHash |-> Nil, balance |-> 2],
                 [address |-> "acc2", codeHash |-> "Demo2", balance |-> 1],
                 [address |-> "acc3", codeHash |-> "Demo1", balance |-> 0] }


eth_storageRoot@3={ [address |-> "acc2", demo1 |-> "acc3"],
                    [address |-> "acc3", storedData1 |-> Nil] }


step 3:
- total gasUsed = 4
      - Demo2() starting instrinc gas 1
      - Demo1() creation instrinc gas 1
      - Demo2() creation transaction gas 1
      - Demo2() transaction gas 1

- balances:
      - acc1: 6 mined - 3 units gasUsed - 1 moved to acc2      
      - acc2: 1 received 1 wei from acc1
features/100-contructors/200-contract-constructs.feature:103
Given I generate, translate, and model check setup `setup1`
Then State space extract `gen/setup1/tla/state.dump` contains
Tick Variable Field Value
1 step p_personal_newAccount__
2 step p_geth_mine__
3 step p_Demo2__
1 eth_accounts address acc1
2 eth_accounts address acc1
3 eth_accounts address acc1
3 eth_accounts address acc2
3 eth_accounts address acc3
3 eth_storageRoot address acc2
3 eth_storageRoot address acc3
3 eth_storageRoot demo1 acc3
3 eth_account codeHash Demo1
3 eth_account codeHash Demo2
3 eth_gasUsed 4