-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate rounds and passport query to data layer (#2731)
* chore: migrate `get round by id` query to data layer * chore: eagerly validate chains against chain ids * chore: make config item optional * chore: move get rounds query to data layer * chore: move passport verification to the data layer * chore: tidy up test * chore: remove positional arguments * lint * fix: handle empty string for round filter
- Loading branch information
Showing
35 changed files
with
1,004 additions
and
546 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { faker } from "@faker-js/faker"; | ||
import { describe, test, expect } from "vitest"; | ||
import { cleanRoundData, sortRounds } from "./legacy"; | ||
import { RoundMetadata, RoundOverview } from ".."; | ||
|
||
// TODO switch to ESM and move these tests into `legacy.ts` using in-source test | ||
// definition with `import.meta.vitest` | ||
|
||
describe("legacy", () => { | ||
const MOCKED_ROUNDS_COUNT = 5; | ||
|
||
const MOCKED_ROUNDS = Array.from({ length: MOCKED_ROUNDS_COUNT }).map(() => | ||
generateRoundOverviewData(), | ||
); | ||
|
||
const DEFAULT_FILTER = { | ||
orderBy: "", | ||
orderDirection: "", | ||
status: "", | ||
network: "", | ||
type: "", | ||
} as const; | ||
|
||
test("cleanRoundData", async () => { | ||
expect( | ||
// Fix milliseconds to seconds | ||
cleanRoundData([ | ||
{ | ||
...MOCKED_ROUNDS[0], | ||
// Multiply by 1000 and check that it's still the value in seconds | ||
roundStartTime: String(+MOCKED_ROUNDS[0].roundStartTime * 1000), | ||
}, | ||
])[0].roundStartTime, | ||
).toBe(MOCKED_ROUNDS[0].roundStartTime); | ||
|
||
expect( | ||
// Fix overflowed timestamp | ||
cleanRoundData([ | ||
{ | ||
...MOCKED_ROUNDS[0], | ||
// Multiply by 1000 and check that it's still the value in seconds | ||
roundStartTime: | ||
"115792089237316195423570985008687907853269984665640564039457584007913129639935", | ||
}, | ||
])[0].roundStartTime, | ||
).toBe(undefined); | ||
}); | ||
|
||
test("sortRounds", async () => { | ||
const sortedAsc = sortRounds( | ||
[{ matchAmount: "10" }, { matchAmount: "1" }] as RoundOverview[], | ||
{ | ||
...DEFAULT_FILTER, | ||
orderBy: "matchAmount", | ||
orderDirection: "asc", | ||
}, | ||
); | ||
expect(sortedAsc[0].matchAmount).toEqual("1"); | ||
expect(sortedAsc[1].matchAmount).toEqual("10"); | ||
|
||
const sortedDesc = sortRounds( | ||
[{ matchAmount: "10" }, { matchAmount: "1" }] as RoundOverview[], | ||
{ | ||
...DEFAULT_FILTER, | ||
orderBy: "matchAmount", | ||
orderDirection: "desc", | ||
}, | ||
); | ||
expect(sortedDesc[0].matchAmount).toEqual("10"); | ||
expect(sortedDesc[1].matchAmount).toEqual("1"); | ||
}); | ||
}); | ||
|
||
const generateRoundOverviewData = ( | ||
overrides?: Partial<RoundOverview>, | ||
roundMetadataOverrides?: Partial<RoundMetadata>, | ||
): RoundOverview => { | ||
return { | ||
id: faker.finance.ethereumAddress(), | ||
chainId: 1, | ||
createdAt: generateTimestamp(), | ||
roundMetaPtr: { | ||
protocol: 1, | ||
pointer: generateIpfsCid(), | ||
}, | ||
applicationMetaPtr: { | ||
protocol: 1, | ||
pointer: generateIpfsCid(), | ||
}, | ||
applicationsStartTime: generateTimestamp(), | ||
applicationsEndTime: generateTimestamp(10), | ||
roundStartTime: generateTimestamp(20), | ||
roundEndTime: generateTimestamp(30), | ||
matchAmount: "1000000000000000000000000", | ||
token: faker.finance.ethereumAddress(), | ||
roundMetadata: generateRoundMetadata(roundMetadataOverrides), | ||
projects: Array.from({ length: 2 }).map((_, i) => ({ id: String(i) })), | ||
payoutStrategy: { | ||
id: "someid", | ||
strategyName: "MERKLE", | ||
}, | ||
...overrides, | ||
}; | ||
}; | ||
|
||
const generateIpfsCid = (): string => { | ||
return faker.string.alpha({ length: { min: 59, max: 59 }, casing: "lower" }); | ||
}; | ||
|
||
const generateTimestamp = (days?: number): string => | ||
Math.floor(Number(faker.date.soon({ days })) / 1000).toString(); | ||
|
||
const generateRoundMetadata = ( | ||
overrides?: Partial<RoundMetadata>, | ||
): RoundMetadata => ({ | ||
name: faker.company.name(), | ||
roundType: "public", | ||
eligibility: { | ||
description: faker.lorem.sentence(), | ||
requirements: [ | ||
{ requirement: faker.lorem.sentence() }, | ||
{ requirement: faker.lorem.sentence() }, | ||
], | ||
}, | ||
programContractAddress: faker.finance.ethereumAddress(), | ||
...overrides, | ||
}); |
Oops, something went wrong.
6516537
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
manager-staging – ./packages/round-manager
manager-staging-grants-stack.vercel.app
manager-staging-git-main-grants-stack.vercel.app
grants-stack-manager-staging.vercel.app
6516537
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
manager – ./packages/round-manager
manager.gitcoin.co
manager-git-main-grants-stack.vercel.app
grants-stack-round-manager.vercel.app
manager-grants-stack.vercel.app
6516537
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
builder – ./packages/builder
builder-grants-stack.vercel.app
builder-git-main-grants-stack.vercel.app
builder.gitcoin.co
builder-kappa-one.vercel.app
6516537
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
explorer-staging – ./packages/grant-explorer
explorer-staging-grants-stack.vercel.app
grants-stack-explorer-staging.vercel.app
explorer-staging-git-main-grants-stack.vercel.app
6516537
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
builder-staging – ./packages/builder
grants-stack-builder-staging.vercel.app
builder-staging-git-main-grants-stack.vercel.app
builder-staging-grants-stack.vercel.app