Copy import { Blockchain, SandboxContract } from '@ton/sandbox';
import { TychoExecutor } from '@tychosdk/emulator';
import { TonApiClient } from '@ton-api/client';
import { Address, toNano } from '@ton/core';
import { SimpleCounter } from '../wrappers/SimpleCounter';
import { compile } from '@ton/blueprint';
describe('SimpleCounter', () => {
let blockchain: Blockchain;
let simpleCounter: SandboxContract<SimpleCounter>;
beforeAll(async () => {
// Initialize TetraChain
const tonapi = new TonApiClient({
baseUrl: 'https://tetra.tonapi.io/',
});
const configAccount = await tonapi.blockchain.getBlockchainRawAccount(
Address.parse('-1:5555555555555555555555555555555555555555555555555555555555555555'),
);
const config = configAccount.data!.asSlice().loadRef();
blockchain = await Blockchain.create({
executor: await TychoExecutor.create(),
config,
});
});
beforeEach(async () => {
simpleCounter = blockchain.openContract(
SimpleCounter.createFromConfig(
{
id: 0,
counter: 0
},
await compile('SimpleCounter')
)
);
const deployer = await blockchain.treasury('deployer');
await simpleCounter.sendDeploy(deployer.getSender(), toNano('0.05'));
});
it('should deploy', async () => {
const counter = await simpleCounter.getCounter();
expect(counter).toBe(0);
});
it('should increase counter', async () => {
const sender = await blockchain.treasury('sender');
await simpleCounter.sendIncrease(sender.getSender(), {
value: toNano('0.05'),
increaseBy: 5,
});
expect(await simpleCounter.getCounter()).toBe(5);
});
it('should increase multiple times', async () => {
const sender = await blockchain.treasury('sender');
await simpleCounter.sendIncrease(sender.getSender(), {
value: toNano('0.05'),
increaseBy: 3,
});
await simpleCounter.sendIncrease(sender.getSender(), {
value: toNano('0.05'),
increaseBy: 7,
});
expect(await simpleCounter.getCounter()).toBe(15);
});
});