import { toNano } from "ton"; import { ContractSystem } from "ton-emulator"; import { TONB } from '../output/jetton_TONB'; import { Foundation } from '../output/jetton_Foundation'; import { default_content } from '../utils/config'; import { TONBWallet } from '../output/jetton_TONBWallet'; import { beginCell } from 'ton-core'; import { PseudoStaking } from '../output/jetton_PseudoStaking'; import { createDistribution, createAddressList } from "../utils/interactions"; import { logEvents } from '../utils/helpers'; describe('jetton', () => { it('should be able to distribute profits among admins', async () => { // Create jetton let system = await ContractSystem.create(); let owner = system.treasure('owner'); let someadmin = system.treasure('someadmin'); let pseudostaking_contract = system.open(await PseudoStaking.fromInit()); let tonb = system.open(await TONB.fromInit(owner.address, default_content, pseudostaking_contract.address)); let foundation = system.open(await Foundation.fromInit( createDistribution([owner.address, someadmin.address], [40n, 60n]), createAddressList([owner.address]), tonb.address)); let tonb_tracker = system.track(tonb.address); tonb.send(owner, { value: toNano('1') }, { $$type: 'SetOwner', owner: foundation.address }); await pseudostaking_contract.send(owner, { value: toNano('10000') }, "Deposit"); await tonb.send(owner, { value: toNano('0.1') }, { $$type: "SetStakingPool", staking_pool: pseudostaking_contract.address }); await system.run(); await tonb.send(owner, { value: toNano('100.2') }, { $$type: 'Deposit', amount: toNano('100') }); await system.run(); let tonb_events = tonb_tracker.events(); let addressBook = { 'tonb': (tonb_events[1] as any).message.to, 'owner': (tonb_events[1] as any).message.from, 'staking': (tonb_events[9] as any).messages[0].to, 'someadmin': 'unknown' as any, 'foundation': 'unknown' as any }; let tracker = system.track(foundation.address); await foundation.send(owner, { value: toNano('0.1') }, { $$type: 'RequestUnstake', founderIndex: 0n }); await system.run(); await foundation.send(someadmin, { value: toNano('0.1') }, { $$type: 'CollectProfit', adminIndex: 1n }); await foundation.send(owner, { value: toNano('0.1') }, { $$type: 'CollectProfit', adminIndex: 0n }); await system.run(); let foundation_events = tracker.events(); addressBook['foundation'] = (foundation_events[1] as any).message.to; expect((foundation_events[11] as any).messages[0].value).toBeGreaterThan(toNano('3.9')); expect((foundation_events[11] as any).messages[0].value).toBeLessThan(toNano('4.1')); expect((foundation_events[11] as any).messages[0].to).toEqual(addressBook['owner']); expect((foundation_events[8] as any).messages[0].value).toBeGreaterThan(toNano('5.9')); expect((foundation_events[8] as any).messages[0].value).toBeLessThan(toNano('6.1')); }); it('should be able to create a vote for blacklisting', async () => { let system = await ContractSystem.create(); let owner = system.treasure('owner'); let someadmin = system.treasure('someadmin'); let pseudostaking_contract = system.open(await PseudoStaking.fromInit()); let tonb = system.open(await TONB.fromInit(owner.address, default_content, pseudostaking_contract.address)); let foundation = system.open(await Foundation.fromInit( createDistribution([owner.address, someadmin.address], [60n, 40n]), createAddressList([owner.address]), tonb.address)); let tonb_tracker = system.track(tonb.address); let foundation_tracker = system.track(foundation.address); tonb.send(owner, { value: toNano('1') }, { $$type: 'SetOwner', owner: foundation.address }); await tonb.send(owner, { value: toNano('100.2') }, { $$type: 'Deposit', amount: toNano('100') }); await system.run(); let tonb_events = tonb_tracker.events(); await foundation.send(someadmin, { value: toNano('1.1') }, { $$type: "InitiateBlacklistVote", wallet: owner.address, adminIndex: 1n, quorum_percent: 50n, vote_time: 0n }); await system.run(); let addressBook = { 'tonb': (tonb_events[1] as any).message.to, 'owner': (tonb_events[1] as any).message.from, 'someadmin': 'unknown' as any, 'foundation': 'unknown' as any }; let foundation_events = foundation_tracker.events(); addressBook['foundation'] = (foundation_events[1] as any).message.to; addressBook['someadmin'] = (foundation_events[1] as any).message.from; let v = await foundation.getNthVote(0n) as any; expect(v.votes.get(0n)).toEqual(-1n); expect(v.votes.get(1n)).toEqual(-1n); expect(v.ended).toBeFalsy(); expect(v.quorum_percent).toEqual(50n); await foundation.send(someadmin, { value: toNano('1.1') }, { $$type: "VoteMsg", vote: 2n, adminIndex: 1n, voteId: 0n }); await foundation.send(owner, { value: toNano('1.1') }, { $$type: "VoteMsg", vote: 1n, adminIndex: 0n, voteId: 0n }); await system.run(); await foundation.send(someadmin, { value: toNano('1.1') }, { $$type: "FinishVote", voteId: 0n }); await system.run(); v = await foundation.getNthVote(0n) as any; foundation_events = foundation_tracker.events(); expect(v.votes.get(0n)).toEqual(1n); expect(v.votes.get(1n)).toEqual(2n); expect(v.ended).toBeTruthy(); expect(v.result).toBeTruthy(); await system.run(); tonb_events = tonb_tracker.events(); expect((tonb_events[5] as any).messages[0].to).toEqual(addressBook['owner']); expect((tonb_events[5] as any).messages[0].value).toBeGreaterThan(toNano('99')); }); });