|
| 1 | +import { toNano } from "@ton/core"; |
| 2 | +import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox"; |
| 3 | +import { TextMessageReceivers } from "./contracts/output/text-message-receivers_TextMessageReceivers"; |
| 4 | +import "@ton/test-utils"; |
| 5 | + |
| 6 | +describe("text-message-receivers", () => { |
| 7 | + let blockchain: Blockchain; |
| 8 | + let treasure: SandboxContract<TreasuryContract>; |
| 9 | + let contract: SandboxContract<TextMessageReceivers>; |
| 10 | + |
| 11 | + beforeEach(async () => { |
| 12 | + blockchain = await Blockchain.create(); |
| 13 | + blockchain.verbosity.print = false; |
| 14 | + treasure = await blockchain.treasury("treasure"); |
| 15 | + |
| 16 | + contract = blockchain.openContract( |
| 17 | + await TextMessageReceivers.fromInit(), |
| 18 | + ); |
| 19 | + }); |
| 20 | + |
| 21 | + it("should deploy", async () => { |
| 22 | + // Deploy the contract |
| 23 | + const deployResult = await contract.send( |
| 24 | + treasure.getSender(), |
| 25 | + { value: toNano("1") }, |
| 26 | + { $$type: "Deploy", queryId: 0n }, |
| 27 | + ); |
| 28 | + |
| 29 | + expect(deployResult.transactions).toHaveTransaction({ |
| 30 | + from: treasure.address, |
| 31 | + to: contract.address, |
| 32 | + success: true, |
| 33 | + deploy: true, |
| 34 | + }); |
| 35 | + |
| 36 | + // Verify initial state |
| 37 | + expect(await contract.getGetCounter()).toBe(0n); |
| 38 | + }); |
| 39 | + |
| 40 | + it("should increment counter with different text messages", async () => { |
| 41 | + // Deploy the contract |
| 42 | + const deployResult = await contract.send( |
| 43 | + treasure.getSender(), |
| 44 | + { value: toNano("1") }, |
| 45 | + { $$type: "Deploy", queryId: 0n }, |
| 46 | + ); |
| 47 | + expect(deployResult.transactions).toHaveTransaction({ |
| 48 | + from: treasure.address, |
| 49 | + to: contract.address, |
| 50 | + success: true, |
| 51 | + deploy: true, |
| 52 | + }); |
| 53 | + |
| 54 | + // Verify initial state |
| 55 | + expect(await contract.getGetCounter()).toBe(0n); |
| 56 | + |
| 57 | + const sendMessage = async ( |
| 58 | + message: |
| 59 | + | "increment'" |
| 60 | + | 'increment-2\\"' |
| 61 | + | "increment-3`" |
| 62 | + | "\\\\increment-4\\\\", |
| 63 | + ) => { |
| 64 | + const incrementResult1 = await contract.send( |
| 65 | + treasure.getSender(), |
| 66 | + { value: toNano("1") }, |
| 67 | + message, |
| 68 | + ); |
| 69 | + expect(incrementResult1.transactions).toHaveTransaction({ |
| 70 | + from: treasure.address, |
| 71 | + to: contract.address, |
| 72 | + success: true, |
| 73 | + }); |
| 74 | + }; |
| 75 | + |
| 76 | + // Increment counter |
| 77 | + await sendMessage("increment'"); |
| 78 | + expect(await contract.getGetCounter()).toBe(1n); |
| 79 | + |
| 80 | + await sendMessage('increment-2\\"'); |
| 81 | + expect(await contract.getGetCounter()).toBe(3n); |
| 82 | + |
| 83 | + await sendMessage("increment-3`"); |
| 84 | + expect(await contract.getGetCounter()).toBe(6n); |
| 85 | + |
| 86 | + await sendMessage("\\\\increment-4\\\\"); |
| 87 | + expect(await contract.getGetCounter()).toBe(10n); |
| 88 | + }); |
| 89 | +}); |
0 commit comments