Skip to content

Commit

Permalink
Merge pull request #345 from ubq-testing/development
Browse files Browse the repository at this point in the history
Update `rpc-handler` and fix tests following beta merge
  • Loading branch information
rndquu authored Oct 25, 2024
2 parents 9b88dd6 + c7c04f1 commit d430ef4
Show file tree
Hide file tree
Showing 24 changed files with 8,581 additions and 11,640 deletions.
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" &

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
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
131 changes: 78 additions & 53 deletions cypress/e2e/claim-gift-card.cy.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,100 @@
/* 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=W3sidHlwZSI6ImVyYzIwLXBlcm1pdCIsInBlcm1pdCI6eyJwZXJtaXR0ZWQiOnsidG9rZW4iOiIweGU5MUQxNTNFMGI0MTUxOEEyQ2U4RGQzRDc5NDRGYTg2MzQ2M2E5N2QiLCJhbW91bnQiOiIzMDAwMDAwMDAwMDAwMDAwMDAwMCJ9LCJub25jZSI6IjczMDU2NzU0MjU1ODU4ODMxMzQ0NTMzNDgxMDc0Njg5NTE1ODEyNzIzNDE5NTkwNjMwOTY2MTUwOTIxNzk3ODEzMzExMDE4NjgyMDMzIiwiZGVhZGxpbmUiOiIxMTU3OTIwODkyMzczMTYxOTU0MjM1NzA5ODUwMDg2ODc5MDc4NTMyNjk5ODQ2NjU2NDA1NjQwMzk0NTc1ODQwMDc5MTMxMjk2Mzk5MzUifSwidHJhbnNmZXJEZXRhaWxzIjp7InRvIjoiMHhmMzlGZDZlNTFhYWQ4OEY2RjRjZTZhQjg4MjcyNzljZmZGYjkyMjY2IiwicmVxdWVzdGVkQW1vdW50IjoiMzAwMDAwMDAwMDAwMDAwMDAwMDAifSwib3duZXIiOiIweDcwOTk3OTcwQzUxODEyZGMzQTAxMEM3ZDAxYjUwZTBkMTdkYzc5QzgiLCJzaWduYXR1cmUiOiIweDdkYWYxMTNhNTA0ZjYxYzk5MDg0ZGM2ZGFlZTZkZDFkZjhhM2I4YjM5ZT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wMDAwMDAwMDAwMCJ9LCJub25jZSI6IjYyOTc2MjY4MDU3NjQ1MTA0ODc3MTI4NDU3MTU1NDgwNTU5NzU1OTQwMjA4MzExMDQ3Mjc1Njc2NjAyNDI3NzQwODY1NzE0MDkxMzAwIiwiZGVhZGxpbmUiOiIxMTU3OTIwODkyMzczMTYxOTU0MjM1NzA5ODUwMDg2ODc5MDc4NTMyNjk5ODQ2NjU2NDA1NjQwMzk0NTc1ODQwMDc5MTMxMjk2Mzk5MzUifSwidHJhbnNmZXJEZXRhaWxzIjp7InRvIjoiMHhmMzlGZDZlNTFhYWQ4OEY2RjRjZTZhQjg4MjcyNzljZmZGYjkyMjY2IiwicmVxdWVzdGVkQW1vdW50IjoiOTAwMDAwMDAwMDAwMDAwMDAwMCJ9LCJvd25lciI6IjB4NzA5OTc5NzBDNTE4MTJkYzNBMDEwQzdkMDFiNTBlMGQxN2RjNzlDOCIsInNpZ25hdHVyZSI6IjB4N2RhZjExM2E1MDRmNjFjOTkwODRkYzZkYWVlNmRkMWRmOGEzYjhiMzllNTQ3ZWRhYjEyM2E3NDE2MGE1ZWE0NjBkODI4N2ZhYzUwOWFhNzkzZmE2NzkzZGU5ODliZWE5ODhjYzc0MDI0YTlmZDI2MDIyNjZhNDNmODUwOWFhMmQxYiIsIm5ldHdvcmtJZCI6MzEzMzd9XQ=="
);
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 +126,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 +177,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 +188,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 +197,7 @@ function stubEthereum(signer: JsonRpcSigner) {
}

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

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

1 comment on commit d430ef4

@ubiquity-os
Copy link
Contributor

@ubiquity-os ubiquity-os bot commented on d430ef4 Oct 25, 2024

Choose a reason for hiding this comment

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

@rndquu Configuration is invalid.

Caution

approvalsRequired:

path: plugins/5/uses/0/with
value: {"approvalsRequired":{"collaborator":1},"mergeTimeout":{"collaborator":"3.5 days"},"repos":{"ignore":["ubiquibot","launch-party","staging","production"]}}
message: Property "approvalsRequired" does not match schema.

Caution

path: plugins/5/uses/0/with/approvalsRequired
value: {"collaborator":1}
message: Instance does not have required property "contributor".

Caution

approvalsRequired:

path: plugins/5/uses/0/with
value: {"approvalsRequired":{"collaborator":1},"mergeTimeout":{"collaborator":"3.5 days"},"repos":{"ignore":["ubiquibot","launch-party","staging","production"]}}
message: Property "mergeTimeout" does not match schema.

Caution

collaborator: "3.5 days"

path: plugins/5/uses/0/with/mergeTimeout
value: {"collaborator":"3.5 days"}
message: Instance does not have required property "contributor".

Caution

approvalsRequired:

path: plugins/5/uses/0/with
value: {"approvalsRequired":{"collaborator":1},"mergeTimeout":{"collaborator":"3.5 days"},"repos":{"ignore":["ubiquibot","launch-party","staging","production"]}}
message: Property "repos" does not match schema.

Caution

path: plugins/5/uses/0/with/repos
value: {"ignore":["ubiquibot","launch-party","staging","production"]}
message: Instance does not have required property "monitor".

Caution

reviewDelayTolerance: "3 Days"

path: plugins/6/uses/0/with
value: {"reviewDelayTolerance":"3 Days","taskStaleTimeoutDuration":"30 Days","startRequiresWallet":true}
message: Instance does not have required property "maxConcurrentTasks".

Caution

reviewDelayTolerance: "3 Days"

path: plugins/6/uses/0/with
value: {"reviewDelayTolerance":"3 Days","taskStaleTimeoutDuration":"30 Days","startRequiresWallet":true}
message: Instance does not have required property "emptyWalletText".

Caution

reviewDelayTolerance: "3 Days"

path: plugins/6/uses/0/with
value: {"reviewDelayTolerance":"3 Days","taskStaleTimeoutDuration":"30 Days","startRequiresWallet":true}
message: Instance does not have required property "rolesWithReviewAuthority".

Caution

path: plugins/7/uses/0/with
value: undefined
message: Instance does not have required property "matchThreshold".

Caution

path: plugins/7/uses/0/with
value: undefined
message: Instance does not have required property "warningThreshold".

Caution

path: plugins/7/uses/0/with
value: undefined
message: Instance does not have required property "jobMatchingThreshold".

Please sign in to comment.