Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nikitaghost opened this issue Apr 13, 2022 · 0 comments
Open

Comments

@nikitaghost
Copy link

nikitaghost commented Apr 13, 2022

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant