Skip to content

Commit

Permalink
Merge pull request #149 from GeneralMagicio/feat/batch-minting-eligib…
Browse files Browse the repository at this point in the history
…le-users-v2

Implemented Batch Minting Eligible User v2
  • Loading branch information
aminlatifi authored Dec 9, 2024
2 parents 8173ef2 + ab53e2c commit d3c394b
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 46 deletions.
3 changes: 3 additions & 0 deletions config/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,6 @@ QACC_DONATION_TOKEN_DECIMALS=18
QACC_DONATION_TOKEN_NAME=Polygon Ecosystem Token
QACC_DONATION_TOKEN_SYMBOL=POL


GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE=50
GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE=15
164 changes: 139 additions & 25 deletions src/resolvers/userResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import {
acceptedTermsOfService,
batchMintingEligibleUsers,
batchMintingEligibleUsersV2,
checkUserPrivadoVerifiedState,
refreshUserScores,
updateUser,
Expand All @@ -32,6 +33,11 @@ import { updateUserTotalDonated } from '../services/userService';
import { getUserEmailConfirmationFields } from '../repositories/userRepository';
import { UserEmailVerification } from '../entities/userEmailVerification';
import { PrivadoAdapter } from '../adapters/privado/privadoAdapter';
import { UserKycType } from './userResolver';
import {
GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE,
GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE,
} from '../constants/gitcoin';

describe('updateUser() test cases', updateUserTestCases);
describe('userByAddress() test cases', userByAddressTestCases);
Expand All @@ -58,6 +64,10 @@ describe(
'batchMintingEligibleUsers() test cases',
batchMintingEligibleUsersTestCases,
);
describe(
'batchMintingEligibleV2Users() test cases',
batchMintingEligibleUsersV2TestCases,
);

// TODO I think we can delete addUserVerification query
// describe('addUserVerification() test cases', addUserVerificationTestCases);
Expand Down Expand Up @@ -1179,37 +1189,85 @@ function batchMintingEligibleUsersTestCases() {
// clear all users not empty accepted terms of service
await User.delete({ acceptedToS: true });
});
it('should return users who have accepted terms of service and privado verified', async () => {
const user1 = await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
privadoVerifiedRequestIds: [PrivadoAdapter.privadoRequestId],
acceptedToS: true,
// 2 days ago
acceptedToSDate: new Date(Date.now() - DAY * 3),
});

const user2 = await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
privadoVerifiedRequestIds: [PrivadoAdapter.privadoRequestId],
acceptedToS: true,
// yesterday
acceptedToSDate: new Date(Date.now() - DAY * 2),
});

const user3 = await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
privadoVerifiedRequestIds: [PrivadoAdapter.privadoRequestId],
acceptedToS: true,
// yesterday
acceptedToSDate: new Date(Date.now() - DAY),
});

it('should return empty array if there is no user to mint', async () => {
const result = await axios.post(graphqlUrl, {
query: batchMintingEligibleUsers,
});

assert.deepEqual(result.data.data.batchMintingEligibleUsers.users, []);
assert.deepEqual(result.data.data.batchMintingEligibleUsers.users, [
user1.walletAddress,
user2.walletAddress,
user3.walletAddress,
]);
});
}

function batchMintingEligibleUsersV2TestCases() {
const DAY = 86400000;
beforeEach(async () => {
// clear all users not empty accepted terms of service
await User.delete({ acceptedToS: true });
});

it('should return empty array if there is no user to mint', async () => {
const result = await axios.post(graphqlUrl, {
query: batchMintingEligibleUsersV2,
});

assert.deepEqual(result.data.data.batchMintingEligibleUsersV2.users, []);
});

it('should return users who have accepted terms of service and privado verified', async () => {
it('should return users who have accepted terms of service and has valid kyc status', async () => {
const user1 = await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
privadoVerifiedRequestIds: [PrivadoAdapter.privadoRequestId],
acceptedToS: true,
// 2 days ago
acceptedToSDate: new Date(Date.now() - DAY * 2),
acceptedToSDate: new Date(Date.now() - DAY * 3),
});

const user2 = await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
privadoVerifiedRequestIds: [PrivadoAdapter.privadoRequestId],
analysisScore: GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE + 0.001,
acceptedToS: true,
// yesterday
acceptedToSDate: new Date(Date.now() - DAY * 2),
});

const user3 = await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
passportScore: GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE + 0.001,
acceptedToS: true,
// yesterday
acceptedToSDate: new Date(Date.now() - DAY),
});

const result = await axios.post(graphqlUrl, {
query: batchMintingEligibleUsers,
query: batchMintingEligibleUsersV2,
});

assert.deepEqual(result.data.data.batchMintingEligibleUsers.users, [
user1.walletAddress,
user2.walletAddress,
assert.deepEqual(result.data.data.batchMintingEligibleUsersV2.users, [
{ address: user1.walletAddress, kycType: UserKycType.zkId },
{ address: user2.walletAddress, kycType: UserKycType.GTCPass },
{ address: user3.walletAddress, kycType: UserKycType.GTCPass },
]);
});

Expand All @@ -1225,32 +1283,35 @@ function batchMintingEligibleUsersTestCases() {
});

const result = await axios.post(graphqlUrl, {
query: batchMintingEligibleUsers,
query: batchMintingEligibleUsersV2,
});

assert.deepEqual(result.data.data.batchMintingEligibleUsers.users, [
user.walletAddress,
assert.deepEqual(result.data.data.batchMintingEligibleUsersV2.users, [
{ address: user.walletAddress, kycType: UserKycType.zkId },
]);
});

it('should not return users who have accepted terms of service but have not privado verified', async () => {
it('should not return users who have accepted terms of service but have not valid kyc status', async () => {
const user1 = await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
privadoVerifiedRequestIds: [PrivadoAdapter.privadoRequestId],
acceptedToS: true,
acceptedToSDate: new Date(Date.now() - DAY),
});

await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
privadoVerifiedRequestIds: [PrivadoAdapter.privadoRequestId + 1],
passportScore: GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE - 0.001,
analysisScore: GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE - 0.001,
acceptedToS: true,
acceptedToSDate: new Date(Date.now() - DAY),
});

const result = await axios.post(graphqlUrl, {
query: batchMintingEligibleUsers,
query: batchMintingEligibleUsersV2,
});

assert.deepEqual(result.data.data.batchMintingEligibleUsers.users, [
user1.walletAddress,
assert.deepEqual(result.data.data.batchMintingEligibleUsersV2.users, [
{ address: user1.walletAddress, kycType: UserKycType.zkId },
]);
});

Expand All @@ -1262,40 +1323,93 @@ function batchMintingEligibleUsersTestCases() {
});

const user2 = await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
privadoVerifiedRequestIds: [PrivadoAdapter.privadoRequestId],
analysisScore: GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE + 0.001,
acceptedToS: true,
acceptedToSDate: new Date(Date.now() - DAY * 2),
});

const user3 = await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
privadoVerifiedRequestIds: [PrivadoAdapter.privadoRequestId],
passportScore: GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE + 0.001,
acceptedToS: true,
acceptedToSDate: new Date(Date.now() - DAY),
});

let result = await axios.post(graphqlUrl, {
query: batchMintingEligibleUsers,
query: batchMintingEligibleUsersV2,
variables: {
limit: 2,
skip: 0,
},
});

assert.deepEqual(result.data.data.batchMintingEligibleUsers.users, [
user1.walletAddress,
user2.walletAddress,
assert.deepEqual(result.data.data.batchMintingEligibleUsersV2.users, [
{ address: user1.walletAddress, kycType: UserKycType.zkId },
{ address: user2.walletAddress, kycType: UserKycType.GTCPass },
]);

result = await axios.post(graphqlUrl, {
query: batchMintingEligibleUsers,
query: batchMintingEligibleUsersV2,
variables: {
limit: 2,
skip: 2,
},
});

assert.deepEqual(result.data.data.batchMintingEligibleUsers.users, [
user3.walletAddress,
assert.deepEqual(result.data.data.batchMintingEligibleUsersV2.users, [
{ address: user3.walletAddress, kycType: UserKycType.GTCPass },
]);
});

it('should prioritize zkId over GTCPass', async () => {
const user1 = await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
privadoVerifiedRequestIds: [PrivadoAdapter.privadoRequestId],
analysisScore: GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE + 0.001,
passportScore: GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE + 0.001,
acceptedToS: true,
acceptedToSDate: new Date(Date.now() - DAY * 4),
});

const user2 = await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
privadoVerifiedRequestIds: [PrivadoAdapter.privadoRequestId],
analysisScore: GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE - 0.001,
passportScore: GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE + 0.001,
acceptedToS: true,
acceptedToSDate: new Date(Date.now() - DAY * 3),
});

const user3 = await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
privadoVerifiedRequestIds: [PrivadoAdapter.privadoRequestId],
analysisScore: GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE + 0.001,
passportScore: GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE - 0.001,
acceptedToS: true,
acceptedToSDate: new Date(Date.now() - DAY * 2),
});

const user4 = await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
privadoVerifiedRequestIds: [PrivadoAdapter.privadoRequestId + 1],
analysisScore: GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE + 0.001,
passportScore: GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE + 0.001,
acceptedToS: true,
acceptedToSDate: new Date(Date.now() - DAY),
});

await saveUserDirectlyToDb(generateRandomEtheriumAddress(), {
privadoVerifiedRequestIds: [PrivadoAdapter.privadoRequestId + 1],
analysisScore: GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE - 0.001,
passportScore: GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE - 0.001,
acceptedToS: true,
acceptedToSDate: new Date(Date.now() - DAY),
});

const result = await axios.post(graphqlUrl, {
query: batchMintingEligibleUsersV2,
});

assert.deepEqual(result.data.data.batchMintingEligibleUsersV2.users, [
{ address: user1.walletAddress, kycType: UserKycType.zkId },
{ address: user2.walletAddress, kycType: UserKycType.zkId },
{ address: user3.walletAddress, kycType: UserKycType.zkId },
{ address: user4.walletAddress, kycType: UserKycType.GTCPass },
]);
});
}
Loading

0 comments on commit d3c394b

Please sign in to comment.