anchor.diff:      ContractBalance = 10000,
   
       %% Initialise contract owned by Alice setting balance to 10000.
  -    {EncodedContractPubkey,DecodedContractPubkey,_} =
  -        create_compute_contract(NodeName, APubkey, APrivkey,
  +    {EncCPub,DecCPub,_} =
  +        create_compute_contract(Node, APub, APriv,
                                   Code, <<"(0)">>, #{amount => ContractBalance}),
   
       %% Get the initial balance.
  -    ABal1 = get_balance(APubkey),
  -
  -    call_compute_func(NodeName, APubkey, APrivkey, EncodedContractPubkey,
  -                      <<"set_remote">>,
  -                      args_to_binary([DecodedContractPubkey])),
  +    BBal1 = get_balance(BPub),
  +
  +    init_fun_calls(),
  +
  +    call_func(BPub, BPriv, EncCPub, <<"set_remote">>, args_to_binary([DecCPub])),
   
       %% Address.
       ct:pal("Calling contract_address\n"),
  -    call_compute_func(NodeName, APubkey, APrivkey, EncodedContractPubkey,
  -                      <<"contract_address">>, <<"()">>),
  +    call_func(BPub, BPriv, EncCPub, <<"contract_address">>, <<"()">>),
       ct:pal("Calling nested_address\n"),
  -    call_compute_func(NodeName, APubkey, APrivkey, EncodedContractPubkey,
  -                      <<"nested_address">>,
  -                      args_to_binary([DecodedContractPubkey])),
  +    call_func(BPub, BPriv, EncCPub, <<"nested_address">>, args_to_binary([DecCPub])),
   
       %% Balance.
       ct:pal("Calling contract_balance\n"),
  -    {CBValue,_} = call_compute_func(NodeName, APubkey, APrivkey,
  -                                    EncodedContractPubkey,
  -                                   <<"contract_balance">>, <<"()">>),
  -    #{<<"value">> := ContractBalance} = decode_data(<<"int">>, CBValue),
  +    call_func(BPub, BPriv, EncCPub, <<"contract_balance">>, <<"()">>,
  +              {<<"int">>, ContractBalance}),
   
       %% Origin.
       ct:pal("Calling call_origin\n"),
  -    call_compute_func(NodeName, APubkey, APrivkey, EncodedContractPubkey,
  -                      <<"call_origin">>, <<"()">>),
  +    call_func(BPub, BPriv, EncCPub, <<"call_origin">>, <<"()">>),
   
       ct:pal("Calling nested_origin\n"),
  -    call_compute_func(NodeName, APubkey, APrivkey, EncodedContractPubkey,
  -                      <<"nested_origin">>, <<"()">>),
  +    call_func(BPub, BPriv, EncCPub, <<"nested_origin">>, <<"()">>),
   
       %% Caller.
       ct:pal("Calling call_caller\n"),
  -    call_compute_func(NodeName, APubkey, APrivkey, EncodedContractPubkey,
  -                      <<"call_caller">>, <<"()">>),
  +    call_func(BPub, BPriv, EncCPub, <<"call_caller">>, <<"()">>),
       ct:pal("Calling nested_caller\n"),
  -    call_compute_func(NodeName, APubkey, APrivkey, EncodedContractPubkey,
  -                      <<"nested_caller">>, <<"()">>),
  +    call_func(BPub, BPriv, EncCPub, <<"nested_caller">>, <<"()">>),
   
       %% Value.
       ct:pal("Calling call_value\n"),
  -    ExpectedValue = 5,
  -    {CVValue,_} = call_compute_func(NodeName, BPubkey, BPrivkey,
  -                                    EncodedContractPubkey,
  -                                    <<"call_value">>, <<"()">>,
  -                                    #{amount => ExpectedValue}
  -                                   ),
  -    #{<<"value">> := CallValue} = decode_data(<<"int">>, CVValue),
  -    ct:pal("Call value ~p\n", [CallValue]),
  -    ?assertEqual(ExpectedValue, CallValue),
  +    call_func(BPub, BPriv, EncCPub, <<"call_value">>, <<"()">>,
  +              #{amount => 5}, {<<"int">>, 5}),
       ct:pal("Calling nested_value\n"),
  -    {NestedValue, _} = call_compute_func(NodeName, BPubkey, BPrivkey,
  -                                         EncodedContractPubkey,
  -                                         <<"nested_value">>, <<"(42)">>),
  -    ct:pal("Nested value ~p\n", [NestedValue]),
  +    call_func(BPub, BPriv, EncCPub, <<"nested_value">>, <<"(42)">>),
   
       %% Gas price.
       ct:pal("Calling call_gas_price\n"),
       ExpectedGasPrice = 2,
  -    {GPValue,_} = call_compute_func(NodeName, BPubkey, BPrivkey,
  -                                    EncodedContractPubkey,
  -                                    <<"call_gas_price">>, <<"()">>,
  -                                    #{gas_price => ExpectedGasPrice}
  -                                   ),
  -    #{<<"value">> := GasPrice} = decode_data(<<"int">>, GPValue),
  -    ct:pal("Gas price ~p\n", [GasPrice]),
  -    ?assertEqual(ExpectedGasPrice, GasPrice),
  +    call_func(BPub, BPriv, EncCPub, <<"call_gas_price">>, <<"()">>,
  +              #{gas_price => ExpectedGasPrice}, {<<"int">>, ExpectedGasPrice}),
   
       %% Account balances.
  -    ct:pal("Calling get_balance twice\n"),
  -    {BBalValue,_} = call_compute_func(NodeName, BPubkey, BPrivkey,
  -                                      EncodedContractPubkey,
  -                                      <<"get_balance">>,
  -                                      args_to_binary([BPubkey])),
  -    #{<<"value">> := BBalance} = decode_data(<<"int">>, BBalValue),
  -    ct:pal("Balance B ~p\n", [BBalance]),
  -
  -    {DBalValue,_} = call_compute_func(NodeName, BPubkey, BPrivkey,
  -                                      EncodedContractPubkey,
  -                                      <<"get_balance">>,
  -                                      args_to_binary([DPubkey])),
  -    #{<<"value">> := DBalance} = decode_data(<<"int">>, DBalValue),
  -    ct:pal("Balance D ~p\n", [DBalance]),
  +    ct:pal("Calling get_balance\n"),
  +    call_func(BPub, BPriv, EncCPub, <<"get_balance">>, args_to_binary([BPub])),
   
       %% Block hash.
       ct:pal("Calling block_hash\n"),
  -    {BHValue,_} = call_compute_func(NodeName, CPubkey, CPrivkey,
  -                                    EncodedContractPubkey,
  -                                    <<"block_hash">>, <<"(21)">>),
  -    #{<<"value">> := BlockHashValue} = decode_data(<<"int">>, BHValue),
  -    {ok, 200, #{<<"hash">> := ExpectedBlockHash}} = get_key_block_at_height(21),
  -    ct:pal("Block hash ~p\n", [BlockHashValue]),
  -    ?assertEqual({key_block_hash, <<BlockHashValue:256/integer-unsigned>>},
  -                 aec_base58c:decode(ExpectedBlockHash)),
  +    {ok, 200, #{<<"hash">> := ExpectedBlockHash}} = get_key_block_at_height(2),
  +    {_, <<BHInt:256/integer-unsigned>>} = aec_base58c:decode(ExpectedBlockHash),
  +
  +    call_func(BPub, BPriv, EncCPub, <<"block_hash">>, <<"(2)">>, {<<"int">>, BHInt}),
  +
   
       %% Block hash. With value out of bounds
  -    ct:pal("Calling block_hash\n"),
  -    {BHValue1,_} = call_compute_func(NodeName, CPubkey, CPrivkey,
  -                                    EncodedContractPubkey,
  -                                    <<"block_hash">>, <<"(10000000)">>),
  -    #{<<"value">> := BlockHashValue1} = decode_data(<<"int">>, BHValue1),
  -    ct:pal("Block hash ~p\n", [BlockHashValue1]),
  -    ?assertEqual(0, BlockHashValue1),
  +    ct:pal("Calling block_hash out of bounds\n"),
  +    call_func(BPub, BPriv, EncCPub, <<"block_hash">>, <<"(10000000)">>, {<<"int">>, 0}),
   
       %% Coinbase.
       ct:pal("Calling coinbase\n"),
  -    {CoinBaseValue, #{header := CBHeader}} =
  -        call_compute_func(NodeName, CPubkey, CPrivkey,
  -                          EncodedContractPubkey,
  -                          <<"coinbase">>, <<"()">>),
  -    #{<<"value">> := CoinBase} = decode_data(<<"address">>, CoinBaseValue),
  -    ct:pal("CoinBase ~p\n", [CoinBase]),
  -    #{<<"prev_key_hash">> := CBKeyHash} = CBHeader,
  -    ExpectedBeneficiary = aec_base58c:encode(account_pubkey, <<CoinBase:256>>),
  -    ?assertMatch({ok, 200, #{<<"beneficiary">> := ExpectedBeneficiary}},
  -                 get_key_block(CBKeyHash)),
  +
  +    Beneficiary = fun(Hdr) ->
  +                    #{<<"prev_key_hash">> := KeyHash} = Hdr,
  +                    {ok, 200, #{<<"beneficiary">> := B}} = get_key_block(KeyHash),
  +                    {_, <<BInt:256/integer-unsigned>>} = aec_base58c:decode(B),
  +                    BInt
  +                  end,
  +    call_func(BPub, BPriv, EncCPub, <<"coinbase">>, <<"()">>, {<<"address">>, Beneficiary}),
   
       %% Block timestamp.
       ct:pal("Calling timestamp\n"),
  -    {TimeStampValue, #{header := TSHeader}} =
  -        call_compute_func(NodeName, CPubkey, CPrivkey,
  -                          EncodedContractPubkey,
  -                          <<"timestamp">>, <<"()">>),
  -    #{<<"value">> := TimeStamp} = decode_data(<<"int">>, TimeStampValue),
  -    ct:pal("Timestamp ~p\n", [TimeStamp]),
  -    ?assertEqual(maps:get(<<"time">>, TSHeader), TimeStamp),
  +
  +    Timestamp = fun(Hdr) -> maps:get(<<"time">>, Hdr) end,
  +    call_func(BPub, BPriv, EncCPub, <<"timestamp">>, <<"()">>, {<<"int">>, Timestamp}),
   
       %% Block height.
       ct:pal("Calling block_height\n"),
  -    {HeightValue,#{header := HeightHeader}} =
  -        call_compute_func(NodeName, DPubkey, DPrivkey,
  -                          EncodedContractPubkey,
  -                          <<"block_height">>, <<"()">>),
  -    #{<<"value">> := BlockHeight} = decode_data(<<"int">>, HeightValue),
  -    ct:pal("Block height ~p\n", [BlockHeight]),
  -    ?assertEqual(maps:get(<<"height">>, HeightHeader), BlockHeight),
  +    BlockHeight = fun(Hdr) -> maps:get(<<"height">>, Hdr) end,
  +    call_func(BPub, BPriv, EncCPub, <<"block_height">>, <<"()">>, {<<"int">>, BlockHeight}),
   
       %% Difficulty.
       ct:pal("Calling difficulty\n"),
  -    {DiffValue,#{header := DiffHeader}} =
  -        call_compute_func(NodeName, DPubkey, DPrivkey,
  -                          EncodedContractPubkey,
  -                          <<"difficulty">>, <<"()">>),
  -    #{<<"value">> := Difficulty} = decode_data(<<"int">>, DiffValue),
  -    ct:pal("Difficulty ~p\n", [Difficulty]),
  -    #{<<"prev_key_hash">> := DiffKeyHash} = DiffHeader,
  -    {ok, 200, #{<<"target">> := Target}} = get_key_block(DiffKeyHash),
  -    ?assertMatch(Difficulty, aec_pow:target_to_difficulty(Target)),
  +    Difficulty = fun(Hdr) ->
  +                    #{<<"prev_key_hash">> := KeyHash} = Hdr,
  +                    {ok, 200, #{<<"target">> := T}} = get_key_block(KeyHash),
  +                    aec_pow:target_to_difficulty(T)
  +                 end,
  +    call_func(BPub, BPriv, EncCPub, <<"difficulty">>, <<"()">>, {<<"int">>, Difficulty}),
   
       %% Gas limit.
       ct:pal("Calling gas_limit\n"),
  -    {GLValue,_} = call_compute_func(NodeName, DPubkey, DPrivkey,
  -                                    EncodedContractPubkey,
  -                                    <<"gas_limit">>, <<"()">>),
  -    #{<<"value">> := GasLimit} = decode_data(<<"int">>, GLValue),
  -    ct:pal("Gas limit ~p\n", [GasLimit]),
  -    ?assertEqual(aec_governance:block_gas_limit(), GasLimit),
  -
  -    aecore_suite_utils:mine_key_blocks(NodeName, 3),
  -
  -    ct:pal("A Balances ~p, ~p, ~p\n", [ABal0,ABal1,get_balance(APubkey)]),
  -    ct:pal("B Balances ~p, ~p\n", [BBal0,get_balance(BPubkey)]),
  -    ct:pal("C Balances ~p, ~p\n", [CBal0,get_balance(CPubkey)]),
  -    ct:pal("D Balances ~p, ~p\n", [DBal0,get_balance(DPubkey)]),
  +    call_func(BPub, BPriv, EncCPub, <<"gas_limit">>, <<"()">>,
  +              {<<"int">>, aec_governance:block_gas_limit()}),
  +
  +    force_fun_calls(Node),
  +
  +    ct:pal("B Balances ~p, ~p, ~p\n", [BBal0, BBal1, get_balance(BPub)]),
   
       ok.
   
  
positive.code: %%  we have gas loses as well.
  
  dutch_auction_contract(Config) ->
      NodeName = proplists:get_value(node_name, Config),
      %% Get account information.
      #{acc_a := #{pub_key := APubkey,
                   priv_key := APrivkey},
        acc_b := #{pub_key := BPubkey,
                   priv_key := BPrivkey},
        acc_c := #{pub_key := CPubkey}} = proplists:get_value(accounts, Config),
  
      %% Make sure accounts have enough tokens.
      _ABal0 = ensure_balance(APubkey, 500000),
      _BBal0 = ensure_balance(BPubkey, 500000),
      _CBal0 = ensure_balance(CPubkey, 500000),
      {ok,[_]} = aecore_suite_utils:mine_key_blocks(NodeName, 1),
  
      %% Compile test contract "dutch_auction.aes"
      Code = compile_test_contract("dutch_auction"),
  
      %% Set auction start amount and decrease per mine and fee.
      StartAmt = 50000,
      Decrease = 500,
      Fee = 100,
  
      %% Initialise contract owned by Alice with Carl as benficiary.
      InitArgument = args_to_binary([CPubkey,StartAmt,Decrease]),
      {EncodedContractPubkey,_,InitReturn} =
          create_compute_contract(NodeName, APubkey, APrivkey, Code, InitArgument),
      #{<<"height">> := Height0} = InitReturn,
  
      %% Mine 10 times to decrement value.
      {ok,_} = aecore_suite_utils:mine_key_blocks(NodeName, 10),
  
      _ABal1 = get_balance(APubkey),
      BBal1 = get_balance(BPubkey),
      CBal1 = get_balance(CPubkey),
  
      %% Call the contract bid function by Bert.
      {_,#{return := BidReturn}} =
          call_compute_func(NodeName, BPubkey, BPrivkey,
                            EncodedContractPubkey,
                            <<"bid">>, <<"()">>,
                            #{amount => 100000,fee => Fee}),
      #{<<"gas_used">> := GasUsed,<<"height">> := Height1} = BidReturn,
  
negative.code: %%  Check the SpendTest contract.
  
  spend_test_contract(Config) ->
      Node = proplists:get_value(node_name, Config),
      #{acc_a := #{pub_key := APub,
                   priv_key := APriv},
        acc_b := #{pub_key := BPub,
                   priv_key := _BPriv}} = proplists:get_value(accounts, Config),
  
      %% Make sure accounts have enough tokens.
      _ABal0 = ensure_balance(APub, 200000),
      BBal0 = ensure_balance(BPub, 50000),
  
      %% Compile test contract "spend_test.aes"
      Code = compile_test_contract("spend_test"),
  
      %% Initialise contracts owned by Alice with balance set to 10000 and 20000.
      {EncC1Pub,DecC1Pub,_} =
          create_compute_contract(Node, APub, APriv, Code, <<"()">>, #{amount => 10000}),
      {EncC2Pub,DecC2Pub,_} =
          create_compute_contract(Node, APub, APriv, Code, <<"()">>, #{amount => 20000}),
  
      init_fun_calls(),
  
      %% Alice does all the operations on the contract and spends on Bert.
      %% Check the contract balances.
      call_func(APub, APriv, EncC1Pub, <<"get_balance">>, <<"()">>, {<<"int">>, 10000}),
      call_func(APub, APriv, EncC2Pub, <<"get_balance">>, <<"()">>, {<<"int">>, 20000}),
  
      %% Spend 15000 on to Bert.
      Sp1Arg = args_to_binary([BPub,15000]),
      call_func(APub, APriv, EncC2Pub, <<"spend">>, Sp1Arg, {<<"int">>, 5000}),
  
      %% Check that contract spent it.
      GBO1Arg = args_to_binary([DecC2Pub]),
      call_func(APub, APriv, EncC1Pub, <<"get_balance_of">>, GBO1Arg, {<<"int">>, 5000}),
  
      %% Check that Bert got it.
      GBO2Arg = args_to_binary([BPub]),
      call_func(APub, APriv, EncC1Pub, <<"get_balance_of">>, GBO2Arg, {<<"int">>, BBal0 + 15000}),
  
      %% Spend 6000 explicitly from contract 1 to Bert.
      SF1Arg = args_to_binary([DecC1Pub,BPub,6000]),
      call_func(APub, APriv, EncC2Pub, <<"spend_from">>, SF1Arg, {<<"int">>, BBal0 + 21000}),
  
      %% Check that Bert got it.
      GBO3Arg = args_to_binary([BPub]),
      call_func(APub, APriv, EncC1Pub, <<"get_balance_of">>, GBO3Arg, {<<"int">>, BBal0 + 21000}),
  
      %% Check contract 2 balance.
      GBO4Arg = args_to_binary([DecC2Pub]),
      call_func(APub, APriv, EncC1Pub, <<"get_balance_of">>, GBO4Arg, {<<"int">>, 5000}),
  
      force_fun_calls(Node),
  
      ok.
  
  