Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
run format
Browse files Browse the repository at this point in the history
  • Loading branch information
cds-amal committed Jan 22, 2019
1 parent 11749fc commit f211093
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 17 deletions.
7 changes: 6 additions & 1 deletion src/blocks/blocksSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ function * callCreateBlockChannel ({ drizzle, web3, syncAlways }) {
* Poll for Blocks
*/

export function createBlockPollChannel ({ drizzle, interval, web3, syncAlways }) {
export function createBlockPollChannel ({
drizzle,
interval,
web3,
syncAlways
}) {
return eventChannel(emit => {
const blockTracker = new BlockTracker({
provider: web3.currentProvider,
Expand Down
6 changes: 5 additions & 1 deletion src/contracts/contractsSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ export function * instantiateContract ({
* Events
*/

export function createContractEventChannel ({ contract, eventName, eventOptions }) {
export function createContractEventChannel ({
contract,
eventName,
eventOptions
}) {
const name = contract.contractName

return eventChannel(emit => {
Expand Down
6 changes: 3 additions & 3 deletions src/web3/web3Saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var Web3 = require('web3')
* Initialization
*/

export function* initializeWeb3({ options }) {
export function * initializeWeb3 ({ options }) {
try {
var web3 = {}

Expand Down Expand Up @@ -65,7 +65,7 @@ export function* initializeWeb3({ options }) {
* Network ID
*/

export function* getNetworkId({ web3 }) {
export function * getNetworkId ({ web3 }) {
try {
const networkId = yield call(web3.eth.net.getId)

Expand All @@ -80,7 +80,7 @@ export function* getNetworkId({ web3 }) {
}
}

function* web3Saga() {
function * web3Saga () {
yield takeLatest('NETWORK_ID_FETCHING', getNetworkId)
}

Expand Down
6 changes: 4 additions & 2 deletions test/accounts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ describe('Accounts Saga', () => {
let web3, dispatchedActions, mockedStore

beforeAll(() => {
[mockedStore, dispatchedActions] = mockDrizzleStore()
;[mockedStore, dispatchedActions] = mockDrizzleStore()
web3 = getWeb3()
})

test('retrieves Metamask accounts', async () => {
await runSaga(mockedStore, getAccounts, { web3 }).done
expect(dispatchedActions[0]['accounts']).toHaveLength(global.accounts.length)
expect(dispatchedActions[0]['accounts']).toHaveLength(
global.accounts.length
)
})
})
27 changes: 22 additions & 5 deletions test/contracts/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ describe('Creates a contract', () => {
let mockedStore, web3, truffleArtifact, accounts

beforeEach(async () => {
({ web3, accounts, truffleArtifact } = await getWeb3Assets())
;[mockedStore] = mockDrizzleStore({ web3: { networkId: global.defaultNetworkId }, accounts })
;({ web3, accounts, truffleArtifact } = await getWeb3Assets())
;[mockedStore] = mockDrizzleStore({
web3: { networkId: global.defaultNetworkId },
accounts
})
})

test('with instantiateWeb3Contract Saga', async () => {
Expand All @@ -31,10 +34,20 @@ describe('Creates a contract', () => {
web3
}

const contractInstance = await runSaga(mockedStore, instantiateWeb3Contract, options).done
const contractInstance = await runSaga(
mockedStore,
instantiateWeb3Contract,
options
).done
expect(MockedDrizzleContract).toHaveBeenCalledTimes(1)

const expectedArgs = [mockedWeb3Contract, web3, mockedContractName, mockedStore, mockedContractEvents]
const expectedArgs = [
mockedWeb3Contract,
web3,
mockedContractName,
mockedStore,
mockedContractEvents
]
expect(MockedDrizzleContract).toHaveBeenCalledWith(...expectedArgs)

// It returns a Contract with the proper shape
Expand All @@ -54,7 +67,11 @@ describe('Creates a contract', () => {
const web3ContractCreator = jest.fn()
web3.eth.Contract = web3ContractCreator

const contractInstance = await runSaga(mockedStore, instantiateContract, options).done
const contractInstance = await runSaga(
mockedStore,
instantiateContract,
options
).done
expect(web3ContractCreator).toHaveBeenCalledTimes(1)
expect(MockedDrizzleContract).toHaveBeenCalledTimes(1)

Expand Down
7 changes: 4 additions & 3 deletions test/environments/ganache-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const NodeEnvironment = require('jest-environment-node')

const defaultSeed = 'drizzle'
const defaultNetworkId = 6777
const defaultAccounts = [ // based on default Mnemonic
const defaultAccounts = [
// based on default Mnemonic
'0x8aDB46251E9cd45b5027501766531825C04a2E06',
'0xb50CF9eD8f60605bEbB967776925f21Ba5c81D5D',
'0x7fC9AD8C7A3232Aed94d6C68728D22D722694824',
Expand All @@ -17,7 +18,7 @@ const defaultAccounts = [ // based on default Mnemonic
]

class GanacheEnvironment extends NodeEnvironment {
async setup() {
async setup () {
await super.setup()

// Startup a Ganache server.
Expand All @@ -31,7 +32,7 @@ class GanacheEnvironment extends NodeEnvironment {
this.global.defaultNetworkId = defaultNetworkId
}

async teardown() {
async teardown () {
// close provider engine gracefully
this.global.provider.close(() => {})
await super.teardown()
Expand Down
8 changes: 6 additions & 2 deletions test/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ const getWeb3Assets = async () => {
const accounts = await web3.eth.getAccounts() // use global.accounts?

const instance = new web3.eth.Contract(abi)
const deployedByteCode = await instance.deploy({ data: byteCode.object }).send({ from: accounts[0], gas: 150000 })
const deployedByteCode = await instance
.deploy({ data: byteCode.object })
.send({ from: accounts[0], gas: 150000 })

const truffleArtifact = {
contractName: 'TestContract',
abi,
byteCode,
deployedByteCode,
networks: { [global.defaultNetworkId]: { address: deployedByteCode._address } }
networks: {
[global.defaultNetworkId]: { address: deployedByteCode._address }
}
}

return { web3, accounts, truffleArtifact }
Expand Down

0 comments on commit f211093

Please sign in to comment.