/
ton-org
/
blueprint
Обзор
Документация
Войти
/
ton-org
/
blueprint
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
develop
example/tests/Counter.spec.ts
79 строк
2 KB
KardanovIR
Updated all dependencies to @ton organization packages
30 июл 2023, 00:52
30 июл 2023, 00:52
ef89a7e
Код
Авторство
О чём код?
import { Blockchain, SandboxContract } from '@ton/sandbox'; import { Cell, toNano } from '@ton/core'; import { Counter } from '../wrappers/Counter'; import '@ton/test-utils'; import { compile } from '@ton/blueprint'; describe('Counter', () => { let code: Cell; beforeAll(async () => { code = await compile('Counter'); }); let blockchain: Blockchain; let counter: SandboxContract<Counter>; beforeEach(async () => { blockchain = await Blockchain.create(); counter = blockchain.openContract( Counter.createFromConfig( { id: 0, counter: 0, }, code ) ); const deployer = await blockchain.treasury('deployer'); const deployResult = await counter.sendDeploy(deployer.getSender(), toNano('0.05')); expect(deployResult.transactions).toHaveTransaction({ from: deployer.address, to: counter.address, deploy: true, }); }); it('should deploy', async () => { // the check is done inside beforeEach // blockchain and counter are ready to use }); it('should increase counter', async () => { const increaseTimes = 3; for (let i = 0; i < increaseTimes; i++) { console.log(`increase ${i + 1}/${increaseTimes}`); const increaser = await blockchain.treasury('increaser' + i); const counterBefore = await counter.getCounter(); console.log('counter before increasing', counterBefore); const increaseBy = Math.floor(Math.random() * 100); console.log('increasing by', increaseBy); const increaseResult = await counter.sendIncrease(increaser.getSender(), { increaseBy, value: toNano('0.05'), }); expect(increaseResult.transactions).toHaveTransaction({ from: increaser.address, to: counter.address, success: true, }); const counterAfter = await counter.getCounter(); console.log('counter after increasing', counterAfter); expect(counterAfter).toBe(counterBefore + increaseBy); } }); });