diff --git a/__e2e__/mock-server.ts b/__e2e__/mock-server.ts index 6ddfe3ca..f553fc68 100644 --- a/__e2e__/mock-server.ts +++ b/__e2e__/mock-server.ts @@ -34,6 +34,9 @@ async function main() { displayName: 'Carla', description: 'Test user 3', })) + if (inviteRequired) { + await server.mocker.createInvite(server.mocker.users.alice.did) + } } if ('follows' in url.query) { console.log('Generating mock follows') diff --git a/jest/test-pds.ts b/jest/test-pds.ts index 3c14c553..34c3e8bc 100644 --- a/jest/test-pds.ts +++ b/jest/test-pds.ts @@ -1,20 +1,9 @@ -import {AddressInfo} from 'net' -import os from 'os' import net from 'net' import path from 'path' import fs from 'fs' -import * as crypto from '@atproto/crypto' -import {PDS, ServerConfig, Database, MemoryBlobStore} from '@atproto/pds' -import * as plc from '@did-plc/lib' -import {PlcServer, Database as PlcDatabase} from '@did-plc/server' +import {TestPds as DevEnvTestPDS, TestNetworkNoAppView} from '@atproto/dev-env' import {BskyAgent} from '@atproto/api' -const ADMIN_PASSWORD = 'admin-pass' -const SECOND = 1000 -const MINUTE = SECOND * 60 -const HOUR = MINUTE * 60 -const DAY = HOUR * 24 - export interface TestUser { email: string did: string @@ -32,81 +21,13 @@ export interface TestPDS { export async function createServer( {inviteRequired}: {inviteRequired: boolean} = {inviteRequired: false}, ): Promise { - const repoSigningKey = await crypto.Secp256k1Keypair.create() - const plcRotationKey = await crypto.Secp256k1Keypair.create() const port = await getPort() - - const plcDb = PlcDatabase.mock() - - const plcServer = PlcServer.create({db: plcDb}) - const plcListener = await plcServer.start() - const plcPort = (plcListener.address() as AddressInfo).port - const plcUrl = `http://localhost:${plcPort}` - - const recoveryKey = (await crypto.Secp256k1Keypair.create()).did() - - const plcClient = new plc.Client(plcUrl) - const serverDid = await plcClient.createDid({ - signingKey: repoSigningKey.did(), - rotationKeys: [recoveryKey, plcRotationKey.did()], - handle: 'localhost', - pds: `http://localhost:${port}`, - signer: plcRotationKey, - }) - - const blobstoreLoc = path.join(os.tmpdir(), crypto.randomStr(5, 'base32')) - - const cfg = new ServerConfig({ - debugMode: true, - version: '0.0.0', - scheme: 'http', - hostname: 'localhost', - port, - serverDid, - recoveryKey, - adminPassword: ADMIN_PASSWORD, - inviteRequired, - didPlcUrl: plcUrl, - didCacheMaxTTL: DAY, - didCacheStaleTTL: HOUR, - jwtSecret: 'jwt-secret', - availableUserDomains: ['.test'], - appUrlPasswordReset: 'app://forgot-password', - emailNoReplyAddress: 'noreply@blueskyweb.xyz', - publicUrl: `http://localhost:${port}`, - imgUriSalt: '9dd04221f5755bce5f55f47464c27e1e', - imgUriKey: - 'f23ecd142835025f42c3db2cf25dd813956c178392760256211f9d315f8ab4d8', - dbPostgresUrl: process.env.DB_POSTGRES_URL, - blobstoreLocation: `${blobstoreLoc}/blobs`, - blobstoreTmp: `${blobstoreLoc}/tmp`, - maxSubscriptionBuffer: 200, - repoBackfillLimitMs: HOUR, - userInviteInterval: 1, - labelerDid: 'did:example:labeler', - labelerKeywords: {}, - }) - - const db = - cfg.dbPostgresUrl !== undefined - ? Database.postgres({ - url: cfg.dbPostgresUrl, - schema: cfg.dbPostgresSchema, - }) - : Database.memory() - await db.migrateToLatestOrThrow() - - const blobstore = new MemoryBlobStore() - - const pds = PDS.create({ - db, - blobstore, - repoSigningKey, - plcRotationKey, - config: cfg, - }) - await pds.start() + const port2 = await getPort(port + 1) const pdsUrl = `http://localhost:${port}` + const {pds, plc} = await TestNetworkNoAppView.create({ + pds: {port, publicUrl: pdsUrl, inviteRequired}, + plc: {port: port2}, + }) const profilePic = fs.readFileSync( path.join(__dirname, '..', 'assets', 'default-avatar.jpg'), @@ -116,8 +37,8 @@ export async function createServer( pdsUrl, mocker: new Mocker(pds, pdsUrl, profilePic), async close() { - await pds.destroy() - await plcServer.destroy() + await pds.server.destroy() + await plc.server.destroy() }, } } @@ -127,7 +48,7 @@ class Mocker { users: Record = {} constructor( - public pds: PDS, + public pds: DevEnvTestPDS, public service: string, public profilePic: Uint8Array, ) { @@ -152,7 +73,11 @@ class Mocker { const inviteRes = await agent.api.com.atproto.server.createInviteCode( {useCount: 1}, { - headers: {authorization: `Basic ${btoa(`admin:${ADMIN_PASSWORD}`)}`}, + headers: { + authorization: `Basic ${btoa( + `admin:${this.pds.ctx.cfg.adminPassword}`, + )}`, + }, encoding: 'application/json', }, ) @@ -265,6 +190,21 @@ class Mocker { return await agent.like(uri, cid) } + async createInvite(forAccount: string) { + const agent = new BskyAgent({service: this.agent.service}) + await agent.api.com.atproto.server.createInviteCode( + {useCount: 1, forAccount}, + { + headers: { + authorization: `Basic ${btoa( + `admin:${this.pds.ctx.cfg.adminPassword}`, + )}`, + }, + encoding: 'application/json', + }, + ) + } + async labelAccount(label: string, user: string) { const did = this.users[user]?.did if (!did) { @@ -380,8 +320,8 @@ const checkAvailablePort = (port: number) => }) }) -async function getPort() { - for (let i = 3000; i < 65000; i++) { +async function getPort(start = 3000) { + for (let i = start; i < 65000; i++) { if (await checkAvailablePort(i)) { return i } diff --git a/package.json b/package.json index bbfa5f93..053a4d2f 100644 --- a/package.json +++ b/package.json @@ -142,7 +142,8 @@ "zod": "^3.20.2" }, "devDependencies": { - "@atproto/pds": "^0.1.10", + "@atproto/dev-env": "^0.2.2", + "@atproto/pds": "^0.2.0-beta.2", "@babel/core": "^7.20.0", "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", diff --git a/src/view/com/lists/ListActions.tsx b/src/view/com/lists/ListActions.tsx index 4e6f7e6b..ee5a2afc 100644 --- a/src/view/com/lists/ListActions.tsx +++ b/src/view/com/lists/ListActions.tsx @@ -25,7 +25,8 @@ export const ListActions = ({ let buttons = [ ),