Skip to content

Commit

Permalink
Partially fixed checks
Browse files Browse the repository at this point in the history
  • Loading branch information
krau5 committed Oct 13, 2023
1 parent 6e3aea4 commit 45830f7
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 38 deletions.
6 changes: 3 additions & 3 deletions 01-wallet/test/npmton/step7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ 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)
// Update step7.expected.txt before running the test, since it depends on your wallet address
const mnemonic = process.env.MNEMONIC; // your 24 secret words
const key = await mnemonicToWalletKey(mnemonic!.split(" "));
const wallet = WalletContractV4.create({ publicKey: key.publicKey, workchain: 0 });

Expand All @@ -17,4 +17,4 @@ async function main() {
console.log("workchain:", wallet.address.workChain);
}

main();
main();
5 changes: 3 additions & 2 deletions 01-wallet/test/tonweb/step7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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)
// Update step7.expected.txt before running the test, since it depends on your wallet address
const mnemonic = process.env.MNEMONIC; // your 24 secret words
const key = await mnemonicToKeyPair(mnemonic!.split(" "));

// open wallet v4 (notice the correct wallet version here)
Expand All @@ -21,4 +22,4 @@ async function main() {
console.log("workchain:", walletAddress.wc);
}

main();
main();
8 changes: 4 additions & 4 deletions 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 All @@ -10,7 +10,7 @@ export default class Counter implements Contract {
const address = contractAddress(workchain, { code, data });
return new Counter(address, { code, data });
}

constructor(readonly address: Address, readonly init?: { code: Cell, data: Cell }) {}

async sendDeploy(provider: ContractProvider, via: Sender) {
Expand All @@ -19,7 +19,7 @@ export default class Counter implements Contract {
bounce: false
});
}

async sendIncrement(provider: ContractProvider, via: Sender) {
const messageBody = beginCell()
.storeUint(1, 32) // op (op #1 = increment)
Expand All @@ -35,4 +35,4 @@ export default class Counter implements Contract {
const { stack } = await provider.get("counter", []);
return stack.readBigNumber();
}
}
}
8 changes: 4 additions & 4 deletions 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 All @@ -10,13 +10,13 @@ export default class Counter implements Contract {
const address = contractAddress(workchain, { code, data });
return new Counter(address, { code, data });
}

constructor(readonly address: Address, readonly init?: { code: Cell, data: Cell }) {}

async sendDeploy(provider: ContractProvider, via: Sender) {
await provider.internal(via, {
value: "0.01", // send 0.01 TON to contract for rent
bounce: false
});
}
}
}
}
8 changes: 4 additions & 4 deletions 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 All @@ -10,7 +10,7 @@ export default class Counter implements Contract {
const address = contractAddress(workchain, { code, data });
return new Counter(address, { code, data });
}

constructor(readonly address: Address, readonly init?: { code: Cell, data: Cell }) {}

async sendDeploy(provider: ContractProvider, via: Sender) {
Expand All @@ -19,9 +19,9 @@ export default class Counter implements Contract {
bounce: false
});
}

async getCounter(provider: ContractProvider) {
const { stack } = await provider.get("counter", []);
return stack.readBigNumber();
}
}
}
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/ton";
import { mnemonicToWalletKey } from "ton-crypto";
import { TonClient, Cell, WalletContractV4 } from "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));
}
File renamed without changes.
4 changes: 3 additions & 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/ton";
import { TonClient, Address } from "ton";
import Counter from "./counter.step9"; // this is the interface class we just implemented

export async function run() {
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");
}

run(); // only for testing purposes
File renamed without changes.
12 changes: 6 additions & 6 deletions 02-contract/test/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ npm init --yes
npm install dotenv
npm install ts-node
npm install @ton-community/func-js
npm install @ton/ton @ton/core @ton/crypto
npm install ton ton-core ton-crypto
npm install @orbs-network/ton-access
npx func-js stdlib.fc counter.fc --boc counter.cell
npx func-js counter.fc --boc counter.cell
npx ts-node deploy.step8.ts > deploy.step8.output.txt
COUNTER_ADDRESS=`cut -d : -s -f 2 < deploy.step8.output.txt` npx ts-node step9.ts > step9.output.txt
diff step9.output.txt step9.expected.txt
COUNTER_ADDRESS=`cut -d : -s -f 2 < deploy.step8.output.txt` npx ts-node step10.ts > step10.output.txt
diff step10.output.txt step10.expected.txt
COUNTER_ADDRESS=`cut -d : -s -f 2 < deploy.step8.output.txt` npx ts-node getCounter.ts > getCounter.output.txt
diff getCounter.output.txt getCounter.expected.txt
COUNTER_ADDRESS=`cut -d : -s -f 2 < deploy.step8.output.txt` npx ts-node sendIncrement.ts > sendIncrement.output.txt
diff sendIncrement.output.txt sendIncrement.expected.txt
File renamed without changes.
6 changes: 4 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/ton";
import { mnemonicToWalletKey } from "ton-crypto";
import { TonClient, WalletContractV4, Address } from "ton";
import Counter from "./counter.step10"; // this is the interface class we just implemented

export async function run() {
Expand Down Expand Up @@ -46,3 +46,5 @@ export async function run() {
function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

run(); // only for testing purposes
2 changes: 1 addition & 1 deletion 04-testing/test/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ npx jest step2
npx jest step3
npx jest step4
npx jest step5 | grep "#DEBUG#" > step5.output.txt
diff step5.output.txt step5.expected.txt
diff step5.output.txt step5.expected.txt
6 changes: 3 additions & 3 deletions 04-testing/test/step3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import * as fs from "fs";
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;
let wallet1: SandboxContract<TreasuryContract>;
let counterContract: SandboxContract<Counter>;

beforeEach(async () => {
// prepare Counter's initial code and data cells for deployment
const counterCode = Cell.fromBoc(fs.readFileSync("counter.cell"))[0]; // compilation output from tutorial 2
Expand All @@ -28,4 +28,4 @@ describe("Counter tests", () => {
const value = await counterContract.getCounter();
expect(value).toEqual(17n);
});
});
});
6 changes: 3 additions & 3 deletions 04-testing/test/step4.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import * as fs from "fs";
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;
let wallet1: SandboxContract<TreasuryContract>;
let counterContract: SandboxContract<Counter>;

beforeEach(async () => {
// prepare Counter's initial code and data cells for deployment
const counterCode = Cell.fromBoc(fs.readFileSync("counter.cell"))[0]; // compilation output from tutorial 2
Expand All @@ -34,4 +34,4 @@ describe("Counter tests", () => {
const counterValue = await counterContract.getCounter();
expect(counterValue).toEqual(18n);
})
});
});
6 changes: 3 additions & 3 deletions 04-testing/test/step5.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import * as fs from "fs";
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;
let wallet1: SandboxContract<TreasuryContract>;
let counterContract: SandboxContract<Counter>;

beforeEach(async () => {
// prepare Counter's initial code and data cells for deployment
const counterCode = Cell.fromBoc(fs.readFileSync("counter.debug.cell"))[0]; // version with ~dump instruction
Expand Down Expand Up @@ -36,4 +36,4 @@ describe("Counter tests", () => {
console.log("sending increment message");
await counterContract.sendIncrement(wallet1.getSender());
})
});
});

0 comments on commit 45830f7

Please sign in to comment.