-
Notifications
You must be signed in to change notification settings - Fork 109
/
recursion.spec.ts
45 lines (38 loc) · 1.58 KB
/
recursion.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { toNano } from "@ton/core";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox";
import { RecursionTester } from "./contracts/output/recursion_RecursionTester";
import "@ton/test-utils";
describe("recursion", () => {
let blockchain: Blockchain;
let treasure: SandboxContract<TreasuryContract>;
let contract: SandboxContract<RecursionTester>;
beforeEach(async () => {
blockchain = await Blockchain.create();
blockchain.verbosity.print = false;
treasure = await blockchain.treasury("treasure");
contract = blockchain.openContract(await RecursionTester.fromInit());
const deployResult = await contract.send(
treasure.getSender(),
{ value: toNano("10") },
{ $$type: "Deploy", queryId: 0n },
);
expect(deployResult.transactions).toHaveTransaction({
from: treasure.address,
to: contract.address,
success: true,
deploy: true,
});
});
it("should perform recursive operations correctly", async () => {
// Check Fibonacci sequence
expect(await contract.getFib(0n)).toBe(0n);
expect(await contract.getFib(1n)).toBe(1n);
expect(await contract.getFib(2n)).toBe(1n);
expect(await contract.getFib(3n)).toBe(2n);
// Check Factorial calculations
expect(await contract.getFact(0n)).toBe(1n);
expect(await contract.getFact(1n)).toBe(1n);
expect(await contract.getFact(2n)).toBe(2n);
expect(await contract.getFact(3n)).toBe(6n);
});
});