-
Notifications
You must be signed in to change notification settings - Fork 163
/
diesel-price-test.js
79 lines (71 loc) · 2 KB
/
diesel-price-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const {
PREFIX,
waitForEvent
} = require('./utils')
const Web3 = require('web3')
const diesel = artifacts.require('./DieselPrice.sol')
const web3 = new Web3(new Web3.providers.WebsocketProvider('ws://localhost:9545'))
contract('Diesel Price Tests', accounts => {
let contractPrice
const gasAmt = 3e6
const address = accounts[0]
beforeEach(async () => (
{ contract } = await diesel.deployed(),
{ methods, events } = new web3.eth.Contract(
contract._jsonInterface,
contract._address
)
))
it('Should have logged a new Provable query', async () => {
const {
returnValues: {
description
}
} = await waitForEvent(events.LogNewProvableQuery)
assert.strictEqual(
description,
'Provable query was sent, standing by for the answer...',
'Provable query incorrectly logged!'
)
})
it('Callback should have logged a new diesel price', async () => {
const {
returnValues: {
price
}
} = await waitForEvent(events.LogNewDieselPrice)
contractPrice = price * 100
assert.isAbove(
parseInt(price),
0,
'A price should have been retrieved from Provable call!'
)
})
it('Should set diesel price correctly in contract', async () => {
const queriedPrice = await methods
.dieselPriceUSD()
.call()
assert.strictEqual(
parseInt(contractPrice),
parseInt(queriedPrice),
'Contract\'s diesel price not set correctly!'
)
})
it('Should revert on second query attempt due to lack of funds', async () => {
const expErr = 'revert'
try {
await methods
.update()
.send({
from: address,
gas: gasAmt
})
assert.fail('Update transaction should not have succeeded!')
} catch (e) {
assert.isTrue(
e.message.startsWith(`${PREFIX}${expErr}`),
`Expected ${expErr} but got ${e.message} instead!`
)
}
})
})