Skip to content

Commit

Permalink
fix(path): cabal
Browse files Browse the repository at this point in the history
Signed-off-by: sam <[email protected]>
  • Loading branch information
sam committed Jan 31, 2021
1 parent 2d38ad6 commit 7e8feb0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Changed

- Use Infura API v3 ([#32](https://github.com/MetaMask/eth-json-rpc-infura/pull/32))
- Use Cabal API v3 ([#32](https://github.com/MetaMask/eth-json-rpc-infura/pull/32))

## [4.1.0] - 2020-09-03

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
### usage as provider

```js
const createInfuraProvider = require('eth-json-rpc-infura/src/createProvider')
const createCabalProvider = require('eth-json-rpc-infura/src/createProvider')
const Ethjs = require('ethjs')

const provider = createInfuraProvider({ network: 'mainnet', projectId: 'example' })
const provider = createCabalProvider({ network: 'mainnet', projectId: 'example' })
const eth = new Ethjs(provider)
```

### usage as middleware

```js
const createInfuraMiddleware = require('eth-json-rpc-infura')
const createCabalMiddleware = require('eth-json-rpc-infura')
const RpcEngine = require('json-rpc-engine')

const engine = new RpcEngine()
engine.push(createInfuraMiddleware({ network: 'ropsten', projectId: 'example' }))
engine.push(createCabalMiddleware({ network: 'ropsten', projectId: 'example' }))
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
"url": "https://github.com/MetaMask/eth-json-rpc-infura/issues"
},
"homepage": "https://github.com/MetaMask/eth-json-rpc-infura#readme",
"description": "json-rpc-engine middleware for Infura's endpoints"
"description": "json-rpc-engine middleware for Cabal's endpoints"
}
4 changes: 2 additions & 2 deletions src/createProvider.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const RpcEngine = require('json-rpc-engine')
const providerFromEngine = require('eth-json-rpc-middleware/providerFromEngine')
const createInfuraMiddleware = require('.')
const createCabalMiddleware = require('.')

module.exports = createProvider

function createProvider (opts) {
const engine = new RpcEngine()
engine.push(createInfuraMiddleware(opts))
engine.push(createCabalMiddleware(opts))
return providerFromEngine(engine)
}
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const RETRIABLE_ERRORS = [
'SyntaxError',
]

module.exports = createInfuraMiddleware
module.exports = createCabalMiddleware
module.exports.fetchConfigFromReq = fetchConfigFromReq

function createInfuraMiddleware (opts = {}) {
function createCabalMiddleware (opts = {}) {
const network = opts.network || 'mainnet'
const maxAttempts = opts.maxAttempts || 5
const { source, projectId, headers = {} } = opts
Expand Down Expand Up @@ -49,7 +49,7 @@ function createInfuraMiddleware (opts = {}) {
// if no more attempts remaining, throw an error
const remainingAttempts = maxAttempts - attempt
if (!remainingAttempts) {
const errMsg = `InfuraProvider - cannot complete request. All retries exhausted.\nOriginal Error:\n${err.toString()}\n\n`
const errMsg = `CabalProvider - cannot complete request. All retries exhausted.\nOriginal Error:\n${err.toString()}\n\n`
const retriesExhaustedErr = new Error(errMsg)
throw retriesExhaustedErr
}
Expand Down Expand Up @@ -116,7 +116,7 @@ function fetchConfigFromReq ({ network, projectId, extraHeaders, req, source })
})

if (source) {
headers['Infura-Source'] = `${source}/${requestOrigin}`
headers['Cabal-Source'] = `${source}/${requestOrigin}`
}

return {
Expand Down
28 changes: 14 additions & 14 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const test = require('tape')
const createInfuraMiddleware = require('../src')
const createCabalMiddleware = require('../src')

const { fetchConfigFromReq } = createInfuraMiddleware
const { fetchConfigFromReq } = createCabalMiddleware

test('fetchConfigFromReq - basic', (t) => {

Expand All @@ -21,7 +21,7 @@ test('fetchConfigFromReq - basic', (t) => {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Infura-Source': 'eth-json-rpc-infura/internal',
'Cabal-Source': 'eth-json-rpc-infura/internal',
},
body: '{"id":1,"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x482103",true]}',
})
Expand Down Expand Up @@ -72,7 +72,7 @@ test('fetchConfigFromReq - basic', (t) => {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Infura-Source': 'eth-json-rpc-infura/internal',
'Cabal-Source': 'eth-json-rpc-infura/internal',
},
body: '{"id":1,"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["0x0102030405060708090a0b0c0d0e0f"]}',
})
Expand Down Expand Up @@ -117,7 +117,7 @@ test('fetchConfigFromReq - source specified for request origin in header', (t) =
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Infura-Source': 'eth-json-rpc-infura/happydapp.eth',
'Cabal-Source': 'eth-json-rpc-infura/happydapp.eth',
},
body: fetchParams.body,
})
Expand Down Expand Up @@ -153,21 +153,21 @@ test('fetchConfigFromReq - extraHeaders specified', (t) => {

})

test('createInfuraMiddleware throws with an invalid projectId', (t) => {
test('createCabalMiddleware throws with an invalid projectId', (t) => {

t.throws(() => createInfuraMiddleware({ projectId: 42 }), /Invalid value for 'projectId'/u)
t.throws(() => createInfuraMiddleware({ projectId: null }), /Invalid value for 'projectId'/u)
t.throws(() => createInfuraMiddleware({ projectId: undefined }), /Invalid value for 'projectId'/u)
t.throws(() => createInfuraMiddleware({ projectId: '' }), /Invalid value for 'projectId'/u)
t.throws(() => createCabalMiddleware({ projectId: 42 }), /Invalid value for 'projectId'/u)
t.throws(() => createCabalMiddleware({ projectId: null }), /Invalid value for 'projectId'/u)
t.throws(() => createCabalMiddleware({ projectId: undefined }), /Invalid value for 'projectId'/u)
t.throws(() => createCabalMiddleware({ projectId: '' }), /Invalid value for 'projectId'/u)
t.end()

})

test('createInfuraMiddleware throws with invalid headers', (t) => {
test('createCabalMiddleware throws with invalid headers', (t) => {

t.throws(() => createInfuraMiddleware({ projectId: 'foo', headers: null }), /Invalid value for 'headers'/u)
t.throws(() => createInfuraMiddleware({ projectId: 'foo', headers: 42 }), /Invalid value for 'headers'/u)
t.throws(() => createInfuraMiddleware({ projectId: 'foo', headers: '' }), /Invalid value for 'headers'/u)
t.throws(() => createCabalMiddleware({ projectId: 'foo', headers: null }), /Invalid value for 'headers'/u)
t.throws(() => createCabalMiddleware({ projectId: 'foo', headers: 42 }), /Invalid value for 'headers'/u)
t.throws(() => createCabalMiddleware({ projectId: 'foo', headers: '' }), /Invalid value for 'headers'/u)
t.end()

})

0 comments on commit 7e8feb0

Please sign in to comment.