Skip to content

Commit

Permalink
Update ton libs and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sun-rhythms committed Oct 13, 2023
1 parent ecccce7 commit d369298
Show file tree
Hide file tree
Showing 27 changed files with 61 additions and 55 deletions.
28 changes: 14 additions & 14 deletions 01-wallet/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ If you click on the top left in the Tonkeeper app you will copy your wallet addr
It should look something like this:

```console
kQCJRglfvsQzAIF0UAhkYH6zkdGPFxVNYMH1nPTN_UpDqEFK
kQBwP1UC3dbBjqOgWHNu3Nfa10FbQI-VGwck7JeOO92qnaEv
```

This wallet address isn't secret. You can share it with anyone you want and they won't be able to touch your funds. If you want anyone to send you some TON, you will need to give them this address. You should be aware though of some privacy matters. Wallet addresses in TON and most blockchains are [pseudo-anonymous](https://en.wikipedia.org/wiki/Pseudonymization), this means that they don't reveal your identity in the real world. If you tell somebody your address and they know you in the real world, they can now make the connection.
Expand Down 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,8 +159,8 @@ Create the file `step7.ts` with the following content:
network:testnet library:npmton
---
```ts
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 All @@ -184,8 +184,8 @@ main();
network:mainnet library:npmton
---
```ts
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 Expand Up @@ -302,8 +302,8 @@ network:testnet library:npmton
---
```ts
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 Expand Up @@ -335,8 +335,8 @@ network:mainnet library:npmton
---
```ts
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 Expand Up @@ -458,8 +458,8 @@ network:testnet library:npmton
---
```ts
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 Expand Up @@ -516,8 +516,8 @@ network:mainnet library:npmton
---
```ts
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
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/crypto @ton/core
npm install @orbs-network/ton-access
npx ts-node step7.ts > step7.output.txt
diff step7.output.txt step7.expected.txt
Expand Down
2 changes: 1 addition & 1 deletion 01-wallet/test/npmton/step7.expected.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
kQCJRglfvsQzAIF0UAhkYH6zkdGPFxVNYMH1nPTN_UpDqEFK
kQBwP1UC3dbBjqOgWHNu3Nfa10FbQI-VGwck7JeOO92qnaEv
workchain: 0
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
2 changes: 1 addition & 1 deletion 01-wallet/test/tonweb/step7.expected.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
kQCJRglfvsQzAIF0UAhkYH6zkdGPFxVNYMH1nPTN_UpDqEFK
kQBwP1UC3dbBjqOgWHNu3Nfa10FbQI-VGwck7JeOO92qnaEv
workchain: 0
2 changes: 1 addition & 1 deletion 02-contract/test/counter.fc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "imports/stdlib.fc";
#include "stdlib.fc";

;; =============== storage =============================

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
6 changes: 4 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 Expand Up @@ -51,6 +51,8 @@ export async function run() {
console.log("deploy transaction confirmed!");
}

run()

function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ 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() {
export async function main() {
// initialize ton rpc client on testnet
const endpoint = await getHttpEndpoint({ network: "testnet" });
const client = new TonClient({ endpoint });
Expand Down Expand Up @@ -43,6 +43,8 @@ export async function run() {
console.log("transaction confirmed!");
}

main()

function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
8 changes: 5 additions & 3 deletions 02-contract/test/getCounter.ts → 02-contract/test/step9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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() {
export async function main() {
// initialize ton rpc client on testnet
const endpoint = await getHttpEndpoint({ network: "testnet" });
const client = new TonClient({ endpoint });
//const client = new TonClient({ endpoint: "https://testnet.toncenter.com/api/v2/jsonRPC", apiKey: "f20ff0043ded8c132d0b4b870e678b4bbab3940788cbb8c8762491935cf3a460" });

// open Counter instance by address
const counterAddress = Address.parse(process.env.COUNTER_ADDRESS!.trim());
const counter = new Counter(counterAddress);
Expand All @@ -21,3 +21,5 @@ export async function run() {
//console.log("value:", counterValue.toString());
console.log("value:", counterValue >= 1000000000000n ? "more than 1T" : "less than 1T");
}

main()
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
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
6 changes: 3 additions & 3 deletions 04-testing/test/step3.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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
import "@ton/test-utils"; // register matchers

describe("Counter tests", () => {
let blockchain: Blockchain;
Expand Down
6 changes: 3 additions & 3 deletions 04-testing/test/step4.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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
import "@ton/test-utils"; // register matchers

describe("Counter tests", () => {
let blockchain: Blockchain;
Expand Down
6 changes: 3 additions & 3 deletions 04-testing/test/step5.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as fs from "fs";
import { Cell, toNano } from "ton-core";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton-community/sandbox";
import { Cell, toNano } 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
import "@ton/test-utils"; // register matchers

describe("Counter tests", () => {
let blockchain: Blockchain;
Expand Down

0 comments on commit d369298

Please sign in to comment.