From f0c8c0244d813f089768cb3d4999be96e7b159ca Mon Sep 17 00:00:00 2001 From: ennucore Date: Sun, 12 Feb 2023 18:31:40 +0100 Subject: [PATCH] Redistribution test --- sources/foundation.tact | 8 ++++++-- sources/tests/foundation.spec.ts | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/sources/foundation.tact b/sources/foundation.tact index d11e91a..8f024c7 100644 --- a/sources/foundation.tact +++ b/sources/foundation.tact @@ -55,7 +55,7 @@ contract Foundation { i = i + 1; } let n_total: Int = n_yes + n_no + n_abstain; - let present: Int = n_total * 100 / self.admins.addresses.length; + let present: Int = n_total; if (present < vote.quorum_percent) { vote.result = false; } else if (n_yes > n_no) { @@ -139,7 +139,7 @@ contract Foundation { require(ctx.sender == self.admins.addresses.addresses.get(msg.adminIndex), "Only an admin can initiate a vote"); require(ctx.value >= ton("1.0"), "Voting requires at least 1 ton for the fees"); require(msg.quorum_percent > 20 && msg.quorum_percent <= 100, "Invalid quorum percent"); - require(msg.vote_time > 0 && msg.vote_time < 3 * 24 * 3600, "Invalid vote time"); + require(msg.vote_time >= 0 && msg.vote_time < 3 * 24 * 3600, "Invalid vote time"); let proposal: Proposal = Proposal { type: 2, blacklistAddress: null, @@ -254,4 +254,8 @@ contract Foundation { get fun AdminList(): AddressList { return self.admins.addresses; } + + get fun AdminPercents(): map[Int]Int { + return self.admins.percents; + } } \ No newline at end of file diff --git a/sources/tests/foundation.spec.ts b/sources/tests/foundation.spec.ts index 669f953..c8a403f 100644 --- a/sources/tests/foundation.spec.ts +++ b/sources/tests/foundation.spec.ts @@ -43,10 +43,11 @@ describe('jetton', () => { 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 () => { + it('should be able to create a vote for blacklisting and redistribution', async () => { let system = await ContractSystem.create(); let owner = system.treasure('owner'); let someadmin = system.treasure('someadmin'); + let someadmin2 = system.treasure('someadmin2'); 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( @@ -87,5 +88,26 @@ describe('jetton', () => { 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')); + await foundation.send(someadmin, { value: toNano('1.1') }, { + $$type: "InitiateDistributionVote", + adminIndex: 1n, quorum_percent: 50n, vote_time: 0n, + distribution: createDistribution([owner.address, someadmin.address, someadmin2.address], [40n, 40n, 20n]) + }); + await system.run(); + await foundation.send(someadmin, { value: toNano('1.1') }, { $$type: "VoteMsg", vote: 1n, adminIndex: 1n, voteId: 1n }); + await foundation.send(owner, { value: toNano('1.1') }, { $$type: "VoteMsg", vote: 1n, adminIndex: 0n, voteId: 1n }); + await system.run(); + await foundation.send(someadmin, { value: toNano('1.1') }, { $$type: "FinishVote", voteId: 1n }); + await system.run(); + v = await foundation.getNthVote(1n) as any; + foundation_events = foundation_tracker.events(); + expect(v.votes.get(0n)).toEqual(1n); + expect(v.votes.get(1n)).toEqual(1n); + expect(v.ended).toBeTruthy(); + expect(v.result).toBeTruthy(); + let admin_list = await foundation.getAdminList(); + expect(admin_list.addresses.get(2n)).toBeDefined(); + let admin_percents = await foundation.getAdminPercents(); + expect(admin_percents.get(2n)).toEqual(20n); }); }); \ No newline at end of file