Skip to content

Commit 09bb1ce

Browse files
fix(Linguo): updated test file
1 parent 145db5a commit 09bb1ce

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

contracts/standard/arbitration/Linguo.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @authors: [@unknownunknown1*]
2+
* @authors: [@unknownunknown1]
33
* @reviewers: [@ferittuncer*, @clesaege*, @satello*]
44
* @auditors: []
55
* @bounties: []

test/linguo.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
const {
66
increaseTime
77
} = require('openzeppelin-solidity/test/helpers/increaseTime')
8+
const { latestTime } = require('openzeppelin-solidity/test/helpers/latestTime')
89

910
const Linguo = artifacts.require('./Linguo.sol')
1011
const Arbitrator = artifacts.require(
@@ -37,6 +38,7 @@ contract('Linguo', function(accounts) {
3738
let linguo
3839
let MULTIPLIER_DIVISOR
3940
let taskTx
41+
let currentTime
4042
let secondsPassed
4143
beforeEach('initialize the contract', async function() {
4244
arbitrator = await Arbitrator.new(
@@ -62,16 +64,19 @@ contract('Linguo', function(accounts) {
6264
)
6365

6466
MULTIPLIER_DIVISOR = (await linguo.MULTIPLIER_DIVISOR()).toNumber()
67+
currentTime = await latestTime()
6568
taskTx = await linguo.createTask(
66-
submissionTimeout,
69+
currentTime + submissionTimeout,
6770
taskMinPrice,
6871
'TestMetaEvidence',
6972
{
7073
from: requester,
7174
value: taskMaxPrice
7275
}
7376
)
74-
secondsPassed = randomInt(submissionTimeout)
77+
// Because of time fluctuation the timeout stored in the contract can deviate a little from the variable value.
78+
// So subtract small amount to prevent the time increase going out of timeout range.
79+
secondsPassed = randomInt(submissionTimeout - 5)
7580
await increaseTime(secondsPassed)
7681
})
7782

@@ -88,10 +93,10 @@ contract('Linguo', function(accounts) {
8893

8994
it('Should set the correct values in newly created task and fire an event', async () => {
9095
const task = await linguo.tasks(0)
91-
92-
assert.equal(
93-
task[0].toNumber(),
94-
submissionTimeout,
96+
// An error up to 0.1% is allowed because of time fluctuation
97+
assert(
98+
Math.abs(submissionTimeout - task[0].toNumber()) <=
99+
submissionTimeout / 1000,
95100
'The submissionTimeout is not set up properly'
96101
)
97102
assert.equal(
@@ -151,12 +156,18 @@ contract('Linguo', function(accounts) {
151156
})
152157

153158
it('Should not be possible to deposit less than min price when creating a task', async () => {
159+
currentTime = await latestTime()
154160
// Invert max and min price to make sure it throws when less than min price is deposited.
155161
await expectThrow(
156-
linguo.createTask(submissionTimeout, taskMaxPrice, 'TestMetaEvidence', {
157-
from: requester,
158-
value: taskMinPrice
159-
})
162+
linguo.createTask(
163+
currentTime + submissionTimeout,
164+
taskMaxPrice,
165+
'TestMetaEvidence',
166+
{
167+
from: requester,
168+
value: taskMinPrice
169+
}
170+
)
160171
)
161172
})
162173

0 commit comments

Comments
 (0)