Lev
2 years ago
3 changed files with 38 additions and 13 deletions
@ -1,23 +1,48 @@ |
|||||||
import { toNano } from "ton"; |
import { toNano } from "ton"; |
||||||
import { ContractSystem } from "ton-emulator"; |
import { ContractSystem } from "ton-emulator"; |
||||||
import {TONB} from '../output/jetton_TONB'; |
import { TONB } from '../output/jetton_TONB'; |
||||||
import {Foundation} from '../output/jetton_Foundation'; |
import { Foundation } from '../output/jetton_Foundation'; |
||||||
import { default_content } from '../utils/config'; |
import { default_content } from '../utils/config'; |
||||||
import { TONBWallet } from '../output/jetton_TONBWallet'; |
import { TONBWallet } from '../output/jetton_TONBWallet'; |
||||||
import { beginCell } from 'ton-core'; |
import { beginCell } from 'ton-core'; |
||||||
import { PseudoStaking } from '../output/jetton_PseudoStaking'; |
import { PseudoStaking } from '../output/jetton_PseudoStaking'; |
||||||
import { createDistribution, createAddressList } from "../utils/interactions"; |
import { createDistribution, createAddressList } from "../utils/interactions"; |
||||||
|
import { logEvents } from '../utils/helpers'; |
||||||
|
|
||||||
describe('jetton', () => { |
describe('jetton', () => { |
||||||
it('should be able to create a vote', async () => { |
it('should be able to distribute profits among admins', async () => { |
||||||
// Create jetton
|
// Create jetton
|
||||||
let system = await ContractSystem.create(); |
let system = await ContractSystem.create(); |
||||||
let owner = system.treasure('owner'); |
let owner = system.treasure('owner'); |
||||||
let tonb = system.open(await TONB.fromInit(owner.address, default_content, null)); |
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( |
let foundation = system.open(await Foundation.fromInit( |
||||||
createDistribution([owner.address], [100n]),
|
createDistribution([owner.address, someadmin.address], [40n, 60n]), |
||||||
createAddressList([]), tonb.address)); |
createAddressList([owner.address]), tonb.address)); |
||||||
|
let tonb_tracker = system.track(tonb.address); |
||||||
tonb.send(owner, { value: toNano('1') }, { $$type: 'SetOwner', owner: foundation.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 }; |
||||||
|
logEvents(tonb_events, addressBook); |
||||||
let tracker = system.track(foundation.address); |
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; |
||||||
|
logEvents(foundation_events, addressBook); |
||||||
|
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')); |
||||||
}); |
}); |
||||||
}); |
}); |
Loading…
Reference in new issue