Skip to content

Commit 9c155a6

Browse files
author
Chris Hatch
committed
fix intermittent test timing failure - use timelock 2 seconds instead of 1 second so that now != timelock in HTLC ERC20 newContract call
1 parent 88129e1 commit 9c155a6

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

test/htlc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ contract('HashedTimelock', accounts => {
213213
const contractId = txContractId(newContractTx)
214214

215215
// wait one second so we move past the timelock time
216-
return new Promise((resolve, reject) => {
216+
return new Promise((resolve, reject) =>
217217
setTimeout(async () => {
218218
// attempt to withdraw and check that it is not allowed
219219
try {
@@ -226,7 +226,7 @@ contract('HashedTimelock', accounts => {
226226
resolve()
227227
}
228228
}, 1000)
229-
})
229+
)
230230
})
231231

232232
it('refund() should pass after timelock expiry', async () => {
@@ -246,7 +246,7 @@ contract('HashedTimelock', accounts => {
246246
const contractId = txContractId(newContractTx)
247247

248248
// wait one second so we move past the timelock time
249-
return new Promise((resolve, reject) => {
249+
return new Promise((resolve, reject) =>
250250
setTimeout(async () => {
251251
try {
252252
const balBefore = web3.eth.getBalance(sender)
@@ -266,7 +266,7 @@ contract('HashedTimelock', accounts => {
266266
reject(err)
267267
}
268268
}, 1000)
269-
})
269+
)
270270
})
271271

272272
it('refund() should fail before the timelock expiry', async () => {

test/htlcERC20.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ contract('HashedTimelockERC20', accounts => {
195195
it('withdraw() should fail after timelock expiry', async () => {
196196
const hashPair = newSecretHashPair()
197197
const curBlkTime = web3.eth.getBlock('latest').timestamp
198-
const timelock1Second = curBlkTime + 1
198+
const timelock2Seconds = curBlkTime + 2
199199

200200
const newContractTx = await newContract({
201201
hashlock: hashPair.hash,
202-
timelock: timelock1Second,
202+
timelock: timelock2Seconds,
203203
})
204204
const contractId = txContractId(newContractTx)
205205

@@ -214,26 +214,26 @@ contract('HashedTimelockERC20', accounts => {
214214
)
215215
} catch (err) {
216216
assert.equal(err.message, REQUIRE_FAILED_MSG)
217-
resolve()
217+
resolve({message: 'success'})
218218
}
219-
}, 1000)
219+
}, 2000)
220220
})
221221
})
222222

223223
it('refund() should pass after timelock expiry', async () => {
224224
const hashPair = newSecretHashPair()
225225
const curBlkTime = web3.eth.getBlock('latest').timestamp
226-
const timelock1Second = curBlkTime + 1
226+
const timelock2Seconds = curBlkTime + 2
227227

228228
await token.approve(htlc.address, tokenAmount, {from: sender})
229229
const newContractTx = await newContract({
230-
timelock: timelock1Second,
230+
timelock: timelock2Seconds,
231231
hashlock: hashPair.hash,
232232
})
233233
const contractId = txContractId(newContractTx)
234234

235235
// wait one second so we move past the timelock time
236-
return new Promise((resolve, reject) => {
236+
return new Promise((resolve, reject) =>
237237
setTimeout(async () => {
238238
try {
239239
// attempt to get the refund now we've moved past the timelock time
@@ -255,8 +255,8 @@ contract('HashedTimelockERC20', accounts => {
255255
} catch (err) {
256256
reject(err)
257257
}
258-
}, 1000)
259-
})
258+
}, 2000)
259+
)
260260
})
261261

262262
it('refund() should fail before the timelock expiry', async () => {

0 commit comments

Comments
 (0)