Skip to content

Commit

Permalink
Migrate makeTask helper functions to Expenditures IV
Browse files Browse the repository at this point in the history
  • Loading branch information
kronosapiens committed Aug 23, 2023
1 parent d3d5d03 commit b198c73
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 593 deletions.
130 changes: 18 additions & 112 deletions test/reputation-system/client-calculations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const {
setupColonyNetwork,
setupMetaColonyWithLockedCLNYToken,
giveUserCLNYTokensAndStake,
setupClaimedExpenditure,
fundColonyWithTokens,
} = require("../../helpers/test-data-generator");

Expand Down Expand Up @@ -42,6 +41,8 @@ const setupNewNetworkInstance = async (MINER1, MINER2) => {
// \-> 2
await metaColony.addDomain(1, UINT256_MAX, 1);
await metaColony.addDomain(1, 1, 2);
// 1 -> M
// -> 2 -> 3

await giveUserCLNYTokensAndStake(colonyNetwork, MINER1, DEFAULT_STAKE);
await giveUserCLNYTokensAndStake(colonyNetwork, MINER2, DEFAULT_STAKE);
Expand All @@ -51,14 +52,6 @@ const setupNewNetworkInstance = async (MINER1, MINER2) => {
goodClient = new ReputationMinerTestWrapper({ loader, realProviderPort, useJsTree, minerAddress: MINER1 });
};

async function customSetupClaimedExpenditure(args) {
const newArgs = Object.assign(args, {
evaluatorPayout: 0,
managerPayout: 0,
});
return setupClaimedExpenditure(newArgs);
}

process.env.SOLIDITY_COVERAGE
? contract.skip
: contract("Reputation mining - client reputation calculations", (accounts) => {
Expand Down Expand Up @@ -96,54 +89,23 @@ process.env.SOLIDITY_COVERAGE

describe("core functionality", () => {
it("should correctly calculate increments and decrements in parent reputations", async () => {
await customSetupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
workerPayout: 100,
worker: OTHER,
domainId: 3,
});
await metaColony.emitDomainReputationReward(3, OTHER, 100);
// Skills in 1 / 5 / 6
// OTHER: (100 / 100 / 100)

await customSetupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
workerPayout: 100,
worker: WORKER,
domainId: 3,
});
await metaColony.emitDomainReputationReward(3, WORKER, 100);
// WORKER: (100 / 100 / 100)
// OTHER: (100 / 100 / 100)

await customSetupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
workerPayout: 900,
worker: OTHER,
domainId: 2,
});
await metaColony.emitDomainReputationReward(2, OTHER, 900);
// WORKER: (100 / 100 / 100)
// OTHER: (1000 / 1000 / 100)

await customSetupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
workerPayout: 1000,
worker: OTHER,
domainId: 1,
});
await metaColony.emitDomainReputationReward(1, OTHER, 1000);
// WORKER: (100 / 100 / 100)
// OTHER: (2000 / 1000 / 100)

await customSetupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
workerPayout: 200,
workerRating: 1,
worker: OTHER,
domainId: 3,
});
await metaColony.emitDomainReputationPenalty(1, 2, 3, OTHER, -100);
// WORKER: (100 / 100 / 100)
// OTHER: (1900 / 900 / 0)

Expand Down Expand Up @@ -171,44 +133,19 @@ process.env.SOLIDITY_COVERAGE
});

it("should correctly calculate decrements in child reputations", async () => {
await customSetupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
workerPayout: 100,
worker: OTHER,
domainId: 3,
});
await metaColony.emitDomainReputationReward(3, OTHER, 100);
// Skills in 1 / 5 / 6
// OTHER: (100 / 100 / 100)

await customSetupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
workerPayout: 100,
worker: WORKER,
domainId: 3,
});
await metaColony.emitDomainReputationReward(3, WORKER, 100);
// WORKER: (100 / 100 / 100)
// OTHER: (100 / 100 / 100)

await customSetupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
workerPayout: 900,
worker: OTHER,
domainId: 2,
});
await metaColony.emitDomainReputationReward(2, OTHER, 900);
// WORKER: (100 / 100 / 100)
// THER: (1000 / 1000 / 100)

await customSetupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
workerPayout: 200,
workerRating: 1,
worker: OTHER,
domainId: 2,
});
// OTHER: (1000 / 1000 / 100)

await metaColony.emitDomainReputationPenalty(1, 1, 2, OTHER, -200);
// WORKER: (100 / 100 / 100)
// OTHER: (800 / 800 / 80)

Expand Down Expand Up @@ -236,54 +173,23 @@ process.env.SOLIDITY_COVERAGE
});

it("should correctly calculate decrements in child reputations if the user loses all reputation", async () => {
await customSetupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
workerPayout: 100,
worker: OTHER,
domainId: 3,
});
await metaColony.emitDomainReputationReward(3, OTHER, 100);
// Skills in 1 / 5 / 6
// OTHER: (100 / 100 / 100)

await customSetupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
workerPayout: 100,
worker: WORKER,
domainId: 3,
});
await metaColony.emitDomainReputationReward(3, WORKER, 100);
// WORKER: (100 / 100 / 100)
// OTHER: (100 / 100 / 100)

await customSetupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
workerPayout: 900,
worker: OTHER,
domainId: 2,
});
await metaColony.emitDomainReputationReward(2, OTHER, 900);
// WORKER: (100 / 100 / 100)
// OTHER: (1000 / 1000 / 100)

await customSetupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
workerPayout: 500,
worker: OTHER,
domainId: 1,
});
await metaColony.emitDomainReputationReward(1, OTHER, 500);
// WORKER: (100 / 100 / 100)
// OTHER: (1500 / 1000 / 100)

await customSetupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
workerPayout: 100000000,
workerRating: 1,
worker: OTHER,
domainId: 2,
});
await metaColony.emitDomainReputationPenalty(1, 1, 2, OTHER, -100000000);
// WORKER: (100 / 100 / 100)
// OTHER: (500 / 0 / 0)

Expand Down
83 changes: 30 additions & 53 deletions test/reputation-system/dispute-resolution-misbehaviour.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const {
CHALLENGE_RESPONSE_WINDOW_DURATION,
ALL_ENTRIES_ALLOWED_END_OF_WINDOW,
HASHZERO,
GLOBAL_SKILL_ID,
} = require("../../helpers/constants");

const ReputationMinerTestWrapper = require("../../packages/reputation-miner/test/ReputationMinerTestWrapper");
Expand Down Expand Up @@ -83,6 +84,8 @@ const setupNewNetworkInstance = async (MINER1, MINER2) => {
};

contract("Reputation Mining - disputes resolution misbehaviour", (accounts) => {
const USER0 = accounts[0];

const MINER1 = accounts[5];
const MINER2 = accounts[6];
const MINER3 = accounts[7];
Expand Down Expand Up @@ -525,16 +528,12 @@ contract("Reputation Mining - disputes resolution misbehaviour", (accounts) => {
await fundColonyWithTokens(metaColony, clnyToken, INITIAL_FUNDING.muln(4));
await setupClaimedExpenditure({ colonyNetwork, colony: metaColony });
await setupClaimedExpenditure({ colonyNetwork, colony: metaColony });
await setupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
manager: MINER1,
worker: MINER2,
workerRating: 1,
managerPayout: 1,
evaluatorPayout: 1,
workerPayout: 1,
});

// Manager, evaluator, worker
await metaColony.emitDomainReputationReward(1, USER0, 1);
await metaColony.emitDomainReputationReward(1, MINER1, 1);
await metaColony.emitDomainReputationPenalty(1, UINT256_MAX, 1, MINER2, -1);
await metaColony.emitSkillReputationPenalty(GLOBAL_SKILL_ID, MINER2, -1);

await advanceMiningCycleNoContest({ colonyNetwork, client: goodClient, test: this });

Expand All @@ -543,16 +542,11 @@ contract("Reputation Mining - disputes resolution misbehaviour", (accounts) => {

let powerTwoEntries = false;
while (!powerTwoEntries) {
await setupClaimedExpenditure({ // eslint-disable-line prettier/prettier
colonyNetwork,
colony: metaColony,
evaluator: MINER1,
worker: MINER2,
workerRating: 1,
managerPayout: 1,
evaluatorPayout: 1,
workerPayout: 1,
});
// Manager, evaluator, worker
await metaColony.emitDomainReputationReward(1, USER0, 1);
await metaColony.emitDomainReputationReward(1, MINER1, 1);
await metaColony.emitDomainReputationPenalty(1, UINT256_MAX, 1, MINER2, -1);
await metaColony.emitSkillReputationPenalty(GLOBAL_SKILL_ID, MINER2, -1);

const nLogEntries = await inactiveRepCycle.getReputationUpdateLogLength();
const lastLogEntry = await inactiveRepCycle.getReputationUpdateLogEntry(nLogEntries - 1);
Expand Down Expand Up @@ -918,17 +912,11 @@ contract("Reputation Mining - disputes resolution misbehaviour", (accounts) => {

await advanceMiningCycleNoContest({ colonyNetwork, test: this });

await setupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
domainId: 2,
managerPayout: 1000000000000,
evaluatorPayout: 1000000000000,
workerPayout: 1000000000000,
managerRating: 1,
workerRating: 1,
worker: MINER2,
});
// Manager, evaluator, worker
await metaColony.emitDomainReputationPenalty(1, 1, 2, USER0, -1000000000000);
await metaColony.emitDomainReputationReward(2, USER0, 1000000000000);
await metaColony.emitDomainReputationPenalty(1, 1, 2, MINER2, -1000000000000);
await metaColony.emitSkillReputationPenalty(GLOBAL_SKILL_ID, MINER2, -1000000000000);

await advanceMiningCycleNoContest({ colonyNetwork, test: this });

Expand Down Expand Up @@ -974,29 +962,18 @@ contract("Reputation Mining - disputes resolution misbehaviour", (accounts) => {
await fundColonyWithTokens(metaColony, clnyToken, new BN("1000000000000").muln(4).add(new BN(5000000000000)).add(new BN(1000000000)));

await advanceMiningCycleNoContest({ colonyNetwork, test: this });
await setupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
domainId: 2,
managerPayout: 1000000000000,
evaluatorPayout: 1000000000,
workerPayout: 5000000000000,
managerRating: 3,
workerRating: 3,
worker: MINER2,
});

await setupClaimedExpenditure({
colonyNetwork,
colony: metaColony,
domainId: 2,
managerPayout: 1000000000000,
evaluatorPayout: 1000000000000,
workerPayout: 1,
managerRating: 1,
workerRating: 1,
worker: MINER2,
});
// Manager, evaluator, worker
await metaColony.emitDomainReputationReward(2, USER0, 1500000000000);
await metaColony.emitDomainReputationReward(2, USER0, 1000000000);
await metaColony.emitDomainReputationReward(2, MINER2, 7500000000000);
await metaColony.emitSkillReputationReward(GLOBAL_SKILL_ID, MINER2, 7500000000000);

// Manager, evaluator, worker
await metaColony.emitDomainReputationPenalty(1, 1, 2, USER0, -1000000000000);
await metaColony.emitDomainReputationReward(2, USER0, 1000000000000);
await metaColony.emitDomainReputationPenalty(1, 1, 2, MINER2, -1);
await metaColony.emitSkillReputationPenalty(GLOBAL_SKILL_ID, MINER2, -1);

await advanceMiningCycleNoContest({ colonyNetwork, test: this });

Expand Down
Loading

0 comments on commit b198c73

Please sign in to comment.