-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add base chain #1579
Add base chain #1579
Changes from 8 commits
c42bd24
39c3e59
4799551
f03ab1f
197f7ea
bfcff65
933111e
b48c030
e00842a
8895529
28cf3eb
38ac33f
dc7e7fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
import { Token } from '../src/entities/token'; | ||
import seedTokens from './data/seedTokens'; | ||
import config from '../src/config'; | ||
import { NETWORK_IDS } from '../src/provider'; | ||
|
||
export class AddBaseChainTokens1716367359560 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
const environment = config.get('ENVIRONMENT') as string; | ||
|
||
const networkId = | ||
environment === 'production' | ||
? NETWORK_IDS.BASE_MAINNET | ||
: NETWORK_IDS.BASE_SEPOLIA; | ||
|
||
await queryRunner.manager.save( | ||
Token, | ||
seedTokens | ||
.filter(token => token.networkId === networkId) | ||
.map(token => { | ||
const t = { | ||
...token, | ||
}; | ||
t.address = t.address?.toLowerCase(); | ||
delete t.chainType; | ||
return t; | ||
}), | ||
); | ||
const tokens = await queryRunner.query(` | ||
SELECT * FROM token | ||
WHERE "networkId" = ${networkId} | ||
`); | ||
const givethOrganization = ( | ||
await queryRunner.query(`SELECT * FROM organization | ||
WHERE label='giveth'`) | ||
)[0]; | ||
|
||
const traceOrganization = ( | ||
await queryRunner.query(`SELECT * FROM organization | ||
WHERE label='trace'`) | ||
)[0]; | ||
|
||
for (const token of tokens) { | ||
// Add all Base tokens to Giveth organization | ||
await queryRunner.query(`INSERT INTO organization_tokens_token ("tokenId","organizationId") VALUES | ||
(${token.id}, ${givethOrganization.id}), | ||
(${token.id}, ${traceOrganization.id}) | ||
;`); | ||
} | ||
} | ||
|
||
public async down(_queryRunner: QueryRunner): Promise<void> { | ||
// | ||
} | ||
Comment on lines
+52
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider implementing a rollback mechanism in the |
||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -918,7 +918,6 @@ | |||
), | ||||
); | ||||
}); | ||||
|
||||
it('should return projects, filter by accept donation on arbitrum, not return when it doesnt have arbitrum address', async () => { | ||||
const arbitrumProject = await saveProjectDirectlyToDb({ | ||||
...createProjectData(), | ||||
|
@@ -964,6 +963,113 @@ | |||
); | ||||
}); | ||||
|
||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unnecessary newline. - ⏎ Committable suggestion
Suggested change
|
||||
it('should return projects, filter by accept donation on base', async () => { | ||||
const savedProject = await saveProjectDirectlyToDb({ | ||||
...createProjectData(), | ||||
title: String(new Date().getTime()), | ||||
slug: String(new Date().getTime()), | ||||
networkId: NETWORK_IDS.BASE_MAINNET, | ||||
}); | ||||
const result = await axios.post(graphqlUrl, { | ||||
query: fetchMultiFilterAllProjectsQuery, | ||||
variables: { | ||||
filters: ['AcceptFundOnBase'], | ||||
sortingBy: SortingField.Newest, | ||||
}, | ||||
}); | ||||
result.data.data.allProjects.projects.forEach(project => { | ||||
assert.isOk( | ||||
project.addresses.find( | ||||
address => | ||||
address.isRecipient === true && | ||||
(address.networkId === NETWORK_IDS.BASE_MAINNET || | ||||
address.networkId === NETWORK_IDS.BASE_SEPOLIA), | ||||
), | ||||
); | ||||
}); | ||||
assert.isOk( | ||||
result.data.data.allProjects.projects.find( | ||||
project => Number(project.id) === Number(savedProject.id), | ||||
), | ||||
); | ||||
}); | ||||
it('should return projects, filter by accept donation on base', async () => { | ||||
const savedProject = await saveProjectDirectlyToDb({ | ||||
...createProjectData(), | ||||
title: String(new Date().getTime()), | ||||
slug: String(new Date().getTime()), | ||||
networkId: NETWORK_IDS.BASE_MAINNET, | ||||
}); | ||||
const result = await axios.post(graphqlUrl, { | ||||
query: fetchMultiFilterAllProjectsQuery, | ||||
variables: { | ||||
filters: ['AcceptFundOnBase'], | ||||
sortingBy: SortingField.Newest, | ||||
}, | ||||
}); | ||||
result.data.data.allProjects.projects.forEach(project => { | ||||
assert.isOk( | ||||
project.addresses.find( | ||||
address => | ||||
address.isRecipient === true && | ||||
(address.networkId === NETWORK_IDS.BASE_MAINNET || | ||||
address.networkId === NETWORK_IDS.BASE_SEPOLIA) && | ||||
address.chainType === ChainType.EVM, | ||||
), | ||||
); | ||||
}); | ||||
assert.isOk( | ||||
result.data.data.allProjects.projects.find( | ||||
project => Number(project.id) === Number(savedProject.id), | ||||
), | ||||
); | ||||
}); | ||||
it('should return projects, filter by accept donation on base, not return when it doesnt have base address', async () => { | ||||
const baseProject = await saveProjectDirectlyToDb({ | ||||
...createProjectData(), | ||||
title: String(new Date().getTime()), | ||||
slug: String(new Date().getTime()), | ||||
networkId: NETWORK_IDS.BASE_MAINNET, | ||||
}); | ||||
const polygonProject = await saveProjectDirectlyToDb({ | ||||
...createProjectData(), | ||||
title: String(new Date().getTime()), | ||||
slug: String(new Date().getTime()), | ||||
networkId: NETWORK_IDS.POLYGON, | ||||
}); | ||||
|
||||
const result = await axios.post(graphqlUrl, { | ||||
query: fetchMultiFilterAllProjectsQuery, | ||||
variables: { | ||||
filters: ['AcceptFundOnBase'], | ||||
sortingBy: SortingField.Newest, | ||||
}, | ||||
}); | ||||
|
||||
result.data.data.allProjects.projects.forEach(project => { | ||||
assert.isOk( | ||||
project.addresses.find( | ||||
address => | ||||
address.isRecipient === true && | ||||
(address.networkId === NETWORK_IDS.BASE_MAINNET || | ||||
address.networkId === NETWORK_IDS.BASE_SEPOLIA) && | ||||
address.chainType === ChainType.EVM, | ||||
), | ||||
); | ||||
}); | ||||
assert.isNotOk( | ||||
result.data.data.allProjects.projects.find( | ||||
project => Number(project.id) === Number(polygonProject.id), | ||||
), | ||||
); | ||||
assert.isOk( | ||||
result.data.data.allProjects.projects.find( | ||||
project => Number(project.id) === Number(baseProject.id), | ||||
), | ||||
); | ||||
}); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor to use - result.data.data.allProjects.projects.forEach(project => {
+ for (const project of result.data.data.allProjects.projects) {
assert.isOk(
project.addresses.find(
address =>
address.isRecipient === true &&
(address.networkId === NETWORK_IDS.BASE_MAINNET ||
address.networkId === NETWORK_IDS.BASE_SEPOLIA) &&
address.chainType === ChainType.EVM,
),
);
- });
+ }
Comment on lines
+966
to
+1070
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor repeated test cases for better maintainability. The test cases for filtering by 'AcceptFundOnBase' are repeated three times with slight variations. Consider refactoring these into a single parameterized test function to reduce code duplication and improve maintainability. - it('should return projects, filter by accept donation on base', async () => { ... });
- it('should return projects, filter by accept donation on base', async () => { ... });
- it('should return projects, filter by accept donation on base, not return when it doesnt have base address', async () => { ... });
+ function testAcceptDonationOnBase(description, setup, assertCondition) {
+ it(description, async () => {
+ await setup();
+ const result = await axios.post(graphqlUrl, {
+ query: fetchMultiFilterAllProjectsQuery,
+ variables: {
+ filters: ['AcceptFundOnBase'],
+ sortingBy: SortingField.Newest,
+ },
+ });
+ result.data.data.allProjects.projects.forEach(project => {
+ assertCondition(project);
+ });
+ });
+ }
+ testAcceptDonationOnBase('should return projects, filter by accept donation on base', async () => {
+ await saveProjectDirectlyToDb({ ...createProjectData(), title: String(new Date().getTime()), slug: String(new Date().getTime()), networkId: NETWORK_IDS.BASE_MAINNET });
+ }, project => {
+ assert.isOk(project.addresses.find(address => address.isRecipient === true && (address.networkId === NETWORK_IDS.BASE_MAINNET || address.networkId === NETWORK_IDS.BASE_SEPOLIA) && address.chainType === ChainType.EVM));
+ });
|
||||
|
||||
it('should return projects, filter by accept donation on mainnet', async () => { | ||||
const savedProject = await saveProjectDirectlyToDb({ | ||||
...createProjectData(), | ||||
|
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.
Ensure proper transaction handling in the
up
method.Consider wrapping the database operations within a transaction to ensure atomicity. This is crucial for maintaining data integrity, especially in production environments.