From 534fe43322e80a01d3334a1d21fb3a09946fee1a Mon Sep 17 00:00:00 2001 From: Henrique Barcelos Date: Tue, 21 Apr 2020 18:48:25 -0300 Subject: [PATCH 1/2] feat: added getChallengeValue method --- contracts/standard/arbitration/Linguo.sol | 16 +++++++- test/linguo.js | 49 ++++++++--------------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/contracts/standard/arbitration/Linguo.sol b/contracts/standard/arbitration/Linguo.sol index ecf07730..907a229f 100644 --- a/contracts/standard/arbitration/Linguo.sol +++ b/contracts/standard/arbitration/Linguo.sol @@ -1,5 +1,5 @@ /** - * @authors: [@unknownunknown1] + * @authors: [@unknownunknown1*] * @reviewers: [@ferittuncer*, @clesaege*, @satello*, @hbarcelos] * @auditors: [] * @bounties: [] @@ -578,6 +578,20 @@ contract Linguo is Arbitrable { } } + /** @dev Gets the deposit required for challenging the translation. + * @param _taskID The ID of the task. + * @return deposit The challengers's deposit. + */ + function getChallengeValue(uint _taskID) public view returns (uint deposit) { + Task storage task = tasks[_taskID]; + if (now - task.lastInteraction > reviewTimeout || task.status != Status.AwaitingReview) { + deposit = NOT_PAYABLE_VALUE; + } else { + uint arbitrationCost = arbitrator.arbitrationCost(arbitratorExtraData); + deposit = arbitrationCost.addCap((challengeMultiplier.mulCap(task.requesterDeposit)) / MULTIPLIER_DIVISOR); + } + } + /** @dev Gets the current price of a specified task. * @param _taskID The ID of the task. * @return price The price of the task. diff --git a/test/linguo.js b/test/linguo.js index 2bf73894..24ea163d 100644 --- a/test/linguo.js +++ b/test/linguo.js @@ -412,11 +412,9 @@ contract('Linguo', function(accounts) { await linguo.submitTranslation(0, 'ipfs:/X', { from: translator }) await expectThrow(linguo.acceptTranslation(0)) - const task = await linguo.tasks(0) - const price = task[6].toNumber() // add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers const challengerDeposit = - arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000 + (await linguo.getChallengeValue(0)).toNumber() + 1000 await linguo.challengeTranslation(0, { from: challenger, value: challengerDeposit @@ -436,10 +434,9 @@ contract('Linguo', function(accounts) { await linguo.submitTranslation(0, 'ipfs:/X', { from: translator }) task = await linguo.tasks(0) - const price = task[6].toNumber() // add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers const challengerDeposit = - arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000 + (await linguo.getChallengeValue(0)).toNumber() + 1000 const challengeTx = await linguo.challengeTranslation(0, { from: challenger, value: challengerDeposit @@ -516,10 +513,9 @@ contract('Linguo', function(accounts) { await linguo.submitTranslation(0, 'ipfs:/X', { from: translator }) task = await linguo.tasks(0) - const price = task[6].toNumber() // add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers const challengerDeposit = - arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000 + (await linguo.getChallengeValue(0)).toNumber() + 1000 await linguo.challengeTranslation(0, { from: challenger, value: challengerDeposit @@ -574,11 +570,9 @@ contract('Linguo', function(accounts) { }) await linguo.submitTranslation(0, 'ipfs:/X', { from: translator }) - task = await linguo.tasks(0) - const price = task[6].toNumber() // add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers const challengerDeposit = - arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000 + (await linguo.getChallengeValue(0)).toNumber() + 1000 await linguo.challengeTranslation(0, { from: challenger, value: challengerDeposit @@ -633,10 +627,9 @@ contract('Linguo', function(accounts) { await linguo.submitTranslation(0, 'ipfs:/X', { from: translator }) task = await linguo.tasks(0) - const price = task[6].toNumber() // add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers const challengerDeposit = - arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000 + (await linguo.getChallengeValue(0)).toNumber() + 1000 await linguo.challengeTranslation(0, { from: challenger, value: challengerDeposit @@ -687,11 +680,9 @@ contract('Linguo', function(accounts) { }) await linguo.submitTranslation(0, 'ipfs:/X', { from: translator }) - const task = await linguo.tasks(0) - const price = task[6].toNumber() // add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers const challengerDeposit = - arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000 + (await linguo.getChallengeValue(0)).toNumber() + 1000 await linguo.challengeTranslation(0, { from: challenger, value: challengerDeposit @@ -805,11 +796,10 @@ contract('Linguo', function(accounts) { }) await linguo.submitTranslation(0, 'ipfs:/X', { from: translator }) - const task = await linguo.tasks(0) - const price = task[6].toNumber() + // DEL: const task = await linguo.tasks(0) // add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers const challengerDeposit = - arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000 + (await linguo.getChallengeValue(0)).toNumber() + 1000 await linguo.challengeTranslation(0, { from: challenger, value: challengerDeposit @@ -832,11 +822,10 @@ contract('Linguo', function(accounts) { }) await linguo.submitTranslation(0, 'ipfs:/X', { from: translator }) - const task = await linguo.tasks(0) - const price = task[6].toNumber() + // DEL: const task = await linguo.tasks(0) // add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers const challengerDeposit = - arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000 + (await linguo.getChallengeValue(0)).toNumber() + 1000 await linguo.challengeTranslation(0, { from: challenger, value: challengerDeposit @@ -862,10 +851,9 @@ contract('Linguo', function(accounts) { await linguo.submitTranslation(0, 'ipfs:/X', { from: translator }) task = await linguo.tasks(0) - const price = task[6].toNumber() // add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers const challengerDeposit = - arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000 + (await linguo.getChallengeValue(0)).toNumber() + 1000 await linguo.challengeTranslation(0, { from: challenger, value: challengerDeposit @@ -926,12 +914,11 @@ contract('Linguo', function(accounts) { }) await linguo.submitTranslation(0, 'ipfs:/X', { from: translator }) - const task = await linguo.tasks(0) - const price = task[6].toNumber() + // DEL: const task = await linguo.tasks(0) // add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers const challengerDeposit = - arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000 + (await linguo.getChallengeValue(0)).toNumber() + 1000 await linguo.challengeTranslation(0, { from: challenger, value: challengerDeposit @@ -1029,11 +1016,10 @@ contract('Linguo', function(accounts) { }) await linguo.submitTranslation(0, 'ipfs:/X', { from: translator }) - const task = await linguo.tasks(0) - const price = task[6].toNumber() + // DEL: const task = await linguo.tasks(0) // add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers const challengerDeposit = - arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000 + (await linguo.getChallengeValue(0)).toNumber() + 1000 await linguo.challengeTranslation(0, { from: challenger, value: challengerDeposit @@ -1113,11 +1099,10 @@ contract('Linguo', function(accounts) { }) await linguo.submitTranslation(0, 'ipfs:/X', { from: translator }) - const task = await linguo.tasks(0) - const price = task[6].toNumber() + // DEL: const task = await linguo.tasks(0) // add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers const challengerDeposit = - arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000 + (await linguo.getChallengeValue(0)).toNumber() + 1000 await linguo.challengeTranslation(0, { from: challenger, value: challengerDeposit From 2536256807578259a3327ea6e162ce49fc904774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Lesaege?= Date: Tue, 21 Apr 2020 23:33:21 +0100 Subject: [PATCH 2/2] Kept * because of view --- contracts/standard/arbitration/Linguo.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/standard/arbitration/Linguo.sol b/contracts/standard/arbitration/Linguo.sol index 907a229f..ee68a01b 100644 --- a/contracts/standard/arbitration/Linguo.sol +++ b/contracts/standard/arbitration/Linguo.sol @@ -1,5 +1,5 @@ /** - * @authors: [@unknownunknown1*] + * @authors: [@unknownunknown1] * @reviewers: [@ferittuncer*, @clesaege*, @satello*, @hbarcelos] * @auditors: [] * @bounties: []