|
|
|
import { toNano, Address } from "ton";
|
|
|
|
import { ContractSystem } from "ton-emulator";
|
|
|
|
import {TONB} from '../output/jetton_TONB';
|
|
|
|
import { default_content } from '../utils/config';
|
|
|
|
import { TONBWallet } from '../output/jetton_TONBWallet';
|
|
|
|
import { beginCell } from 'ton-core';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('jetton', () => {
|
|
|
|
it('should deploy and deposit the wallet with the correct sum of money', async () => {
|
|
|
|
|
|
|
|
// Create jetton
|
|
|
|
let system = await ContractSystem.create();
|
|
|
|
let owner = system.treasure('owner');
|
|
|
|
let contract = system.open(await TONB.fromInit(owner.address, default_content));
|
|
|
|
let tracker = system.track(contract.address);
|
|
|
|
|
|
|
|
// Mint
|
|
|
|
await contract.send(owner, { value: toNano('1.2') }, { $$type: 'Deposit', amount: toNano('1') });
|
|
|
|
let log = await system.run();
|
|
|
|
let events = tracker.events();
|
|
|
|
expect(events).toMatchSnapshot();
|
|
|
|
|
|
|
|
let addr = Address.parse((events[4] as any).messages[0].to);
|
|
|
|
let wallet_contract = system.contract(addr);
|
|
|
|
let wdata = ((await wallet_contract.get(97026, [])) as any).stack.items;
|
|
|
|
expect(wdata[0].value).toEqual(1000000000n);
|
|
|
|
|
|
|
|
let linker_contract = system.contract(Address.parse((events[3] as any).messages[0].to));
|
|
|
|
let linker_owner = ((await linker_contract.get('owner', [])) as any).stack.items[0];
|
|
|
|
expect(linker_owner.cell.toBoc()).toEqual(beginCell().storeAddress(addr).endCell().toBoc());
|
|
|
|
|
|
|
|
// Check owner
|
|
|
|
expect((await contract.getOwner()).toString()).toEqual(owner.address.toString());
|
|
|
|
|
|
|
|
// Withdraw
|
|
|
|
await contract.send(owner, { value: toNano('0.15') }, { $$type: 'Withdraw', amount: toNano('0.3') });
|
|
|
|
log = await system.run();
|
|
|
|
events = tracker.events();
|
|
|
|
expect((events[5] as any).messages[0].value).toBeGreaterThan(toNano('0.29'));
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|