mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
test and package fixes
This commit is contained in:
parent
a8c695e16f
commit
3df046bbea
@ -13,6 +13,16 @@ const oceanMock = {
|
||||
}
|
||||
},
|
||||
assets: {
|
||||
query: () => {
|
||||
return {
|
||||
results: [],
|
||||
page: 1,
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
total_pages: 1611,
|
||||
total_results: 1611
|
||||
/* eslint-enable @typescript-eslint/camelcase */
|
||||
}
|
||||
},
|
||||
resolve: jest.fn(),
|
||||
order: () => {
|
||||
return {
|
||||
|
25284
client/package-lock.json
generated
25284
client/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -24,8 +24,7 @@
|
||||
"ethereum-blockies": "github:MyEtherWallet/blockies",
|
||||
"filesize": "^6.0.1",
|
||||
"history": "^4.10.1",
|
||||
"ipfs": "^0.40.0",
|
||||
"ipfs-http-client": "^40.0.1",
|
||||
"ipfs-http-client": "^39.0.2",
|
||||
"is-url-superb": "^3.0.0",
|
||||
"moment": "^2.24.0",
|
||||
"query-string": "^6.9.0",
|
||||
|
@ -1,8 +1,10 @@
|
||||
import Web3 from 'web3'
|
||||
import { nodeUri } from '../config'
|
||||
import HDWalletProvider from '@truffle/hdwallet-provider'
|
||||
import { nodeUri } from '../config'
|
||||
import { requestFromFaucet } from '../ocean'
|
||||
const bip39 = require('bip39') // eslint-disable-line @typescript-eslint/no-var-requires
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const bip39 = require('bip39')
|
||||
|
||||
export class BurnerWalletProvider {
|
||||
private web3: Web3
|
||||
@ -12,10 +14,6 @@ export class BurnerWalletProvider {
|
||||
this.web3 = null as any
|
||||
}
|
||||
|
||||
public async isAvailable() {
|
||||
return true
|
||||
}
|
||||
|
||||
public async isLogged() {
|
||||
if (localStorage.getItem('seedphrase') !== null) {
|
||||
return true
|
||||
@ -35,7 +33,7 @@ export class BurnerWalletProvider {
|
||||
}
|
||||
|
||||
localStorage.setItem('logType', 'BurnerWallet')
|
||||
const provider = new HDWalletProvider(mnemonic, `${nodeUri}`, 0, 1)
|
||||
const provider = new HDWalletProvider(mnemonic, nodeUri, 0, 1)
|
||||
this.web3 = new Web3(provider as any)
|
||||
const accounts = await this.web3.eth.getAccounts()
|
||||
const balance = await this.web3.eth.getBalance(accounts[0])
|
||||
|
@ -24,6 +24,7 @@ export default function useIpfsApi(config: IpfsConfig) {
|
||||
ipfsMessage = 'Checking IPFS gateway...'
|
||||
|
||||
try {
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
ipfs = await ipfsClient(config)
|
||||
const version = await ipfs.version()
|
||||
ipfsVersion = version.version
|
||||
@ -38,7 +39,6 @@ export default function useIpfsApi(config: IpfsConfig) {
|
||||
}, [config])
|
||||
|
||||
useEffect(() => {
|
||||
// just like componentWillUnmount()
|
||||
return function cleanup() {
|
||||
if (ipfs) {
|
||||
setIpfsReady(false)
|
||||
|
@ -1,27 +0,0 @@
|
||||
import React from 'react'
|
||||
import { render, wait, act } from '@testing-library/react'
|
||||
import useIpfs from './use-ipfs'
|
||||
|
||||
export default function TestComponent() {
|
||||
const { ipfsVersion, isIpfsReady, ipfsError, ipfsMessage } = useIpfs()
|
||||
|
||||
return (
|
||||
<div>
|
||||
{isIpfsReady && <span>Ready</span>}
|
||||
{ipfsVersion} - {ipfsMessage} - {ipfsError}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
describe('use-ipfs', () => {
|
||||
it('renders without crashing', async () => {
|
||||
let element: any
|
||||
|
||||
await act(async () => {
|
||||
element = render(<TestComponent />)
|
||||
})
|
||||
|
||||
expect(element.container.firstChild).toBeInTheDocument()
|
||||
await wait(() => element.getByText('Ready'))
|
||||
})
|
||||
})
|
@ -1,74 +0,0 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
import Ipfs from 'ipfs'
|
||||
import { useEffect, useState } from 'react'
|
||||
import os from 'os'
|
||||
import shortid from 'shortid'
|
||||
|
||||
let ipfs: any = null
|
||||
let ipfsMessage = ''
|
||||
let ipfsVersion = ''
|
||||
|
||||
export default function useIpfs() {
|
||||
const [isIpfsReady, setIpfsReady] = useState(Boolean(ipfs))
|
||||
const [ipfsError, setIpfsError] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
async function startIpfs() {
|
||||
ipfsMessage = 'Starting IPFS...'
|
||||
|
||||
if (ipfs) {
|
||||
console.log('IPFS already started')
|
||||
// } else if (window.ipfs && window.ipfs.enable) {
|
||||
// console.log('Found window.ipfs')
|
||||
// ipfs = await window.ipfs.enable()
|
||||
} else {
|
||||
try {
|
||||
const message = 'IPFS started'
|
||||
console.time(message)
|
||||
|
||||
ipfs = await Ipfs.create({
|
||||
repo: `${os.homedir()}/.jsipfs-${shortid.generate()}`,
|
||||
config: {
|
||||
Addresses: {
|
||||
// 0 for port so system just assigns a new free port
|
||||
// to allow multiple nodes running at same time
|
||||
Swarm: ['/ip4/0.0.0.0/tcp/0']
|
||||
}
|
||||
}
|
||||
})
|
||||
console.timeEnd(message)
|
||||
ipfsMessage = message
|
||||
|
||||
const { agentVersion } = await ipfs.id()
|
||||
ipfsVersion = agentVersion
|
||||
} catch (error) {
|
||||
const message = `IPFS init error: ${error.message}`
|
||||
ipfsMessage = message
|
||||
console.error(message)
|
||||
ipfs = null
|
||||
setIpfsError(error.message)
|
||||
}
|
||||
}
|
||||
setIpfsReady(Boolean(ipfs))
|
||||
}
|
||||
|
||||
startIpfs()
|
||||
|
||||
// just like componentWillUnmount()
|
||||
return function cleanup() {
|
||||
if (ipfs && ipfs.stop) {
|
||||
console.time('IPFS stopped')
|
||||
ipfs.stop()
|
||||
setIpfsReady(false)
|
||||
ipfs = null
|
||||
ipfsMessage = ''
|
||||
ipfsVersion = ''
|
||||
setIpfsError('')
|
||||
console.timeEnd('IPFS stopped')
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
|
||||
return { ipfs, ipfsVersion, isIpfsReady, ipfsError, ipfsMessage }
|
||||
}
|
@ -26,19 +26,4 @@ describe('IPFS', () => {
|
||||
const addingText = await waitForElement(() => getByText(/Adding /))
|
||||
expect(addingText).toBeDefined()
|
||||
})
|
||||
|
||||
// it('Local Node: files can be dropped', async () => {
|
||||
// const { debug, container, findByText, getByText } = render(
|
||||
// <Ipfs addFile={addFile} node />
|
||||
// )
|
||||
// expect(container).toBeInTheDocument()
|
||||
// // wait for IPFS node
|
||||
// await findByText(/IPFS started/)
|
||||
// // drop a file
|
||||
// const dropzoneInput = container.querySelector('.dropzone input')
|
||||
// Object.defineProperty(dropzoneInput, 'files', { value: [file] })
|
||||
// dropzoneInput && fireEvent.drop(dropzoneInput)
|
||||
// await waitForElement(() => getByText(/File found/), { timeout: 100000 })
|
||||
// expect(addFile).toHaveBeenCalledTimes(1)
|
||||
// })
|
||||
})
|
||||
|
@ -28,14 +28,14 @@ const mockResponse = {
|
||||
result: {
|
||||
url: 'https://demo.com',
|
||||
contentType: 'application/zip',
|
||||
contentLength: 237347827,
|
||||
contentLength: '237347827',
|
||||
found: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const renderComponent = () =>
|
||||
render(
|
||||
describe('Files', () => {
|
||||
const ui = (
|
||||
<Files
|
||||
files={files}
|
||||
placeholder="Hello"
|
||||
@ -44,16 +44,15 @@ const renderComponent = () =>
|
||||
/>
|
||||
)
|
||||
|
||||
describe('Files', () => {
|
||||
it('renders without crashing', async () => {
|
||||
const { container } = renderComponent()
|
||||
it('renders without crashing', () => {
|
||||
const { container } = render(ui)
|
||||
|
||||
expect(container.firstChild).toBeInTheDocument()
|
||||
expect(container.querySelector('.itemForm')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('new file form can be opened and closed', async () => {
|
||||
const { container, getByText } = renderComponent()
|
||||
const { container, getByText } = render(ui)
|
||||
|
||||
// open
|
||||
fireEvent.click(getByText('+ From URL'))
|
||||
@ -67,7 +66,7 @@ describe('Files', () => {
|
||||
})
|
||||
|
||||
it('new IPFS file form can be opened and closed', async () => {
|
||||
const { getByText } = renderComponent()
|
||||
const { getByText } = render(ui)
|
||||
|
||||
// open
|
||||
fireEvent.click(getByText('+ Add to IPFS'))
|
||||
@ -82,15 +81,15 @@ describe('Files', () => {
|
||||
expect(text).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('item can be removed', async () => {
|
||||
const { getByTitle } = renderComponent()
|
||||
it('item can be removed', () => {
|
||||
const { getByTitle } = render(ui)
|
||||
|
||||
fireEvent.click(getByTitle('Remove item'))
|
||||
expect(files.length).toBe(0)
|
||||
})
|
||||
|
||||
it('item can be added', async () => {
|
||||
const { getByText, getByPlaceholderText } = renderComponent()
|
||||
const { getByText, getByPlaceholderText } = render(ui)
|
||||
|
||||
fireEvent.click(getByText('+ From URL'))
|
||||
await waitForElement(() => getByText('- Cancel'))
|
||||
|
@ -1,3 +1 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
import '@testing-library/jest-dom/extend-expect'
|
||||
|
Loading…
Reference in New Issue
Block a user