diff --git a/app/src/renderer/lcdClient.js b/app/src/renderer/lcdClient.js index 5799f223e1..8b6be7c21d 100644 --- a/app/src/renderer/lcdClient.js +++ b/app/src/renderer/lcdClient.js @@ -92,18 +92,12 @@ Object.assign(Client.prototype, { } }, - // Tendermint RPC - status: req('GET', '/tendermint/status'), - // staking - candidate: argReq('GET', '/query/stake/candidates'), + candidate: argReq('GET', '/query/stake/candidate'), candidates: req('GET', '/query/stake/candidates'), buildDelegate: req('POST', '/build/stake/delegate'), buildUnbond: req('POST', '/build/stake/unbond'), - bondingsByDelegator: argReq('GET', '/tx/bondings/delegator'), - bondingsByValidator: argReq('GET', '/tx/bondings/validator') - - // TODO: separate API registration for different modules + bondingsByDelegator: argReq('GET', '/query/stake/delegator') }) module.exports = Client diff --git a/app/src/renderer/vuex/modules/delegates.js b/app/src/renderer/vuex/modules/delegates.js index 12523c9f29..651463e422 100644 --- a/app/src/renderer/vuex/modules/delegates.js +++ b/app/src/renderer/vuex/modules/delegates.js @@ -1,4 +1,3 @@ -import axios from 'axios' import indicateValidators from 'scripts/indicateValidators' export default ({ dispatch, node }) => { @@ -41,9 +40,7 @@ export default ({ dispatch, node }) => { return state.delegates }, async getDelegate ({ commit }, pubkey) { - let delegate = (await axios.get(`http://localhost:${node.relayPort}/query/stake/candidate/${pubkey.data}`)).data.data - // TODO move into cosmos-sdk - // let delegate = (await node.candidate(pubkeyToString(pubkey))).data + let delegate = (await node.candidate(pubkey.data)).data delegate.isValidator = false commit('addDelegate', delegate) return delegate diff --git a/app/src/renderer/vuex/modules/delegation.js b/app/src/renderer/vuex/modules/delegation.js index a3680ce6a5..015f2ba975 100644 --- a/app/src/renderer/vuex/modules/delegation.js +++ b/app/src/renderer/vuex/modules/delegation.js @@ -1,5 +1,3 @@ -import axios from 'axios' - export default ({ commit, node }) => { let state = { loading: false, @@ -63,8 +61,7 @@ export default ({ commit, node }) => { }, // load committed delegation from LCD async getBondedDelegate ({ commit }, { address, pubkey }) { - // TODO move into cosmos-sdk - let bond = (await axios.get(`http://localhost:${node.relayPort}/query/stake/delegator/${address}/${pubkey}`)).data.data + let bond = (await node.bondingsByDelegator([address, pubkey])).data commit('setCommittedDelegation', { candidateId: bond.PubKey.data, value: bond.Shares }) }, walletDelegate ({ dispatch }, args) { diff --git a/tasks/testnet.js b/tasks/testnet.js index 832fc9d67e..678446dd93 100644 --- a/tasks/testnet.js +++ b/tasks/testnet.js @@ -24,17 +24,17 @@ async function main () { // save to tmp dir and pass to app dev runner console.log(`fetching genesis for network "${network}"`) let genesisJson = await get(`https://github.com/tendermint/testnets/raw/master/${network}/gaia/genesis.json`) - .catch(e => { - throw new Error(`Can't load genesis.json: ${e.message}`) - }) + .catch(e => { + throw new Error(`Can't load genesis.json: ${e.message}`) + }) let configToml = await get(`https://github.com/tendermint/testnets/raw/master/${network}/gaia/config.toml`) - .catch(e => { - throw new Error(`Can't load config.toml: ${e.message}`) - }) + .catch(e => { + throw new Error(`Can't load config.toml: ${e.message}`) + }) let gaiaVersionTxt = await get(`https://github.com/tendermint/testnets/raw/master/${network}/gaia/gaiaversion.txt`) - .catch(e => { - throw new Error(`Can't load config.toml: ${e.message}`) - }) + .catch(e => { + throw new Error(`Can't load config.toml: ${e.message}`) + }) let path = join(tmpdir(), Math.random().toString(36).slice(2)) mkdirp(path) write(join(path, 'genesis.json'), genesisJson) diff --git a/test/unit/helpers/node_mock.js b/test/unit/helpers/node_mock.js index 68b68f35ed..d3857918a1 100644 --- a/test/unit/helpers/node_mock.js +++ b/test/unit/helpers/node_mock.js @@ -30,6 +30,18 @@ module.exports = { deliver_tx: { code: 0 } }), sign: () => Promise.resolve(null), + candidate: () => Promise.resolve({ + data: { + pub_key: { data: '' }, + description: { name: 'test' } + } + }), + bondingsByDelegator: () => Promise.resolve({ + data: { + PubKey: { data: '' }, + Shares: 0 + } + }), // RPC rpc: { diff --git a/test/unit/specs/components/staking/__snapshots__/PageDelegates.spec.js.snap b/test/unit/specs/components/staking/__snapshots__/PageDelegates.spec.js.snap index e0b010ff7f..d31c15c8a6 100644 --- a/test/unit/specs/components/staking/__snapshots__/PageDelegates.spec.js.snap +++ b/test/unit/specs/components/staking/__snapshots__/PageDelegates.spec.js.snap @@ -247,7 +247,7 @@ exports[`PageDelegates should filter the delegates 1`] = `
+
+
+
+
+
+
`; diff --git a/test/unit/specs/lcdClient.spec.js b/test/unit/specs/lcdClient.spec.js index 8c0b0b280f..48136438a5 100644 --- a/test/unit/specs/lcdClient.spec.js +++ b/test/unit/specs/lcdClient.spec.js @@ -8,10 +8,10 @@ describe('LCD Client', () => { axios.get = jest.fn() .mockReturnValueOnce(Promise.resolve({ data: { foo: 'bar' } })) - let res = await client.status() + let res = await client.listKeys() expect(res).toEqual({ foo: 'bar' }) expect(axios.get.mock.calls[0]).toEqual([ - 'http://localhost:8998/tendermint/status', + 'http://localhost:8998/keys', undefined ]) }) @@ -35,7 +35,7 @@ describe('LCD Client', () => { let res = await client.bondingsByDelegator([ 'foo', 'bar' ]) expect(res).toEqual({ foo: 'bar' }) expect(axios.get.mock.calls[0]).toEqual([ - 'http://localhost:8998/tx/bondings/delegator/foo/bar', + 'http://localhost:8998/query/stake/delegator/foo/bar', undefined ]) }) @@ -76,13 +76,13 @@ describe('LCD Client', () => { })) try { - await client.status() + await await client.listKeys() } catch (err) { expect(err.message).toBe('foo') expect(err.code).toBe(123) } expect(axios.get.mock.calls[0]).toEqual([ - 'http://localhost:8998/tendermint/status', + 'http://localhost:8998/keys', undefined ]) }) diff --git a/test/unit/specs/store/delegates.spec.js b/test/unit/specs/store/delegates.spec.js index 8bee389824..cc1bb939ea 100644 --- a/test/unit/specs/store/delegates.spec.js +++ b/test/unit/specs/store/delegates.spec.js @@ -1,7 +1,5 @@ import setup from '../../helpers/vuex-setup' -let axios = require('axios') - let instance = setup() describe('Module: Delegates', () => { @@ -36,37 +34,29 @@ describe('Module: Delegates', () => { }) it('fetches a candidate', async () => { - axios.get = jest.fn() + node.candidate = jest.fn() .mockReturnValueOnce(Promise.resolve({ data: { - data: { - pub_key: { data: 'foo' }, - test: 123 - } + pub_key: { data: 'foo' }, + test: 123 } })) - await store.dispatch('getDelegate', { data: 'foo' }) - expect(axios.get.mock.calls[0][0]).toBe('http://localhost:9060/query/stake/candidate/foo') expect(store.state.delegates.delegates[0].test).toBe(123) }) it('fetches all candidates', async () => { - axios.get = jest.fn() + node.candidate = jest.fn() .mockReturnValueOnce(Promise.resolve({ data: { - data: { - pub_key: { data: 'foo' }, - test: 123 - } + pub_key: { data: 'foo' }, + test: 123 } })) .mockReturnValueOnce(Promise.resolve({ data: { - data: { - pub_key: { data: 'bar' }, - test: 456 - } + pub_key: { data: 'bar' }, + test: 456 } })) @@ -79,8 +69,6 @@ describe('Module: Delegates', () => { }) await store.dispatch('getDelegates') - expect(axios.get.mock.calls[0][0]).toBe('http://localhost:9060/query/stake/candidate/foo') - expect(axios.get.mock.calls[1][0]).toBe('http://localhost:9060/query/stake/candidate/bar') expect(store.state.delegates.delegates[0].test).toBe(123) expect(store.state.delegates.delegates[1].test).toBe(456) }) diff --git a/test/unit/specs/store/delegation.spec.js b/test/unit/specs/store/delegation.spec.js index 18e5fc0b83..203462fe79 100644 --- a/test/unit/specs/store/delegation.spec.js +++ b/test/unit/specs/store/delegation.spec.js @@ -1,7 +1,5 @@ import setup from '../../helpers/vuex-setup' -let axios = require('axios') - let instance = setup() describe('Module: Delegations', () => { @@ -65,21 +63,17 @@ describe('Module: Delegations', () => { }) it('fetches bonded delegates', async () => { - axios.get = jest.fn() + node.bondingsByDelegator = jest.fn() .mockReturnValueOnce({ data: { - data: { - PubKey: { data: 'foo' }, - Shares: 123 - } + PubKey: { data: 'foo' }, + Shares: 123 } }) .mockReturnValueOnce({ data: { - data: { - PubKey: { data: 'bar' }, - Shares: 456 - } + PubKey: { data: 'bar' }, + Shares: 456 } }) @@ -87,8 +81,8 @@ describe('Module: Delegations', () => { { pub_key: { data: 'foo' } }, { pub_key: { data: 'bar' } } ]) - expect(axios.get.mock.calls[0][0]).toEqual('http://localhost:9060/query/stake/delegator/someaddress/foo') - expect(axios.get.mock.calls[1][0]).toEqual('http://localhost:9060/query/stake/delegator/someaddress/bar') + expect(node.bondingsByDelegator.mock.calls[0][0]).toEqual(['someaddress', 'foo']) + expect(node.bondingsByDelegator.mock.calls[1][0]).toEqual(['someaddress', 'bar']) expect(store.state.delegation.committedDelegates).toEqual({ foo: 123,