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

Prep Distribitor for V2 by renaming to V1 #754

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions apps/distributor/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express, { type Request, type Response, Router } from 'express'
import pino from 'pino'
import { DistributorWorker } from './distributor'
import { DistributorV1Worker } from './distributor'
import { StandardMerkleTree } from '@openzeppelin/merkle-tree'
import { selectAll } from 'app/utils/supabase/selectAll'
import { supabaseAdmin } from './supabase'
Expand All @@ -11,7 +11,7 @@ const logger = pino({
})

// Initialize DistributorWorker
const distributorWorker = new DistributorWorker(logger)
const distributorV1Worker = new DistributorV1Worker(logger)

// Initialize Express app
const app = express()
Expand All @@ -25,10 +25,10 @@ app.get('/', (req, res) => {

const distributorRouter = Router()

distributorRouter.get('/', async (req: Request, res: Response) => {
distributorRouter.get('/v1', async (req: Request, res: Response) => {
res.json({
distributor: true,
...distributorWorker.toJSON(),
...distributorV1Worker.toJSON(),
})
})

Expand Down Expand Up @@ -97,11 +97,11 @@ distributorRouter.post('/merkle', checkAuthorization, async (req: Request, res:
res.json(result)
})

distributorRouter.post('/', checkAuthorization, async (req, res) => {
distributorRouter.post('/v1', checkAuthorization, async (req, res) => {
const { id } = req.body as { id: string }
logger.info({ id }, 'Received request to calculate distribution')
try {
await distributorWorker.calculateDistribution(id)
await distributorV1Worker.calculateDistribution(id)
} catch (err) {
logger.error(err, 'Error while calculating distribution')
res.status(500).json({
Expand Down
12 changes: 6 additions & 6 deletions apps/distributor/src/distributor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import request from 'supertest'
import app from './app'
import { supabaseAdmin } from './supabase'
import pino from 'pino'
import { DistributorWorker } from './distributor'
import { DistributorV1Worker } from './distributor'
import type { Tables } from '@my/supabase/database.types'

describe('Root Route', () => {
Expand All @@ -20,19 +20,19 @@ describe('Root Route', () => {

describe('Distributor Route', () => {
it('should reject unauthorized requests', async () => {
const res = await request(app).post('/distributor')
const res = await request(app).post('/distributor/v1')

expect(res.statusCode).toBe(401)
expect(res.body).toEqual('Unauthorized')
})

it('should handle authorization correctly', async () => {
const res = await request(app).get('/distributor')
const res = await request(app).get('/distributor/v1')

expect(res.statusCode).toBe(200)
expect(res.body).toMatchObject({
distributor: true,
running: true,
running: false,
})
})

Expand All @@ -58,7 +58,7 @@ describe('Distributor Route', () => {
expect(distribution).toBeDefined()

const res = await request(app)
.post('/distributor')
.post('/distributor/v1')
.set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${process.env.SUPABASE_SERVICE_ROLE}`)
.send({ id: distribution.number })
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('Distributor Worker', () => {
const logger = pino({
level: 'silent',
})
const distributor = new DistributorWorker(logger, false)
const distributor = new DistributorV1Worker(logger, false)
await distributor.calculateDistribution('4')

const expectedShares = [
Expand Down
2 changes: 1 addition & 1 deletion apps/distributor/src/distributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const jsonBigint = (key, value) => {
return value
}

export class DistributorWorker {
export class DistributorV1Worker {
private log: Logger
private running: boolean
private id: string
Expand Down
Loading
Loading