-
Notifications
You must be signed in to change notification settings - Fork 105
/
test-data-generator.js
141 lines (134 loc) · 4.89 KB
/
test-data-generator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import web3Utils from "web3-utils";
import { BN } from "bn.js";
import {
EVALUATOR,
WORKER,
MANAGER_PAYOUT,
EVALUATOR_PAYOUT,
WORKER_PAYOUT,
MANAGER_RATING,
WORKER_RATING,
RATING_1_SALT,
RATING_2_SALT,
MANAGER_ROLE,
EVALUATOR_ROLE,
WORKER_ROLE,
SPECIFICATION_HASH
} from "../helpers/constants";
import testHelper from "../helpers/test-helper";
module.exports = {
async setupAssignedTask(
colonyNetwork,
colony,
dueDate = testHelper.currentBlockTime(),
domain = 1,
skill = 0,
evaluator = EVALUATOR,
worker = WORKER
) {
await colony.makeTask(SPECIFICATION_HASH, domain);
let taskId = await colony.getTaskCount.call();
taskId = taskId.toNumber();
// If the skill is not specified, default to the root global skill
if (skill === 0) {
const rootGlobalSkill = await colonyNetwork.getRootGlobalSkillId.call();
if (rootGlobalSkill === 0) throw new Error("Common Colony is not setup and therefore the root global skill does not exist");
await colony.setTaskSkill(taskId, rootGlobalSkill);
} else {
await colony.setTaskSkill(taskId, skill);
}
await colony.setTaskRoleUser(taskId, EVALUATOR_ROLE, evaluator);
await colony.setTaskRoleUser(taskId, WORKER_ROLE, worker);
const txData = await colony.contract.setTaskDueDate.getData(taskId, dueDate);
await colony.proposeTaskChange(txData, 0, MANAGER_ROLE);
const transactionId = await colony.getTransactionCount.call();
await colony.approveTaskChange(transactionId, WORKER_ROLE, { from: worker });
return taskId;
},
async setupFundedTask(
colonyNetwork,
colony,
token,
dueDate,
domain,
skill,
evaluator = EVALUATOR,
worker = WORKER,
manager_payout = MANAGER_PAYOUT,
evaluator_payout = EVALUATOR_PAYOUT,
worker_payout = WORKER_PAYOUT
) {
let tokenAddress;
if (token === undefined) {
tokenAddress = await colony.getToken.call();
} else {
tokenAddress = token === 0x0 ? 0x0 : token.address;
}
const taskId = await this.setupAssignedTask(colonyNetwork, colony, dueDate, domain, skill, evaluator, worker);
const task = await colony.getTask.call(taskId);
const potId = task[6].toNumber();
const managerPayout = new BN(manager_payout);
const workerPayout = new BN(worker_payout);
const evaluatorPayout = new BN(evaluator_payout);
const totalPayouts = managerPayout.add(workerPayout).add(evaluatorPayout);
await colony.moveFundsBetweenPots(1, potId, totalPayouts.toString(), tokenAddress);
await colony.setTaskManagerPayout(taskId, tokenAddress, managerPayout.toString());
let txData = await colony.contract.setTaskEvaluatorPayout.getData(taskId, tokenAddress, evaluatorPayout.toString());
await colony.proposeTaskChange(txData, 0, MANAGER_ROLE);
let transactionId = await colony.getTransactionCount.call();
await colony.approveTaskChange(transactionId, EVALUATOR_ROLE, { from: evaluator });
txData = await colony.contract.setTaskWorkerPayout.getData(taskId, tokenAddress, workerPayout.toString());
await colony.proposeTaskChange(txData, 0, MANAGER_ROLE);
transactionId = await colony.getTransactionCount.call();
await colony.approveTaskChange(transactionId, WORKER_ROLE, { from: worker });
return taskId;
},
async setupRatedTask(
colonyNetwork,
colony,
token,
dueDate,
domain,
skill,
evaluator = EVALUATOR,
worker = WORKER,
manager_payout = MANAGER_PAYOUT,
evaluator_payout = EVALUATOR_PAYOUT,
worker_payout = WORKER_PAYOUT,
manager_rating = MANAGER_RATING,
manager_rating_salt = RATING_1_SALT,
worker_rating = WORKER_RATING,
worker_rating_salt = RATING_2_SALT
) {
const taskId = await this.setupFundedTask(
colonyNetwork,
colony,
token,
dueDate,
domain,
skill,
evaluator,
worker,
manager_payout,
evaluator_payout,
worker_payout
);
const WORKER_RATING_SECRET = web3Utils.soliditySha3(worker_rating_salt, worker_rating);
const MANAGER_RATING_SECRET = web3Utils.soliditySha3(manager_rating_salt, manager_rating);
await colony.submitTaskWorkRating(taskId, WORKER_ROLE, WORKER_RATING_SECRET, { from: evaluator });
await colony.submitTaskWorkRating(taskId, MANAGER_ROLE, MANAGER_RATING_SECRET, { from: worker });
await colony.revealTaskWorkRating(taskId, WORKER_ROLE, worker_rating, worker_rating_salt, { from: evaluator });
await colony.revealTaskWorkRating(taskId, MANAGER_ROLE, manager_rating, manager_rating_salt, { from: worker });
return taskId;
},
async fundColonyWithTokens(colony, token, tokenAmount) {
const colonyToken = await colony.getToken.call();
if (colonyToken === token.address) {
await colony.mintTokens(tokenAmount);
} else {
await token.mint(tokenAmount);
await token.transfer(colony.address, tokenAmount);
}
await colony.claimColonyFunds(token.address);
}
};