Skip to content

Commit

Permalink
Update ton libs and fix tests
Browse files Browse the repository at this point in the history
Update ton libs and fix tests

Update ton libs and fix tests

Update ton libs and fix tests

Update ton libs and fix tests

Update ton libs and fix tests

Update ton libs and fix tests

Update ton libs and fix tests

Update ton libs and fix tests

Update ton libs and fix tests

Update ton libs and fix tests
  • Loading branch information
sun-rhythms committed Oct 13, 2023
1 parent ecccce7 commit 6d3e44b
Show file tree
Hide file tree
Showing 42 changed files with 137 additions and 119 deletions.
26 changes: 13 additions & 13 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,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
10 changes: 6 additions & 4 deletions 01-wallet/test/npmton/step7.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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)
const mnemonic = process.env.MNEMONIC;; // your 24 secret words (replace ... with the rest of the words)
// use your mnemonic phrase from .end file in the root of the project and change wallet address
// const mnemonic = process.env.MNEMONIC;
// also you need to change your wallet address in step7.expected.txt to run test
const mnemonic = "memory album during buyer copper until arm forest identify race eyebrow bunker dawn phrase butter knock owner thumb click lottery catalog desk trial copper"; // your 24 secret words (replace ... with the rest of the words)
const key = await mnemonicToWalletKey(mnemonic!.split(" "));
const wallet = WalletContractV4.create({ publicKey: key.publicKey, workchain: 0 });

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
5 changes: 4 additions & 1 deletion 01-wallet/test/tonweb/step7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { mnemonicToKeyPair } from "tonweb-mnemonic";
import TonWeb from "tonweb";

async function main() {
const mnemonic = process.env.MNEMONIC; // your 24 secret words (replace ... with the rest of the words)
// use your mnemonic phrase from .end file in the root of the project and change wallet address
// const mnemonic = process.env.MNEMONIC;
// also you need to change your wallet address in step7.expected.txt to run test
const mnemonic = "memory album during buyer copper until arm forest identify race eyebrow bunker dawn phrase butter knock owner thumb click lottery catalog desk trial copper"; // your 24 secret words (replace ... with the rest of the words)
const key = await mnemonicToKeyPair(mnemonic!.split(" "));

// open wallet v4 (notice the correct wallet version here)
Expand Down
3 changes: 2 additions & 1 deletion 01-wallet/test/tonweb/step8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { mnemonicToKeyPair } from "tonweb-mnemonic";
import TonWeb from "tonweb";

async function main() {
const mnemonic = process.env.MNEMONIC; // your 24 secret words (replace ... with the rest of the words)
// const mnemonic = process.env.MNEMONIC; // use your mnemonic phrase from .end file in the root of the project
const mnemonic = "memory album during buyer copper until arm forest identify race eyebrow bunker dawn phrase butter knock owner thumb click lottery catalog desk trial copper"; // your 24 secret words (replace ... with the rest of the words)
const key = await mnemonicToKeyPair(mnemonic!.split(" "));

// initialize ton rpc client on testnet
Expand Down
3 changes: 2 additions & 1 deletion 01-wallet/test/tonweb/step9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { mnemonicToKeyPair } from "tonweb-mnemonic";
import TonWeb from "tonweb";

async function main() {
const mnemonic = process.env.MNEMONIC;
// const mnemonic = process.env.MNEMONIC; // use your mnemonic phrase from .end file in the root of the project
const mnemonic = "memory album during buyer copper until arm forest identify race eyebrow bunker dawn phrase butter knock owner thumb click lottery catalog desk trial copper";
const key = await mnemonicToKeyPair(mnemonic!.split(" "));

// initialize ton rpc client on testnet
Expand Down
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));
}
13 changes: 10 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,22 +2,29 @@ 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);
const counterContract = client.open(counter);

// call the getter on chain
await sleep(1500);
const counterValue = await counterContract.getCounter();
//console.log("value:", counterValue.toString());
console.log("value:", counterValue >= 1000000000000n ? "more than 1T" : "less than 1T");
}

main()

function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
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
Loading

0 comments on commit 6d3e44b

Please sign in to comment.