Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

feat: new debugging page #233

Merged
merged 16 commits into from
Jun 12, 2024
Merged

Conversation

novusnota
Copy link
Member

Closes #4

WIP, but almost there.

Preview:
image

novusnota and others added 2 commits May 26, 2024 13:16
Co-authored-by: Anton Trunov <anton.a.trunov@gmail.com>
@anton-trunov
Copy link
Member

anton-trunov commented May 29, 2024

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

@novusnota
Copy link
Member Author

novusnota commented May 29, 2024

@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
Copy link
Member

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
Copy link
Member Author

novusnota commented Jun 2, 2024

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
Copy link
Member

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

@novusnota
Copy link
Member Author

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
Copy link
Member

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
Copy link
Member Author

Oh, I see. Sure!

@novusnota novusnota marked this pull request as ready for review June 10, 2024 05:18
Copy link
Member

@anton-trunov anton-trunov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tremendous improvement!

Let's add dump usage example to this page, though. Maybe modify the play receiver and show how to observe the results of dumping. I believe we don't have these dump logs anywhere in the Tact docs

@novusnota
Copy link
Member Author

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

1. dump
2. dump
3. dump
4. ???
5. ~~Profit!~~ dump
Copy link
Member

@anton-trunov anton-trunov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great stuff!

@anton-trunov anton-trunov merged commit 639f56b into tact-lang:main Jun 12, 2024
1 check passed
@anton-trunov
Copy link
Member

Let's publish!

@novusnota novusnota deleted the debugging branch June 12, 2024 12:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document how to debug your contract and dump variables
2 participants