mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
Merge pull request #148 from oceanprotocol/feature/dont-re-agreement
Reuse agreements on consume flow
This commit is contained in:
commit
2d512f341e
25
client/__mocks__/ocean-mock.ts
Normal file
25
client/__mocks__/ocean-mock.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
const oceanMock = {
|
||||||
|
ocean: {
|
||||||
|
accounts: {
|
||||||
|
list: () => ['xxx', 'xxx']
|
||||||
|
},
|
||||||
|
aquarius: {
|
||||||
|
queryMetadata: () => {
|
||||||
|
return {
|
||||||
|
results: [],
|
||||||
|
totalResults: 1,
|
||||||
|
totalPages: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
keeper: {
|
||||||
|
conditions: {
|
||||||
|
accessSecretStoreCondition: {
|
||||||
|
getGrantedDidByConsumer: jest.fn()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default oceanMock
|
@ -1,3 +1,5 @@
|
|||||||
|
import oceanMock from './ocean-mock'
|
||||||
|
|
||||||
const userMock = {
|
const userMock = {
|
||||||
isLogged: false,
|
isLogged: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@ -5,11 +7,7 @@ const userMock = {
|
|||||||
isOceanNetwork: false,
|
isOceanNetwork: false,
|
||||||
account: '',
|
account: '',
|
||||||
web3: {},
|
web3: {},
|
||||||
ocean: {
|
...oceanMock,
|
||||||
aquarius: {
|
|
||||||
queryMetadata: jest.fn()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
balance: { eth: 0, ocn: 0 },
|
balance: { eth: 0, ocn: 0 },
|
||||||
network: '',
|
network: '',
|
||||||
requestFromFaucet: jest.fn(),
|
requestFromFaucet: jest.fn(),
|
||||||
@ -24,11 +22,7 @@ const userMockConnected = {
|
|||||||
isOceanNetwork: true,
|
isOceanNetwork: true,
|
||||||
account: '0xxxxxx',
|
account: '0xxxxxx',
|
||||||
web3: {},
|
web3: {},
|
||||||
ocean: {
|
...oceanMock,
|
||||||
aquarius: {
|
|
||||||
queryMetadata: jest.fn()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
balance: { eth: 0, ocn: 0 },
|
balance: { eth: 0, ocn: 0 },
|
||||||
network: '',
|
network: '',
|
||||||
requestFromFaucet: jest.fn(),
|
requestFromFaucet: jest.fn(),
|
||||||
|
6
client/package-lock.json
generated
6
client/package-lock.json
generated
@ -1296,9 +1296,9 @@
|
|||||||
"integrity": "sha512-nOpbSE/BG+tQBfLXZ/EqSOvUPzOuot84vHxjAfEU8K3v4eOnqFJVo+oyB7KlcF87wBJXDmi/Ir9qHY4c0Saipg=="
|
"integrity": "sha512-nOpbSE/BG+tQBfLXZ/EqSOvUPzOuot84vHxjAfEU8K3v4eOnqFJVo+oyB7KlcF87wBJXDmi/Ir9qHY4c0Saipg=="
|
||||||
},
|
},
|
||||||
"@oceanprotocol/squid": {
|
"@oceanprotocol/squid": {
|
||||||
"version": "0.5.11",
|
"version": "0.5.12",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/squid/-/squid-0.5.11.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/squid/-/squid-0.5.12.tgz",
|
||||||
"integrity": "sha512-vgwu0ibLPAi97+i9hWCRdBOG+RChm1dkvHNdLE6T0dA3Xw6gEbdAmOZ/iWYoBxYiYr8DXyjgOdChU6kb7jAepQ==",
|
"integrity": "sha512-RhP0wK4nA9ro/HQl3SohJ21XknxD1PtOCY+gQS3iUyyAabcGKVgMrpcuKKPi7SJLMBpUlV5O1V+4qPozCQZbWg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@oceanprotocol/keeper-contracts": "^0.9.7",
|
"@oceanprotocol/keeper-contracts": "^0.9.7",
|
||||||
"bignumber.js": "^8.1.1",
|
"bignumber.js": "^8.1.1",
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/art": "^2.2.0",
|
"@oceanprotocol/art": "^2.2.0",
|
||||||
"@oceanprotocol/squid": "^0.5.11",
|
"@oceanprotocol/squid": "^0.5.12",
|
||||||
"@oceanprotocol/typographies": "^0.1.0",
|
"@oceanprotocol/typographies": "^0.1.0",
|
||||||
"@sindresorhus/slugify": "^0.9.1",
|
"@sindresorhus/slugify": "^0.9.1",
|
||||||
"axios": "^0.18.0",
|
"axios": "^0.18.0",
|
||||||
|
@ -2,7 +2,7 @@ import React from 'react'
|
|||||||
import { render } from 'react-testing-library'
|
import { render } from 'react-testing-library'
|
||||||
import App from './App'
|
import App from './App'
|
||||||
import { User } from './context'
|
import { User } from './context'
|
||||||
import { userMock } from '../__mocks__/user-mock'
|
import { userMock, userMockConnected } from '../__mocks__/user-mock'
|
||||||
|
|
||||||
describe('App', () => {
|
describe('App', () => {
|
||||||
it('should be able to run tests', () => {
|
it('should be able to run tests', () => {
|
||||||
@ -10,7 +10,11 @@ describe('App', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('renders without crashing', () => {
|
it('renders without crashing', () => {
|
||||||
const { container } = render(<App />)
|
const { container } = render(
|
||||||
|
<User.Provider value={userMockConnected}>
|
||||||
|
<App />
|
||||||
|
</User.Provider>
|
||||||
|
)
|
||||||
expect(container.firstChild).toBeInTheDocument()
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -2,13 +2,17 @@ import React from 'react'
|
|||||||
import { BrowserRouter as Router } from 'react-router-dom'
|
import { BrowserRouter as Router } from 'react-router-dom'
|
||||||
import { render } from 'react-testing-library'
|
import { render } from 'react-testing-library'
|
||||||
import Routes from './Routes'
|
import Routes from './Routes'
|
||||||
|
import { User } from './context'
|
||||||
|
import { userMockConnected } from '../__mocks__/user-mock'
|
||||||
|
|
||||||
describe('Routes', () => {
|
describe('Routes', () => {
|
||||||
it('renders without crashing', () => {
|
it('renders without crashing', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<Router>
|
<User.Provider value={userMockConnected}>
|
||||||
<Routes />
|
<Router>
|
||||||
</Router>
|
<Routes />
|
||||||
|
</Router>
|
||||||
|
</User.Provider>
|
||||||
)
|
)
|
||||||
expect(container.firstChild).toBeInTheDocument()
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import { BrowserRouter } from 'react-router-dom'
|
||||||
import { render } from 'react-testing-library'
|
import { render } from 'react-testing-library'
|
||||||
import AssetsLatest from './AssetsLatest'
|
import AssetsLatest from './AssetsLatest'
|
||||||
import { BrowserRouter } from 'react-router-dom'
|
import { User } from '../../context'
|
||||||
|
import { userMockConnected } from '../../../__mocks__/user-mock'
|
||||||
|
|
||||||
describe('AssetsLatest', () => {
|
describe('AssetsLatest', () => {
|
||||||
it('renders without crashing', () => {
|
it('renders without crashing', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<BrowserRouter>
|
<User.Provider value={userMockConnected}>
|
||||||
<AssetsLatest />
|
<BrowserRouter>
|
||||||
</BrowserRouter>
|
<AssetsLatest />
|
||||||
|
</BrowserRouter>
|
||||||
|
</User.Provider>
|
||||||
)
|
)
|
||||||
expect(container.firstChild).toBeInTheDocument()
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
@ -2,13 +2,17 @@ import React from 'react'
|
|||||||
import { render } from 'react-testing-library'
|
import { render } from 'react-testing-library'
|
||||||
import ChannelTeaser from './ChannelTeaser'
|
import ChannelTeaser from './ChannelTeaser'
|
||||||
import { BrowserRouter } from 'react-router-dom'
|
import { BrowserRouter } from 'react-router-dom'
|
||||||
|
import { User } from '../../context'
|
||||||
|
import { userMockConnected } from '../../../__mocks__/user-mock'
|
||||||
|
|
||||||
describe('ChannelTeaser', () => {
|
describe('ChannelTeaser', () => {
|
||||||
it('renders without crashing', () => {
|
it('renders without crashing', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<BrowserRouter>
|
<User.Provider value={userMockConnected}>
|
||||||
<ChannelTeaser channel="ai-for-good" />
|
<BrowserRouter>
|
||||||
</BrowserRouter>
|
<ChannelTeaser channel="ai-for-good" />
|
||||||
|
</BrowserRouter>
|
||||||
|
</User.Provider>
|
||||||
)
|
)
|
||||||
expect(container.firstChild).toBeInTheDocument()
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
@ -7,6 +7,7 @@ import { StateMock } from '@react-mock/state'
|
|||||||
import ReactGA from 'react-ga'
|
import ReactGA from 'react-ga'
|
||||||
import { User } from '../../../context'
|
import { User } from '../../../context'
|
||||||
import AssetFile, { messages } from './AssetFile'
|
import AssetFile, { messages } from './AssetFile'
|
||||||
|
import { userMockConnected } from '../../../../__mocks__/user-mock'
|
||||||
|
|
||||||
const file = {
|
const file = {
|
||||||
index: 0,
|
index: 0,
|
||||||
@ -15,22 +16,7 @@ const file = {
|
|||||||
contentLength: 100
|
contentLength: 100
|
||||||
}
|
}
|
||||||
|
|
||||||
const ddo = ({ id: 'xxx' } as any) as DDO
|
const ddo = ({ id: 'xxx', findServiceByType: jest.fn() } as any) as DDO
|
||||||
|
|
||||||
const contextConnectedMock = {
|
|
||||||
isLogged: true,
|
|
||||||
isLoading: false,
|
|
||||||
isWeb3: true,
|
|
||||||
isOceanNetwork: true,
|
|
||||||
account: '',
|
|
||||||
web3: {},
|
|
||||||
ocean: {},
|
|
||||||
balance: { eth: 0, ocn: 0 },
|
|
||||||
network: '',
|
|
||||||
requestFromFaucet: () => {},
|
|
||||||
unlockAccounts: () => {},
|
|
||||||
message: ''
|
|
||||||
}
|
|
||||||
|
|
||||||
ReactGA.initialize('foo', { testMode: true })
|
ReactGA.initialize('foo', { testMode: true })
|
||||||
|
|
||||||
@ -47,7 +33,7 @@ describe('AssetFile', () => {
|
|||||||
|
|
||||||
it('button to be enabled when connected', async () => {
|
it('button to be enabled when connected', async () => {
|
||||||
const { getByText } = render(
|
const { getByText } = render(
|
||||||
<User.Provider value={contextConnectedMock}>
|
<User.Provider value={userMockConnected}>
|
||||||
<AssetFile file={file} ddo={ddo} />
|
<AssetFile file={file} ddo={ddo} />
|
||||||
</User.Provider>
|
</User.Provider>
|
||||||
)
|
)
|
||||||
|
@ -59,9 +59,22 @@ export default class AssetFile extends PureComponent<
|
|||||||
const accounts = await ocean.accounts.list()
|
const accounts = await ocean.accounts.list()
|
||||||
const service = ddo.findServiceByType('Access')
|
const service = ddo.findServiceByType('Access')
|
||||||
|
|
||||||
const agreementId = await ocean.assets
|
const agreements = await ocean.keeper.conditions.accessSecretStoreCondition.getGrantedDidByConsumer(
|
||||||
.order(ddo.id, service.serviceDefinitionId, accounts[0])
|
accounts[0].id
|
||||||
.next((step: number) => this.setState({ step }))
|
)
|
||||||
|
const agreement = agreements.find((element: any) => {
|
||||||
|
return element.did === ddo.id
|
||||||
|
})
|
||||||
|
|
||||||
|
let agreementId
|
||||||
|
|
||||||
|
if (agreement) {
|
||||||
|
;({ agreementId } = agreement)
|
||||||
|
} else {
|
||||||
|
agreementId = await ocean.assets
|
||||||
|
.order(ddo.id, service.serviceDefinitionId, accounts[0])
|
||||||
|
.next((step: number) => this.setState({ step }))
|
||||||
|
}
|
||||||
|
|
||||||
// manually add another step here for better UX
|
// manually add another step here for better UX
|
||||||
this.setState({ step: 4 })
|
this.setState({ step: 4 })
|
||||||
@ -81,7 +94,7 @@ export default class AssetFile extends PureComponent<
|
|||||||
})
|
})
|
||||||
this.setState({ isLoading: false })
|
this.setState({ isLoading: false })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.log('error', error.message)
|
Logger.error('error', error.message)
|
||||||
this.setState({
|
this.setState({
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
error: `${error.message}. Sorry about that, can you try again?`
|
error: `${error.message}. Sorry about that, can you try again?`
|
||||||
|
@ -3,38 +3,14 @@ import { render } from 'react-testing-library'
|
|||||||
import Channel from './Channel'
|
import Channel from './Channel'
|
||||||
import { User } from '../../context'
|
import { User } from '../../context'
|
||||||
import { createMemoryHistory } from 'history'
|
import { createMemoryHistory } from 'history'
|
||||||
|
import { userMockConnected } from '../../../__mocks__/user-mock'
|
||||||
|
|
||||||
describe('Channel', () => {
|
describe('Channel', () => {
|
||||||
it('renders without crashing', () => {
|
it('renders without crashing', () => {
|
||||||
const history = createMemoryHistory()
|
const history = createMemoryHistory()
|
||||||
|
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<User.Provider
|
<User.Provider value={userMockConnected}>
|
||||||
value={{
|
|
||||||
isLogged: false,
|
|
||||||
isLoading: false,
|
|
||||||
isWeb3: false,
|
|
||||||
isOceanNetwork: false,
|
|
||||||
account: '',
|
|
||||||
web3: {},
|
|
||||||
ocean: {
|
|
||||||
aquarius: {
|
|
||||||
queryMetadata: () => {
|
|
||||||
return {
|
|
||||||
results: [],
|
|
||||||
totalResults: 1,
|
|
||||||
totalPages: 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
balance: { eth: 0, ocn: 0 },
|
|
||||||
network: '',
|
|
||||||
requestFromFaucet: () => {},
|
|
||||||
unlockAccounts: () => {},
|
|
||||||
message: ''
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Channel
|
<Channel
|
||||||
match={{
|
match={{
|
||||||
params: { channel: 'ai-for-good' }
|
params: { channel: 'ai-for-good' }
|
||||||
|
@ -2,13 +2,17 @@ import React from 'react'
|
|||||||
import { BrowserRouter as Router } from 'react-router-dom'
|
import { BrowserRouter as Router } from 'react-router-dom'
|
||||||
import { render } from 'react-testing-library'
|
import { render } from 'react-testing-library'
|
||||||
import Channels from './Channels'
|
import Channels from './Channels'
|
||||||
|
import { User } from '../context'
|
||||||
|
import { userMockConnected } from '../../__mocks__/user-mock'
|
||||||
|
|
||||||
describe('Channels', () => {
|
describe('Channels', () => {
|
||||||
it('renders without crashing', () => {
|
it('renders without crashing', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<Router>
|
<User.Provider value={userMockConnected}>
|
||||||
<Channels />
|
<Router>
|
||||||
</Router>
|
<Channels />
|
||||||
|
</Router>
|
||||||
|
</User.Provider>
|
||||||
)
|
)
|
||||||
expect(container.firstChild).toBeInTheDocument()
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
@ -4,38 +4,14 @@ import Search from './Search'
|
|||||||
import { User } from '../context'
|
import { User } from '../context'
|
||||||
import { createMemoryHistory } from 'history'
|
import { createMemoryHistory } from 'history'
|
||||||
import { BrowserRouter as Router } from 'react-router-dom'
|
import { BrowserRouter as Router } from 'react-router-dom'
|
||||||
|
import { userMockConnected } from '../../__mocks__/user-mock'
|
||||||
|
|
||||||
describe('Search', () => {
|
describe('Search', () => {
|
||||||
it('renders without crashing', () => {
|
it('renders without crashing', () => {
|
||||||
const history = createMemoryHistory()
|
const history = createMemoryHistory()
|
||||||
|
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<User.Provider
|
<User.Provider value={userMockConnected}>
|
||||||
value={{
|
|
||||||
isLogged: false,
|
|
||||||
isLoading: false,
|
|
||||||
isWeb3: false,
|
|
||||||
isOceanNetwork: false,
|
|
||||||
account: '',
|
|
||||||
web3: {},
|
|
||||||
ocean: {
|
|
||||||
aquarius: {
|
|
||||||
queryMetadata: () => {
|
|
||||||
return {
|
|
||||||
results: [],
|
|
||||||
totalResults: 1,
|
|
||||||
totalPages: 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
balance: { eth: 0, ocn: 0 },
|
|
||||||
network: '',
|
|
||||||
requestFromFaucet: () => {},
|
|
||||||
unlockAccounts: () => {},
|
|
||||||
message: ''
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Router>
|
<Router>
|
||||||
<Search
|
<Search
|
||||||
location={{
|
location={{
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "squid-js",
|
"name": "squid-js",
|
||||||
"version": "~0.5.11"
|
"version": "~0.5.12"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "faucet",
|
"name": "faucet",
|
||||||
|
Loading…
Reference in New Issue
Block a user