Skip to content
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

Update rpc-handler and fix tests following beta merge #345

Merged
merged 23 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e1fad5e
feat: bump rpc-handler
Keyrxng Oct 20, 2024
7d6043d
chore: remove networkId param from render-ens-name
Keyrxng Oct 20, 2024
504b7e5
chore: export NetworkId convert util
Keyrxng Oct 20, 2024
4aa8195
chore: use getters from rpc-handler for adding new network
Keyrxng Oct 20, 2024
a63df44
chore: add localhost default anvil
Keyrxng Oct 20, 2024
eca8322
chore: use getters in appState
Keyrxng Oct 20, 2024
6b6dd4c
chore: consolidate rpc-handler import
Keyrxng Oct 20, 2024
f2ccbe6
chore: fix view claim onclick
Keyrxng Oct 21, 2024
4931e58
chore: return the original anvil spawner
Keyrxng Oct 21, 2024
ba2a65d
fix: reset view claim on pagination
Keyrxng Oct 21, 2024
be25449
chore: comment and no need to throw error on fail to store permit
Keyrxng Oct 21, 2024
70c6f83
chore: use and fix button visibilty for reset after view claim
Keyrxng Oct 21, 2024
2dd7efd
chore: multi permit fn, max seems to be around 3 or 4
Keyrxng Oct 21, 2024
0f43b4b
chore: use gnosis id for anvil fork
Keyrxng Oct 21, 2024
43c9de4
chore: success and failure tests
Keyrxng Oct 21, 2024
7b4301f
chore: gift card tests
Keyrxng Oct 21, 2024
ee55943
Merge remote-tracking branch 'upstream/development' into development
Keyrxng Oct 21, 2024
4eb4ce9
chore: fix last card test
Keyrxng Oct 21, 2024
0a86f01
chore: separate funding step
Keyrxng Oct 21, 2024
593b9d8
chore: yarn start on cypress action
Keyrxng Oct 21, 2024
379d6c1
chore: use wrangler build as cypress wf start cmd
Keyrxng Oct 21, 2024
682977a
chore: remove duplicate step
Keyrxng Oct 21, 2024
c7c04f1
chore: use hardcoded permit url
Keyrxng Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/.ubiquity-os.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ plugins:
formattingEvaluator:
multipliers:
- role:
- ISSUE_SPECIFICATION
- ISSUE_SPECIFICATION
multiplier: 3
rewards:
wordValue: 0.1
Expand Down Expand Up @@ -114,9 +114,9 @@ plugins:
score: 1
countWords: true
- role:
- ISSUE_AUTHOR
- ISSUE_COLLABORATOR
- PULL_COLLABORATOR
- ISSUE_AUTHOR
- ISSUE_COLLABORATOR
- PULL_COLLABORATOR
multiplier: 1
rewards:
wordValue: 0.1
Expand Down Expand Up @@ -182,8 +182,8 @@ plugins:
score: 1
countWords: true
- role:
- ISSUE_CONTRIBUTOR
- PULL_CONTRIBUTOR
- ISSUE_CONTRIBUTOR
- PULL_CONTRIBUTOR
multiplier: 0.25
rewards:
wordValue: 0.1
Expand Down Expand Up @@ -249,10 +249,10 @@ plugins:
score: 1
countWords: true
- role:
- PULL_SPECIFICATION
- PULL_AUTHOR
- ISSUE_ASSIGNEE
- PULL_ASSIGNEE
- PULL_SPECIFICATION
- PULL_AUTHOR
- ISSUE_ASSIGNEE
- PULL_ASSIGNEE
multiplier: 0
rewards:
wordValue: 0
Expand Down
19 changes: 6 additions & 13 deletions .github/workflows/cypress-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,18 @@ jobs:
sleep 1
done || exit 1

- name: Start Cloudflare Wrangler
run: npx wrangler pages dev static --port 8080 --binding USE_RELOADLY_SANDBOX=true RELOADLY_API_CLIENT_ID="$RELOADLY_SANDBOX_API_CLIENT_ID" RELOADLY_API_CLIENT_SECRET="$RELOADLY_SANDBOX_API_CLIENT_SECRET" &
env:
RELOADLY_SANDBOX_API_CLIENT_ID: ${{ secrets.RELOADLY_SANDBOX_API_CLIENT_ID }}
RELOADLY_SANDBOX_API_CLIENT_SECRET: ${{ secrets.RELOADLY_SANDBOX_API_CLIENT_SECRET }}
- name: Funding
run: yarn test:fund

- name: Cypress run
uses: cypress-io/github-action@v6
with:
build: yarn run build
start: yarn test:fund
start: npx wrangler pages dev static --port 8080 --binding USE_RELOADLY_SANDBOX=true RELOADLY_API_CLIENT_ID="$RELOADLY_SANDBOX_API_CLIENT_ID" RELOADLY_API_CLIENT_SECRET="$RELOADLY_SANDBOX_API_CLIENT_SECRET" &
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EresDev you had this as it's own step before but that's not right as the env hadn't fully setup yet that's why I've made this change here.

Is this the correct way to pass reloadly env vars?

Copy link
Member Author

@Keyrxng Keyrxng Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/ubq-testing/pay.ubq.fi/actions/runs/11504344113/job/32023622908#step:7:1

I just added the id and secret for the sandbox taken directly from the google doc to my repo secrets and the errors are still present.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is logic missing inside the cards feature that is not throwing the error properly otherwise Cypress would fail, do you agree?

The log style looks unfamiliar to me also so I'm not 100% where it's coming from, so I think it needs it's own task and shouldn't block this pr.


env:
RELOADLY_SANDBOX_API_CLIENT_ID: ${{ secrets.RELOADLY_SANDBOX_API_CLIENT_ID }}
RELOADLY_SANDBOX_API_CLIENT_SECRET: ${{ secrets.RELOADLY_SANDBOX_API_CLIENT_SECRET }}
SUPABASE_URL: "https://wfzpewmlyiozupulbuur.supabase.co"
SUPABASE_ANON_KEY: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6IndmenBld21seWlvenVwdWxidXVyIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTU2NzQzMzksImV4cCI6MjAxMTI1MDMzOX0.SKIL3Q0NOBaMehH0ekFspwgcu3afp3Dl9EDzPqs1nKs"
AMOUNT_IN_ETH: "0.1"
Expand All @@ -67,10 +66,4 @@ jobs:
with:
name: cypress-screenshots
path: cypress/screenshots
if-no-files-found: ignore
- uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-videos
path: cypress/videos
if-no-files-found: ignore
Keyrxng marked this conversation as resolved.
Show resolved Hide resolved
if-no-files-found: ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ commit.txt
.pnp.cjs
.pnp.loader.mjs
.env
.dev.vars
static/dist
static/bundles

Expand Down
130 changes: 77 additions & 53 deletions cypress/e2e/claim-gift-card.cy.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,99 @@
/* eslint-disable sonarjs/no-duplicate-string */
import { JsonRpcProvider, JsonRpcSigner } from "@ethersproject/providers";
import { Wallet } from "ethers";
import { PermitConfig, generateErc20Permit } from "../../scripts/typescript/generate-erc20-permit-url";
import { PermitConfig, generateErc20Permit, generateMultipleErc20Permits } from "../../scripts/typescript/generate-erc20-permit-url";

const beneficiary = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; // anvil
const SENDER_PRIVATE_KEY = "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"; // anvil

const permitConfig = {
RPC_PROVIDER_URL: "http://localhost:8545",
UBIQUIBOT_PRIVATE_KEY: SENDER_PRIVATE_KEY,
PAYMENT_TOKEN_ADDRESS: "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d",
BENEFICIARY_ADDRESS: beneficiary,
CHAIN_ID: "31337",
AMOUNT_IN_ETH: "30.0",
FRONTEND_URL: "http://localhost:8080",
};

async function createPermitUrl(config: PermitConfig) {
const permit = await generateErc20Permit(config);
cy.wrap(permit).as("permitUrl");
return permit;
}

describe("Gift Cards", () => {
beforeEach(() => {
let permitUrl: string;

beforeEach(async () => {
cy.clearAllCookies();
cy.clearAllLocalStorage();
cy.clearAllSessionStorage();
setupStubs();

setupIntercepts();
});

it.only("should show redeem info", () => {
const permitConfig = Cypress.env("permitConfig");
void cy.getPermitUrl(permitConfig).then((permitUrl) => {
cy.visit(`${permitUrl as string}`);
it("should show redeem info", async () => {
permitUrl = await createPermitUrl(permitConfig);
expect(permitUrl).to.be.a("string");
cy.visit(`/?${permitUrl.split("?")[1]}`);

cy.wait("@getBestCard");
cy.wait(2000);
cy.wait("@getBestCard");
cy.wait(2000);

cy.get("#gift-cards").should("exist").and("include.text", "Or mint a virtual visa/mastercard");
cy.get(".card-section").should("have.length.above", 0);
cy.get(".redeem-info").should("exist");
cy.get(".redeem-info").eq(0).should("include.text", "How to use redeem code?");
});
cy.get("#gift-cards").should("exist").and("include.text", "Or mint a virtual visa/mastercard");
cy.get(".card-section").should("have.length.above", 0);
cy.get(".redeem-info").should("exist");
cy.get(".redeem-info").eq(0).should("include.text", "How to use redeem code?");
});

it("should claim a gift card", () => {
const permitConfig = Cypress.env("permitConfig");

const customPermitConfig = { ...permitConfig, AMOUNT_IN_ETH: "30.0" };
it("should claim a gift card", async () => {
const testPermitConfig = { ...permitConfig, AMOUNT_IN_ETH: "30.0" };
permitUrl = await createPermitUrl(testPermitConfig);
expect(permitUrl).to.be.a("string");

void cy.getPermitUrl(customPermitConfig).then((permitUrl) => {
cy.visit(permitUrl);
cy.wait(2000);
cy.wrap(permitUrl).as("permitUrl");
cy.visit(`/?${permitUrl.split("?")[1]}`);
cy.wait(2000);

cy.wait("@getBestCard");
cy.get(".card-section").should("have.length.above", 0);
cy.get("#offered-card").should("exist");
cy.get("#offered-card .details h3").then(($name) => {
const giftCardName = $name;
cy.wrap(giftCardName).as("giftCardName");
});
cy.wait("@getBestCard");
cy.get(".card-section").should("have.length.above", 0);
cy.get("#offered-card").should("exist");
cy.get("#offered-card .details h3").then(($name) => {
const giftCardName = $name;
cy.wrap(giftCardName).as("giftCardName");
});

cy.intercept({ method: "POST", url: "/post-order?country=US" }).as("postOrder");
cy.intercept({ method: "POST", url: "/post-order?country=US" }).as("postOrder");

cy.get("#offered-card .details #mint").should("exist");
cy.intercept({ method: "GET", url: "/get-order**" }).as("getOrder");
cy.get("#offered-card .details #mint").should("exist");
cy.intercept({ method: "GET", url: "/get-order**" }).as("getOrder");

cy.get("#offered-card .details #mint").invoke("click");
cy.get("#offered-card .details #mint").invoke("click");

cy.get(".notifications", { timeout: 10000 }).should("contain.text", "Processing... Please wait. Do not close this page.");
cy.get(".notifications", { timeout: 10000 }).should("contain.text", "Transaction confirmed. Minting your card now.");
cy.wait("@getOrder", { timeout: 10000 });
cy.get(".notifications", { timeout: 10000 }).should("contain.text", "Processing... Please wait. Do not close this page.");
cy.get(".notifications", { timeout: 10000 }).should("contain.text", "Transaction confirmed. Minting your card now.");
cy.wait("@getOrder", { timeout: 10000 });

cy.get("#gift-cards").should("exist").and("include.text", "Your virtual visa/mastercard");
cy.get("#gift-cards").should("exist").and("include.text", "Your virtual visa/mastercard");

cy.get("#redeem-code").should("exist");
cy.get("@giftCardName").then((name) => {
cy.get("#offered-card .details h3")
.eq(0)
.should("have.text", name.text() as string);
});
cy.get("#redeem-code").should("exist");
cy.get("@giftCardName").then((name) => {
cy.get("#offered-card .details h3")
.eq(0)
.should("have.text", name.text() as string);
});
});

it("should reveal a redeem code after claim", () => {
cy.visit(
"http://localhost:8080/?claim=W3sidHlwZSI6ImVyYzIwLXBlcm1pdCIsInBlcm1pdCI6eyJwZXJtaXR0ZWQiOnsidG9rZW4iOiIweGU5MUQxNTNFMGI0MTUxOEEyQ2U4RGQzRDc5NDRGYTg2MzQ2M2E5N2QiLCJhbW91bnQiOiIzMDAwMDAwMDAwMDAwMDAwMDAwMCJ9LCJub25jZSI6IjczMDU2NzU0MjU1ODU4ODMxMzQ0NTMzNDgxMDc0Njg5NTE1ODEyNzIzNDE5NTkwNjMwOTY2MTUwOTIxNzk3ODEzMzExMDE4NjgyMDMzIiwiZGVhZGxpbmUiOiIxMTU3OTIwODkyMzczMTYxOTU0MjM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dGVkQW1vdW50IjoiOTAwMDAwMDAwMDAwMDAwMDAwMCJ9LCJvd25lciI6IjB4NzA5OTc5NzBDNTE4MTJkYzNBMDEwQzdkMDFiNTBlMGQxN2RjNzlDOCIsInNpZ25hdHVyZSI6IjB4N2RhZjExM2E1MDRmNjFjOTkwODRkYzZkYWVlNmRkMWRmOGEzYjhiMzllNTQ3ZWRhYjEyM2E3NDE2MGE1ZWE0NjBkODI4N2ZhYzUwOWFhNzkzZmE2NzkzZGU5ODliZWE5ODhjYzc0MDI0YTlmZDI2MDIyNjZhNDNmODUwOWFhMmQxYiIsIm5ldHdvcmtJZCI6MzEzMzd9XQ=="
);
cy.wait(2000);

cy.wait("@getBestCard");
expect(permitUrl).to.be.a("string");
cy.get("@permitUrl").then((url: JQuery<HTMLElement>) => {
cy.visit(`/?${url.text().split("?")[1]}`);
cy.wait(2000);
cy.wait("@getBestCard");
});

cy.get("#gift-cards").should("exist").and("include.text", "Your virtual visa/mastercard");
cy.get("#gift-cards").should("exist").and("include.text", "Your virtual card");
cy.get("#redeem-code > h3").eq(0).should("have.text", "Redeem code");
cy.get("#redeem-code > p").eq(0).should("have.text", "xxxxxxxxxxxx");
cy.get("#redeem-code > p").eq(1).should("have.text", "xxxxxxxxxxxx");
Expand Down Expand Up @@ -110,8 +125,16 @@ function setupIntercepts() {
if (req.body.method === "eth_getBlockByNumber") {
req.reply({
statusCode: 200,
body: cy.fixture("eth_getBlockByNumber.json"),
body: {
jsonrpc: "2.0",
id: 1,
result: {
number: "0x1",
},
},
});
} else {
req.continue();
}
});

Expand Down Expand Up @@ -153,7 +176,7 @@ function stubEthereum(signer: JsonRpcSigner) {
((win as any).ethereum = {
isMetaMask: true,
enable: cy.stub().resolves(["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"]),
request: cy.stub().callsFake(async (method) => providerFunctions(method)),
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 @@ -164,7 +187,7 @@ function stubEthereum(signer: JsonRpcSigner) {
chainId: "0x7a69",
selectedAddress: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
requestAccounts: cy.stub().resolves(["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"]),
send: cy.stub().callsFake(async (method) => providerFunctions(method)),
send: cy.stub().callsFake(async ({ method }) => providerFunctions(method)),
getSigner: () => signer,
}),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -173,6 +196,7 @@ function stubEthereum(signer: JsonRpcSigner) {
}

function providerFunctions(method: string) {
console.log("method", method);
switch (method) {
case "eth_requestAccounts":
return ["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"];
Expand All @@ -196,5 +220,5 @@ function providerFunctions(method: string) {
}

Cypress.Commands.add("getPermitUrl", (customPermitConfig: PermitConfig) => {
return generateErc20Permit(customPermitConfig);
return generateMultipleErc20Permits(customPermitConfig);
});
Loading
Loading