Skip to content

Commit

Permalink
Merge pull request #382 from reveloper/test_examples_scheme_patch
Browse files Browse the repository at this point in the history
Test examples scheme patch
  • Loading branch information
reveloper committed Oct 12, 2023
2 parents 33820bf + cbca84f commit 5b0dd38
Show file tree
Hide file tree
Showing 15 changed files with 3,343 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/develop/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Take your first steps in DApps development with a comprehensive DApps building g
* [APIs](/develop/dapps/apis)
* [SDKs](/develop/dapps/apis/sdk)

## TON Education Hub
## TON Education

- [Education](https://github.com/ton-community/awesome-ton#-education) - Unveil the comprehensive list of various educational materials, meticulously crafted by the remarkable TON Community.

Expand Down
40 changes: 29 additions & 11 deletions docs/develop/smart-contracts/testing/writing-test-examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,17 @@ blockchain.verbosity = {
## Direct Unit Tests
Fireworks demonstrate different operating with sending messages in the TON Blockchain.
![](/img/docs/test-examples/fireworks_trace_tonviewer.png?=RAW)
![](/img/docs/writing-test-examples/test-examples-schemes.svg)
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 entities with the following names:
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.
Each 'firework' - is a transaction which executed with unique message body and message sending mode.
* 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.
<details>
Expand All @@ -77,6 +76,8 @@ index - is an ID of a transaction in the `launchResult` array.
</details>
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.
Expand All @@ -85,11 +86,14 @@ Bellow the list of test for each transaction expected successfully executed. Tra
[This test](https://github.com/ton-community/fireworks-func/blob/main/tests/Fireworks.spec.ts#L75) checks if the fireworks are successfully set by sending a transaction with a value of 2.5 TON.
This is the simplest case, the main purpose here to assert result of transaction success property to true.
To filter certain transaction from the `launhcResult.transactions` array, we can use the most convince fields.
With
`from` (contract sender address), `to` (contract destination address), `op` (Op code value) - we will retrieve only one transaction for this combination.
The transaction[ID:1] in Fireworks Setter contract invoked with `op::set_first` and executed with two outbound messages to the Fireworks Launcher-1 and Fireworks Launcher-2
![](/img/docs/writing-test-examples/test-examples-schemes_id1.svg)
The transaction[ID:1] in Fireworks Setter contract invoked with `op::set_first` and executed with two outbound messages to the Fireworks launcher-1 and Fireworks launcher-2
```typescript

Expand All @@ -115,6 +119,8 @@ The transaction[ID:1] in Fireworks Setter contract invoked with `op::set_first`

[This test](https://github.com/ton-community/fireworks-func/blob/main/tests/Fireworks.spec.ts#L92) checks if the transaction[ID:2] executed successfully.

![](/img/docs/writing-test-examples/test-examples-schemes_id2.svg)

The transaction in the Fireworks launcher 1 invoked with `op::launch_first`, and executed with four outbound messages to the Launcher.

```typescript
Expand Down Expand Up @@ -154,6 +160,8 @@ The full list of Account Status related fields:

[This test](https://github.com/ton-community/fireworks-func/blob/main/tests/Fireworks.spec.ts#L113) checks if the transaction[ID:3] executed successfully.

![](/img/docs/writing-test-examples/test-examples-schemes_id3.svg)

The transaction[ID:3] carries out in the Fireworks launcher 1, invokes with `op::launch_first`, and executes with four outbound messages to the Launcher.


Expand Down Expand Up @@ -189,6 +197,8 @@ The transaction[ID:3] carries out in the Fireworks launcher 1, invokes with `op:

[This test](https://github.com/ton-community/fireworks-func/blob/main/tests/Fireworks.spec.ts#L133) checks if the transaction[ID:4] executed successfully.

![](/img/docs/writing-test-examples/test-examples-schemes_id4.svg)

Transaction[ID:4] carries out in the Launcher(Deploy Wallet) with incoming message from the Fireworks launcher 1. This message sent with `send mode = 0` in the Transaction[ID:2].

```typescript
Expand Down Expand Up @@ -216,6 +226,8 @@ Transaction[ID:4] carries out in the Launcher(Deploy Wallet) with incoming messa

[This test](https://github.com/ton-community/fireworks-func/blob/main/tests/Fireworks.spec.ts#L152) checks if the transaction[ID:5] executed successfully.

![](/img/docs/writing-test-examples/test-examples-schemes_id5.svg)

Transaction[ID:5] carries out in the Launcher with incoming message from the Fireworks launcher 1. This message sent with `send mode = 1`

```typescript
Expand Down Expand Up @@ -244,6 +256,8 @@ Transaction[ID:5] carries out in the Launcher with incoming message from the Fi

[This test](https://github.com/ton-community/fireworks-func/blob/main/tests/Fireworks.spec.ts#L170) checks if the transaction[ID:6] executed successfully.

![](/img/docs/writing-test-examples/test-examples-schemes_id6.svg)

The transaction[ID:6] carries out in the Launcher with incoming message from the Fireworks launcher 1. This message sent with `send mode = 2`


Expand Down Expand Up @@ -271,6 +285,8 @@ The transaction[ID:6] carries out in the Launcher with incoming message from the

[This test](https://github.com/ton-community/fireworks-func/blob/main/tests/Fireworks.spec.ts#L188) checks if the transaction[ID:7] executed successfully.

![](/img/docs/writing-test-examples/test-examples-schemes_id7.svg)

The transaction[ID:7] carries out in the Launcher with incoming message from the Fireworks launcher 1. This message sent with `send mode = 128 + 32`

```typescript
Expand All @@ -292,10 +308,12 @@ The transaction[ID:7] carries out in the Launcher with incoming message from the
})
```

#### ### Transaction ID:8 Success Test
### Transaction ID:8 Success Test

[This test](https://github.com/ton-community/fireworks-func/blob/main/tests/Fireworks.spec.ts#L188) checks if the transaction[ID:8] executed successfully.

![](/img/docs/writing-test-examples/test-examples-schemes_id8.svg)

The transaction[ID:8] carries out in the Launcher with incoming message from the Fireworks launcher 2. This message sent with `send mode = 64`

```typescript
Expand All @@ -320,7 +338,7 @@ The transaction[ID:8] carries out in the Launcher with incoming message from the

```

### Printing and Reading Transaction Fees
## Printing and Reading Transaction Fees

During the test, reading the details about fees can be useful for optimizing the contract. The printTransactionFees function prints the entire transaction chain in a convenient manner."
```typescript
Expand Down Expand Up @@ -357,7 +375,7 @@ For instance, in case of `launchResult` the following table will be printed:



![](/img/docs/test-examples/fireworks_trace_tonviewer.png?=RAW)
![](/img/docs/writing-test-examples/fireworks_trace_tonviewer.png?=RAW)

index - is an ID of a transaction in the `launchResult` array.
* `0` - External request to the treasury (the Launcher) that resulted in a message `op::set_first` to Fireworks
Expand All @@ -371,7 +389,7 @@ index - is an ID of a transaction in the `launchResult` array.
* `8` - Transaction on Launcher with incoming message from the Launched Fireworks - 2, message sent with `send mode = 64`


### Transaction Fees Tests
## Transaction Fees Tests

This test verifies whether the transaction fees for launching the fireworks are as expected. It is possible to define custom assertions for different parts of commission fees.

Expand Down
Loading

0 comments on commit 5b0dd38

Please sign in to comment.