Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 01-wallet and 02-contract tests #75

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions 01-wallet/test/npmton/step8.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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/ton";

Expand All @@ -19,10 +18,10 @@ async function main() {
const key = await mnemonicToWalletKey(mnemonic!.split(" "));
const wallet = WalletContractV4.create({ publicKey: key.publicKey, workchain: 0 });

// 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" });
const client = new TonClient({
endpoint: 'https://testnet.toncenter.com/api/v2/jsonRPC',
apiKey: 'f20ff0043ded8c132d0b4b870e678b4bbab3940788cbb8c8762491935cf3a460'
});

// query balance from chain
const balance = await client.getBalance(wallet.address);
Expand Down
11 changes: 6 additions & 5 deletions 01-wallet/test/npmton/step9.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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/ton";
import { retry } from "../../../helpers/retry"

async function main() {
// Notice:
Expand All @@ -20,9 +20,10 @@ async function main() {
const wallet = WalletContractV4.create({ publicKey: key.publicKey, workchain: 0 });

// 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" });
const client = new TonClient({
endpoint: 'https://testnet.toncenter.com/api/v2/jsonRPC',
apiKey: 'f20ff0043ded8c132d0b4b870e678b4bbab3940788cbb8c8762491935cf3a460'
});

// make sure wallet is deployed
if (!await client.isContractDeployed(wallet.address)) {
Expand Down Expand Up @@ -50,7 +51,7 @@ async function main() {
while (currentSeqno == seqno) {
//console.log("waiting for transaction to confirm...");
await sleep(1500);
currentSeqno = await walletContract.getSeqno();
await retry(async () => { currentSeqno = await walletContract.getSeqno(); }, {retries: 10, delay: 1000});
}
console.log("transaction confirmed!");
}
Expand Down
5 changes: 1 addition & 4 deletions 01-wallet/test/tonweb/step8.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import dotenv from "dotenv";
dotenv.config({ path: "../../../.env" });

import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToKeyPair } from "tonweb-mnemonic";
import TonWeb from "tonweb";

Expand All @@ -19,9 +18,7 @@ async function main() {
const key = await mnemonicToKeyPair(mnemonic!.split(" "));

// initialize ton rpc client on testnet
const endpoint = await getHttpEndpoint({ network: "testnet" });
const tonweb = new TonWeb(new TonWeb.HttpProvider(endpoint));
//const tonweb = new TonWeb(new TonWeb.HttpProvider("https://testnet.toncenter.com/api/v2/jsonRPC", { apiKey: "f20ff0043ded8c132d0b4b870e678b4bbab3940788cbb8c8762491935cf3a460" }));
const tonweb = new TonWeb(new TonWeb.HttpProvider("https://testnet.toncenter.com/api/v2/jsonRPC", { apiKey: "f20ff0043ded8c132d0b4b870e678b4bbab3940788cbb8c8762491935cf3a460" }));

// open wallet v4 (notice the correct wallet version here)
const WalletClass = tonweb.wallet.all["v4R2"];
Expand Down
5 changes: 1 addition & 4 deletions 01-wallet/test/tonweb/step9.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import dotenv from "dotenv";
dotenv.config({ path: "../../../.env" });

import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToKeyPair } from "tonweb-mnemonic";
import TonWeb from "tonweb";

Expand All @@ -19,9 +18,7 @@ async function main() {
const key = await mnemonicToKeyPair(mnemonic!.split(" "));

// initialize ton rpc client on testnet
const endpoint = await getHttpEndpoint({ network: "testnet" });
const tonweb = new TonWeb(new TonWeb.HttpProvider(endpoint));
//const tonweb = new TonWeb(new TonWeb.HttpProvider("https://testnet.toncenter.com/api/v2/jsonRPC", { apiKey: "f20ff0043ded8c132d0b4b870e678b4bbab3940788cbb8c8762491935cf3a460" }));
const tonweb = new TonWeb(new TonWeb.HttpProvider("https://testnet.toncenter.com/api/v2/jsonRPC", { apiKey: "f20ff0043ded8c132d0b4b870e678b4bbab3940788cbb8c8762491935cf3a460" }));

// open wallet v4 (notice the correct wallet version here)
const WalletClass = tonweb.wallet.all["v4R2"];
Expand Down
8 changes: 3 additions & 5 deletions 02-contract/test/deploy.step8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import dotenv from "dotenv";
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/ton";
import Counter from "./counter.step7"; // this is the interface class from step 7
import { retry } from "../../helpers/retry"

export async function run() {
// 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" });
const client = new TonClient({ endpoint: "https://testnet.toncenter.com/api/v2/jsonRPC", apiKey: "f20ff0043ded8c132d0b4b870e678b4bbab3940788cbb8c8762491935cf3a460" });

// prepare Counter's initial code and data cells for deployment
const counterCode = Cell.fromBoc(fs.readFileSync("counter.cell"))[0]; // compilation output from step 6
Expand Down Expand Up @@ -46,7 +44,7 @@ export async function run() {
while (currentSeqno == seqno) {
//console.log("waiting for deploy transaction to confirm...");
await sleep(1500);
currentSeqno = await walletContract.getSeqno();
await retry(async () => { currentSeqno = await walletContract.getSeqno(); }, {retries: 10, delay: 1000});
}
console.log("deploy transaction confirmed!");
}
Expand Down
10 changes: 5 additions & 5 deletions 02-contract/test/getCounter.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import dotenv from "dotenv";
dotenv.config({ path: "../../.env" });

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

export async function run() {
// 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" });
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());
Expand All @@ -18,7 +16,9 @@ export async function run() {

// call the getter on chain
await sleep(1500);
const counterValue = await counterContract.getCounter();
var counterValue:bigint = 0n;
await retry(async () => { counterValue = await counterContract.getCounter(); }, {retries: 10, delay: 1000});

//console.log("value:", counterValue.toString());
console.log("value:", counterValue >= 1000000000000n ? "more than 1T" : "less than 1T");
}
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 @@ -2,7 +2,7 @@ set -ev
npm init --yes
npm install dotenv
npm install typescript
npx tsc --init
npx tsc --init -t es2020
npm install ts-node
npm install @ton-community/func-js
npm install @ton/ton @ton/core @ton/crypto
Expand Down
5 changes: 1 addition & 4 deletions 02-contract/test/sendIncrement.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
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/ton";
import Counter from "./counter.step10"; // this is the interface class we just implemented

export async function run() {
// 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" });
const client = new TonClient({ endpoint: "https://testnet.toncenter.com/api/v2/jsonRPC", apiKey: "f20ff0043ded8c132d0b4b870e678b4bbab3940788cbb8c8762491935cf3a460" });

// open wallet v4 (notice the correct wallet version here)
const mnemonic = process.env.MNEMONIC;
Expand Down
15 changes: 15 additions & 0 deletions helpers/retry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export async function retry<T>(fn: () => Promise<T>, options: { retries: number, delay: number }): Promise<T> {
let lastError: Error | undefined;
for (let i = 0; i < options.retries; i++) {
try {
return await fn();
} catch (e) {
if (e instanceof Error) {
lastError = e;
}
await new Promise(resolve => setTimeout(resolve, options.delay));
}
}
throw lastError;
}