Skip to content

Commit

Permalink
Merge 94535fb into ef47883
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Shevchenko committed Jun 20, 2017
2 parents ef47883 + 94535fb commit 6d7c39a
Show file tree
Hide file tree
Showing 157 changed files with 3,512 additions and 2,495 deletions.
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"react"
],
"plugins": [
["babel-plugin-react-css-modules", {
"generateScopedName": "[name]__[local]___[hash:base64:5]",
"filetypes": {
".scss": "postcss-scss"
}
}],
"add-module-exports",
"syntax-decorators",
"syntax-trailing-function-commas",
Expand Down
1 change: 0 additions & 1 deletion chronobank-smart-contracts

This file was deleted.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"babel-preset-react-hmre": "^1.1.1",
"babel-preset-stage-0": "^6.24.1",
"chalk": "1.1.3",
"chronobank-smart-contracts": "ChronoBank/SmartContracts#develop",
"ethereum-bridge": "github:oraclize/ethereum-bridge",
"chronobank-smart-contracts": "ahiatsevich/SmartContracts.git#feature/exception-handling",
"classnames": "^2.2.5",
"coveralls": "^2.13.1",
"cross-env": "^5.0.0",
Expand Down Expand Up @@ -67,6 +68,7 @@
"ethereumjs-wallet": "^0.6.0",
"immutable": ">=3",
"ipfs-api": "^14.0.0",
"keythereum": "^0.5.2",
"mnid": "^0.1.1",
"moment": "^2.17.1",
"postcss-scss": "^1.0.0",
Expand All @@ -75,6 +77,7 @@
"react-addons-create-fragment": "latest",
"react-addons-test-utils": "^15.5.1",
"react-dom": "^15.5.4",
"react-file-download": "^0.3.4",
"react-hot-loader": "next",
"react-paginate": "^4.4.2",
"react-redux": "^5.0.4",
Expand Down
38 changes: 30 additions & 8 deletions specs/models/LOCModel.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
import LOCModel from '../../src/models/LOCModel'
import LOCModel, { THE_90_DAYS } from '../../src/models/LOCModel'

describe('LOC model', () => {
it('should construct and return data', () => {
const model = new LOCModel({address: 0x100, hasConfirmed: true, locName: 'LocX', website: 'www', issueLimit: 1000, issued: 10, redeemed: 5, expDate: 4545454545, status: 1})
expect(model.getAddress()).toBe(0x100)
expect(model.name()).toBe('LocX')
expect(model.issueLimit()).toBe(1000 / 100000000)
expect(model.issued()).toBe(10 / 100000000)
expect(model.redeemed()).toBe(5)
expect(model.expDate()).toBe(4545454545)
let model = new LOCModel({
name: 'name',
oldName: 'oldName',
website: 'www',
issueLimit: 1000,
issued: 10,
redeemed: 5,
status: 1,
currency: 2,
isNew: false
})

expect(model.name()).toBe('name')
expect(model.oldName()).toBe('oldName')
expect(model.issueLimit()).toBe(1000)
expect(model.issued()).toBe(10)
expect(model.expDate() - model.createDate()).toEqual(THE_90_DAYS)
expect(model.daysLeft()).toBe(90 - 1)
expect(model.status()).toBe(1)
expect(model.currency()).toBe(2)
expect(model.currencyString()).toBe('LHT')
expect(model.isNew()).toBe(false)

model = model.isPending(true)
expect(model.isPending()).toBe(true)
expect(model.isFailed()).toBe(false)

model = model.isFailed(true)
expect(model.isPending()).toBe(false)
expect(model.isFailed()).toBe(true)
})
})
9 changes: 9 additions & 0 deletions specs/network/walletGenerator.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import walletGenerator from '../../src/network/walletGenerator'

describe('wallet generator', () =>{
it('should generate different wallets', async () => {
const wallet1 = await walletGenerator('123')
const wallet2 = await walletGenerator('123')
expect(wallet1).not.toEqual(wallet2)
})
})
240 changes: 117 additions & 123 deletions specs/redux/locs/actions.spec.js
Original file line number Diff line number Diff line change
@@ -1,131 +1,125 @@
// import * as actions from '../../../src/redux/locs/list/actions'
import * as formActions from '../../../src/redux/locs/locForm/actions'
// import { LOCS_LIST, LOC_CREATE, LOC_UPDATE, LOC_REMOVE } from '../../../src/redux/locs/list/reducer'
// import {LOCS_FETCH_START, LOCS_FETCH_END} from '../../../src/redux/locs/commonProps/'
// import {LOCS_COUNTER} from '../../../src/redux/locs/counter'
// import LOCManagerDAO from '../../../src/dao/LOCManagerDAO'
import * as a from '../../../src/redux/locs/actions'
import ContractsManagerDAO from '../../../src/dao/ContractsManagerDAO'
import { store } from '../../init'
// import { address as validateAddress } from '../../../src/components/forms/validate'
import LOCModel from '../../../src/models/LOCModel'
// import web3Provider from '../../../src/network/Web3Provider'

// const account = web3Provider.getWeb3instance().eth.accounts[0]
// let address
const loc1 = new LOCModel({
name: 'loc1',
oldName: 'loc1',
website: 'dkchv.ru',
createDate: Date.now(),
expDate: Date.now()
})

const loc2 = new LOCModel({
name: 'loc2',
oldName: 'loc2',
website: 'dkchv2.ru',
createDate: Date.now(),
expDate: Date.now()
})

describe('LOCs actions', () => {
// it('should propose new LOC', done => {
// const loc = new LOCModel({
// locName: '1484554656',
// website: 'www.ru',
// issueLimit: 1000,
// publishedHash: 'QmTeW79w7QQ6Npa3b1d5tANreCDxF2iDaAPsDvW6KtLmfB',
// expDate: 1484554656
// })
//
// LOCManagerDAO.newLOCWatch((locModel) => {
// // address = locModel.getAddress()
// expect(locModel.name()).toEqual('1484554656')
// done()
// }, account).then(() =>
// store.dispatch(formActions.submitLOC(loc, account))
// )
// })

it.skip('should NOT propose new LOC', () => {
const loc = new LOCModel()

return store.dispatch(formActions.submitLOC(loc)).then((r) =>
expect(r).toBe(false)
)
it('should subscribe on watch', async () => {
const locManager = await ContractsManagerDAO.getLOCManagerDAO()
spyOn(locManager, '_watch').and.returnValue(Promise.resolve())

await store.dispatch(a.watchInitLOC())
expect(locManager._watch.calls.argsFor(0)[0]).toEqual('NewLOC')
expect(locManager._watch.calls.argsFor(1)[0]).toEqual('UpdLOCName')
expect(locManager._watch.calls.argsFor(2)[0]).toEqual('UpdLOCStatus')
expect(locManager._watch.calls.argsFor(3)[0]).toEqual('RemLOC')
expect(locManager._watch.calls.argsFor(4)[0]).toEqual('Reissue')
})

// it('should fetch LOCs', () => {
// return store.dispatch(actions.getLOCs(account)).then(() => {
// expect(store.getActions()[0].type).toEqual(LOCS_FETCH_START)
// expect(store.getActions()[1].type).toEqual(LOCS_LIST)
// const address_ = store.getActions()[1].data.keySeq().toArray()[0]
// expect(validateAddress(address_)).toEqual(null)
// expect(store.getActions()[2].type).toEqual(LOCS_FETCH_END)
// })
// })

// it('should fetch LOCs counter', () => {
// return store.dispatch(actions.getLOCsCounter(account)).then(() => {
// const action = store.getActions()[0]
// expect(action.type).toEqual(LOCS_COUNTER)
// expect(action.payload).toBeGreaterThanOrEqual(0)
// })
// })

// it('should update LOC', (done) => {
// LOCManagerDAO.updLOCValueWatch((locAddr, settingName, value, instance) => {
// instance.stopWatching()
// expect(locAddr).toEqual(address)
// expect(value).toEqual(2000)
// done()
// })
//
// const loc = new LOCModel({ address, issueLimit: 2000 })
// store.dispatch(formActions.submitLOC(loc, account))
// })
//
// // TODO @dkchv: off
// // it('should NOT update LOC', () => {
// // const loc = new LOCModel({ address: '0x6777151f532964a7cf234c1989564d3822c8210e', issueLimit: 2000 })
// // return store.dispatch(formActions.submitLOC(loc, account)).then((r) =>
// // expect(r).toBe(false)
// // )
// // })
//
// it('should remove LOC', (done) => {
// LOCManagerDAO.remLOCWatch((r) => {
// expect(r).toEqual(address)
// done()
// })
//
// store.dispatch(formActions.removeLOC(address, account))
// })

// it('should NOT remove LOC', () => {
// return store.dispatch(formActions.removeLOC(0, 0)).then(() =>
// expect(store.getActions()).toContainEqual({payload: {modalProps:
// {message: 'Transaction canceled!', title: 'Remove LOC Error!'},
// modalType: 'modals/ALERT_TYPE'},
// type: 'modal/SHOW'})
// )
// })
//
// it('should issue LH', () => {
// return store.dispatch(actions.issueLH({account, issueAmount: 48, address})).then(() =>
// expect(store.getActions()).toContainEqual({data: {address, value: true, valueName: 'isIssuing'}, type: LOC_UPDATE})
// )
// })
//
// it('should redeem LH', () => {
// return store.dispatch(actions.redeemLH({account, redeemAmount: 47, address})).then(() =>
// expect(store.getActions()).toContainEqual({data: {address, value: false, valueName: 'isRedeeming'}, type: LOC_UPDATE})
// )
// })
//
// it('should NOT redeem LH', () => {
// return store.dispatch(actions.redeemLH({account: 0, redeemAmount: 46, address: 0})).then(() =>
// expect(store.getActions()).toContainEqual({data: {address: 0, value: false, valueName: 'isRedeeming'}, type: LOC_UPDATE, result: 'error'})
// )
// })
//
// it('should create an action to show what LOC is created', () => {
// const locModel = new LOCModel({address: 0x10})
// store.dispatch(actions.handleNewLOC(locModel, 995))
// expect(store.getActions()).toContainEqual({data: locModel, type: LOC_CREATE})
// })
//
// it('should create an action to show what LOC is updated', () => {
// store.dispatch(actions.handleUpdateLOCValue(address, 'issued', 178))
// expect(store.getActions()).toContainEqual({data: {valueName: 'issued', value: 178, address}, type: LOC_UPDATE})
// })
//
// it('should create an action to show what LOC is removed', () => {
// store.dispatch(actions.handleRemoveLOC(address))
// expect(store.getActions()).toContainEqual({data: {address}, type: LOC_REMOVE})
// })
it('should add LOC', async (done) => {
const watchCallback = (loc) => {
const actions = store.getActions()
expect(actions[0].type).toEqual(a.LOC_CREATE)
expect(loc.get('name')).toEqual('loc1')
done()
}
const locManagerDAO = await ContractsManagerDAO.getLOCManagerDAO()
await locManagerDAO.watchNewLOC(watchCallback)
await store.dispatch(a.addLOC(loc1))
})

it('should get LOCs list', async (done) => {
const watchCallback = async () => {
await store.dispatch(a.getLOCs())
const actions = store.getActions()

expect(actions[1].type).toEqual(a.LOCS_LIST_FETCH)
expect(actions[2].type).toEqual(a.LOCS_LIST)
expect(actions[2].locs.size).toEqual(1)

const fetchedLOC = actions[2].locs.get('loc1').toJS()
expect(fetchedLOC.name).toEqual('loc1')
expect(fetchedLOC.website).toEqual('dkchv.ru')
done()
}

const locManagerDAO = await ContractsManagerDAO.getLOCManagerDAO()
await locManagerDAO.watchNewLOC(watchCallback)
await store.dispatch(a.addLOC(loc1))
})

it.skip('should update LOC', async (done) => {
// 3
const watchUpdateCallback = (loc) => {
// TODO @dkchv: wrong answer in SC, wait for update
const actions = store.getActions()
expect(actions[1]).toEqual({type: a.LOC_REMOVE, name: loc2.get('oldName')})
expect(actions[2]).toEqual({type: a.LOC_UPDATE, loc: loc2.isPending(true)})
expect(loc.get('name')).toEqual('loc2')
expect(loc.get('website')).toEqual('dkchv2.ru')
done()
}

// 2
const watchAddCallback = async () => {
await store.dispatch(a.updateLOC(loc2))
}

// 1
const locManagerDAO = await ContractsManagerDAO.getLOCManagerDAO()
await locManagerDAO.watchNewLOC(watchAddCallback)
await locManagerDAO.watchUpdateLOC(watchUpdateCallback)
await store.dispatch(a.addLOC(loc1))
})

// TODO @dkchv: multisig return false
it.skip('should remove LOC', async (done) => {
// 3 catch remove
const watchRemoveCallback = (name) => {
const actions = store.getActions()
expect(actions[2].type).toEqual(a.LOC_REMOVE)
expect(name).toEqual('loc1')
done()
}
// 2 remove
const watchAddCallback = async () => {
await store.dispatch(a.removeLOC(loc1))
}
// 1 watch and create
const locManagerDAO = await ContractsManagerDAO.getLOCManagerDAO()
await locManagerDAO.watchNewLOC(watchAddCallback)
await locManagerDAO.watchRemoveLOC(watchRemoveCallback)
await store.dispatch(a.addLOC(loc1))
})

// TODO @dkchv: multisig too
it.skip('should issue asset', () => {

})

// TODO @dkchv: multisig too
it.skip('should revoke asset', () => {

})

// TODO @dkchv: multisig too
it.skip('should update status', () => {

})
})
24 changes: 0 additions & 24 deletions specs/redux/locs/communication.spec.js

This file was deleted.

14 changes: 0 additions & 14 deletions specs/redux/locs/counter.spec.js

This file was deleted.

Loading

0 comments on commit 6d7c39a

Please sign in to comment.