-
Notifications
You must be signed in to change notification settings - Fork 16
chore(ens-referrals): Update referral program edition defaults #1849
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
Open
Y3drk
wants to merge
11
commits into
main
Choose a base branch
from
y3drk/chore/update-referral-program-edition-defaults
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f69570f
Update Referral Program Edition defaults
Y3drk f02d544
docs(changeset): Updated the Referral Program edition defaults to mat…
Y3drk 1f3e88c
Apply ai assistant's suggestions, pt.1 --> add unit tests and update …
Y3drk 621556e
Fix lint errors
Y3drk a9af00b
docs(changeset): Added unit tests for Referral Program edition defaults.
Y3drk 03dc906
Apply ai assistant's suggestions, pt.2 --> refine unit tests
Y3drk 08dca2d
Apply ai assistant's suggestions, pt.3
Y3drk 221abd6
Apply ai assistant's suggestions, pt.4
Y3drk 8b750bc
Merge branch 'main' of https://github.com/namehash/ensnode into y3drk…
Y3drk 2091e38
Apply 03/31/26 GitHub review feedback
Y3drk b350e0f
Apply ai assistant's suggestions, pt.5
Y3drk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| "@namehash/ens-referrals": minor | ||
| --- | ||
|
|
||
| Added unit tests for Referral Program edition defaults. |
This file contains hidden or 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,5 @@ | ||
| --- | ||
| "@namehash/ens-referrals": minor | ||
| --- | ||
|
|
||
| Updated the Referral Program edition defaults to match the [production configuration](https://ensawards.org/production-editions.json). | ||
This file contains hidden or 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 hidden or 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,208 @@ | ||
| import { beforeAll, describe, expect, it } from "vitest"; | ||
|
|
||
| import { ENSNamespaceIds, priceUsdc } from "@ensnode/ensnode-sdk"; | ||
|
|
||
| import { deserializeReferralProgramEditionConfigSetArray } from "./api"; | ||
| import type { ReferralProgramRulesPieSplit } from "./award-models/pie-split/rules"; | ||
| import type { ReferralProgramRulesRevShareLimit } from "./award-models/rev-share-limit/rules"; | ||
| import { ReferralProgramAwardModels } from "./award-models/shared/rules"; | ||
| import { | ||
| REFERRAL_PROGRAM_EDITION_SLUG_PATTERN, | ||
| type ReferralProgramEditionConfig, | ||
| } from "./edition"; | ||
| import { getDefaultReferralProgramEditionConfigSet } from "./edition-defaults"; | ||
|
|
||
| const PRODUCTION_EDITIONS_URL = "https://ensawards.org/production-editions.json"; | ||
|
|
||
| async function fetchProductionEditions(): Promise<ReferralProgramEditionConfig[] | null> { | ||
| let response: Response; | ||
| try { | ||
| response = await fetch(PRODUCTION_EDITIONS_URL); | ||
| } catch { | ||
| return null; | ||
| } | ||
Y3drk marked this conversation as resolved.
Show resolved
Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (!response.ok) return null; | ||
| // Intentionally let deserialize errors throw so parity regressions fail the suite. | ||
| return deserializeReferralProgramEditionConfigSetArray(await response.json()); | ||
Y3drk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| describe("getDefaultReferralProgramEditionConfigSet", () => { | ||
| const configSet = getDefaultReferralProgramEditionConfigSet(ENSNamespaceIds.Mainnet); | ||
|
|
||
| describe("Should match production editions", () => { | ||
| let productionEditions: ReferralProgramEditionConfig[] | null = null; | ||
|
|
||
| beforeAll(async () => { | ||
| productionEditions = await fetchProductionEditions(); | ||
| }); | ||
|
|
||
| it("Returns the expected number of editions", ({ skip }) => { | ||
| if (!productionEditions) | ||
| return skip(`Could not fetch production editions from ${PRODUCTION_EDITIONS_URL}`); | ||
| expect(configSet.size).toBe(productionEditions.length); | ||
| }); | ||
|
|
||
| it("Contains all expected edition `slug`s", ({ skip }) => { | ||
| if (!productionEditions) | ||
| return skip(`Could not fetch production editions from ${PRODUCTION_EDITIONS_URL}`); | ||
| expect(new Set(configSet.keys())).toStrictEqual( | ||
| new Set(productionEditions.map((e) => e.slug)), | ||
| ); | ||
| }); | ||
|
|
||
| it("Each edition matches its production counterpart", ({ skip }) => { | ||
| if (!productionEditions) | ||
| return skip(`Could not fetch production editions from ${PRODUCTION_EDITIONS_URL}`); | ||
|
|
||
| for (const expected of productionEditions) { | ||
| const edition = configSet.get(expected.slug); | ||
| expect(edition, `edition "${expected.slug}" should exist`).toBeDefined(); | ||
|
|
||
| if (edition === undefined) continue; | ||
|
|
||
| const rules = edition.rules; | ||
|
|
||
| expect( | ||
| edition.displayName, | ||
| `edition "${expected.slug}" should have the correct <displayName>. Expected "${expected.displayName}", got "${edition.displayName}"`, | ||
| ).toBe(expected.displayName); | ||
| expect( | ||
| rules.awardModel, | ||
| `edition "${expected.slug}" should have the correct <awardModel>. Expected "${expected.rules.awardModel}", got "${rules.awardModel}"`, | ||
| ).toBe(expected.rules.awardModel); | ||
| expect( | ||
| rules.startTime, | ||
| `edition "${expected.slug}" should have the correct <startTime>. Expected "${expected.rules.startTime}", got "${rules.startTime}"`, | ||
| ).toBe(expected.rules.startTime); | ||
| expect( | ||
| rules.endTime, | ||
| `edition "${expected.slug}" should have the correct <endTime>. Expected "${expected.rules.endTime}", got "${rules.endTime}"`, | ||
| ).toBe(expected.rules.endTime); | ||
| expect( | ||
| rules.subregistryId, | ||
| `edition "${expected.slug}" should have the correct <subregistryId>. Expected "${expected.rules.subregistryId}", got "${rules.subregistryId}"`, | ||
| ).toStrictEqual(expected.rules.subregistryId); | ||
| expect( | ||
| rules.rulesUrl.href, | ||
| `edition "${expected.slug}" should have the correct <rulesUrl>. Expected "${expected.rules.rulesUrl.href}", got "${rules.rulesUrl.href}"`, | ||
| ).toStrictEqual(expected.rules.rulesUrl.href); | ||
| expect( | ||
| rules.areAwardsDistributed, | ||
| `edition "${expected.slug}" should have the correct <areAwardsDistributed>. Expected "${expected.rules.areAwardsDistributed}", got "${rules.areAwardsDistributed}"`, | ||
| ).toBe(expected.rules.areAwardsDistributed); | ||
|
|
||
| if ( | ||
| rules.awardModel !== ReferralProgramAwardModels.Unrecognized && | ||
| expected.rules.awardModel !== ReferralProgramAwardModels.Unrecognized | ||
| ) { | ||
| expect( | ||
| rules.totalAwardPoolValue, | ||
| `edition "${expected.slug}" should have the correct <totalAwardPoolValue>. Expected "${priceUsdc(expected.rules.totalAwardPoolValue.amount)}", got "${rules.totalAwardPoolValue}"`, | ||
| ).toStrictEqual(priceUsdc(expected.rules.totalAwardPoolValue.amount)); | ||
| } | ||
|
|
||
| // If statements required for type-safety. | ||
| // The equality of the `awardModel` field is guaranteed by the test above | ||
| if ( | ||
| rules.awardModel === ReferralProgramAwardModels.PieSplit && | ||
| expected.rules.awardModel === ReferralProgramAwardModels.PieSplit | ||
| ) { | ||
| const expectedPieSplitRules = expected.rules as ReferralProgramRulesPieSplit; | ||
| expect( | ||
| rules.maxQualifiedReferrers, | ||
| `edition "${expected.slug}" should have the correct <maxQualifiedReferrers>. Expected "${expectedPieSplitRules.maxQualifiedReferrers}", got "${rules.maxQualifiedReferrers}"`, | ||
| ).toBe(expectedPieSplitRules.maxQualifiedReferrers); | ||
| } | ||
|
|
||
| if ( | ||
| rules.awardModel === ReferralProgramAwardModels.RevShareLimit && | ||
| expected.rules.awardModel === ReferralProgramAwardModels.RevShareLimit | ||
| ) { | ||
| const expectedRevShareLimitRules = expected.rules as ReferralProgramRulesRevShareLimit; | ||
| expect( | ||
| rules.minQualifiedRevenueContribution, | ||
| `edition "${expected.slug}" should have the correct <minQualifiedRevenueContribution>. Expected "${priceUsdc(expectedRevShareLimitRules.minQualifiedRevenueContribution.amount)}", got "${rules.minQualifiedRevenueContribution}"`, | ||
| ).toStrictEqual( | ||
| priceUsdc(expectedRevShareLimitRules.minQualifiedRevenueContribution.amount), | ||
| ); | ||
| expect( | ||
| rules.qualifiedRevenueShare, | ||
| `edition "${expected.slug}" should have the correct <qualifiedRevenueShare>. Expected "${expectedRevShareLimitRules.qualifiedRevenueShare}", got "${rules.qualifiedRevenueShare}"`, | ||
| ).toBe(expectedRevShareLimitRules.qualifiedRevenueShare); | ||
|
|
||
| // Skipping the test of `disqualifications` intentionally due to high volatility of the field. | ||
| // Additionally it should not be expected of edition defaults to provide up-to-date disqualifications info. | ||
| } | ||
Y3drk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe("Should have a valid structure", () => { | ||
| it("Maintains the config set invariant (map key === config.slug)", () => { | ||
| for (const [key, config] of configSet) { | ||
| expect(key, `config key "${key}" should match config.slug "${config.slug}"`).toBe( | ||
| config.slug, | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| it("All editions have valid `slug` format", () => { | ||
| for (const [slug] of configSet) { | ||
| expect(slug, `edition "${slug}" should match the slug pattern`).toMatch( | ||
| REFERRAL_PROGRAM_EDITION_SLUG_PATTERN, | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| it("All editions have non-empty `displayName`s", () => { | ||
| for (const [, config] of configSet) { | ||
| expect( | ||
| config.displayName.length, | ||
| `edition "${config.slug}" should have a non-empty <displayName>`, | ||
| ).toBeGreaterThan(0); | ||
| } | ||
| }); | ||
|
|
||
| it("All editions have `endTime` >= `startTime`", () => { | ||
| for (const [, config] of configSet) { | ||
| expect( | ||
| config.rules.endTime, | ||
| `edition "${config.slug}" should have <endTime> >= <startTime>. Got endTime: "${config.rules.endTime}", startTime: "${config.rules.startTime}"`, | ||
| ).toBeGreaterThanOrEqual(config.rules.startTime); | ||
| } | ||
| }); | ||
|
|
||
| it("All editions have a recognized `awardModel`", () => { | ||
| const recognizedModels: string[] = [ | ||
| ReferralProgramAwardModels.PieSplit, | ||
| ReferralProgramAwardModels.RevShareLimit, | ||
| ]; | ||
| for (const [, config] of configSet) { | ||
| expect( | ||
| recognizedModels, | ||
| `edition "${config.slug}" should have a recognized <awardModel>`, | ||
| ).toContain(config.rules.awardModel); | ||
| } | ||
| }); | ||
|
|
||
| it("All editions have valid `rulesUrl`s", () => { | ||
| for (const [, config] of configSet) { | ||
| expect( | ||
| config.rules.rulesUrl, | ||
| `edition "${config.slug}" should have a valid <rulesUrl>`, | ||
| ).toBeInstanceOf(URL); | ||
| expect( | ||
| config.rules.rulesUrl.protocol, | ||
| `edition "${config.slug}" should have a valid <rulesUrl> protocol`, | ||
| ).toBe("https:"); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe("Error handling", () => { | ||
| it("Throws for an unsupported namespace", () => { | ||
| expect(() => getDefaultReferralProgramEditionConfigSet("invalid-namespace" as any)).toThrow(); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.