Skip to content

Contract methods in tests do not work the same way as in blockchain #2

@ilyar

Description

@ilyar

Test contract:

pragma ton-solidity ^0.58.1;
pragma AbiHeader expire;
pragma AbiHeader pubkey;

contract Test {

    constructor() public {
        tvm.accept();
    }

    function foo() public view {
        require(msg.value > 1 ever);
        tvm.rawReserve(0, 4);

        msg.sender.transfer({value: 0, flag: 128});

        msg.sender.transfer({value: 0.3 ever, flag: 0});
        msg.sender.transfer({value: 0.3 ever, flag: 0});
    }    

}

In the blockchain, its foo method will be executed without errors:
image
As we see the contract balance after the deposit = 0.3 ever. Following from this, we can say that, theoretically, the transfer of 2 transactions after the payment of the change is impossible because the amount of transactions is greater than the reserved balance of the contract.

But in tests, the call to the foo method does not pass and falls into an error:
image

test.py:

from tonos_ts4 import ts4

eq = ts4.eq

ts4.init('../build', verbose = True)

def deploy_setcodemultisig():
    keypair = ts4.make_keypair()
    setcode = ts4.BaseContract('SetcodeMultisigWallet', ctor_params={'owners': [keypair[1]], 'reqConfirms': 1}, keypair=keypair)
    return setcode

def deploy_test():
    test = ts4.BaseContract('Test', ctor_params = {}, balance=300000000)
    return test

def test_contract(setcode, test):
    payload = ts4.encode_message_body('Test', 'foo', params={})
    setcode.call_method_signed('sendTransaction', {'dest': test.address, 'value': 1100000000, 'bounce': False, 'flags': 0, 'payload': payload}, expect_ec = 0)
    ts4.dispatch_messages()

setcode = deploy_setcodemultisig()
test = deploy_test()
test_contract(setcode, test)

reference: everx-labs/TestSuite4#14

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions