Skip to content

Commit

Permalink
adds functionality to remove passport data points
Browse files Browse the repository at this point in the history
  • Loading branch information
aminah-io authored Nov 18, 2022
2 parents a8df157 + 4505de6 commit d597f16
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 101 deletions.
62 changes: 34 additions & 28 deletions app/components/GenericPlatform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,39 +127,45 @@ export const GenericPlatform = ({ platFormGroupSpec, platform }: PlatformProps):
const state = `${platform.path}-` + generateUID(10);
const providerPayload = (await platform.getProviderPayload({ state, window, screen, waitForRedirect })) as {};

const verified: VerifiableCredentialRecord = await fetchVerifiableCredential(
iamUrl,
{
type: platform.platformId,
types: selectedProviders,
version: "0.0.0",
address: address || "",
proofs: providerPayload,
rpcUrl,
},
signer as { signMessage: (message: string) => Promise<string> }
);
// because we provided a types array in the params we expect to receive a
// credentials array in the response...
const vcs =
verified.credentials
?.map((cred: CredentialResponseBody): Stamp | undefined => {
if (!cred.error) {
// This array will contain all providers that new validated VCs
let vcs: Stamp[] = [];

if (selectedProviders.length > 0) {
const verified: VerifiableCredentialRecord = await fetchVerifiableCredential(
iamUrl,
{
type: platform.platformId,
types: selectedProviders,
version: "0.0.0",
address: address || "",
proofs: providerPayload,
rpcUrl,
},
signer as { signMessage: (message: string) => Promise<string> }
);

// because we provided a types array in the params we expect to receive a
// credentials array in the response...
if (verified.credentials) {
for (let i = 0; i < verified.credentials.length; i++) {
let cred = verified.credentials[i];
if (!cred.error && providerIds.find((providerId: PROVIDER_ID) => cred?.record?.type === providerId)) {
// add each of the requested/received stamps to the passport...
return {
vcs.push({
provider: cred.record?.type as PROVIDER_ID,
credential: cred.credential as VerifiableCredential,
};
});
}
})
.filter((v: Stamp | undefined) => v) || [];

// Update the selected stamps for removal
}
}
}
// Delete all stamps ...
await handleDeleteStamps(providerIds as PROVIDER_ID[]);
console.log("vcs**", vcs);

// Add all the stamps to the passport at once
await handleAddStamps(vcs as Stamp[]);
// .. and now add all newly validate stamps
if (vcs.length > 0) {
await handleAddStamps(vcs);
}
datadogLogs.logger.info("Successfully saved Stamp", { platform: platform.platformId });
// grab all providers who are verified from the verify response
const actualVerifiedProviders = providerIds.filter(
Expand Down Expand Up @@ -273,7 +279,7 @@ export const GenericPlatform = ({ platFormGroupSpec, platform }: PlatformProps):
data-testid={`button-verify-${platform.platformId}`}
className="sidebar-verify-btn"
>
Verify
{verifiedProviders.length > 0 ? "Save" : "Verify"}
</button>
}
/>
Expand Down
2 changes: 1 addition & 1 deletion platforms/src/ETH/Providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { ethErc20PossessionProviderOptions, EthErc20PossessionProvider } from "./ethErc20Possession";
export { EthErc20PossessionProvider } from "./ethErc20Possession";
export { EthGTEOneTxnProvider, EthGasProvider, FirstEthTxnProvider } from "./ethTransactions";
77 changes: 41 additions & 36 deletions platforms/src/GtcStaking/__tests__/communityStaking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,33 @@ import {
// ----- Libs
import axios from "axios";

jest.mock("axios");
const mockedAxios = axios as jest.Mocked<typeof axios>;
const mockedAxiosPost = jest.spyOn(axios, "post");

const MOCK_ADDRESS = "0xcF314CE817E25b4F784bC1f24c9A79A525fEC50f";
const MOCK_ADDRESS_LOWER = MOCK_ADDRESS.toLowerCase();

const generateSubgraphResponse = (address: string, total: string): DataResult => {
return {
data: {
const generateSubgraphResponse = (address: string, total: string): Promise<DataResult> => {
return new Promise((resolve) => {
resolve({
data: {
address: address,
users: [
{
xstakeAggregates: [
{
total: total,
round: {
id: "1",
data: {
address: address,
users: [
{
xstakeAggregates: [
{
total: total,
round: {
id: "1",
},
},
},
],
},
],
],
},
],
},
},
},
};
});
});
};

const invalidCommunityStakingResponse = {
Expand Down Expand Up @@ -73,7 +74,7 @@ interface RequestData {
describe("Attempt verification", function () {
beforeEach(() => {
jest.clearAllMocks();
mockedAxios.post.mockImplementation(async (url, data) => {
mockedAxiosPost.mockImplementation((url, data) => {
const query: string = (data as RequestData).query;
if (url === stakingSubgraph && query.includes(MOCK_ADDRESS_LOWER)) {
return generateSubgraphResponse(MOCK_ADDRESS_LOWER, "220000000000000000000");
Expand All @@ -88,7 +89,7 @@ describe("Attempt verification", function () {
} as unknown as RequestPayload);

// Check the request to verify the subgraph query
expect(mockedAxios.post).toBeCalledWith(stakingSubgraph, {
expect(mockedAxiosPost).toBeCalledWith(stakingSubgraph, {
query: getSubgraphQuery(MOCK_ADDRESS_LOWER),
});

Expand All @@ -107,7 +108,7 @@ describe("Attempt verification", function () {
} as unknown as RequestPayload);

// Check the request to verify the subgraph query
expect(mockedAxios.post).toBeCalledWith(stakingSubgraph, {
expect(mockedAxiosPost).toBeCalledWith(stakingSubgraph, {
query: getSubgraphQuery("not_address"),
});
expect(verifiedPayload).toEqual({
Expand All @@ -116,10 +117,12 @@ describe("Attempt verification", function () {
});
});
it("handles invalid subgraph response", async () => {
mockedAxios.post.mockImplementationOnce(async (url, data) => {
mockedAxiosPost.mockImplementationOnce((url, data) => {
const query: string = (data as RequestData).query;
if (url === stakingSubgraph && query.includes(MOCK_ADDRESS_LOWER)) {
return invalidCommunityStakingResponse;
return new Promise((resolve) => {
resolve(invalidCommunityStakingResponse);
});
}
});
const communityStakingProvider = new CommunityStakingBronzeProvider();
Expand All @@ -128,7 +131,8 @@ describe("Attempt verification", function () {
} as unknown as RequestPayload);

// Check the request to verify the subgraph query
expect(mockedAxios.post).toBeCalledWith(stakingSubgraph, {
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(mockedAxiosPost).toBeCalledWith(stakingSubgraph, {
query: getSubgraphQuery(MOCK_ADDRESS_LOWER),
});
expect(verifiedPayload).toEqual({
Expand All @@ -137,7 +141,7 @@ describe("Attempt verification", function () {
});
});
it("handles invalid verification attempt where an exception is thrown", async () => {
mockedAxios.post.mockImplementationOnce(async (url, data) => {
mockedAxiosPost.mockImplementationOnce((url, data) => {
throw Error("Community Staking Bronze Provider verifyStake Error");
});
const communityStakingProvider = new CommunityStakingBronzeProvider();
Expand All @@ -146,7 +150,8 @@ describe("Attempt verification", function () {
} as unknown as RequestPayload);

// Check the request to verify the subgraph query
expect(mockedAxios.post).toBeCalledWith(stakingSubgraph, {
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(mockedAxiosPost).toBeCalledWith(stakingSubgraph, {
query: getSubgraphQuery(MOCK_ADDRESS_LOWER),
});
expect(verifiedPayload).toEqual({
Expand All @@ -163,7 +168,7 @@ describe("should return invalid payload", function () {
});
it("when stake amount is below 1 GTC for Bronze", async () => {
jest.clearAllMocks();
mockedAxios.post.mockImplementation(async () => {
mockedAxiosPost.mockImplementation(async () => {
return generateSubgraphResponse(MOCK_ADDRESS_LOWER, "500000000");
});

Expand All @@ -177,7 +182,7 @@ describe("should return invalid payload", function () {
});
it("when stake amount is below 10 GTC for Silver", async () => {
jest.clearAllMocks();
mockedAxios.post.mockImplementation(async () => {
mockedAxiosPost.mockImplementation(async () => {
return generateSubgraphResponse(MOCK_ADDRESS_LOWER, "5000000000000000000");
});

Expand All @@ -191,7 +196,7 @@ describe("should return invalid payload", function () {
});
it("when stake amount is below 100 GTC for Gold", async () => {
jest.clearAllMocks();
mockedAxios.post.mockImplementation(async () => {
mockedAxiosPost.mockImplementation(async () => {
return generateSubgraphResponse(MOCK_ADDRESS_LOWER, "40000000000000000000");
});

Expand All @@ -208,7 +213,7 @@ describe("should return invalid payload", function () {
// All the positive cases for thresholds are tested
describe("should return valid payload", function () {
it("when stake amount above 1 GTC for Bronze", async () => {
mockedAxios.post.mockImplementation(async () => {
mockedAxiosPost.mockImplementation(async () => {
return generateSubgraphResponse(MOCK_ADDRESS_LOWER, "2000000000000000000");
});

Expand All @@ -224,7 +229,7 @@ describe("should return valid payload", function () {
});
});
it("when stake amount above 10 GTC for Silver", async () => {
mockedAxios.post.mockImplementation(async () => {
mockedAxiosPost.mockImplementation(async () => {
return generateSubgraphResponse(MOCK_ADDRESS_LOWER, "15000000000000000000");
});

Expand All @@ -240,7 +245,7 @@ describe("should return valid payload", function () {
});
});
it("when stake amount above 100 GTC for Gold", async () => {
mockedAxios.post.mockImplementation(async () => {
mockedAxiosPost.mockImplementation(async () => {
return generateSubgraphResponse(MOCK_ADDRESS_LOWER, "500000000000000000000");
});

Expand All @@ -258,7 +263,7 @@ describe("should return valid payload", function () {
// All values equal to tier amount
it("when stake amount is equal to 1 GTC for Bronze", async () => {
jest.clearAllMocks();
mockedAxios.post.mockImplementation(async () => {
mockedAxiosPost.mockImplementation(async () => {
return generateSubgraphResponse(MOCK_ADDRESS_LOWER, "1000000000000000000");
});

Expand All @@ -275,7 +280,7 @@ describe("should return valid payload", function () {
});
it("when stake amount is equal to 10 GTC for Silver", async () => {
jest.clearAllMocks();
mockedAxios.post.mockImplementation(async () => {
mockedAxiosPost.mockImplementation(async () => {
return generateSubgraphResponse(MOCK_ADDRESS_LOWER, "10000000000000000000");
});

Expand All @@ -292,7 +297,7 @@ describe("should return valid payload", function () {
});
it("when stake amount is equal to 100 GTC for Gold", async () => {
jest.clearAllMocks();
mockedAxios.post.mockImplementation(async () => {
mockedAxiosPost.mockImplementation(async () => {
return generateSubgraphResponse(MOCK_ADDRESS_LOWER, "100000000000000000000");
});

Expand Down
Loading

0 comments on commit d597f16

Please sign in to comment.