Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subgraphs integration #198

Merged
merged 27 commits into from Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8efe3ce
Further refactor of the events:
r-marques Jan 29, 2022
92a9572
Added yarn.lock to gitignore
r-marques Jan 29, 2022
88d648c
remove wrongly committed yarn.lock
r-marques Jan 29, 2022
fcba6ff
plug in the subgraph events
r-marques Jan 31, 2022
c003c8d
Merge branch 'master' into feature/subgraphs
r-marques Feb 3, 2022
fc92692
Added more tests
r-marques Feb 4, 2022
93d9be4
createAgreement issue solved
r-marques Feb 4, 2022
01cabe2
fixed an issue with getAttributesByOwner
r-marques Feb 4, 2022
28f4cd6
Fixed subgraph related issues with Access proofs
r-marques Feb 5, 2022
0b8b2c3
CI waits for subgraphs
r-marques Feb 7, 2022
427fe1d
fixed CI
r-marques Feb 7, 2022
27882e7
fix CI
r-marques Feb 7, 2022
df5c9df
cleanup ci script
r-marques Feb 7, 2022
cfedbf1
fix CI
r-marques Feb 7, 2022
66bde09
fix CI
r-marques Feb 7, 2022
0368113
fix CI. last one I promise
r-marques Feb 7, 2022
1e859f0
nop
r-marques Feb 7, 2022
a20fffb
properly wait for subgraphs to be up and running
r-marques Feb 8, 2022
95a5712
cleanup code
r-marques Feb 8, 2022
43bc3a4
Re-organize code
r-marques Feb 8, 2022
d085387
remove debug messages
r-marques Feb 8, 2022
daecad0
fixed unit tests
r-marques Feb 8, 2022
fb8778d
Merge branch 'master' into feature/subgraphs
r-marques Feb 8, 2022
acbc1df
Upgraded to contracts version 1.3.6
r-marques Feb 9, 2022
85c078d
Merge branch 'master' into feature/subgraphs
r-marques Feb 9, 2022
132590f
make metadataUri macOS friendly
r-marques Feb 9, 2022
eeb7628
disable celo mainnet test for now
r-marques Feb 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,6 +6,7 @@ doc/
test/**/*.js
src/**/*.js
package-lock.json
yarn.lock

src/metadata\.json
.idea
Expand Down
3 changes: 2 additions & 1 deletion integration/config.ts
Expand Up @@ -6,11 +6,12 @@ LoggerInstance.setLevel(LogLevel.Error)

const configBase: Config = {
nodeUri: 'http://localhost:8545',
metadataUri: 'http://nevermined-metadata:5000',
metadataUri: 'http://172.17.0.1:5000',
r-marques marked this conversation as resolved.
Show resolved Hide resolved
faucetUri: 'http://localhost:3001',
gatewayUri: 'http://localhost:8030',
secretStoreUri: 'http://localhost:12001',
gatewayAddress: '0x068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0',
// graphHttpUri: 'http://localhost:9000/subgraphs/name/neverminedio',
gasMultiplier: 1.1,
verbose: LogLevel.Error
}
Expand Down
128 changes: 128 additions & 0 deletions integration/nevermined/ContractEvent.test.ts
@@ -0,0 +1,128 @@
import { Account, Nevermined } from '../../src'
import { config } from '../config'
import { assert } from 'chai'
import Web3 from 'web3'
import { ContractEvent } from '../../src/keeper/ContractEvent'
import { TransactionReceipt } from 'web3-core'

describe('ContractEvent', () => {
let account: Account
let nevermined: Nevermined
let executeTransaction: () => Promise<any>

before(async () => {
config.graphHttpUri = undefined
nevermined = await Nevermined.getInstance(config)
;[account] = await nevermined.accounts.list()

await nevermined.keeper.dispenser.requestTokens(1, account.getId())

executeTransaction = () =>
nevermined.keeper.dispenser.requestTokens(1, account.getId())
})

it('should get a ContractEvent instance', async () => {
assert.instanceOf(nevermined.keeper.token.events, ContractEvent)
})

it('should query for the event', async () => {
const response = await nevermined.keeper.token.events.getEventData({
filterJsonRpc: {
to: account.getId()
},
result: {
to: true,
value: true
},
eventName: 'Transfer'
})
assert.strictEqual(
Web3.utils.toChecksumAddress(response.pop().returnValues.to),
Web3.utils.toChecksumAddress(account.getId())
)
})

it('should be able to listen to events', async () => {
let validResolve = false
let subscription

const waitUntilEvent = new Promise(resolve => {
subscription = nevermined.keeper.token.events.subscribe(
events => {
assert.isDefined(events)
assert.isAtLeast(events.length, 1)
if (validResolve) {
resolve(0)
}
},
{
eventName: 'Transfer',
filterJsonRpc: { to: account.getId() },
fromBlock: 0,
toBlock: 'latest'
}
)
})

await Promise.all([executeTransaction(), executeTransaction()])

await new Promise(resolve => setTimeout(resolve, 2000))
validResolve = true

await Promise.all([executeTransaction(), executeTransaction()])

await waitUntilEvent

subscription.unsubscribe()
})

it('should listen to event only once', async () => {
const to = account.getId()
// const event = await eventHandler.getEvent(nevermined.keeper.token)
const event = nevermined.keeper.token.events
let canBeRejected = false

const waitUntilEvent = new Promise((resolve, reject) => {
event.once(
() => {
if (canBeRejected) {
reject(new Error(''))
}
setTimeout(resolve, 600)
},
{
eventName: 'Transfer',
filterJsonRpc: {
to
}
}
)
})

await executeTransaction()

await new Promise(resolve => setTimeout(resolve, 2000))
canBeRejected = true

await executeTransaction()

await waitUntilEvent
})

it('should get the event like a promise', async () => {
const to = account.getId()
// const event = await eventHandler.getEvent(nevermined.keeper.token)
const event = nevermined.keeper.token.events

const waitUntilEvent = event.once(events => console.log(events), {
eventName: 'Transfer',
filterJsonRpc: { to }
})

await new Promise(resolve => setTimeout(resolve, 400))

await executeTransaction()

await waitUntilEvent
})
})
145 changes: 145 additions & 0 deletions integration/nevermined/SubgraphEvent.test.ts
@@ -0,0 +1,145 @@
import { Account, Nevermined } from '../../src'
import { config } from '../config'
import { assert } from 'chai'
import Web3 from 'web3'

describe('SubgraphEvent', () => {
let account: Account
let nevermined: Nevermined
let executeTransaction: () => Promise<any>

before(async () => {
config.graphHttpUri =
config.graphHttpUri || 'http://localhost:9000/subgraphs/name/neverminedio'
nevermined = await Nevermined.getInstance(config)
;[account] = await nevermined.accounts.list()

await nevermined.keeper.dispenser.requestTokens(1, account.getId())

executeTransaction = () =>
nevermined.keeper.dispenser.requestTokens(1, account.getId())
})

it('should query for the event', async () => {
const response = await nevermined.keeper.token.events.getEventData({
methodName: 'getTransfers',
filterSubgraph: {
where: {
to: account.getId()
}
},
result: {
to: true,
value: true
}
})
console.log(response)
assert.strictEqual(
Web3.utils.toChecksumAddress(response.pop().to),
Web3.utils.toChecksumAddress(account.getId())
)
})

it('should be able to listen to events', async () => {
let validResolve = false
let subscription

const waitUntilEvent = new Promise(resolve => {
subscription = nevermined.keeper.token.events.subscribe(
events => {
assert.isDefined(events)
assert.isAtLeast(events.length, 1)
if (validResolve) {
resolve(0)
}
},
{
methodName: 'getTransfers',
filterSubgraph: {
where: {
to: account.getId()
}
},
result: {
to: true,
value: true
}
}
)
})

await Promise.all([executeTransaction(), executeTransaction()])

await new Promise(resolve => setTimeout(resolve, 2000))
validResolve = true

await Promise.all([executeTransaction(), executeTransaction()])

await waitUntilEvent

subscription.unsubscribe()
})

it('should listen to event only once', async () => {
// const event = await eventHandler.getEvent(nevermined.keeper.token)
const event = nevermined.keeper.token.events
let canBeRejected = false

const waitUntilEvent = new Promise((resolve, reject) => {
event.once(
events => {
if (canBeRejected) {
reject(new Error(''))
}
setTimeout(resolve, 600)
},
{
methodName: 'getTransfers',
filterSubgraph: {
where: {
to: account.getId()
}
},
result: {
to: true,
value: true
}
}
)
})

await executeTransaction()

await new Promise(resolve => setTimeout(resolve, 2000))
canBeRejected = true

await executeTransaction()

await waitUntilEvent
})

it('should get the event like a promise', async () => {
const to = account.getId()
// const event = await eventHandler.getEvent(nevermined.keeper.token)
const event = nevermined.keeper.token.events

const waitUntilEvent = event.once(events => console.log(events), {
methodName: 'getTransfers',
filterSubgraph: {
where: {
to: account.getId()
}
},
result: {
to: true,
value: true
}
})

await new Promise(resolve => setTimeout(resolve, 400))

await executeTransaction()

await waitUntilEvent
})
})
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -55,6 +55,7 @@
"dependencies": {
"@nevermined-io/contracts": "^1.3.4",
"@nevermined-io/secret-store-client": "^0.0.16",
"@nevermined-io/subgraphs": "0.2.1",
"bignumber.js": "^9.0.0",
"circom": "^0.5.45",
"circomlib": "^0.5.3",
Expand Down Expand Up @@ -159,4 +160,4 @@
"!src/**/*.d.ts"
]
}
}
}
3 changes: 2 additions & 1 deletion src/Instantiable.abstract.ts
Expand Up @@ -65,7 +65,8 @@ export abstract class Instantiable {
return { nevermined, web3, config, logger }
}

public static async getInstance(...args: any[]): Promise<any>
public static getInstance(...args: any[]): any
// public static async getInstance(...args: any[]): Promise<any>

public static async getInstance(config: InstantiableConfig): Promise<any> {
LoggerInstance.warn('getInstance() methods has needs to be added to child class.')
Expand Down