Writing Tests Examples
This page demonstrates how to write test for FunC contracts created in with Blueprint SDK (Sandbox).
Test suites built for demo contract fireworks. The fireworks is a smart contract which initially run via set_first
message.
Once a new FunC project is created via npm create ton@latest
, a test file tests/contract.spec.ts
will be autogenerated in the project directory for testing the contract:
import ...
describe('Fireworks', () => {
...
expect(deployResult.transactions).toHaveTransaction({
...
});
});
it('should deploy', async () => {
// the check is done inside beforeEach
// blockchain and fireworks are ready to use
});
Running tests using the following command:
npx blueprint test
Additional options and vmLogs may be specified with blockchain.verbosity
:
blockchain.verbosity = {
...blockchain.verbosity,
blockchainLogs: true,
vmLogs: 'vm_logs_full',
debugLogs: true,
print: false,
}
Direct Unit Tests
Fireworks demonstrate different operating with sending messages in the TON Blockchain.
Once you deploy this with message set_first
with enough TON amount, it will be automatically executed with primary and usable combinations of send modes.
Fireworks redeployed itself, as result it will be created 3 entities of Fireworks entities, while each of entity has own ID(keep it in storage) and, as a result, different Smart Contract Address.
For clearness define different by ID Fireworks instances (different state_init
) with the following names:
- 1 - Fireworks setter - The entity that spread different launch op codes. Could be extended up to four different opcodes.
- 2 - Fireworks launcher-1 - The Fireworks instance, which launch first fireworks, means messages will be sent to the launcher.
- 3 - Fireworks launcher-2 - The Fireworks instance, which launch second fireworks, means messages will be sent launcher.
Expand details on transactions
index - is an ID of a transaction in the launchResult
array.
0
- External request to the treasury (the Launcher) that resulted with a outbound messageop::set_first
with 2.5 to fireworks1
- The transaction in Fireworks setter contract invoked withop::set_first
and executed with two outbound messages to the Fireworks Launcher-1 and Fireworks Launcher-22
- The transaction in the Fireworks launcher 1 invoked withop::launch_first
, and executed with four outbound messages to the Launcher.3
- The transaction in the Fireworks launcher 2 invoked withop::launch_second
, and executed with a outbound message to the Launcher.4
- Transaction in the Launcher with incoming message from the Fireworks launcher 1. This message sent withsend mode = 0
.5
- Transaction in the Launcher with incoming message from the Fireworks launcher 1. This message sent withsend mode = 1
6
- Transaction in the Launcher with incoming message from the Fireworks launcher 1. This message sent withsend mode = 2
7
- Transaction in the Launcher with incoming message from the Fireworks launcher 1. This message sent withsend mode = 128 + 32
8
- Transaction in the Launcher with incoming message from the Fireworks launcher 2. This message sent withsend mode = 64
Each 'firework' - is outbound message with a unique message body appears in transactions with ID:3 and ID:4.
Bellow the list of test for each transaction expected successfully executed. Transaction[ID:0] External request to the treasury (the Launcher) that resulted with a outbound message op::set_first
with 2.5 to fireworks. In case you will deploy Fireworks to the blockchain launcher is your wallet.