Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Install the package with `npm install --save ethapi-js` from the [npm registry e
import EthApi from 'ethapi-js';

// do the setup
const transport = new EthApi.Transport.Http('127.0.0.1', 8545);
const transport = new EthApi.Transport.Http('http://localhost:8545'); // or .Ws('ws://localhost:8546')
const ethapi = new EthApi(transport);
```

Expand Down
10 changes: 5 additions & 5 deletions lib/contract/contract.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BigNumber from 'bignumber.js';

import { TEST_HOST, TEST_PORT, mockRpc } from '../../test/mockRpc';
import { TEST_HOST, TEST_PORT, mockHttp } from '../../test/mockRpc';

import EthAbi from 'ethabi-js';

Expand Down Expand Up @@ -174,7 +174,7 @@ describe('contract/Contract', () => {
let scope;

beforeEach(() => {
scope = mockRpc([{ method: 'eth_sendTransaction', reply: { result: ['hashId'] } }]);
scope = mockHttp([{ method: 'eth_sendTransaction', reply: { result: ['hashId'] } }]);
});

it('encodes options and mades an eth_sendTransaction call', () => {
Expand All @@ -195,7 +195,7 @@ describe('contract/Contract', () => {
let scope;

beforeEach(() => {
scope = mockRpc([{ method: 'eth_estimateGas', reply: { result: ['0x123'] } }]);
scope = mockHttp([{ method: 'eth_estimateGas', reply: { result: ['0x123'] } }]);
});

it('encodes options and mades an eth_estimateGas call', () => {
Expand All @@ -215,7 +215,7 @@ describe('contract/Contract', () => {

describe('call', () => {
it('encodes options and mades an eth_call call', () => {
const scope = mockRpc([{ method: 'eth_call', reply: { result: RETURN1 } }]);
const scope = mockHttp([{ method: 'eth_call', reply: { result: RETURN1 } }]);

return func
.call({ someExtras: 'foo' }, VALUES)
Expand All @@ -231,7 +231,7 @@ describe('contract/Contract', () => {
});

it('encodes options and mades an eth_call call (multiple returns)', () => {
const scope = mockRpc([{ method: 'eth_call', reply: { result: `${RETURN1}${RETURN2}` } }]);
const scope = mockHttp([{ method: 'eth_call', reply: { result: `${RETURN1}${RETURN2}` } }]);

return contract.functions[1]
.call({}, [])
Expand Down
5 changes: 3 additions & 2 deletions lib/ethApi.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Http from './transport/http';
import { Http, Ws } from './transport/index';
import Contract from './contract/index';

import { Db, Eth, Ethcore, Net, Personal, Shh, Trace, Web3 } from './rpc/index';
Expand Down Expand Up @@ -55,6 +55,7 @@ export default class EthApi {
static Contract = Contract

static Transport = {
Http: Http
Http: Http,
Ws: Ws
}
}
4 changes: 2 additions & 2 deletions lib/rpc/db/db.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TEST_HOST, TEST_PORT, mockRpc } from '../../../test/mockRpc';
import { TEST_HOST, TEST_PORT, mockHttp } from '../../../test/mockRpc';

import Http from '../../transport/http';
import Db from './db';
Expand All @@ -10,7 +10,7 @@ describe('lib/Db', () => {

describe('putHex', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'db_putHex', reply: { result: [] } }]);
scope = mockHttp([{ method: 'db_putHex', reply: { result: [] } }]);
});

it('formats the inputs correctly', () => {
Expand Down
3 changes: 2 additions & 1 deletion lib/rpc/eth/eth.e2e.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import ethapi from '../../../test/e2e/ethapi';
import { createHttpApi } from '../../../test/e2e/ethapi';
import { isAddress } from '../../../test/types';

describe('ethapi.eth', () => {
const ethapi = createHttpApi();
const address = '0x63cf90d3f0410092fc0fca41846f596223979195';

let latestBlockNumber;
Expand Down
46 changes: 23 additions & 23 deletions lib/rpc/eth/eth.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TEST_HOST, TEST_PORT, mockRpc } from '../../../test/mockRpc';
import { TEST_HOST, TEST_PORT, mockHttp } from '../../../test/mockRpc';
import { isBigNumber } from '../../../test/types';

import Http from '../../transport/http';
Expand All @@ -12,7 +12,7 @@ describe('lib/Eth', () => {

describe('accounts', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_accounts', reply: { result: [address.toLowerCase()] } }]);
scope = mockHttp([{ method: 'eth_accounts', reply: { result: [address.toLowerCase()] } }]);
});

it('returns a list of accounts, formatted', () => {
Expand All @@ -24,7 +24,7 @@ describe('lib/Eth', () => {

describe('blockNumber', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_blockNumber', reply: { result: '0x123456' } }]);
scope = mockHttp([{ method: 'eth_blockNumber', reply: { result: '0x123456' } }]);
});

it('returns the current blockNumber, formatted', () => {
Expand All @@ -37,7 +37,7 @@ describe('lib/Eth', () => {

describe('call', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_call', reply: { result: [] } }]);
scope = mockHttp([{ method: 'eth_call', reply: { result: [] } }]);
});

it('formats the input options & blockNumber', () => {
Expand All @@ -55,7 +55,7 @@ describe('lib/Eth', () => {

describe('coinbase', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_coinbase', reply: { result: address.toLowerCase() } }]);
scope = mockHttp([{ method: 'eth_coinbase', reply: { result: address.toLowerCase() } }]);
});

it('returns the coinbase, formatted', () => {
Expand All @@ -70,7 +70,7 @@ describe('lib/Eth', () => {

describe(method, () => {
beforeEach(() => {
scope = mockRpc([{ method: `eth_${method}`, reply: { result: '0x123' } }]);
scope = mockHttp([{ method: `eth_${method}`, reply: { result: '0x123' } }]);
});

it('formats the input as data, returns the output', () => {
Expand All @@ -84,7 +84,7 @@ describe('lib/Eth', () => {

describe('estimateGas', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_estimateGas', reply: { result: '0x123' } }]);
scope = mockHttp([{ method: 'eth_estimateGas', reply: { result: '0x123' } }]);
});

it('converts the options correctly', () => {
Expand All @@ -103,7 +103,7 @@ describe('lib/Eth', () => {

describe('gasPrice', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_gasPrice', reply: { result: '0x123' } }]);
scope = mockHttp([{ method: 'eth_gasPrice', reply: { result: '0x123' } }]);
});

it('returns the fomratted price', () => {
Expand All @@ -116,7 +116,7 @@ describe('lib/Eth', () => {

describe('getBalance', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getBalance', reply: { result: '0x123' } }]);
scope = mockHttp([{ method: 'eth_getBalance', reply: { result: '0x123' } }]);
});

it('passes in the address (default blockNumber)', () => {
Expand All @@ -141,7 +141,7 @@ describe('lib/Eth', () => {

describe('getBlockByHash', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getBlockByHash', reply: { result: { miner: address.toLowerCase() } } }]);
scope = mockHttp([{ method: 'eth_getBlockByHash', reply: { result: { miner: address.toLowerCase() } } }]);
});

it('formats the input hash as a hash, default full', () => {
Expand All @@ -165,7 +165,7 @@ describe('lib/Eth', () => {

describe('getBlockByNumber', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getBlockByNumber', reply: { result: { miner: address.toLowerCase() } } }]);
scope = mockHttp([{ method: 'eth_getBlockByNumber', reply: { result: { miner: address.toLowerCase() } } }]);
});

it('assumes blockNumber latest & full false', () => {
Expand Down Expand Up @@ -195,7 +195,7 @@ describe('lib/Eth', () => {

describe('getBlockTransactionCountByHash', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getBlockTransactionCountByHash', reply: { result: '0x123' } }]);
scope = mockHttp([{ method: 'eth_getBlockTransactionCountByHash', reply: { result: '0x123' } }]);
});

it('formats input hash properly', () => {
Expand All @@ -214,7 +214,7 @@ describe('lib/Eth', () => {

describe('getBlockTransactionCountByNumber', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getBlockTransactionCountByNumber', reply: { result: '0x123' } }]);
scope = mockHttp([{ method: 'eth_getBlockTransactionCountByNumber', reply: { result: '0x123' } }]);
});

it('specified blockNumber latest when none specified', () => {
Expand All @@ -239,7 +239,7 @@ describe('lib/Eth', () => {

describe('getCode', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getCode', reply: { result: '0x1234567890' } }]);
scope = mockHttp([{ method: 'eth_getCode', reply: { result: '0x1234567890' } }]);
});

it('passes in the address (default blockNumber)', () => {
Expand All @@ -263,7 +263,7 @@ describe('lib/Eth', () => {

describe('getStorageAt', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getStorageAt', reply: { result: '0x1234567890' } }]);
scope = mockHttp([{ method: 'eth_getStorageAt', reply: { result: '0x1234567890' } }]);
});

it('passes in the address (default index& blockNumber)', () => {
Expand All @@ -287,7 +287,7 @@ describe('lib/Eth', () => {

describe('getTransactionByBlockHashAndIndex', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getTransactionByBlockHashAndIndex', reply: { result: { to: address.toLowerCase() } } }]);
scope = mockHttp([{ method: 'eth_getTransactionByBlockHashAndIndex', reply: { result: { to: address.toLowerCase() } } }]);
});

it('passes in the hash (default index)', () => {
Expand All @@ -311,7 +311,7 @@ describe('lib/Eth', () => {

describe('getTransactionByBlockNumberAndIndex', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getTransactionByBlockNumberAndIndex', reply: { result: { to: address.toLowerCase() } } }]);
scope = mockHttp([{ method: 'eth_getTransactionByBlockNumberAndIndex', reply: { result: { to: address.toLowerCase() } } }]);
});

it('passes in the default parameters', () => {
Expand All @@ -335,7 +335,7 @@ describe('lib/Eth', () => {

describe('getTransactionByHash', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getTransactionByHash', reply: { result: { to: address.toLowerCase() } } }]);
scope = mockHttp([{ method: 'eth_getTransactionByHash', reply: { result: { to: address.toLowerCase() } } }]);
});

it('passes in the hash', () => {
Expand All @@ -353,7 +353,7 @@ describe('lib/Eth', () => {

describe('getTransactionCount', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getTransactionCount', reply: { result: '0x123' } }]);
scope = mockHttp([{ method: 'eth_getTransactionCount', reply: { result: '0x123' } }]);
});

it('passes in the address (default blockNumber)', () => {
Expand All @@ -378,7 +378,7 @@ describe('lib/Eth', () => {

describe('getUncleByBlockHashAndIndex', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getUncleByBlockHashAndIndex', reply: { result: [] } }]);
scope = mockHttp([{ method: 'eth_getUncleByBlockHashAndIndex', reply: { result: [] } }]);
});

it('passes in the hash (default index)', () => {
Expand All @@ -396,7 +396,7 @@ describe('lib/Eth', () => {

describe('getUncleByBlockNumberAndIndex', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getUncleByBlockNumberAndIndex', reply: { result: [] } }]);
scope = mockHttp([{ method: 'eth_getUncleByBlockNumberAndIndex', reply: { result: [] } }]);
});

it('passes in the default parameters', () => {
Expand All @@ -414,7 +414,7 @@ describe('lib/Eth', () => {

describe('getUncleCountByBlockHash', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getUncleCountByBlockHash', reply: { result: '0x123' } }]);
scope = mockHttp([{ method: 'eth_getUncleCountByBlockHash', reply: { result: '0x123' } }]);
});

it('passes in the hash', () => {
Expand All @@ -433,7 +433,7 @@ describe('lib/Eth', () => {

describe('getUncleCountByBlockNumber', () => {
beforeEach(() => {
scope = mockRpc([{ method: 'eth_getUncleCountByBlockNumber', reply: { result: '0x123' } }]);
scope = mockHttp([{ method: 'eth_getUncleCountByBlockNumber', reply: { result: '0x123' } }]);
});

it('passes in the default parameters', () => {
Expand Down
4 changes: 3 additions & 1 deletion lib/rpc/ethcore/ethcore.e2e.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import ethapi from '../../../test/e2e/ethapi';
import { createHttpApi } from '../../../test/e2e/ethapi';

describe('ethapi.ethcore', () => {
const ethapi = createHttpApi();

describe('gasFloorTarget', () => {
it('returns and translates the target', () => {
return ethapi.ethcore.gasFloorTarget().then((value) => {
Expand Down
12 changes: 6 additions & 6 deletions lib/rpc/ethcore/ethcore.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TEST_HOST, TEST_PORT, mockRpc } from '../../../test/mockRpc';
import { TEST_HOST, TEST_PORT, mockHttp } from '../../../test/mockRpc';
import { isBigNumber } from '../../../test/types';

import Http from '../../transport/http';
Expand All @@ -9,7 +9,7 @@ const instance = new Ethcore(new Http(TEST_HOST, TEST_PORT));
describe('lib/Ethcore', () => {
describe('gasFloorTarget', () => {
it('returns the gasfloor, formatted', () => {
mockRpc([{ method: 'ethcore_gasFloorTarget', reply: { result: '0x123456' } }]);
mockHttp([{ method: 'ethcore_gasFloorTarget', reply: { result: '0x123456' } }]);

return instance.gasFloorTarget().then((count) => {
expect(isBigNumber(count)).to.be.true;
Expand All @@ -20,7 +20,7 @@ describe('lib/Ethcore', () => {

describe('minGasPrice', () => {
it('returns the min gasprice, formatted', () => {
mockRpc([{ method: 'ethcore_minGasPrice', reply: { result: '0x123456' } }]);
mockHttp([{ method: 'ethcore_minGasPrice', reply: { result: '0x123456' } }]);

return instance.minGasPrice().then((count) => {
expect(isBigNumber(count)).to.be.true;
Expand All @@ -31,7 +31,7 @@ describe('lib/Ethcore', () => {

describe('netMaxPeers', () => {
it('returns the max peers, formatted', () => {
mockRpc([{ method: 'ethcore_netMaxPeers', reply: { result: 25 } }]);
mockHttp([{ method: 'ethcore_netMaxPeers', reply: { result: 25 } }]);

return instance.netMaxPeers().then((count) => {
expect(isBigNumber(count)).to.be.true;
Expand All @@ -42,7 +42,7 @@ describe('lib/Ethcore', () => {

describe('netPort', () => {
it('returns the connected port, formatted', () => {
mockRpc([{ method: 'ethcore_netPort', reply: { result: 33030 } }]);
mockHttp([{ method: 'ethcore_netPort', reply: { result: 33030 } }]);

return instance.netPort().then((count) => {
expect(isBigNumber(count)).to.be.true;
Expand All @@ -53,7 +53,7 @@ describe('lib/Ethcore', () => {

describe('transactionsLimit', () => {
it('returns the tx limit, formatted', () => {
mockRpc([{ method: 'ethcore_transactionsLimit', reply: { result: 1024 } }]);
mockHttp([{ method: 'ethcore_transactionsLimit', reply: { result: 1024 } }]);

return instance.transactionsLimit().then((count) => {
expect(isBigNumber(count)).to.be.true;
Expand Down
4 changes: 3 additions & 1 deletion lib/rpc/net/net.e2e.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import ethapi from '../../../test/e2e/ethapi';
import { createHttpApi } from '../../../test/e2e/ethapi';
import { isBoolean } from '../../../test/types';

describe('ethapi.net', () => {
const ethapi = createHttpApi();

describe('listening', () => {
it('returns the listening status', () => {
return ethapi.net.listening().then((status) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/rpc/net/net.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TEST_HOST, TEST_PORT, mockRpc } from '../../../test/mockRpc';
import { TEST_HOST, TEST_PORT, mockHttp } from '../../../test/mockRpc';
import { isBigNumber } from '../../../test/types';

import Http from '../../transport/http';
Expand All @@ -9,7 +9,7 @@ const instance = new Net(new Http(TEST_HOST, TEST_PORT));
describe('lib/Net', () => {
describe('peerCount', () => {
it('returns the connected peers, formatted', () => {
mockRpc([{ method: 'net_peerCount', reply: { result: '0x123456' } }]);
mockHttp([{ method: 'net_peerCount', reply: { result: '0x123456' } }]);

return instance.peerCount().then((count) => {
expect(isBigNumber(count)).to.be.true;
Expand Down
3 changes: 2 additions & 1 deletion lib/rpc/personal/personal.e2e.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import ethapi from '../../../test/e2e/ethapi';
import { createHttpApi } from '../../../test/e2e/ethapi';
import { isAddress, isBoolean } from '../../../test/types';

describe.skip('ethapi.personal', () => {
const ethapi = createHttpApi();
const password = 'P@55word';
let address;

Expand Down
Loading