Skip to content

Commit

Permalink
Added chainType to token
Browse files Browse the repository at this point in the history
Refactored project filter query builder
Added tests
  • Loading branch information
aminlatifi committed Dec 13, 2023
1 parent 65c9ea4 commit d516e86
Show file tree
Hide file tree
Showing 11 changed files with 527 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ export class addChainTypeToProjectAddressAndDonation1702374813793
`ALTER TABLE "donation" ADD "chainType" character varying NOT NULL DEFAULT 'EVM'`,
);

// Add chainType to token
await queryRunner.query(
`ALTER TABLE "token" ADD "chainType" character varying NOT NULL DEFAULT 'EVM'`,
);

// Update chainType for projectAddress
await queryRunner.query(`UPDATE "project_address" SET "chainType" = 'EVM'`);
// Update chainType for donation
await queryRunner.query(`UPDATE "donation" SET "chainType" = 'EVM'`);
// Update chainType for token
await queryRunner.query(`UPDATE "token" SET "chainType" = 'EVM'`);
}

public async down(queryRunner: QueryRunner): Promise<void> {}
Expand Down
3 changes: 3 additions & 0 deletions migration/data/seedTokens.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NETWORK_IDS } from '../../src/provider';
import { ChainType } from '../../src/types/network';

interface ITokenData {
name: string;
Expand All @@ -8,6 +9,7 @@ interface ITokenData {
isGivbackEligible?: boolean;
decimals: number;
networkId: number;
chainType?: ChainType;
}
const seedTokens: ITokenData[] = [
{
Expand Down Expand Up @@ -1171,6 +1173,7 @@ const seedTokens: ITokenData[] = [
decimals: 18,
networkId: NETWORK_IDS.CELO_ALFAJORES,
},
// TODO: Add solana token
];

export default seedTokens;
9 changes: 9 additions & 0 deletions src/entities/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
JoinTable,
} from 'typeorm';
import { Organization } from './organization';
import { ChainType } from '../types/network';

@Entity()
@ObjectType()
Expand Down Expand Up @@ -40,6 +41,14 @@ export class Token extends BaseEntity {
@Column()
networkId: number;

@Field()
@Column({
type: 'enum',
enum: ChainType,
default: ChainType.EVM,
})
chainType: ChainType;

@Field()
@Column()
decimals: number;
Expand Down
9 changes: 9 additions & 0 deletions src/repositories/projectAddressRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {
createProjectData,
generateRandomEtheriumAddress,
generateRandomSolanaAddress,
saveProjectDirectlyToDb,
saveUserDirectlyToDb,
} from '../../test/testUtils';
Expand Down Expand Up @@ -206,6 +207,7 @@ function addBulkNewProjectAddressTestCases() {
});
const newAddress1 = generateRandomEtheriumAddress();
const newAddress2 = generateRandomEtheriumAddress();
const newAddress3 = generateRandomSolanaAddress();
await addBulkNewProjectAddress([
{
address: newAddress1,
Expand All @@ -221,6 +223,13 @@ function addBulkNewProjectAddressTestCases() {
project,
user,
},
{
address: newAddress3,
networkId: 0,
chainType: ChainType.SOLANA,
project,
user,
},
]);
const newRelatedAddress1 = await findRelatedAddressByWalletAddress(
newAddress1,
Expand Down
18 changes: 10 additions & 8 deletions src/repositories/projectVerificationRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import {
createProjectData,
generateRandomEtheriumAddress,
generateRandomSolanaAddress,
saveProjectDirectlyToDb,
saveUserDirectlyToDb,
SEED_DATA,
Expand All @@ -28,6 +29,8 @@ import {
verifyMultipleForms,
} from './projectVerificationRepository';
import { assert } from 'chai';
import { ChainType } from '../types/network';
import { ProjectAddress } from '../entities/projectAddress';

describe(
'createProjectVerificationForm test cases',
Expand Down Expand Up @@ -274,21 +277,20 @@ function updateManagingFundsOfProjectVerificationTestCases() {
address: generateRandomEtheriumAddress(),
networkId: 100,
},
{
title: 'thirdAddress',
address: generateRandomSolanaAddress(),
networkId: 0,
chainType: ChainType.SOLANA,
},
],
};
const updatedProjectVerification =
await updateManagingFundsOfProjectVerification({
projectVerificationId: projectVerificationForm.id,
managingFunds,
});
assert.equal(
updatedProjectVerification?.managingFunds.relatedAddresses.length,
managingFunds.relatedAddresses.length,
);
assert.equal(
updatedProjectVerification?.managingFunds.description,
managingFunds.description,
);
assert.deepEqual(updatedProjectVerification?.managingFunds, managingFunds);
});
}

Expand Down
2 changes: 0 additions & 2 deletions src/resolvers/donationResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,6 @@ export class DonationResolver {
searchTerm: `%${searchTerm}%`,
});

// WalletAddresses are translanted to huge integers
// this breaks postgresql query integer limit
if (detectAddressChainType(searchTerm) === undefined) {
const amount = Number(searchTerm);

Expand Down
Loading

0 comments on commit d516e86

Please sign in to comment.