Skip to content

Commit

Permalink
Merge pull request #575 from stakwork/feat/v2_payments_cypress_test
Browse files Browse the repository at this point in the history
PR: added v2 cypress payments configurations
  • Loading branch information
elraphty committed Sep 12, 2024
2 parents b9b9344 + ab33290 commit db2d688
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 54 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/prjob_cypress_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- name: Clone Stack
run: |
git clone https://github.com/stakwork/sphinx-stack.git stack
git clone --single-branch --branch change_v2_ports https://github.com/stakwork/sphinx-stack.git stack
- name: Give Permissions to Sphinx Tribes Frontend
run: chmod 777 -R cypress
Expand All @@ -45,20 +45,29 @@ jobs:
timeout_minutes: 10
max_attempts: 3
command: |
GITACTION_ENV=gitactionenv docker compose -f ./stack/alts/proxy.yml --project-directory ./stack up -d;
GITACTION_ENV=gitactionenv docker compose -f ./stack/alts/v1v2.yml --project-directory ./stack up -d;
sleep 240;
docker ps
docker logs alice.sphinx
docker logs meme.sphinx
docker logs dave.sphinx
docker logs tribes.sphinx
docker wait stack_relaysetup_1
cat stack/relay/NODES.json;
cat stack/relay/V2NODES.json;
- name: Copy Node.json
uses: canastro/copy-file-action@master
with:
source: 'stack/relay/NODES.json'
target: 'cypress/fixtures/nodes.json'

- name: Copy V2Node.json
uses: canastro/copy-file-action@master
with:
source: 'stack/relay/V2NODES.json'
target: 'cypress/fixtures/v2nodes.json'

- name: Install Frontend Dependencies
run: yarn install

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# testing
/coverage
cypress/fixtures/nodes.json
cypress/fixtures/v2nodes.json
cypress/screenshots

# production
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/10_payBounty.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('It Pays a bounty ', () => {
cy.get('[data-challenge]')
.invoke('attr', 'data-challenge')
.then((value) => {
cy.pay_invoice({ payersName: 'carol', invoice: value });
cy.pay_invoice({ invoice: value });
cy.wait(4000);
cy.contains('Successfully Deposited');
cy.get('body').click(0, 0);
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/13_depositToWorkspace.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('It desposits to a workspace ', () => {
cy.contains('Deposit').click();
cy.wait(1000);

const budgetAmount = 80000;
const budgetAmount = 2000;

cy.get('[data-testid="input-amount"]').type(String(budgetAmount));
cy.get('[data-testid="generate-button"]').click();
Expand All @@ -36,7 +36,7 @@ describe('It desposits to a workspace ', () => {
cy.get('[data-challenge]')
.invoke('attr', 'data-challenge')
.then((value) => {
cy.pay_invoice({ payersName: 'carol', invoice: value });
cy.pay_invoice({ invoice: value });
cy.wait(4000);
cy.contains('Successfully Deposited');
cy.get('body').click(0, 0);
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/18_withdrawWorkspaceBudget.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('It Withdraws from Workspace budget', () => {
cy.get('[data-challenge]')
.invoke('attr', 'data-challenge')
.then((value) => {
cy.pay_invoice({ payersName: 'carol', invoice: value });
cy.pay_invoice({ invoice: value });
cy.wait(3000);
cy.contains('Successfully Deposited');
cy.get('body').click(0, 0);
Expand All @@ -43,7 +43,7 @@ describe('It Withdraws from Workspace budget', () => {
cy.wait(1000);

// generate lightning invoice and withdraw from workspace
cy.add_invoice({ payersName: 'carol', amount: withdrawAmount, memo: '' }).then((res: any) => {
cy.add_invoice({ amount: withdrawAmount }).then((res: any) => {
const invoice = res?.body.response.invoice;
cy.get('[data-testid="withdrawInvoiceInput"]').type(invoice);
cy.contains('Confirm').click();
Expand Down
19 changes: 13 additions & 6 deletions cypress/e2e/29_paymentHistory.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ describe('It Lists all payments in history', () => {
cy.login(activeUser);
cy.wait(1000);

cy.intercept({
method: 'POST',
url: 'http://localhost:13000/budgetinvoices'
}).as('createInvoice');

// create workspace
const workSpace = {
loggedInAs: activeUser,
name: 'Payment Flow',
name: '3 Payment Flow',
description: 'We are testing out our workspace',
website: 'https://community.sphinx.chat',
github: 'https://github.com/stakwork/sphinx-tribes-frontend'
Expand All @@ -22,23 +27,25 @@ describe('It Lists all payments in history', () => {
cy.wait(1000);

const depositAmount = 10000;
const withdrawAmount = 2000;
const withdrawAmount = 1000;
const paymentAmount = 500;
const afterWithdrawAmount = depositAmount - withdrawAmount;
const finalPaymentAmount = depositAmount - withdrawAmount - paymentAmount;

// add workspace budget
cy.contains('Deposit').click();
cy.wait(1000);
cy.get('[data-testid="input-amount"]').type(String(depositAmount));
cy.get('[data-testid="generate-button"]').click();
cy.wait('@createInvoice');
cy.contains('Invoice Created Successfully');
cy.wait(4000);

// get invoice from clipboard anf pay bounty
cy.get('[data-challenge]')
.invoke('attr', 'data-challenge')
.then((value) => {
cy.pay_invoice({ payersName: 'carol', invoice: value });
cy.pay_invoice({ invoice: value });
cy.wait(3000);
cy.contains('Successfully Deposited');
cy.get('body').click(0, 0);
Expand All @@ -49,8 +56,8 @@ describe('It Lists all payments in history', () => {
cy.wait(1000);

// generate lightning invoice and withdraw from workspace
cy.add_invoice({ payersName: 'carol', amount: withdrawAmount, memo: '' }).then((res: any) => {
const invoice = res?.body.response.invoice;
cy.add_invoice({ amount: withdrawAmount }).then((res: any) => {
const invoice = res?.body.bolt11;
cy.get('[data-testid="withdrawInvoiceInput"]').type(invoice);
cy.contains('Confirm').click();
cy.wait(1000);
Expand All @@ -77,7 +84,7 @@ describe('It Lists all payments in history', () => {
coding_language: ['Typescript', 'Javascript', 'Lightning'],
description: 'This is available',
amount: String(paymentAmount),
assign: 'carol',
assign: 'evan',
deliverables: 'We are good to go man',
workspace: workSpace.name,
tribe: '',
Expand Down
3 changes: 0 additions & 3 deletions cypress/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ declare namespace Cypress {
};

type InvoiceDetail = {
payersName: string;
invoice: string;
};

type AddInvoice = {
payersName: string;
amount: number;
memo: string;
};
}
57 changes: 22 additions & 35 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import { bech32 } from 'bech32';
const EC = require('elliptic').ec;

const v2AdminToken = 'xyzxyzxyz';

Cypress.Commands.add('login', (userAlias: string) => {
let user;
let challenge;
Expand Down Expand Up @@ -412,47 +414,32 @@ Cypress.Commands.add('create_workspace', (workspace) => {
});

Cypress.Commands.add('pay_invoice', (details) => {
let user;

cy.fixture('nodes.json').then((json) => {
for (let i = 0; i < json.length; i++) {
if (json[i].alias === details.payersName) {
user = json[i];
}
const v2BobUrl = 'http://localhost:3006/pay_invoice';
cy.request({
method: 'POST',
url: v2BobUrl,
headers: {
'x-admin-token': `${v2AdminToken}`
},
body: {
bolt11: details.invoice
}
cy.request({
method: 'PUT',
url: `${user.external_ip}/invoices`,
headers: {
'x-user-token': `${user.authToken}`
},
body: {
payment_request: details.invoice
}
}).then((response) => {
console.log(response);
});
}).then((response) => {
console.log(response);
});
});

Cypress.Commands.add('add_invoice', (details) => {
const v2BobUrl = 'http://localhost:3006/invoice';
let user;
cy.fixture('nodes.json').then(async (json) => {
for (let i = 0; i < json.length; i++) {
if (json[i].alias === details.payersName) {
user = json[i];
}
cy.request({
method: 'POST',
url: v2BobUrl,
headers: {
'x-admin-token': `${v2AdminToken}`
},
body: {
amt_msat: details.amount * 1000
}
cy.request({
method: 'POST',
url: `${user.external_ip}/invoices`,
headers: {
'x-user-token': `${user.authToken}`
},
body: {
amount: details.amount,
memo: details.memo
}
});
});
});
49 changes: 48 additions & 1 deletion cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// Import commands.js using ES2015 syntax:
import './commands';
import nodes from '../fixtures/nodes.json';
import nodesv2 from '../fixtures/v2nodes.json';

// Alternatively you can use CommonJS syntax:
// require('./commands')
Expand All @@ -39,5 +40,51 @@ async function postAllUsersToTribe() {
}
}
}

postAllUsersToTribe();

async function postV2UsersToTribe() {
for (let i = 0; i < nodesv2.length; i++) {
const node = nodesv2[i];
const botUrl = `${node.external_ip}/signed_timestamp`;
const tribesUrl = 'http://localhost:13000';
const adminToken = node.adminToken;

try {
const res = await fetch(botUrl, {
method: 'POST',
body: JSON.stringify({}),
headers: { 'x-admin-token': `${adminToken}` }
});

const resJson = await res.json();
const sig = resJson.sig;
const profileUrl = tribesUrl + `/person?token=${sig}`;

let node_alias = '';
if (node.alias === 'alice') {
node_alias = 'raph';
} else {
node_alias = 'evan';
}
// Insert V2 User
await fetch(profileUrl, {
method: 'POST',
body: JSON.stringify({
owner_alias: node_alias,
owner_pubkey: node.pubkey,
owner_route_hint: node.routeHint,
owner_contact_key: node.pubkey,
description: 'V2 Description',
img: '',
tags: [],
price_to_meet: 0,
extras: {},
new_ticket_time: 0
})
});
} catch (error) {
console.log(`Error creating user on bounty platform: ${JSON.stringify(error)}`);
}
}
}
postV2UsersToTribe();
4 changes: 2 additions & 2 deletions src/people/widgetViews/workspace/AddBudgetModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const AddBudgetModal = (props: AddBudgetModalProps) => {
function addSuccessToast() {
setToasts([
{
id: '1',
id: `${Math.random()}`,
title: 'Create Invoice',
color: 'success',
text: 'Invoice Created Successfully'
Expand All @@ -139,7 +139,7 @@ const AddBudgetModal = (props: AddBudgetModalProps) => {
function addErrorToast(text: string) {
setToasts([
{
id: '2',
id: `${Math.random()}`,
title: 'Create Invoice',
color: 'danger',
text
Expand Down

0 comments on commit db2d688

Please sign in to comment.