Skip to content
Closed
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
10 changes: 2 additions & 8 deletions src/escrow/escrow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,20 +584,14 @@ export class EscrowService {
recipients: Array<[string, number]>,
manager?: EntityManager,
): Promise<ContractInvocationResult> {
return this.invokeOnLockedEscrow(escrow, operation, () =>
this.soroban.invoke(
'release',
// `release(issue_id: u64, recipients)` — u64-typed on-chain (#301).
[u64(this.onChainKeyFor(escrow)), recipients],
this.contractOpts(escrow),
),
return this.invokeOnLockedEscrow(
escrow,
operation,
() =>
this.soroban.invoke(
'release',
[this.onChainKeyFor(escrow), recipients],
// `release(issue_id: u64, recipients)` — u64-typed on-chain (#301).
[u64(this.onChainKeyFor(escrow)), recipients],
this.contractOpts(escrow),
),
manager,
Expand Down
3 changes: 3 additions & 0 deletions src/github/github-webhooks.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@ describe('GithubWebhooksService', () => {

expect(bountiesService.markInReview).not.toHaveBeenCalled();
expect(bountiesService.markMergedAndRelease).not.toHaveBeenCalled();
});
});

// #308: a redelivered X-GitHub-Delivery used to hit the unique constraint
// on webhook_events.deliveryId and escape handleEvent as a 500, so every
// redelivery of that event failed forever.
Expand Down
6 changes: 5 additions & 1 deletion src/maintenance-pool/maintenance-pool.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ export class MaintenancePoolService {
}

async list(): Promise<MaintenancePool[]> {
return this.poolRepo.find();
// Load repository/sponsor/escrow — the frontend's adaptMaintenancePool
// needs them; a bare find() returned rows with no relations (#591).
return this.poolRepo.find({
relations: ['repository', 'createdBy', 'escrow'],
});
}
}
32 changes: 26 additions & 6 deletions src/milestones/milestones.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import type { Request } from 'express';
import { Test, TestingModule } from '@nestjs/testing';
import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';
import { MilestonesController } from './milestones.controller';
import { MilestonesService } from './milestones.service';
import { CreateMilestoneDto } from './dto/create-milestone.dto';
import { AssetType, MilestoneStatus } from '../common/enums';
import { getRepositoryToken } from '@nestjs/typeorm';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { RolesGuard } from '../auth/guards/roles.guard';
import { IdempotencyKey } from '../common/entities/idempotency-key.entity';

describe('MilestonesController', () => {
let controller: MilestonesController;
Expand All @@ -33,7 +36,13 @@ describe('MilestonesController', () => {

const module: TestingModule = await Test.createTestingModule({
controllers: [MilestonesController],
providers: [{ provide: MilestonesService, useValue: milestonesService }],
providers: [
{ provide: MilestonesService, useValue: milestonesService },
{
provide: getRepositoryToken(IdempotencyKey),
useValue: { findOne: jest.fn(), save: jest.fn(), create: jest.fn() },
},
],
})
.overrideGuard(JwtAuthGuard)
.useValue({ canActivate: () => true })
Expand All @@ -53,9 +62,14 @@ describe('MilestonesController', () => {
asset: AssetType.USDC,
};

await controller.create(dto);
await controller.create(dto, {
user: { userId: 'sponsor-1' },
} as unknown as Request);

expect(milestonesService.create).toHaveBeenCalledWith(dto);
expect(milestonesService.create).toHaveBeenCalledWith(
dto,
'sponsor-1',
);
});
});

Expand All @@ -77,9 +91,15 @@ describe('MilestonesController', () => {

describe('fund', () => {
it('calls milestonesService.fund with id and funderAddress', async () => {
await controller.fund('m1', { funderAddress: 'GFUNDER' });

expect(milestonesService.fund).toHaveBeenCalledWith('m1', 'GFUNDER');
await controller.fund('m1', { funderAddress: 'GFUNDER' }, {
user: { userId: 'sponsor-1' },
} as unknown as Request);

expect(milestonesService.fund).toHaveBeenCalledWith(
'm1',
'GFUNDER',
'sponsor-1',
);
});
});

Expand Down
13 changes: 8 additions & 5 deletions src/milestones/milestones.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MilestonesService } from './milestones.service';
import { EscrowService } from '../escrow/escrow.service';
import { Issue, Milestone } from '../common/entities';
import { AssetType, MilestoneStatus } from '../common/enums';
import { InvalidMilestoneTransitionError } from './milestone-state-machine';

describe('MilestonesService', () => {
let service: MilestonesService;
Expand Down Expand Up @@ -75,7 +76,7 @@ describe('MilestonesService', () => {
sponsorId: 'sponsor-1',
});

const milestone = await service.fund('m1', 'GFUNDER');
const milestone = await service.fund('m1', 'GFUNDER', 'sponsor-1');

expect(milestone.status).toBe(MilestoneStatus.FUNDED);
expect(milestone.escrowId).toBe('escrow-1');
Expand All @@ -90,7 +91,7 @@ describe('MilestonesService', () => {
sponsorId: 'sponsor-1',
});

await service.fund('m1', 'GFUNDER');
await service.fund('m1', 'GFUNDER', 'sponsor-1');

expect(escrowService.fund).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -110,7 +111,7 @@ describe('MilestonesService', () => {
sponsorId: null,
});

await service.fund('m2', 'GFUNDER');
await service.fund('m2', 'GFUNDER', 'sponsor-1');

expect(escrowService.fund).toHaveBeenCalledWith(
expect.objectContaining({ sponsorId: null }),
Expand All @@ -123,7 +124,7 @@ describe('MilestonesService', () => {
status: MilestoneStatus.FUNDED,
});

await expect(service.fund('m1', 'GFUNDER')).rejects.toThrow(
await expect(service.fund('m1', 'GFUNDER', 'sponsor-1')).rejects.toThrow(
'Milestone m1 is not OPEN (current: funded)',
);
});
Expand Down Expand Up @@ -263,6 +264,7 @@ describe('MilestonesService', () => {
'250.0000000',
'RECIPIENT_ADDR',
'user-1',
expect.anything(),
);
expect(payment.id).toBe('payment-1');
expect(dataSource.transaction).toHaveBeenCalled();
Expand Down Expand Up @@ -341,7 +343,7 @@ describe('MilestonesService', () => {

await expect(
service.resolveIssue('m1', 'i1', 'RECIPIENT_ADDR'),
).rejects.toThrow('Milestone m1 is not accepting distributions');
).rejects.toThrow(InvalidMilestoneTransitionError);
});

it('rejects when the issue does not belong to the milestone (#114)', async () => {
Expand Down Expand Up @@ -406,6 +408,7 @@ describe('MilestonesService', () => {
'333.3333333',
'RECIPIENT_ADDR',
undefined,
expect.anything(),
);
});
});
Expand Down
7 changes: 6 additions & 1 deletion src/milestones/milestones.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ export class MilestonesService {
}

async list(): Promise<Milestone[]> {
return this.milestoneRepo.find();
// Load the relations the frontend's adaptMilestone renders — repository
// (org/repo display), sponsor, escrow (fund status), issues (the linked
// issues). A bare find() returned empty rows (#591).
return this.milestoneRepo.find({
relations: ['repository', 'sponsor', 'escrow', 'issues'],
});
}

allocateBudget(id: string) {
Expand Down
21 changes: 0 additions & 21 deletions src/sponsors/sponsors.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,6 @@ function validatePage(limit?: number, offset?: number) {
throw new BadRequestException('offset must be >= 0');
}
return { limit, offset };
/**
* Parse optional limit/offset query params, rejecting NaN, negatives,
* non-integers, and limits above MAX_PAGE_LIMIT with a 400 (#280).
*/
function parsePagination(limit?: string, offset?: string) {
const parse = (name: string, raw: string | undefined, min: number, max: number) => {
if (raw === undefined || raw === '') return undefined;
const n = Number(raw);
if (!Number.isInteger(n) || n < min || n > max) {
throw new BadRequestException(
`${name} must be an integer between ${min} and ${max}`,
);
}
return n;
};
return {
limit: parse('limit', limit, 1, MAX_PAGE_LIMIT),
offset: parse('offset', offset, 0, Number.MAX_SAFE_INTEGER),
};
}

@ApiTags('sponsors')
Expand Down Expand Up @@ -73,7 +54,6 @@ export class SponsorsController {
) {
this.assertOwnsSponsor(user, id);
return this.sponsorsService.dashboard(id, validatePage(limit, offset));
return this.sponsorsService.dashboard(id, parsePagination(limit, offset));
}

@ApiBearerAuth()
Expand All @@ -91,6 +71,5 @@ export class SponsorsController {
id,
validatePage(limit, offset),
);
return this.sponsorsService.milestoneProgress(id, parsePagination(limit, offset));
}
}