82 lines
2.3 KiB
TypeScript
82 lines
2.3 KiB
TypeScript
import { Blockchain, SandboxContract, TreasuryContract } from '@ton/sandbox';
|
|
import { Cell, toNano } from '@ton/core';
|
|
import { Vault } from '../wrappers/Vault';
|
|
import '@ton/test-utils';
|
|
import { compile } from '@ton/blueprint';
|
|
|
|
describe('Vault', () => {
|
|
let code: Cell;
|
|
|
|
beforeAll(async () => {
|
|
code = await compile('Vault');
|
|
});
|
|
|
|
let blockchain: Blockchain;
|
|
let deployer: SandboxContract<TreasuryContract>;
|
|
let vault: SandboxContract<Vault>;
|
|
|
|
beforeEach(async () => {
|
|
blockchain = await Blockchain.create();
|
|
|
|
vault = blockchain.openContract(
|
|
Vault.createFromConfig(
|
|
{
|
|
id: 0,
|
|
counter: 0,
|
|
},
|
|
code
|
|
)
|
|
);
|
|
|
|
deployer = await blockchain.treasury('deployer');
|
|
|
|
const deployResult = await vault.sendDeploy(deployer.getSender(), toNano('0.05'));
|
|
|
|
expect(deployResult.transactions).toHaveTransaction({
|
|
from: deployer.address,
|
|
to: vault.address,
|
|
deploy: true,
|
|
success: true,
|
|
});
|
|
});
|
|
|
|
it('should deploy', async () => {
|
|
// the check is done inside beforeEach
|
|
// blockchain and vault 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 vault.getCounter();
|
|
|
|
console.log('counter before increasing', counterBefore);
|
|
|
|
const increaseBy = Math.floor(Math.random() * 100);
|
|
|
|
console.log('increasing by', increaseBy);
|
|
|
|
const increaseResult = await vault.sendIncrease(increaser.getSender(), {
|
|
increaseBy,
|
|
value: toNano('0.05'),
|
|
});
|
|
|
|
expect(increaseResult.transactions).toHaveTransaction({
|
|
from: increaser.address,
|
|
to: vault.address,
|
|
success: true,
|
|
});
|
|
|
|
const counterAfter = await vault.getCounter();
|
|
|
|
console.log('counter after increasing', counterAfter);
|
|
|
|
expect(counterAfter).toBe(counterBefore + increaseBy);
|
|
}
|
|
});
|
|
});
|