Skip to content

Commit

Permalink
remove redundant POLPriceAtRoundStart field and use tokenPrice instea…
Browse files Browse the repository at this point in the history
…d of it
  • Loading branch information
ae2079 committed Sep 29, 2024
1 parent 9ba7f4b commit 0cf6243
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 68 deletions.
12 changes: 0 additions & 12 deletions migration/1727434746651-addRoundCaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,21 @@ export class AddRoundCaps1727434746651 implements MigrationInterface {
await queryRunner.query(
`ALTER TABLE "qf_round" ADD "roundUSDCapPerUserPerProject" integer`,
);
await queryRunner.query(
`ALTER TABLE "qf_round" ADD "POLPriceAtRoundStart" numeric(18,8)`,
);
await queryRunner.query(
`ALTER TABLE "early_access_round" ADD "roundUSDCapPerProject" integer`,
);
await queryRunner.query(
`ALTER TABLE "early_access_round" ADD "roundUSDCapPerUserPerProject" integer`,
);
await queryRunner.query(
`ALTER TABLE "early_access_round" ADD "POLPriceAtRoundStart" numeric(18,8)`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "early_access_round" DROP COLUMN "POLPriceAtRoundStart"`,
);
await queryRunner.query(
`ALTER TABLE "early_access_round" DROP COLUMN "roundUSDCapPerUserPerProject"`,
);
await queryRunner.query(
`ALTER TABLE "early_access_round" DROP COLUMN "roundUSDCapPerProject"`,
);
await queryRunner.query(
`ALTER TABLE "qf_round" DROP COLUMN "POLPriceAtRoundStart"`,
);
await queryRunner.query(
`ALTER TABLE "qf_round" DROP COLUMN "roundUSDCapPerUserPerProject"`,
);
Expand Down
6 changes: 1 addition & 5 deletions src/entities/earlyAccessRound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
UpdateDateColumn,
Index,
} from 'typeorm';
import { Field, ID, ObjectType, Int, Float } from 'type-graphql';
import { Field, ID, ObjectType, Int } from 'type-graphql';

@Entity()
@ObjectType()
Expand Down Expand Up @@ -37,10 +37,6 @@ export class EarlyAccessRound extends BaseEntity {
@Column({ nullable: true })
roundUSDCapPerUserPerProject?: number;

@Field(() => Float, { nullable: true })
@Column({ type: 'decimal', precision: 18, scale: 8, nullable: true })
POLPriceAtRoundStart?: number;

@Field(() => Date)
@CreateDateColumn()
createdAt: Date;
Expand Down
4 changes: 0 additions & 4 deletions src/entities/qfRound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ export class QfRound extends BaseEntity {
@Column({ nullable: true })
roundUSDCapPerUserPerProject?: number;

@Field(() => Float, { nullable: true })
@Column({ type: 'decimal', precision: 18, scale: 8, nullable: true })
POLPriceAtRoundStart?: number;

// only projects with status active can be listed automatically
isEligibleNetwork(donationNetworkId: number): boolean {
// when not specified, all are valid
Expand Down
20 changes: 8 additions & 12 deletions src/repositories/earlyAccessRoundRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('EarlyAccessRound Repository Test Cases', () => {
endDate: new Date('2024-09-05'),
roundUSDCapPerProject: 1000000,
roundUSDCapPerUserPerProject: 50000,
POLPriceAtRoundStart: 0.12345678,
tokenPrice: 0.12345678,
};

const savedRound = await saveRoundDirectlyToDb(roundData);
Expand All @@ -61,9 +61,7 @@ describe('EarlyAccessRound Repository Test Cases', () => {
expect(savedRound.roundUSDCapPerUserPerProject).to.equal(
roundData.roundUSDCapPerUserPerProject,
);
expect(savedRound.POLPriceAtRoundStart).to.equal(
roundData.POLPriceAtRoundStart,
);
expect(savedRound.tokenPrice).to.equal(roundData.tokenPrice);
});

it('should find all Early Access Rounds', async () => {
Expand All @@ -74,15 +72,15 @@ describe('EarlyAccessRound Repository Test Cases', () => {
endDate: new Date('2024-09-05'),
roundUSDCapPerProject: 1000000,
roundUSDCapPerUserPerProject: 50000,
POLPriceAtRoundStart: 0.12345678,
tokenPrice: 0.12345678,
});
await saveRoundDirectlyToDb({
roundNumber: 2,
startDate: new Date('2024-09-06'),
endDate: new Date('2024-09-10'),
roundUSDCapPerProject: 2000000,
roundUSDCapPerUserPerProject: 100000,
POLPriceAtRoundStart: 0.23456789,
tokenPrice: 0.23456789,
});

const rounds = await findAllEarlyAccessRounds();
Expand All @@ -92,7 +90,7 @@ describe('EarlyAccessRound Repository Test Cases', () => {
expect(rounds[0]).to.be.an.instanceof(EarlyAccessRound);
expect(rounds[0].roundUSDCapPerProject).to.equal(1000000);
expect(rounds[1].roundUSDCapPerUserPerProject).to.equal(100000);
expect(Number(rounds[0].POLPriceAtRoundStart)).to.equal(0.12345678);
expect(rounds[0].tokenPrice).to.equal(0.12345678);
});

it('should find the active Early Access Round', async () => {
Expand All @@ -102,7 +100,7 @@ describe('EarlyAccessRound Repository Test Cases', () => {
endDate: new Date(new Date().setDate(new Date().getDate() + 1)), // tomorrow
roundUSDCapPerProject: 500000,
roundUSDCapPerUserPerProject: 25000,
POLPriceAtRoundStart: 0.11111111,
tokenPrice: 0.11111111,
};

const inactiveRoundData = {
Expand All @@ -111,7 +109,7 @@ describe('EarlyAccessRound Repository Test Cases', () => {
endDate: new Date(new Date().getDate() + 2),
roundUSDCapPerProject: 1000000,
roundUSDCapPerUserPerProject: 50000,
POLPriceAtRoundStart: 0.22222222,
tokenPrice: 0.22222222,
};

// Save both active and inactive rounds
Expand All @@ -134,9 +132,7 @@ describe('EarlyAccessRound Repository Test Cases', () => {
expect(activeRound?.roundUSDCapPerUserPerProject).to.equal(
activeRoundData.roundUSDCapPerUserPerProject,
);
expect(Number(activeRound?.POLPriceAtRoundStart)).to.equal(
activeRoundData.POLPriceAtRoundStart,
);
expect(activeRound?.tokenPrice).to.equal(activeRoundData.tokenPrice);
});

it('should return null when no active Early Access Round is found', async () => {
Expand Down
39 changes: 16 additions & 23 deletions src/repositories/qfRoundRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,19 +408,18 @@ function findQfRoundByIdTestCases() {
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().add(1, 'days').toDate(),
roundUSDCapPerProject: 500000, // New field
roundUSDCapPerUserPerProject: 25000, // New field
POLPriceAtRoundStart: 0.12345678, // New field
roundUSDCapPerProject: 500000,
roundUSDCapPerUserPerProject: 25000,
tokenPrice: 0.12345678,
});
await qfRound.save();

const result = await findQfRoundById(qfRound.id);
assert.equal(result?.id, qfRound.id);

// Additional assertions for the new fields
assert.equal(result?.roundUSDCapPerProject, 500000);
assert.equal(result?.roundUSDCapPerUserPerProject, 25000);
assert.equal(Number(result?.POLPriceAtRoundStart), 0.12345678);
assert.equal(result?.tokenPrice, 0.12345678);

qfRound.isActive = false;
await qfRound.save();
Expand All @@ -435,19 +434,17 @@ function findQfRoundByIdTestCases() {
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().subtract(1, 'days').toDate(),
roundUSDCapPerProject: 500000, // New field
roundUSDCapPerUserPerProject: 25000, // New field
POLPriceAtRoundStart: 0.12345678, // New field
roundUSDCapPerProject: 500000,
roundUSDCapPerUserPerProject: 25000,
tokenPrice: 0.12345678,
});
await qfRound.save();

const result = await findQfRoundById(qfRound.id);
assert.equal(result?.id, qfRound.id);

// Additional assertions for the new fields
assert.equal(result?.roundUSDCapPerProject, 500000);
assert.equal(result?.roundUSDCapPerUserPerProject, 25000);
assert.equal(Number(result?.POLPriceAtRoundStart), 0.12345678);
assert.equal(result?.tokenPrice, 0.12345678);
});

it('should return null if id is invalid', async () => {
Expand All @@ -466,19 +463,17 @@ function findQfRoundBySlugTestCases() {
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().add(1, 'days').toDate(),
roundUSDCapPerProject: 500000, // New field
roundUSDCapPerUserPerProject: 25000, // New field
POLPriceAtRoundStart: 0.12345678, // New field
roundUSDCapPerProject: 500000,
roundUSDCapPerUserPerProject: 25000,
tokenPrice: 0.12345678,
});
await qfRound.save();

const result = await findQfRoundBySlug(qfRound.slug);
assert.equal(result?.slug, qfRound.slug);

// Additional assertions for the new fields
assert.equal(result?.roundUSDCapPerProject, 500000);
assert.equal(result?.roundUSDCapPerUserPerProject, 25000);
assert.equal(Number(result?.POLPriceAtRoundStart), 0.12345678);
assert.equal(result?.tokenPrice, 0.12345678);

qfRound.isActive = false;
await qfRound.save();
Expand All @@ -493,19 +488,17 @@ function findQfRoundBySlugTestCases() {
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().subtract(1, 'days').toDate(),
roundUSDCapPerProject: 500000, // New field
roundUSDCapPerUserPerProject: 25000, // New field
POLPriceAtRoundStart: 0.12345678, // New field
roundUSDCapPerProject: 500000,
roundUSDCapPerUserPerProject: 25000,
tokenPrice: 0.12345678,
});
await qfRound.save();

const result = await findQfRoundById(qfRound.id);
assert.equal(result?.id, qfRound.id);

// Additional assertions for the new fields
assert.equal(result?.roundUSDCapPerProject, 500000);
assert.equal(result?.roundUSDCapPerUserPerProject, 25000);
assert.equal(Number(result?.POLPriceAtRoundStart), 0.12345678);
assert.equal(result?.tokenPrice, 0.12345678);
});

it('should return null if slug is invalid', async () => {
Expand Down
16 changes: 8 additions & 8 deletions src/resolvers/roundsResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function fetchAllRoundsTestCases() {
endDate: moment().add(10, 'days').toDate(),
roundUSDCapPerProject: 500000, // Nullable field
roundUSDCapPerUserPerProject: 25000, // Nullable field
POLPriceAtRoundStart: 0.12345678, // Nullable field
tokenPrice: 0.12345678, // Nullable field
}).save();

const qfRound2 = await QfRound.create({
Expand Down Expand Up @@ -114,10 +114,10 @@ function fetchAllRoundsTestCases() {
// Verify nullable fields
assert.equal(qfRounds[1].roundUSDCapPerProject, 500000);
assert.equal(qfRounds[1].roundUSDCapPerUserPerProject, 25000);
assert.equal(Number(qfRounds[1].POLPriceAtRoundStart), 0.12345678);
assert.equal(qfRounds[1].tokenPrice, 0.12345678);
assert.isNull(qfRounds[0].roundUSDCapPerProject);
assert.isNull(qfRounds[0].roundUSDCapPerUserPerProject);
assert.isNull(qfRounds[0].POLPriceAtRoundStart);
assert.isNull(qfRounds[0].tokenPrice);
});
}

Expand Down Expand Up @@ -162,7 +162,7 @@ function fetchActiveRoundTestCases() {
endDate: moment().add(2, 'days').toDate(),
roundUSDCapPerProject: 500000,
roundUSDCapPerUserPerProject: 25000,
POLPriceAtRoundStart: 0.12345678,
tokenPrice: 0.12345678,
}).save();

// Create a non-active QF round
Expand All @@ -176,7 +176,7 @@ function fetchActiveRoundTestCases() {
isActive: false,
roundUSDCapPerProject: 100000,
roundUSDCapPerUserPerProject: 5000,
POLPriceAtRoundStart: 0.54321,
tokenPrice: 0.54321,
}).save();

// Query for the active round
Expand All @@ -194,7 +194,7 @@ function fetchActiveRoundTestCases() {
);
assert.equal(response.activeRound.roundUSDCapPerProject, 500000);
assert.equal(response.activeRound.roundUSDCapPerUserPerProject, 25000);
assert.equal(Number(response.activeRound.POLPriceAtRoundStart), 0.12345678);
assert.equal(response.activeRound.tokenPrice, 0.12345678);
});

it('should return the currently active QF round and no active Early Access round', async () => {
Expand All @@ -216,7 +216,7 @@ function fetchActiveRoundTestCases() {
isActive: true,
roundUSDCapPerProject: 500000,
roundUSDCapPerUserPerProject: 25000,
POLPriceAtRoundStart: 0.12345678,
tokenPrice: 0.12345678,
}).save();

// Query for the active round
Expand All @@ -231,7 +231,7 @@ function fetchActiveRoundTestCases() {
assert.equal(response.activeRound.name, activeQfRound.name);
assert.equal(response.activeRound.roundUSDCapPerProject, 500000);
assert.equal(response.activeRound.roundUSDCapPerUserPerProject, 25000);
assert.equal(Number(response.activeRound.POLPriceAtRoundStart), 0.12345678);
assert.equal(response.activeRound.tokenPrice, 0.12345678);
});

it('should return null when there are no active rounds', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/graphqlQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,7 @@ export const fetchAllRoundsQuery = `
updatedAt
roundUSDCapPerProject
roundUSDCapPerUserPerProject
POLPriceAtRoundStart
tokenPrice
}
... on QfRound {
name
Expand All @@ -2063,7 +2063,7 @@ export const fetchAllRoundsQuery = `
endDate
roundUSDCapPerProject
roundUSDCapPerUserPerProject
POLPriceAtRoundStart
tokenPrice
}
}
}
Expand All @@ -2081,7 +2081,7 @@ export const fetchActiveRoundQuery = `
updatedAt
roundUSDCapPerProject
roundUSDCapPerUserPerProject
POLPriceAtRoundStart
tokenPrice
}
... on QfRound {
name
Expand All @@ -2091,7 +2091,7 @@ export const fetchActiveRoundQuery = `
endDate
roundUSDCapPerProject
roundUSDCapPerUserPerProject
POLPriceAtRoundStart
tokenPrice
}
}
}
Expand Down

0 comments on commit 0cf6243

Please sign in to comment.