Skip to content

Commit

Permalink
Merge branch 'master' into v12
Browse files Browse the repository at this point in the history
  • Loading branch information
julien51 committed Nov 2, 2022
2 parents 222a390 + ce98f38 commit 64e7575
Show file tree
Hide file tree
Showing 179 changed files with 5,053 additions and 2,767 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/_subgraph.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Subgraphs deployment

on:
workflow_call:
secrets:
SUBGRAPH_DEPLOY_KEY:
required: true

jobs:
coverage:
name: Redeploy all existing subgraphs
runs-on: ubuntu-latest
env:
DOCKER_BUILDKIT: 1
BUILDKIT_PROGRESS: plain
BLOCKTIME: 0
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Deploying the subgraphs
run: cd subgraph && yarn deploy-all
shell: bash
env:
SUBGRAPH_DEPLOY_KEY: ${{ secrets.SUBGRAPH_DEPLOY_KEY }}
7 changes: 7 additions & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ jobs:
run-all-tests:
uses: ./.github/workflows/_tests.yml

deploy-all-subgraphs:
if: ${{ github.repository_owner == 'unlock-protocol' }}
needs: run-all-tests
uses: ./.github/workflows/_subgraph.yml
secrets:
SUBGRAPH_DEPLOY_KEY: ${{ secrets.SUBGRAPH_DEPLOY_KEY }}

deploy-locksmith-production:
if: ${{ github.repository_owner == 'unlock-protocol' }}
needs: run-all-tests
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ services:
- postgres

ipfs: # Required for subgraph
image: ipfs/go-ipfs:v0.15.0
image: ipfs/go-ipfs:v0.16.0
ports:
- '5001:5001'

Expand Down
6 changes: 3 additions & 3 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
version: '3.2'
services:
graph-node:
image: graphprotocol/graph-node:v0.27.0
image: graphprotocol/graph-node:v0.28.2
ports:
- '8000:8000'
- '8001:8001'
- '8020:8020'

ipfs:
image: ipfs/kubo:v0.15.0
image: ipfs/kubo:v0.16.0
ports:
- '5001:5001'

postgres:
image: postgres:14.5
image: postgres:15.0
104 changes: 101 additions & 3 deletions locksmith/__tests__/controllers/v2/metadataController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ethers } from 'ethers'
import request from 'supertest'
import { loginRandomUser } from '../../test-helpers/utils'
import verifierOperations from '../../../src/operations/verifierOperations'
import logger from '../../../src/logger'

const app = require('../../../src/app')

Expand All @@ -22,6 +23,18 @@ jest.mock('@unlock-protocol/unlock-js', () => {
owner,
}
}),
SubgraphService: jest.fn().mockImplementation(() => {
return {
key: (filter: any, opts: any) => {
logger.info(filter, opts)
return {
owner,
expiration: 0,
tokenId: 1,
}
},
}
}),
}
})

Expand Down Expand Up @@ -62,6 +75,46 @@ describe('Metadata v2 endpoints for locksmith', () => {
})
})

it('Add empty metadata and update it later', async () => {
expect.assertions(4)
const lockAddress = await ethers.Wallet.createRandom().getAddress()
const walletAddress = await ethers.Wallet.createRandom().getAddress()
const metadata = {
public: {},
protected: {},
}

const userMetadataResponse = await request(app)
.post(`/v2/api/metadata/100/locks/${lockAddress}/users/${walletAddress}`)
.send({ metadata })

expect(userMetadataResponse.status).toBe(201)
expect(userMetadataResponse.body).toStrictEqual({
userMetadata: metadata,
})

const metadata2 = {
public: {},
protected: {
email: 'test@gmail.com',
},
}

const userMetadataResponse2 = await request(app)
.post(`/v2/api/metadata/100/locks/${lockAddress}/users/${walletAddress}`)
.send({ metadata: metadata2 })

expect(userMetadataResponse2.body).toStrictEqual({
userMetadata: metadata2,
})

const userMetadataResponse3 = await request(app)
.post(`/v2/api/metadata/100/locks/${lockAddress}/users/${walletAddress}`)
.send({ metadata: metadata2 })

expect(userMetadataResponse3.status).toBe(409)
})

it('Add invalid user metadata', async () => {
expect.assertions(2)
const lockAddress = await ethers.Wallet.createRandom().getAddress()
Expand Down Expand Up @@ -94,11 +147,9 @@ describe('Metadata v2 endpoints for locksmith', () => {
protected: {
email: `${index}@example.com`,
},
}
const keyId = String(index + 1)
} as const
return {
userAddress,
keyId,
lockAddress,
metadata,
}
Expand All @@ -125,6 +176,53 @@ describe('Metadata v2 endpoints for locksmith', () => {
expect(userMetadataResponse2.body.result?.length).toBe(0)
})

it('Add empty users in bulk', async () => {
expect.assertions(3)
const users = await Promise.all(
Array(3)
.fill(0)
.map(async () => {
const lockAddress = await ethers.Wallet.createRandom().getAddress()
const userAddress = await ethers.Wallet.createRandom().getAddress()
const metadata: Record<
'public' | 'protected',
Record<string, any>
> = {
public: {},
protected: {},
}
return {
userAddress,
lockAddress,
metadata,
}
})
)

const userMetadataResponse = await request(app)
.post('/v2/api/metadata/100/users')
.send({ users })

expect(userMetadataResponse.body.result.length).toBe(3)

const metadataAddedUsers = users.map((item, index) => {
item.metadata.protected.email = `${index}@gmail.com`
return item
})

const userMetadataResponse2 = await request(app)
.post('/v2/api/metadata/100/users')
.send({ users: metadataAddedUsers })

expect(userMetadataResponse2.body.result.length).toBe(3)

const userMetadataResponse3 = await request(app)
.post('/v2/api/metadata/100/users')
.send({ users: metadataAddedUsers })

expect(userMetadataResponse3.body.result.length).toBe(0)
})

it('Add bulk broken user metadata', async () => {
expect.assertions(2)

Expand Down
4 changes: 3 additions & 1 deletion locksmith/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"authorize": "./scripts/authorize-lock",
"websub:start": "yarn build && node -r ./src/utils/envLoader.js ./build/src/websub/server.js",
"websub:dev": "NODE_ENV=development yarn db:migrate && ts-node-dev -r ./src/utils/envLoader.js ./src/websub/server.ts",
"websub:prod": "cd build && node -r ./src/utils/envLoader ./src/websub/server.js"
"websub:prod": "cd build && node -r ./src/utils/envLoader ./src/websub/server.js",
"send:email": "cd build && node -r ./src/utils/envLoader.js ./scripts/send_email.js"
},
"lint-staged": {
"*.{js,ts}": [
Expand Down Expand Up @@ -116,6 +117,7 @@
"run-script-os": "1.1.6",
"supertest": "6.2.4",
"ts-jest": "27.1.5",
"ts-node": "10.9.1",
"ts-node-dev": "2.0.0",
"typescript": "4.6.4"
},
Expand Down
60 changes: 60 additions & 0 deletions locksmith/scripts/send_email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { notifyNewKeysToWedlocks } from '../src/operations/wedlocksOperations'
import { SubgraphService } from '@unlock-protocol/unlock-js'
import yargs from 'yargs'

const argv = yargs
.option('network', {
requiresArg: true,
type: 'number',
alias: 'n',
description: 'Network ID of the network',
})
.option('lockAddress', {
requiresArg: true,
type: 'string',
alias: 'l',
description: 'Lock Address to use.',
})
.help()
.alias('h', 'help')
.example(
'yarn ts-node scripts/send_email.ts --network 5 --lockAddress xyz',
'send emails to all users on goerli on xyz lock address.'
).argv

interface Options {
lockAddress: string
network: number
}

async function run({ lockAddress, network }: Options) {
const service = new SubgraphService()
const keys = await service.keys(
{
first: 1000,
where: {
lock_in: [lockAddress.toLowerCase()],
},
},
{
networks: [network.toString()],
}
)
await notifyNewKeysToWedlocks(keys, network)
return keys
}

if (argv.lockAddress && argv.network) {
run({
lockAddress: argv.lockAddress,
network: argv.network,
})
.then((keys) => {
console.log(
`Successfully sent emails to recipients associated with ${keys.length} keys.`
)
})
.catch(console.error)
} else {
console.log(argv)
}

0 comments on commit 64e7575

Please sign in to comment.