Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/update-ton-libs' into update-t…
Browse files Browse the repository at this point in the history
…on-libs
  • Loading branch information
krau5 committed Oct 12, 2023
2 parents 4be183c + cd895e3 commit 6e3aea4
Show file tree
Hide file tree
Showing 40 changed files with 125 additions and 125 deletions.
14 changes: 7 additions & 7 deletions 01-wallet/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ library:npmton
Next, we're going to install a JavaScript package named [ton](https://www.npmjs.com/package/ton) that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running:

```console
npm install ton ton-crypto ton-core
npm install @ton/ton @ton/crypto @ton/core
```

---
Expand Down Expand Up @@ -159,7 +159,7 @@ Create the file `step7.ts` with the following content:
network:testnet library:npmton
---
```ts
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { WalletContractV4 } from "ton";

async function main() {
Expand All @@ -184,7 +184,7 @@ main();
network:mainnet library:npmton
---
```ts
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { WalletContractV4 } from "ton";

async function main() {
Expand Down Expand Up @@ -302,7 +302,7 @@ network:testnet library:npmton
---
```ts
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { WalletContractV4, TonClient, fromNano } from "ton";

async function main() {
Expand Down Expand Up @@ -335,7 +335,7 @@ network:mainnet library:npmton
---
```ts
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { WalletContractV4, TonClient, fromNano } from "ton";

async function main() {
Expand Down Expand Up @@ -458,7 +458,7 @@ network:testnet library:npmton
---
```ts
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, WalletContractV4, internal } from "ton";

async function main() {
Expand Down Expand Up @@ -516,7 +516,7 @@ network:mainnet library:npmton
---
```ts
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, WalletContractV4, internal } from "ton";

async function main() {
Expand Down
2 changes: 1 addition & 1 deletion 01-wallet/test/npmton/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set -ev
npm init --yes
npm install dotenv
npm install ts-node
npm install ton ton-core ton-crypto
npm install @ton/ton @ton/core @ton/crypto
npm install @orbs-network/ton-access
npx ts-node step7.ts > step7.output.txt
diff step7.output.txt step7.expected.txt
Expand Down
4 changes: 2 additions & 2 deletions 01-wallet/test/npmton/step7.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import dotenv from "dotenv";
dotenv.config({ path: "../../../.env" });

import { mnemonicToWalletKey } from "ton-crypto";
import { WalletContractV4 } from "ton";
import { mnemonicToWalletKey } from "@ton/crypto";
import { WalletContractV4 } from "@ton/ton";

async function main() {
// open wallet v4 (notice the correct wallet version here)
Expand Down
4 changes: 2 additions & 2 deletions 01-wallet/test/npmton/step8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import dotenv from "dotenv";
dotenv.config({ path: "../../../.env" });

import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { WalletContractV4, TonClient, fromNano } from "ton";
import { mnemonicToWalletKey } from "@ton/crypto";
import { WalletContractV4, TonClient, fromNano } from "@ton/ton";

async function main() {
// open wallet v4 (notice the correct wallet version here)
Expand Down
4 changes: 2 additions & 2 deletions 01-wallet/test/npmton/step9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import dotenv from "dotenv";
dotenv.config({ path: "../../../.env" });

import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { TonClient, WalletContractV4, internal } from "ton";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, WalletContractV4, internal } from "@ton/ton";

async function main() {
// open wallet v4 (notice the correct wallet version here)
Expand Down
12 changes: 6 additions & 6 deletions 02-contract/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ The recommended way to interact with contracts is to create a small TypeScript c
Use the following code in `wrappers/Counter.ts` to create the initial data cell for deployment:

```ts
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core";
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core";

export default class Counter implements Contract {

Expand All @@ -183,7 +183,7 @@ export default class Counter implements Contract {
}
```

Notice a few interesting things about this TypeScript code. First, it depends on the package [ton-core](https://www.npmjs.com/package/ton-core) instead of [ton](https://www.npmjs.com/package/ton), which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our `save_data()` FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function `contractAddress`.
Notice a few interesting things about this TypeScript code. First, it depends on the package [@ton/core](https://www.npmjs.com/package/@ton/core) instead of [ton](https://www.npmjs.com/package/ton), which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our `save_data()` FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function `contractAddress`.

The actual deployment involves sending the first message that will cause our contract to be deployed. We can piggyback any message that is directed towards our contract. This can even be the increment message with op #1, but we will do something simpler. We will just send some TON coins to our contract (an empty message) and piggyback that. Let's make this part of our interface. Add the function `sendDeploy()` to `wrappers/Counter.ts` - this function will send the deployment message:

Expand Down Expand Up @@ -226,7 +226,7 @@ network:testnet
```ts
import * as fs from "fs";
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, Cell, WalletContractV4 } from "ton";
import Counter from "../wrappers/Counter"; // this is the interface class from step 7

Expand Down Expand Up @@ -286,7 +286,7 @@ network:mainnet
```ts
import * as fs from "fs";
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, Cell, WalletContractV4 } from "ton";
import Counter from "../wrappers/Counter"; // this is the interface class from step 7

Expand Down Expand Up @@ -501,7 +501,7 @@ network:testnet
---
```ts
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, WalletContractV4, Address } from "ton";
import Counter from "../wrappers/Counter"; // this is the interface class we just implemented

Expand Down Expand Up @@ -553,7 +553,7 @@ network:mainnet
---
```ts
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, WalletContractV4, Address } from "ton";
import Counter from "../wrappers/Counter"; // this is the interface class we just implemented

Expand Down
2 changes: 1 addition & 1 deletion 02-contract/test/counter.step10.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core";
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core";

export default class Counter implements Contract {

Expand Down
2 changes: 1 addition & 1 deletion 02-contract/test/counter.step7.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core";
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core";

export default class Counter implements Contract {

Expand Down
2 changes: 1 addition & 1 deletion 02-contract/test/counter.step9.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core";
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core";

export default class Counter implements Contract {

Expand Down
4 changes: 2 additions & 2 deletions 02-contract/test/deploy.step8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ dotenv.config({ path: "../../.env" });

import * as fs from "fs";
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { TonClient, Cell, WalletContractV4 } from "ton";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, Cell, WalletContractV4 } from "@ton/ton";
import Counter from "./counter.step7"; // this is the interface class from step 7

export async function run() {
Expand Down
2 changes: 1 addition & 1 deletion 02-contract/test/getCounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dotenv from "dotenv";
dotenv.config({ path: "../../.env" });

import { getHttpEndpoint } from "@orbs-network/ton-access";
import { TonClient, Address } from "ton";
import { TonClient, Address } from "@ton/ton";
import Counter from "./counter.step9"; // this is the interface class we just implemented

export async function run() {
Expand Down
2 changes: 1 addition & 1 deletion 02-contract/test/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ npm init --yes
npm install dotenv
npm install ts-node
npm install @ton-community/func-js
npm install ton ton-core ton-crypto
npm install @ton/ton @ton/core @ton/crypto
npm install @orbs-network/ton-access
npx func-js stdlib.fc counter.fc --boc counter.cell
npx ts-node deploy.step8.ts > deploy.step8.output.txt
Expand Down
4 changes: 2 additions & 2 deletions 02-contract/test/sendIncrement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import dotenv from "dotenv";
dotenv.config({ path: "../../.env" });

import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { TonClient, WalletContractV4, Address } from "ton";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, WalletContractV4, Address } from "@ton/ton";
import Counter from "./counter.step10"; // this is the interface class we just implemented

export async function run() {
Expand Down
8 changes: 4 additions & 4 deletions 03-client/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ npm install
We will need to install a few more packages that will allow us to interact with TON Blockchain. We've seen these packages in action in the previous tutorial. Run the following in terminal:

```console
npm install ton ton-core ton-crypto
npm install @ton/ton @ton/core @ton/crypto
npm install @orbs-network/ton-access
```

Expand Down Expand Up @@ -209,7 +209,7 @@ import { useEffect, useState } from 'react';
import Counter from '../contracts/counter';
import { useTonClient } from './useTonClient';
import { useAsyncInitialize } from './useAsyncInitialize';
import { Address, OpenedContract } from 'ton-core';
import { Address, OpenedContract } from '@ton/core';

export function useCounterContract() {
const client = useTonClient();
Expand Down Expand Up @@ -292,7 +292,7 @@ Create the file `src/hooks/useTonConnect.ts` with the following content:

```ts
import { useTonConnectUI } from '@tonconnect/ui-react';
import { Sender, SenderArguments } from 'ton-core';
import { Sender, SenderArguments } from '@ton/core';

export function useTonConnect(): { sender: Sender; connected: boolean } {
const [tonConnectUI] = useTonConnectUI();
Expand Down Expand Up @@ -327,7 +327,7 @@ import Counter from '../contracts/counter';
import { useTonClient } from './useTonClient';
import { useAsyncInitialize } from './useAsyncInitialize';
import { useTonConnect } from './useTonConnect';
import { Address, OpenedContract } from 'ton-core';
import { Address, OpenedContract } from '@ton/core';

export function useCounterContract() {
const client = useTonClient();
Expand Down
2 changes: 1 addition & 1 deletion 03-client/test/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ rm -rf ./temp
npm create vite@latest temp -- --template react-ts
cd temp
npm install
npm install ton ton-core ton-crypto
npm install @ton/ton @ton/core @ton/crypto
npm install @orbs-network/ton-access
npm install vite-plugin-node-polyfills
cp -f ../vite.config.ts .
Expand Down
2 changes: 1 addition & 1 deletion 03-client/test/src/contracts/counter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core";
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core";

export default class Counter implements Contract {

Expand Down
2 changes: 1 addition & 1 deletion 03-client/test/src/hooks/useCounterContract.step6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
import Counter from '../contracts/counter';
import { useTonClient } from './useTonClient';
import { useAsyncInitialize } from './useAsyncInitialize';
import { Address, OpenedContract } from 'ton-core';
import { Address, OpenedContract } from '@ton/core';

export function useCounterContract() {
const client = useTonClient();
Expand Down
2 changes: 1 addition & 1 deletion 03-client/test/src/hooks/useCounterContract.step7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Counter from '../contracts/counter';
import { useTonClient } from './useTonClient';
import { useAsyncInitialize } from './useAsyncInitialize';
import { useTonConnect } from './useTonConnect';
import { Address, OpenedContract } from 'ton-core';
import { Address, OpenedContract } from '@ton/core';

export function useCounterContract() {
const client = useTonClient();
Expand Down
2 changes: 1 addition & 1 deletion 03-client/test/src/hooks/useTonClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getHttpEndpoint } from '@orbs-network/ton-access';
import { TonClient } from 'ton';
import { TonClient } from '@ton/ton';
import { useAsyncInitialize } from './useAsyncInitialize';

export function useTonClient() {
Expand Down
2 changes: 1 addition & 1 deletion 03-client/test/src/hooks/useTonConnect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useTonConnectUI } from '@tonconnect/ui-react';
import { Sender, SenderArguments } from 'ton-core';
import { Sender, SenderArguments } from '@ton/core';

export function useTonConnect(): { sender: Sender; connected: boolean } {
const [tonConnectUI] = useTonConnectUI();
Expand Down
14 changes: 7 additions & 7 deletions 04-testing/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Because testing is such as big deal in smart contract development, there's a sur

3. **Writing tests in FunC** - [toncli](https://github.com/disintar/toncli) is a command-line tool written in Python that runs on your machine and supports [debug](https://github.com/disintar/toncli/blob/master/docs/advanced/transaction_debug.md) and [unit tests](https://github.com/disintar/toncli/blob/master/docs/advanced/func_tests_new.md) for FunC contracts where the tests are also written in FunC ([example](https://github.com/BorysMinaiev/func-contest-1-tests-playground/blob/main/task-1/tests/test.fc)).

4. **Bare-bones TVM with Sandbox** - [Sandbox](https://github.com/ton-community/sandbox) is a bare-bones version of just the [TVM](https://ton-blockchain.github.io/docs/tvm.pdf) running on [WebAssembly](https://webassembly.org/) with a thin JavaScript wrapper that allows test interactions from TypeScript.
4. **Bare-bones TVM with Sandbox** - [Sandbox](https://github.com/ton-org/sandbox) is a bare-bones version of just the [TVM](https://ton-blockchain.github.io/docs/tvm.pdf) running on [WebAssembly](https://webassembly.org/) with a thin JavaScript wrapper that allows test interactions from TypeScript.

5. **Deploying beta contracts to mainnet** - This form of "testing in production" simply deploys alternative beta versions of your contracts to mainnet and uses real (not free) TON coin to play with them in a real environment. If you found a bug, you simply deploy new fixed beta versions and waste a little more money.

Expand Down Expand Up @@ -76,10 +76,10 @@ module.exports = {
And finally, run in terminal:

```console
npm install ton-core @ton-community/sandbox @ton-community/test-utils
npm install @ton/core @ton/sandbox @ton/test-utils
```

This will install [Sandbox](https://github.com/ton-community/sandbox) and its dependencies. Sandbox is our magical library that will emulate TON Blockchain locally by running a bare-bones version of the TVM in process. This will guarantee that our tests will be blazingly fast and completely isolated.
This will install [Sandbox](https://github.com/ton-org/sandbox) and its dependencies. Sandbox is our magical library that will emulate TON Blockchain locally by running a bare-bones version of the TVM in process. This will guarantee that our tests will be blazingly fast and completely isolated.

## Step 2: Load our contract in a test

Expand All @@ -104,8 +104,8 @@ Create the file `step2.spec.ts` with the following content:

```ts
import * as fs from "fs";
import { Cell } from "ton-core";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton-community/sandbox";
import { Cell } from "@ton/core";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox";
import Counter from "./counter"; // this is the interface class from tutorial 2

describe("Counter tests", () => {
Expand Down Expand Up @@ -296,7 +296,7 @@ The console output should include something like this:

We can see that the debug messages are printed when the test is running. When we send some TON coin explicitly to the contract (7.123 coins), we can see that the first debug print indeed shows the expected value of `msg_value`. Since the TVM doesn't support floating points, the number is represented internally as a large integer (with 9 decimals, meaning multiplied by 10^9). On the second test, when we send the increment op, we can see both debug prints showing. This is because this message also includes a small amount of coins for gas.

If you would like to see even more verbose log output from running your contracts, you can [increase the verbosity](https://github.com/ton-community/sandbox#viewing-logs) of the `blockchain` object after creating it in beforeEach:
If you would like to see even more verbose log output from running your contracts, you can [increase the verbosity](https://github.com/ton-org/sandbox#viewing-logs) of the `blockchain` object after creating it in beforeEach:

```ts
blockchain.verbosity = {
Expand Down Expand Up @@ -339,7 +339,7 @@ Ready to claim your reward? Simply scan the QR code below or click <a href="ton:

For your convenience, all the code in this tutorial is available in executable form [here](https://github.com/ton-community/tutorials/blob/main/04-testing/test).

In this tutorial we created our project skeleton manually, mostly so we can understand what happens under the hood. When creating a new contract project, you can have an excellent skeleton created automatically by an awesome dev tool called [Blueprint](https://github.com/ton-community/blueprint). To create a new contract project with Blueprint, run in terminal and follow the on-screen instructions:
In this tutorial we created our project skeleton manually, mostly so we can understand what happens under the hood. When creating a new contract project, you can have an excellent skeleton created automatically by an awesome dev tool called [Blueprint](https://github.com/ton-org/blueprint). To create a new contract project with Blueprint, run in terminal and follow the on-screen instructions:

```console
npm create ton@latest
Expand Down
2 changes: 1 addition & 1 deletion 04-testing/test/counter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core";
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core";

export default class Counter implements Contract {

Expand Down
2 changes: 1 addition & 1 deletion 04-testing/test/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set -ev
npm init --yes
npm install dotenv
npm install typescript jest @types/jest ts-jest
npm install ton-core @ton-community/sandbox @ton-community/test-utils
npm install @ton/core @ton/sandbox @ton/test-utils
npx jest step2
npx jest step3
npx jest step4
Expand Down
4 changes: 2 additions & 2 deletions 04-testing/test/step2.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from "fs";
import { Cell } from "ton-core";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton-community/sandbox";
import { Cell } from "@ton/core";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox";
import Counter from "./counter"; // this is the interface class from tutorial 2

describe("Counter tests", () => {
Expand Down
4 changes: 2 additions & 2 deletions 04-testing/test/step3.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from "fs";
import { Cell } from "ton-core";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton-community/sandbox";
import { Cell } from "@ton/core";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox";
import Counter from "./counter"; // this is the interface class from tutorial 2
import "@ton-community/test-utils"; // register matchers

Expand Down
4 changes: 2 additions & 2 deletions 04-testing/test/step4.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from "fs";
import { Cell } from "ton-core";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton-community/sandbox";
import { Cell } from "@ton/core";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox";
import Counter from "./counter"; // this is the interface class from tutorial 2
import "@ton-community/test-utils"; // register matchers

Expand Down
Loading

0 comments on commit 6e3aea4

Please sign in to comment.