tact-lang / tact-docs

Tact main documentation
https://docs.tact-lang.org
54 stars 41 forks source link

feat: new debugging page #233

Closed novusnota closed 3 months ago

novusnota commented 4 months ago

Closes #4

WIP, but almost there.

Preview: image

anton-trunov commented 4 months ago

What needs to be done here to make it "ready for review"?

novusnota commented 4 months ago

@anton-trunov those sub-headings & their inner content:

image

I'll be finishing those today, shortly after I finish with Sublime updates. Hopefully, you'll have a bunch of stuff to review tomorrow morning :)

UPD: Made a lot for Sublime today, don't know if I'll finish this PR today too. I'll try, though.

anton-trunov commented 4 months ago

In the testing/debugging page we should also cover how to test if a contract's receiver throws an exception. Here is a recent user request:

Here is a link of my smart contract: https://github.com/kaseen/LuckySixTON/blob/master/contracts/lucky_six.tact

Inside of receive function, i check if input is valid. If it is not valid i throw error with nativeThrow(12345);.

My question is, how can i catch this error when i'm writing unit tests the behavior of function to expect that it should revert.

For example, in hardhat framework for developing smart contracts in Solidity, there is a function expect(transaction).to.be.revertedWith(errorCode)

novusnota commented 4 months ago

My question is, how can i catch this error when i'm writing unit tests the behavior of function to expect that it should revert.

Sandbox/Blueprint analogue would be to write something like this in tests:

expect(res.transactions).toHaveTransaction({
    success: false,
    exitCode: 5  // or whatever exit code is desired / undesired :)
});

Where res is the result of sending a message to a certain receiver we're testing. I'll add that and more to the debugging page by the end of Tuesday, such that the end page will be comprehensive in many regards.

anton-trunov commented 4 months ago

And one more popular request regarding testing: how to simulated time passing

novusnota commented 4 months ago

And one more popular request regarding testing: how to simulate time passing

Hmm, I suppose simple "sleep/wait" will do. And, maybe, adding a separate test group, which won't overwrite the state of the blockchain between the individual tests in that group. On it!

anton-trunov commented 4 months ago

Wait, no I meant blockchain.now:

        ... setting up things
        blockchain = await Blockchain.create();
        ... more setting up things
        blockchain.now = STARTING_TIME;
        ... more tests
        blockchain.now = SOME_LATER_TIME;
        ... more tests
novusnota commented 4 months ago

Oh, I see. Sure!

novusnota commented 3 months ago

Added a usage example to "Common debugging functions", right before the "Enabling debug mode ..."

anton-trunov commented 3 months ago

Let's publish!