Browse Source

Redistribution test

master
Lev 2 years ago
parent
commit
f0c8c0244d
  1. 8
      sources/foundation.tact
  2. 24
      sources/tests/foundation.spec.ts

8
sources/foundation.tact

@ -55,7 +55,7 @@ contract Foundation {
i = i + 1; i = i + 1;
} }
let n_total: Int = n_yes + n_no + n_abstain; 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) { if (present < vote.quorum_percent) {
vote.result = false; vote.result = false;
} else if (n_yes > n_no) { } 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.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(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.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 { let proposal: Proposal = Proposal {
type: 2, type: 2,
blacklistAddress: null, blacklistAddress: null,
@ -254,4 +254,8 @@ contract Foundation {
get fun AdminList(): AddressList { get fun AdminList(): AddressList {
return self.admins.addresses; return self.admins.addresses;
} }
get fun AdminPercents(): map[Int]Int {
return self.admins.percents;
}
} }

24
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).toBeGreaterThan(toNano('5.9'));
expect((foundation_events[8] as any).messages[0].value).toBeLessThan(toNano('6.1')); 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 system = await ContractSystem.create();
let owner = system.treasure('owner'); let owner = system.treasure('owner');
let someadmin = system.treasure('someadmin'); let someadmin = system.treasure('someadmin');
let someadmin2 = system.treasure('someadmin2');
let pseudostaking_contract = system.open(await PseudoStaking.fromInit()); let pseudostaking_contract = system.open(await PseudoStaking.fromInit());
let tonb = system.open(await TONB.fromInit(owner.address, default_content, pseudostaking_contract.address)); 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(
@ -87,5 +88,26 @@ describe('jetton', () => {
tonb_events = tonb_tracker.events(); 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].to).toEqual(addressBook['owner']);
expect((tonb_events[5] as any).messages[0].value).toBeGreaterThan(toNano('99')); 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);
}); });
}); });
Loading…
Cancel
Save