1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

more tests, document config usage

This commit is contained in:
Matthias Kretschmann 2020-09-08 20:08:08 +02:00
parent 2cb4478ba2
commit 44a26f687f
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 36 additions and 1 deletions

View File

@ -47,6 +47,23 @@ npm install @oceanprotocol/lib
## 🏄 Quick Start
```js
import { Ocean, ConfigHelper } from '@oceanprotocol/lib'
const defaultConfig = new ConfigHelper().getConfig('rinkeby', 'YOUR_INFURA_PROJECT_ID')
const config = {
...defaultConfig,
metadataStoreUri: 'https://your-metadata-store.com',
providerUri: 'https://your-provider.com'
}
async function init() {
const ocean = await Ocean.getInstance(config)
return ocean
}
```
### Simple Flow
This stripped-down flow shows the essence of Ocean. Just downloading, no metadata.

View File

@ -1,4 +1,5 @@
import Config from '../models/Config'
import { Logger } from '../lib'
export declare type ConfigHelperNetworkName =
| 'mainnet'
@ -56,10 +57,15 @@ export class ConfigHelper {
const filterBy = typeof network === 'string' ? 'network' : 'chainId'
const config = configs.find((c) => c[filterBy] === network)
if (!config) {
Logger.error(`No config found for given network '${network}'`)
return null
}
const nodeUri = infuraProjectId
? `${config.nodeUri}/${infuraProjectId}`
: config.nodeUri
return config ? { ...config, nodeUri } : null
return { ...config, nodeUri }
}
}

View File

@ -14,4 +14,16 @@ describe('ConfigHelper', () => {
const config = new ConfigHelper().getConfig(network, infuraId)
assert(config.nodeUri.includes(infuraId))
})
it('should get config based on chain ID', () => {
const network = 4
const config = new ConfigHelper().getConfig(network)
assert(config.chainId === network)
})
it('should return nothing with unknown network', () => {
const network = 'blabla'
const config = new ConfigHelper().getConfig(network)
assert(config === null)
})
})