Skip to content

Commit 0ab87a1

Browse files
authored
Merge pull request #1 from kleros/master
Updating to the latest commit as of 5th May 2020
2 parents 8b70f50 + bb1c9e5 commit 0ab87a1

File tree

2 files changed

+56
-33
lines changed

2 files changed

+56
-33
lines changed

contracts/standard/arbitration/Linguo.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,20 @@ contract Linguo is Arbitrable {
578578
}
579579
}
580580

581+
/** @dev Gets the deposit required for challenging the translation.
582+
* @param _taskID The ID of the task.
583+
* @return deposit The challengers's deposit.
584+
*/
585+
function getChallengeValue(uint _taskID) public view returns (uint deposit) {
586+
Task storage task = tasks[_taskID];
587+
if (now - task.lastInteraction > reviewTimeout || task.status != Status.AwaitingReview) {
588+
deposit = NOT_PAYABLE_VALUE;
589+
} else {
590+
uint arbitrationCost = arbitrator.arbitrationCost(arbitratorExtraData);
591+
deposit = arbitrationCost.addCap((challengeMultiplier.mulCap(task.requesterDeposit)) / MULTIPLIER_DIVISOR);
592+
}
593+
}
594+
581595
/** @dev Gets the current price of a specified task.
582596
* @param _taskID The ID of the task.
583597
* @return price The price of the task.

test/linguo.js

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,31 @@ contract('Linguo', function(accounts) {
209209
assert.equal(
210210
depositLinguo.toNumber(),
211211
deposit,
212-
'Contract returns incorrect required deposit afer submission timeout ended'
212+
'Contract returns incorrect required deposit after submission timeout ended'
213+
)
214+
})
215+
216+
it('Should return correct task price and assignment deposit when status is not `created`', async () => {
217+
const requiredDeposit = (await linguo.getDepositValue(0)).toNumber()
218+
await linguo.assignTask(0, {
219+
from: translator,
220+
value: requiredDeposit + 1e17
221+
})
222+
223+
const expectedTaskPrice = 0
224+
const actualTaskPrice = await linguo.getTaskPrice(0)
225+
assert.equal(
226+
actualTaskPrice,
227+
expectedTaskPrice,
228+
'Contract returns incorrect task price if status is not `created`'
229+
)
230+
231+
const expectedDeposit = NOT_PAYABLE_VALUE
232+
const actualDeposit = await linguo.getDepositValue(0)
233+
assert.equal(
234+
actualDeposit.toNumber(),
235+
expectedDeposit,
236+
'Contract returns incorrect required deposit if status is not `created`'
213237
)
214238
})
215239

@@ -412,11 +436,9 @@ contract('Linguo', function(accounts) {
412436
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
413437
await expectThrow(linguo.acceptTranslation(0))
414438

415-
const task = await linguo.tasks(0)
416-
const price = task[6].toNumber()
417439
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
418440
const challengerDeposit =
419-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
441+
(await linguo.getChallengeValue(0)).toNumber() + 1000
420442
await linguo.challengeTranslation(0, {
421443
from: challenger,
422444
value: challengerDeposit
@@ -436,10 +458,9 @@ contract('Linguo', function(accounts) {
436458
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
437459

438460
task = await linguo.tasks(0)
439-
const price = task[6].toNumber()
440461
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
441462
const challengerDeposit =
442-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
463+
(await linguo.getChallengeValue(0)).toNumber() + 1000
443464
const challengeTx = await linguo.challengeTranslation(0, {
444465
from: challenger,
445466
value: challengerDeposit
@@ -516,10 +537,9 @@ contract('Linguo', function(accounts) {
516537
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
517538

518539
task = await linguo.tasks(0)
519-
const price = task[6].toNumber()
520540
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
521541
const challengerDeposit =
522-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
542+
(await linguo.getChallengeValue(0)).toNumber() + 1000
523543
await linguo.challengeTranslation(0, {
524544
from: challenger,
525545
value: challengerDeposit
@@ -574,11 +594,9 @@ contract('Linguo', function(accounts) {
574594
})
575595
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
576596

577-
task = await linguo.tasks(0)
578-
const price = task[6].toNumber()
579597
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
580598
const challengerDeposit =
581-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
599+
(await linguo.getChallengeValue(0)).toNumber() + 1000
582600
await linguo.challengeTranslation(0, {
583601
from: challenger,
584602
value: challengerDeposit
@@ -633,10 +651,9 @@ contract('Linguo', function(accounts) {
633651
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
634652

635653
task = await linguo.tasks(0)
636-
const price = task[6].toNumber()
637654
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
638655
const challengerDeposit =
639-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
656+
(await linguo.getChallengeValue(0)).toNumber() + 1000
640657
await linguo.challengeTranslation(0, {
641658
from: challenger,
642659
value: challengerDeposit
@@ -687,11 +704,9 @@ contract('Linguo', function(accounts) {
687704
})
688705
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
689706

690-
const task = await linguo.tasks(0)
691-
const price = task[6].toNumber()
692707
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
693708
const challengerDeposit =
694-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
709+
(await linguo.getChallengeValue(0)).toNumber() + 1000
695710
await linguo.challengeTranslation(0, {
696711
from: challenger,
697712
value: challengerDeposit
@@ -805,11 +820,10 @@ contract('Linguo', function(accounts) {
805820
})
806821
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
807822

808-
const task = await linguo.tasks(0)
809-
const price = task[6].toNumber()
823+
// DEL: const task = await linguo.tasks(0)
810824
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
811825
const challengerDeposit =
812-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
826+
(await linguo.getChallengeValue(0)).toNumber() + 1000
813827
await linguo.challengeTranslation(0, {
814828
from: challenger,
815829
value: challengerDeposit
@@ -832,11 +846,10 @@ contract('Linguo', function(accounts) {
832846
})
833847
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
834848

835-
const task = await linguo.tasks(0)
836-
const price = task[6].toNumber()
849+
// DEL: const task = await linguo.tasks(0)
837850
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
838851
const challengerDeposit =
839-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
852+
(await linguo.getChallengeValue(0)).toNumber() + 1000
840853
await linguo.challengeTranslation(0, {
841854
from: challenger,
842855
value: challengerDeposit
@@ -862,10 +875,9 @@ contract('Linguo', function(accounts) {
862875
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
863876

864877
task = await linguo.tasks(0)
865-
const price = task[6].toNumber()
866878
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
867879
const challengerDeposit =
868-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
880+
(await linguo.getChallengeValue(0)).toNumber() + 1000
869881
await linguo.challengeTranslation(0, {
870882
from: challenger,
871883
value: challengerDeposit
@@ -926,12 +938,11 @@ contract('Linguo', function(accounts) {
926938
})
927939
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
928940

929-
const task = await linguo.tasks(0)
930-
const price = task[6].toNumber()
941+
// DEL: const task = await linguo.tasks(0)
931942

932943
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
933944
const challengerDeposit =
934-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
945+
(await linguo.getChallengeValue(0)).toNumber() + 1000
935946
await linguo.challengeTranslation(0, {
936947
from: challenger,
937948
value: challengerDeposit
@@ -1029,11 +1040,10 @@ contract('Linguo', function(accounts) {
10291040
})
10301041
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
10311042

1032-
const task = await linguo.tasks(0)
1033-
const price = task[6].toNumber()
1043+
// DEL: const task = await linguo.tasks(0)
10341044
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
10351045
const challengerDeposit =
1036-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
1046+
(await linguo.getChallengeValue(0)).toNumber() + 1000
10371047
await linguo.challengeTranslation(0, {
10381048
from: challenger,
10391049
value: challengerDeposit
@@ -1113,11 +1123,10 @@ contract('Linguo', function(accounts) {
11131123
})
11141124
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
11151125

1116-
const task = await linguo.tasks(0)
1117-
const price = task[6].toNumber()
1126+
// DEL: const task = await linguo.tasks(0)
11181127
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
11191128
const challengerDeposit =
1120-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
1129+
(await linguo.getChallengeValue(0)).toNumber() + 1000
11211130
await linguo.challengeTranslation(0, {
11221131
from: challenger,
11231132
value: challengerDeposit

0 commit comments

Comments
 (0)