-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
635 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { HttpStatus } from '@nestjs/common'; | ||
import { getQueueToken } from '@nestjs/bull'; | ||
import { Queue } from 'bull'; | ||
import request from 'supertest'; | ||
import { Connection, EntityManager, QueryRunner } from 'typeorm'; | ||
import { DidStore as DidStoreCluster } from 'didStoreCluster'; | ||
import { DidStore as DidStoreGateway } from 'didStoreGateway'; | ||
import { app } from '../app.e2e.spec'; | ||
import { randomUser } from '../utils'; | ||
|
||
export const ipfsModuleTestSuite = () => { | ||
let queryRunner: QueryRunner; | ||
let didStoreCluster: DidStoreCluster; | ||
let didStoreInfura: DidStoreGateway; | ||
let pinsQueue: Queue; | ||
const notPinned = { claimType: 'hello world notpinned' }; | ||
const notPinnedCid = | ||
'bafkreigj4mi6cnegeh6hh6rxdjb63l4d7dowjcxxeyakgnijvoues3svii'; | ||
const notPersistedCid = | ||
'bafkreih5pe7r3ucfdebiu7wjx3jr35qpbxqkxm5eneb2s2zu6t7yfqllci'; // CID of { claimType: 'hello world not persisted bafybeicg2rebjoofv4kbyovkw7af3rpiitvnl6i7ckcywaq6xjcxnc2mby' } | ||
|
||
beforeEach(async () => { | ||
jest.restoreAllMocks(); | ||
|
||
didStoreCluster = app.get(DidStoreCluster); | ||
didStoreInfura = app.get(DidStoreGateway); | ||
pinsQueue = app.get(getQueueToken('pins')); | ||
|
||
const manager = app.get(EntityManager); | ||
const dbConnection = app.get(Connection); | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
queryRunner = manager.queryRunner = | ||
dbConnection.createQueryRunner('master'); | ||
await queryRunner.startTransaction(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await queryRunner.rollbackTransaction(); | ||
await queryRunner.release(); | ||
}); | ||
|
||
it('should be able to post claim', async () => { | ||
const claimData = { | ||
claimType: 'claim type', | ||
claimTypeVersion: 1, | ||
fields: [], | ||
issuerFields: [], | ||
}; | ||
const requester = await randomUser(); | ||
|
||
const { text: cid } = await request(app.getHttpServer()) | ||
.post(`/v1/ipfs/`) | ||
.set('Cookie', requester.cookies) | ||
.send(claimData) | ||
.expect(HttpStatus.CREATED); | ||
|
||
const get = jest.spyOn(didStoreCluster, 'get'); | ||
const { text: stored } = await request(app.getHttpServer()) | ||
.get(`/v1/ipfs/${cid}`) | ||
.set('Cookie', requester.cookies) | ||
.expect(HttpStatus.OK); | ||
expect(get).toBeCalledTimes(1); | ||
|
||
expect(JSON.parse(stored)).toStrictEqual(claimData); | ||
}); | ||
|
||
it('should return 404 if claim was not persisted in IPFS', async () => { | ||
const didStoreInfuraGet = jest.spyOn(didStoreInfura, 'get'); | ||
const requester = await randomUser(); | ||
|
||
const cid = notPersistedCid; | ||
didStoreInfuraGet.mockRejectedValueOnce({ response: { status: 504 } }); | ||
await request(app.getHttpServer()) | ||
.get(`/v1/ipfs/${cid}`) | ||
.set('Cookie', requester.cookies) | ||
.expect(HttpStatus.NOT_FOUND); | ||
}); | ||
|
||
it('claim persisted in IPFS should be pinned in cluster', async () => { | ||
const didStoreClusterGet = jest.spyOn(didStoreCluster, 'get'); | ||
const didStoreInfuraGet = jest.spyOn(didStoreInfura, 'get'); | ||
|
||
const requester = await randomUser(); | ||
|
||
const claim = JSON.stringify(notPinned); | ||
const cid = notPinnedCid; | ||
|
||
const claimPinned = new Promise<void>((resolve) => { | ||
pinsQueue.on('completed', () => { | ||
resolve(); | ||
}); | ||
}); | ||
didStoreInfuraGet.mockResolvedValueOnce(claim); | ||
await request(app.getHttpServer()) | ||
.get(`/v1/ipfs/${cid}`) | ||
.set('Cookie', requester.cookies); | ||
|
||
await claimPinned; | ||
|
||
expect(didStoreClusterGet).toBeCalledTimes(0); | ||
expect(didStoreInfuraGet).toBeCalledTimes(1); | ||
|
||
await request(app.getHttpServer()) | ||
.get(`/v1/ipfs/${cid}`) | ||
.set('Cookie', requester.cookies); | ||
|
||
expect(didStoreClusterGet).toBeCalledTimes(1); | ||
expect(didStoreInfuraGet).toBeCalledTimes(1); | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# This configuration is based on https://github.com/ipfs-cluster/ipfs-cluster/blob/master/docker-compose.yml | ||
|
||
version: '3.4' | ||
|
||
services: | ||
cluster_proxy: | ||
container_name: cluster_proxy | ||
image: nginx:alpine | ||
ports: | ||
- 8080:8080 | ||
volumes: | ||
- ./nginx.conf:/etc/nginx/nginx.conf | ||
depends_on: | ||
- cluster0 | ||
- ipfs0 | ||
|
||
################################################################################## | ||
## Cluster PEER 0 ################################################################ | ||
################################################################################## | ||
|
||
ipfs0: | ||
container_name: ipfs0 | ||
image: ipfs/go-ipfs:latest | ||
expose: | ||
- '8080' | ||
# ports: | ||
# - "4001:4001" # ipfs swarm - expose if needed/wanted | ||
# - "5001:5001" # ipfs api - expose if needed/wanted | ||
# - "8080:8080" # ipfs gateway - expose if needed/wanted | ||
volumes: | ||
- ipfs0:/data/ipfs | ||
|
||
cluster0: | ||
container_name: cluster0 | ||
image: ipfs/ipfs-cluster:latest | ||
depends_on: | ||
- ipfs0 | ||
environment: | ||
CLUSTER_PEERNAME: cluster0 | ||
CLUSTER_SECRET: ${CLUSTER_SECRET} # From shell variable if set | ||
CLUSTER_IPFSHTTP_NODEMULTIADDRESS: /dns4/ipfs0/tcp/5001 | ||
CLUSTER_CRDT_TRUSTEDPEERS: '*' # Trust all peers in Cluster | ||
CLUSTER_RESTAPI_HTTPLISTENMULTIADDRESS: /ip4/0.0.0.0/tcp/9094 # Expose API | ||
CLUSTER_MONITORPINGINTERVAL: 2s # Speed up peer discovery | ||
expose: | ||
- '9094' | ||
# ports: | ||
# Open API port (allows ipfs-cluster-ctl usage on host) | ||
# - "127.0.0.1:9094:9094" | ||
# The cluster swarm port would need to be exposed if this container | ||
# was to connect to cluster peers on other hosts. | ||
# But this is just a testing cluster. | ||
# - "9095:9095" # Cluster IPFS Proxy endpoint | ||
# - "9096:9096" # Cluster swarm endpoint | ||
volumes: | ||
- cluster0:/data/ipfs-cluster | ||
|
||
################################################################################## | ||
## Cluster PEER 1 ################################################################ | ||
################################################################################## | ||
|
||
# See Cluster PEER 0 for comments (all removed here and below) | ||
ipfs1: | ||
container_name: ipfs1 | ||
image: ipfs/go-ipfs:latest | ||
volumes: | ||
- ipfs1:/data/ipfs | ||
|
||
cluster1: | ||
container_name: cluster1 | ||
image: ipfs/ipfs-cluster:latest | ||
depends_on: | ||
- ipfs1 | ||
environment: | ||
CLUSTER_PEERNAME: cluster1 | ||
CLUSTER_SECRET: ${CLUSTER_SECRET} | ||
CLUSTER_IPFSHTTP_NODEMULTIADDRESS: /dns4/ipfs1/tcp/5001 | ||
CLUSTER_CRDT_TRUSTEDPEERS: '*' | ||
CLUSTER_MONITORPINGINTERVAL: 2s # Speed up peer discovery | ||
volumes: | ||
- cluster1:/data/ipfs-cluster | ||
|
||
################################################################################## | ||
## Cluster PEER 2 ################################################################ | ||
################################################################################## | ||
|
||
# See Cluster PEER 0 for comments (all removed here and below) | ||
ipfs2: | ||
container_name: ipfs2 | ||
image: ipfs/go-ipfs:latest | ||
volumes: | ||
- ipfs2:/data/ipfs | ||
|
||
cluster2: | ||
container_name: cluster2 | ||
image: ipfs/ipfs-cluster:latest | ||
depends_on: | ||
- ipfs2 | ||
environment: | ||
CLUSTER_PEERNAME: cluster2 | ||
CLUSTER_SECRET: ${CLUSTER_SECRET} | ||
CLUSTER_IPFSHTTP_NODEMULTIADDRESS: /dns4/ipfs2/tcp/5001 | ||
CLUSTER_CRDT_TRUSTEDPEERS: '*' | ||
CLUSTER_MONITORPINGINTERVAL: 2s # Speed up peer discovery | ||
volumes: | ||
- cluster2:/data/ipfs-cluster | ||
# For adding more peers, copy PEER 1 and rename things to ipfs2, cluster2. | ||
# Keep bootstrapping to cluster0. | ||
|
||
volumes: | ||
ipfs0: | ||
ipfs1: | ||
ipfs2: | ||
cluster0: | ||
cluster1: | ||
cluster2: |
Oops, something went wrong.