|
|
|
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';
|
|
|
|
import { PseudoStaking } from '../output/jetton_PseudoStaking';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('jetton', () => {
|
|
|
|
it('should deploy and deposit the wallet with the correct sum of money + withdraw should be working', async () => {
|
|
|
|
|
|
|
|
// Create jetton
|
|
|
|
let system = await ContractSystem.create();
|
|
|
|
let owner = system.treasure('owner');
|
|
|
|
let contract = system.open(await TONB.fromInit(owner.address, default_content, null));
|
|
|
|
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'));
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
it('should work correctly with the staking', async () => {
|
|
|
|
// Create jetton
|
|
|
|
let system = await ContractSystem.create();
|
|
|
|
let owner = system.treasure('owner');
|
|
|
|
let pseudostaking_contract = system.open(await PseudoStaking.fromInit());
|
|
|
|
let contract = system.open(await TONB.fromInit(owner.address, default_content, pseudostaking_contract.address));
|
|
|
|
await pseudostaking_contract.send(owner, { value: toNano('10000') }, "Deposit");
|
|
|
|
await contract.send(owner, { value: toNano('0.1') }, { $$type: "SetStakingPool", staking_pool: pseudostaking_contract.address });
|
|
|
|
await system.run();
|
|
|
|
let tracker = system.track(contract.address);
|
|
|
|
// Mint - The contract should stake the money
|
|
|
|
await contract.send(owner, { value: toNano('100.2') }, { $$type: 'Deposit', amount: toNano('100') });
|
|
|
|
let log = await system.run();
|
|
|
|
let events = tracker.events();
|
|
|
|
// console.log(events)
|
|
|
|
expect(events).toMatchSnapshot();
|
|
|
|
expect((events[4] as any).messages[0].value).toBeGreaterThan(99000000000n);
|
|
|
|
|
|
|
|
// Try to withdraw
|
|
|
|
await contract.send(owner, { value: toNano('0.15') }, { $$type: 'Withdraw', amount: toNano('50') });
|
|
|
|
await system.run();
|
|
|
|
events = tracker.events();
|
|
|
|
// console.log(events);
|
|
|
|
expect((events[events.length - 1] as any).messages[0].value).toBeGreaterThan(49000000000n);
|
|
|
|
|
|
|
|
});
|
|
|
|
it('should correctly work with transfers', async () => {
|
|
|
|
let system = await ContractSystem.create();
|
|
|
|
let owner = system.treasure('owner');
|
|
|
|
let contract = system.open(await TONB.fromInit(owner.address, default_content, null));
|
|
|
|
let dude = system.treasure('dude')
|
|
|
|
|
|
|
|
// Mint
|
|
|
|
await contract.send(owner, { value: toNano('100.2') }, { $$type: 'Deposit', amount: toNano('100') });
|
|
|
|
await system.run();
|
|
|
|
// let addr = Address.parse((events[4] as any).messages[0].to);
|
|
|
|
// let wallet_contract = system.contract(addr);
|
|
|
|
let wallet_contract = system.open(await TONBWallet.fromInit(contract.address, owner.address))
|
|
|
|
let wallet_contract_2 = system.open(await TONBWallet.fromInit(contract.address, dude.address))
|
|
|
|
let tracker = system.track(wallet_contract.address);
|
|
|
|
let tracker_2 = system.track(wallet_contract_2.address);
|
|
|
|
await wallet_contract.send(owner, { value: toNano("0.2") }, {
|
|
|
|
amount: toNano(10), destination: dude.address, queryId: 0n,
|
|
|
|
forwardTonAmount: 0n, $$type: 'TokenTransfer',
|
|
|
|
forwardPayload: beginCell().endCell(),
|
|
|
|
responseDestination: null, customPayload: null
|
|
|
|
});
|
|
|
|
await system.run();
|
|
|
|
expect((await wallet_contract_2.getGetWalletData()).balance).toEqual(10000000000n);
|
|
|
|
});
|
|
|
|
});
|