-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegration.test.js
56 lines (45 loc) · 1.48 KB
/
integration.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
'use strict'
const Web3 = require('web3')
const Ganache = require('ganache-core')
const Contract = require('truffle-contract')
const ExampleContract = require('../build/contracts/Example.json')
const Store = require('./store')
const provider = Ganache.provider()
const web3 = new Web3(provider)
describe('Integration', () => {
let example
let accounts
beforeAll(async () => {
accounts = await web3.eth.getAccounts()
const Example = new Contract(ExampleContract)
Example.setNetwork('dev')
Example.setProvider(provider)
example = await Example.new({ from: accounts[0] })
})
it('should instantiate', () => {
const store = new Store(provider, ExampleContract.abi, example.address)
expect(store).toBeInstanceOf(Store)
})
it('should subscribe to events', async () => {
const mock = jest.fn()
const store = new Store(provider, ExampleContract.abi, example.address)
const action = {
type: 'ValueUpdated',
}
store.apply(action, mock)
await example.setValue(2, { from: accounts[0] })
expect(mock).toHaveBeenCalledTimes(1)
})
it('should apply reducer', async () => {
const store = new Store(provider, ExampleContract.abi, example.address)
const action = {
type: 'ValueUpdated',
}
store.apply(
action,
(prev = { value: 0 }, action) => Object.assign({}, prev, { value: parseInt(action.value, 10) })
)
await example.setValue(2, { from: accounts[0] })
expect(store.state.value).toEqual(2)
})
})