Skip to content

Commit 1781b16

Browse files
authored
Merge pull request #310 from kleros/feat/task-resolved-event
Feat: added task lifecyle events to Linguo
2 parents 0e27cc7 + 7c1fb1d commit 1781b16

File tree

2 files changed

+77
-10
lines changed

2 files changed

+77
-10
lines changed

contracts/standard/arbitration/Linguo.sol

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @authors: [@unknownunknown1]
3-
* @reviewers: [@ferittuncer*, @clesaege*, @satello*]
3+
* @reviewers: [@ferittuncer*, @clesaege*, @satello*, @hbarcelos]
44
* @auditors: []
55
* @bounties: []
66
* @deployments: []
@@ -76,15 +76,39 @@ contract Linguo is Arbitrable {
7676
/** @dev To be emitted when the new task is created.
7777
* @param _taskID The ID of the newly created task.
7878
* @param _requester The address that created the task.
79+
* @param _timestamp When the task was created.
7980
*/
80-
event TaskCreated(uint indexed _taskID, address indexed _requester);
81+
event TaskCreated(uint indexed _taskID, address indexed _requester, uint _timestamp);
82+
83+
/** @dev To be emitted when a translator assigns the task to himself.
84+
* @param _taskID The ID of the newly created task.
85+
* @param _translator The address that assigned to the task.
86+
* @param _price The task price at the moment it was assigned.
87+
* @param _timestamp When the task was assigned.
88+
*/
89+
event TaskAssigned(uint indexed _taskID, address indexed _translator, uint _price, uint _timestamp);
8190

8291
/** @dev To be emitted when a translation is submitted.
8392
* @param _taskID The ID of the respective task.
8493
* @param _translator The address that performed the translation.
8594
* @param _translatedText A URI to the translated text.
95+
* @param _timestamp When the translation was submitted.
8696
*/
87-
event TranslationSubmitted(uint indexed _taskID, address indexed _translator, string _translatedText);
97+
event TranslationSubmitted(uint indexed _taskID, address indexed _translator, string _translatedText, uint _timestamp);
98+
99+
/** @dev To be emitted when a translation is challenged.
100+
* @param _taskID The ID of the respective task.
101+
* @param _challenger The address of the challenger.
102+
* @param _timestamp When the task was challenged.
103+
*/
104+
event TranslationChallenged(uint indexed _taskID, address indexed _challenger, uint _timestamp);
105+
106+
/** @dev To be emitted when a task is resolved, either by the translation being accepted, the requester being reimbursed or a dispute being settled.
107+
* @param _taskID The ID of the respective task.
108+
* @param _reason Short description of what caused the task to be solved. One of: 'translation-accepted' | 'requester-reimbursed' | 'dispute-settled'
109+
* @param _timestamp When the task was resolved.
110+
*/
111+
event TaskResolved(uint indexed _taskID, string _reason, uint _timestamp);
88112

89113
/** @dev To be emitted when one of the parties successfully paid its appeal fees.
90114
* @param _taskID The ID of the respective task.
@@ -191,7 +215,7 @@ contract Linguo is Arbitrable {
191215
uint _deadline,
192216
uint _minPrice,
193217
string _metaEvidence
194-
) external payable returns (uint taskID){
218+
) external payable returns (uint taskID) {
195219
require(msg.value >= _minPrice, "Deposited value should be greater than or equal to the min price.");
196220
require(_deadline > now, "The deadline should be in the future.");
197221

@@ -205,7 +229,7 @@ contract Linguo is Arbitrable {
205229
task.requesterDeposit = msg.value;
206230

207231
emit MetaEvidence(taskID, _metaEvidence);
208-
emit TaskCreated(taskID, msg.sender);
232+
emit TaskCreated(taskID, msg.sender, now);
209233
}
210234

211235
/** @dev Assigns a specific task to the sender. Requires a translator's deposit.
@@ -234,6 +258,8 @@ contract Linguo is Arbitrable {
234258

235259
remainder = msg.value - deposit;
236260
msg.sender.send(remainder);
261+
262+
emit TaskAssigned(_taskID, msg.sender, price, now);
237263
}
238264

239265
/** @dev Submits translated text for a specific task.
@@ -248,7 +274,7 @@ contract Linguo is Arbitrable {
248274
task.status = Status.AwaitingReview;
249275
task.lastInteraction = now;
250276

251-
emit TranslationSubmitted(_taskID, msg.sender, _translation);
277+
emit TranslationSubmitted(_taskID, msg.sender, _translation, now);
252278
}
253279

254280
/** @dev Reimburses the requester if no one picked the task or the translator failed to submit the translation before deadline.
@@ -265,6 +291,8 @@ contract Linguo is Arbitrable {
265291

266292
task.requesterDeposit = 0;
267293
task.sumDeposit = 0;
294+
295+
emit TaskResolved(_taskID, "requester-reimbursed", now);
268296
}
269297

270298
/** @dev Pays the translator for completed task if no one challenged the translation during review period.
@@ -281,6 +309,8 @@ contract Linguo is Arbitrable {
281309

282310
task.requesterDeposit = 0;
283311
task.sumDeposit = 0;
312+
313+
emit TaskResolved(_taskID, "translation-accepted", now);
284314
}
285315

286316
/** @dev Challenges the translation of a specific task. Requires challenger's deposit.
@@ -308,6 +338,7 @@ contract Linguo is Arbitrable {
308338
msg.sender.send(remainder);
309339

310340
emit Dispute(arbitrator, task.disputeID, _taskID, _taskID);
341+
emit TranslationChallenged(_taskID, msg.sender, now);
311342
}
312343

313344
/** @dev Takes up to the total amount required to fund a side of an appeal. Reimburses the rest. Creates an appeal if all sides are fully funded.
@@ -482,6 +513,8 @@ contract Linguo is Arbitrable {
482513

483514
task.requesterDeposit = 0;
484515
task.sumDeposit = 0;
516+
517+
emit TaskResolved(taskID, "dispute-settled", now);
485518
}
486519

487520
/** @dev Submit a reference to evidence. EVENT.

test/linguo.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,20 @@ contract('Linguo', function(accounts) {
223223
)
224224
})
225225

226+
it('Should emit TaskAssigned event after assigning to the task', async () => {
227+
const requiredDeposit = (await linguo.getDepositValue(0)).toNumber()
228+
const assignTx = await linguo.assignTask(0, {
229+
from: translator,
230+
value: requiredDeposit + 1e17
231+
})
232+
233+
assert.equal(
234+
assignTx.logs[0].event,
235+
'TaskAssigned',
236+
'The TaskAssigned event was not emitted'
237+
)
238+
})
239+
226240
it('Should reimburse requester leftover price after assigning the task and set correct values', async () => {
227241
const oldBalance = await web3.eth.getBalance(requester)
228242

@@ -316,8 +330,14 @@ contract('Linguo', function(accounts) {
316330
it('Should reimburse requester if no one picked the task before submission timeout ended', async () => {
317331
await increaseTime(submissionTimeout + 1)
318332
const oldBalance = await web3.eth.getBalance(requester)
319-
await linguo.reimburseRequester(0)
333+
const reimburseTx = await linguo.reimburseRequester(0)
320334
const newBalance = await web3.eth.getBalance(requester)
335+
336+
assert.equal(
337+
reimburseTx.logs[0].event,
338+
'TaskResolved',
339+
'TaskResolved event was not emitted'
340+
)
321341
assert.equal(
322342
newBalance.toString(),
323343
oldBalance.plus(taskMaxPrice).toString(),
@@ -363,8 +383,15 @@ contract('Linguo', function(accounts) {
363383
const task = await linguo.tasks(0)
364384

365385
const oldBalance = await web3.eth.getBalance(translator)
366-
await linguo.acceptTranslation(0)
386+
const acceptTx = await linguo.acceptTranslation(0)
367387
const newBalance = await web3.eth.getBalance(translator)
388+
389+
assert.equal(
390+
acceptTx.logs[0].event,
391+
'TaskResolved',
392+
'TaskResolved event was not emitted'
393+
)
394+
368395
assert.equal(
369396
newBalance.toString(),
370397
oldBalance
@@ -398,7 +425,7 @@ contract('Linguo', function(accounts) {
398425
await expectThrow(linguo.acceptTranslation(0))
399426
})
400427

401-
it('Should set correct values in contract and in despute after task has been challenged', async () => {
428+
it('Should set correct values in contract and in dispute and emit TranslationChallenged event after task has been challenged', async () => {
402429
let task
403430
const requiredDeposit = (await linguo.getDepositValue(0)).toNumber()
404431

@@ -413,10 +440,17 @@ contract('Linguo', function(accounts) {
413440
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
414441
const challengerDeposit =
415442
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
416-
await linguo.challengeTranslation(0, {
443+
const challengeTx = await linguo.challengeTranslation(0, {
417444
from: challenger,
418445
value: challengerDeposit
419446
})
447+
448+
assert.equal(
449+
challengeTx.logs[1].event,
450+
'TranslationChallenged',
451+
'TranslationChallenged event was not emitted'
452+
)
453+
420454
// get task info again because of updated values
421455
task = await linguo.tasks(0)
422456
const taskInfo = await linguo.getTaskParties(0)

0 commit comments

Comments
 (0)