Skip to content

Commit

Permalink
chore: requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Apr 29, 2024
1 parent 6b74283 commit 418b5ad
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 271 deletions.
140 changes: 33 additions & 107 deletions cypress/e2e/claim-portal-failure.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@ import { JsonRpcProvider, JsonRpcSigner } from "@ethersproject/providers";

const beneficiary = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";

/**
* MM is an extension and communicates with the page in a way that
* cannot be easily intercepted. For instance, calling `eth_accounts`
* via the wallet provider will not be intercepted, and any calls to the provider
* will be made directly to the provider and in the case of anvil we'll always
* have access to the signer without authentication.
*
* For this reason, it's kinda difficult to simulate failed transactions due
* to wallet provider issues as 1. Anvil will always succeed and 2. Returning
* a spoofed error causes the claim-loader to infite spin. This may be due to
* how the tests are structured or due to how errors are being handled in the portal.
*
* We are injecting the signer as a global variable to the window object
* which is applied in an error handler of connectWallet.
*
* This is a bit of a hack, but it's the only way to get a valid signer
* into the test env without having extensions installed.
*
*/

describe("Claims Portal Failures", () => {
describe("No connection to wallet provider", () => {
beforeEach(() => {
Expand Down Expand Up @@ -143,15 +123,15 @@ function setupIntercepts() {
}
});

cy.intercept("POST", "https://gnxgtwvmduxcwucovxqp.supabase.co/rest/v1/*", {
cy.intercept("POST", "https://wfzpewmlyiozupulbuur.supabase.co/rest/v1/*", {
statusCode: 200,
body: {},
});
cy.intercept("PATCH", "https://gnxgtwvmduxcwucovxqp.supabase.co/rest/v1/*", {
cy.intercept("PATCH", "https://wfzpewmlyiozupulbuur.supabase.co/rest/v1/*", {
statusCode: 200,
body: {},
});
cy.intercept("GET", "https://gnxgtwvmduxcwucovxqp.supabase.co/rest/v1/*", {
cy.intercept("GET", "https://wfzpewmlyiozupulbuur.supabase.co/rest/v1/*", {
statusCode: 200,
body: {},
});
Expand All @@ -163,44 +143,7 @@ function stubEthereum(address?: string, signer?: JsonRpcSigner) {
((win as any).ethereum = {
isMetaMask: true,
enable: cy.stub().resolves([address]),
request: cy.stub().callsFake(async (method) => {
if (method == "eth_requestAccounts") {
return [address];
}
if (method == "wallet_sendDomainMetadata") {
return true;
}
if (method == "wallet_addEthereumChain") {
return true;
}
if (method == "wallet_switchEthereumChain") {
return true;
}
if (method == "wallet_watchAsset") {
return true;
}
if (method == "eth_chainId") {
return "0x7a69";
}
if (method == "eth_accounts") {
return [address];
}
if (method == "eth_signTypedData_v4") {
return "address";
}

if (method == "eth_estimateGas") {
return "0x00";
}

if (method == "eth_sendTransaction") {
return "0x";
}

if (method == "eth_call") {
return "0x";
}
}),
request: cy.stub().callsFake(async (method) => providerFunctions(method)),
on: cy.stub().callsFake((event, cb) => {
if (event == "accountsChanged") {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -211,57 +154,40 @@ function stubEthereum(address?: string, signer?: JsonRpcSigner) {
chainId: "0x7a69",
selectedAddress: address,
requestAccounts: cy.stub().resolves([address]),
send: cy.stub().callsFake(async (method) => {
if (method == "eth_requestAccounts") {
return [address];
}
if (method == "wallet_sendDomainMetadata") {
return true;
}
if (method == "wallet_addEthereumChain") {
return true;
}
if (method == "wallet_switchEthereumChain") {
return true;
}
if (method == "wallet_watchAsset") {
return true;
}
if (method == "eth_chainId") {
return "0x7a69";
}
if (method == "eth_accounts") {
return [address];
}
if (method == "eth_signTypedData_v4") {
return;
}

if (method == "eth_sendTransaction") {
return "0x";
}

if (method == "eth_call") {
return "0x";
}

if (method == "eth_estimateGas") {
return "0x00";
}

if (method == "wallet_watchAsset") {
return true;
}
}),
send: cy.stub().callsFake(async (method) => providerFunctions(method)),
}),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
signer ? ((win as any).signer = signer) : null;
});
}

function providerFunctions(method: string) {
switch (method) {
case "eth_requestAccounts":
return [beneficiary];
case "wallet_sendDomainMetadata":
return true;
case "wallet_addEthereumChain":
return true;
case "wallet_switchEthereumChain":
return true;
case "wallet_watchAsset":
return true;
case "eth_chainId":
return "0x7a69";
case "eth_accounts":
return [beneficiary];
case "eth_signTypedData_v4":
return "address";
case "eth_estimateGas":
return "0x00";
case "eth_sendTransaction":
return "0x";
case "eth_call":
return "0x";
}
}

// placed here due to length
const claimUrl =
"?claim=W3sidHlwZSI6ImVyYzIwLXBlcm1pdCIsInBlcm1pdCI6eyJwZXJtaXR0ZWQiOnsidG9rZW4iOiIweGU5MUQxNTNFMGI0MTUxOEEyQ2U4RGQzRDc5NDRGYTg2MzQ2M2E5N2QiLCJhbW91bnQiOiIxMDAwMDAwMDAwMDAwMDAwMCJ9LCJub25jZSI6IjExMTAwMTcxMzI2MzgxMjMwODc0NzIyNjQzODc5NzEyMzUyODY1MDc1NTE5OTAzNDE5OTg2MjExMjE4OTU2NTE5NzY5MDA2MTUwNjk4NiIsImRlYWRsaW5lIjoiMTE1NzkyMDg5MjM3MzE2MTk1NDIzNTcwOTg1MDA4Njg3OTA3ODUzMjY5OTg0NjY1NjQwNTY0MDM5NDU3NTg0MDA3OTEzMTI5NjM5OTM1In0sInRyYW5zZmVyRGV0YWlscyI6eyJ0byI6IjB4ZjM5RmQ2ZTUxYWFkODhGNkY0Y2U2YUI4ODI3Mjc5Y2ZmRmI5MjI2NiIsInJlcXVlc3RlZEFtb3VudCI6IjEwMDAwMDAwMDAwMDAwMDAwIn0sIm93bmVyIjoiMHg3MDk5Nzk3MEM1MTgxMmRjM0EwMTBDN2QwMWI1MGUwZDE3ZGM3OUM4Iiwic2lnbmF0dXJlIjoiMHg1M2U5Mzk4MjU5NmZkNGY5N2VmNTY5MDAzOGQwZjNlNmM0NTk3YzA0YjhiMDM2NDFiZGNkYjRjZWQzNzMxMTA3M2VlMmZlZTQ2MWZkMjI1MWNhYjFhMDIzMGJiNDY3N2UzM2UyNmJjMTUyNDZkMjZmOTFkY2YxZTdmOGI0Zjc1MzFjIiwibmV0d29ya0lkIjozMTMzN30seyJ0eXBlIjoiZXJjMjAtcGVyb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TU3Yzc4MTYxOWNmOWFiYTdjZmZhMmVmMmY1MGVjOTllOGMyNjZhYTMzMDU2N2RlMjkyMWIiLCJuZXR3b3JrSWQiOjMxMzM3fV0=";
6 changes: 3 additions & 3 deletions cypress/e2e/claim-portal-non-web3.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ function setupIntercepts() {
}
});

cy.intercept("POST", "https://gnxgtwvmduxcwucovxqp.supabase.co/rest/v1/*", {
cy.intercept("POST", "https://wfzpewmlyiozupulbuur.supabase.co/rest/v1/*", {
statusCode: 200,
body: {},
});
cy.intercept("PATCH", "https://gnxgtwvmduxcwucovxqp.supabase.co/rest/v1/*", {
cy.intercept("PATCH", "https://wfzpewmlyiozupulbuur.supabase.co/rest/v1/*", {
statusCode: 200,
body: {},
});
cy.intercept("GET", "https://gnxgtwvmduxcwucovxqp.supabase.co/rest/v1/*", {
cy.intercept("GET", "https://wfzpewmlyiozupulbuur.supabase.co/rest/v1/*", {
statusCode: 200,
body: {},
});
Expand Down
Loading

0 comments on commit 418b5ad

Please sign in to comment.