From 3773b72e394e44cee706e6f699c237bbe4785651 Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Sat, 13 Jan 2024 12:36:13 +0530 Subject: [PATCH 01/12] chore:added batch payments --- .../components/batch-payments/index.tsx | 8 +- apps/dashboard/components/upload-button.tsx | 3 +- .../cypress/e2e/batch-payments/index.cy.ts | 56 ++++++++++ apps/dashboard/cypress/fixtures/template.csv | 5 + apps/dashboard/cypress/support/commands.ts | 101 +++++++++++------- .../cypress/support/gql/get-transactions.gql | 16 +++ apps/dashboard/cypress/support/test-data.ts | 32 ++++++ dev/BUCK | 10 ++ dev/Tiltfile | 28 +++++ dev/bin/add-test-users-with-usernames.sh | 4 +- dev/bin/fund-user.sh | 17 +++ dev/helpers/common.sh | 23 ++++ dev/helpers/gql/on-chain-address-create.gql | 8 ++ dev/helpers/gql/transactions.gql | 66 ++++++++++++ dev/helpers/gql/wallets-for-account.gql | 13 +++ dev/helpers/onchain.sh | 65 +++++++++++ 16 files changed, 413 insertions(+), 42 deletions(-) create mode 100644 apps/dashboard/cypress/e2e/batch-payments/index.cy.ts create mode 100644 apps/dashboard/cypress/fixtures/template.csv create mode 100644 apps/dashboard/cypress/support/gql/get-transactions.gql create mode 100755 dev/bin/fund-user.sh create mode 100644 dev/helpers/common.sh create mode 100644 dev/helpers/gql/on-chain-address-create.gql create mode 100644 dev/helpers/gql/transactions.gql create mode 100644 dev/helpers/gql/wallets-for-account.gql create mode 100644 dev/helpers/onchain.sh diff --git a/apps/dashboard/components/batch-payments/index.tsx b/apps/dashboard/components/batch-payments/index.tsx index 0ba1a010ab..01d323335b 100644 --- a/apps/dashboard/components/batch-payments/index.tsx +++ b/apps/dashboard/components/batch-payments/index.tsx @@ -214,7 +214,7 @@ export default function BatchPayments() { > {modalDetails.heading} -

{modalDetails.message}

+

{modalDetails.message}

@@ -250,7 +250,11 @@ export default function BatchPayments() { label="Balance in USD Wallet" value={`$${centsToDollars(paymentDetails.userWalletBalance.USD)} USD`} /> - diff --git a/apps/dashboard/components/upload-button.tsx b/apps/dashboard/components/upload-button.tsx index f73086c127..b40ba6d45f 100644 --- a/apps/dashboard/components/upload-button.tsx +++ b/apps/dashboard/components/upload-button.tsx @@ -99,14 +99,13 @@ export default function FileUpload({ {file ? file.name : "Upload a csv file"} { + beforeEach(() => { + cy.viewport(1920, 1080) + cy.setCookie("next-auth.session-token", testData.NEXT_AUTH_SESSION_TOKEN, { + secure: true, + }) + cy.visit("/batch-payments") + }) + + it("uploads a CSV file via input and checks transactions", () => { + cy.get("[data-testid=csv-upload-input]").selectFile("cypress/fixtures/template.csv") + cy.get("[data-testid=confirm-batch-payments-btn]").click() + cy.get("[data-testid=batch-payments-modal-message]").should( + "contain.text", + "Batch Payment Completed", + ) + cy.loginAndGetToken(testData.PHONE, testData.CODE).then((token) => { + const authToken = token + cy.getTransactions(authToken, 4).then((transactions) => { + // Check for specific BTC transactions + btcPaymentInUSDCurrency.forEach((expectedBtcTransaction) => { + const found = transactions.some( + (transaction) => + transaction.settlementCurrency === + expectedBtcTransaction.settlementCurrency && + transaction.status === expectedBtcTransaction.status && + transaction.settlementDisplayAmount === + expectedBtcTransaction.settlementDisplayAmount, + ) + expect(found).to.be.true + }) + + expectedTransactions.forEach((expectedTransaction) => { + // Exclude the special case transactions + if ( + !btcPaymentInUSDCurrency.some( + (btcTx) => + btcTx.settlementCurrency === expectedTransaction.settlementCurrency && + btcTx.status === expectedTransaction.status && + btcTx.settlementDisplayAmount === + expectedTransaction.settlementDisplayAmount, + ) + ) { + expect(transactions).to.deep.include(expectedTransaction) + } + }) + }) + }) + }) +}) diff --git a/apps/dashboard/cypress/fixtures/template.csv b/apps/dashboard/cypress/fixtures/template.csv new file mode 100644 index 0000000000..a526b53f39 --- /dev/null +++ b/apps/dashboard/cypress/fixtures/template.csv @@ -0,0 +1,5 @@ +username,amount,currency,wallet,memo +test_user_a,12,USD,USD,Testing to send 12 USD +test_user_b,10,USD,USD,Testing to send 10 USD +test_user_c,5,USD,BTC,Testing to send 5 USD +test_user_a,100,SATS,BTC,Testing to send 100 SATS \ No newline at end of file diff --git a/apps/dashboard/cypress/support/commands.ts b/apps/dashboard/cypress/support/commands.ts index b5f5060e04..998bcad38e 100644 --- a/apps/dashboard/cypress/support/commands.ts +++ b/apps/dashboard/cypress/support/commands.ts @@ -1,40 +1,11 @@ /// -// *********************************************** -// This example commands.ts shows you how to -// create various custom commands and overwrite -// existing commands. -// -// For more comprehensive examples of custom -// commands please read more here: -// https://on.cypress.io/custom-commands -// *********************************************** -// -// -// -- This is a parent command -- -// Cypress.Commands.add('login', (email, password) => { ... }) -// -// -// -- This is a child command -- -// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) -// -// -// -- This is a dual command -- -// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) -// -// -// -- This will overwrite an existing command -- -// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) -// -// declare global { -// namespace Cypress { -// interface Chainable { -// login(email: string, password: string): Chainable -// drag(subject: string, options?: Partial): Chainable -// dismiss(subject: string, options?: Partial): Chainable -// visit(originalFn: CommandOriginalFn, url: string, options: Partial): Chainable -// } -// } -// } + +type Transaction = { + settlementAmount: number + settlementCurrency: string + status: string + settlementDisplayAmount: string +} // eslint-disable-next-line @typescript-eslint/no-namespace declare namespace Cypress { @@ -43,6 +14,11 @@ declare namespace Cypress { getOTP(email: string): Chainable requestEmailCode(email: string): Chainable flushRedis(): Chainable + loginAndGetToken(phone: string, code: string): Chainable + getTransactions( + authToken: string, + numberOfTransactions: number, + ): Chainable> } } @@ -69,3 +45,56 @@ Cypress.Commands.add("flushRedis", () => { } }) }) + +Cypress.Commands.add("loginAndGetToken", (phone, code) => { + cy.flushRedis() + cy.request({ + method: "POST", + url: "http://localhost:4455/auth/phone/login", + body: { + phone, + code, + }, + }).then((response) => { + expect(response.body).to.have.property("authToken") + return response.body.authToken + }) +}) + +Cypress.Commands.add("getTransactions", (authToken, numberOfTransactions) => { + cy.request({ + method: "POST", + url: "http://localhost:4455/graphql", + headers: { + "Authorization": `Bearer ${authToken}`, + "Content-Type": "application/json", + }, + body: { + query: ` + query GetFirstTransactions($first: Int!) { + me { + defaultAccount { + transactions(first: $first) { + edges { + node { + settlementAmount + settlementCurrency + status + settlementDisplayAmount + } + } + } + } + } + } + `, + variables: { + first: numberOfTransactions, + }, + }, + }).then((response) => { + return response.body.data.me.defaultAccount.transactions.edges.map( + (edge: { node: Transaction }) => edge.node, + ) + }) +}) diff --git a/apps/dashboard/cypress/support/gql/get-transactions.gql b/apps/dashboard/cypress/support/gql/get-transactions.gql new file mode 100644 index 0000000000..e2193dfa0a --- /dev/null +++ b/apps/dashboard/cypress/support/gql/get-transactions.gql @@ -0,0 +1,16 @@ +query GetFirstTransactions($first: Int!) { + me { + defaultAccount { + transactions(first: $first) { + edges { + node { + settlementAmount + settlementCurrency + status + settlementDisplayAmount + } + } + } + } + } +} diff --git a/apps/dashboard/cypress/support/test-data.ts b/apps/dashboard/cypress/support/test-data.ts index ea00897c80..810c3af51c 100644 --- a/apps/dashboard/cypress/support/test-data.ts +++ b/apps/dashboard/cypress/support/test-data.ts @@ -2,4 +2,36 @@ export const testData = { NEXT_AUTH_SESSION_TOKEN: Cypress.env("NEXT_AUTH_SESSION_TOKEN"), EMAIL: "test@galoy.io", CALLBACK_URL: "https://www.google.com/", + PHONE: "+16505554350", + CODE: "000000", + CORE_URL: "http://localhost:4455", } + +export const expectedTransactions = [ + { + settlementAmount: -100, + settlementCurrency: "BTC", + status: "SUCCESS", + settlementDisplayAmount: "-0.04", + }, + { + settlementAmount: -1000, + settlementCurrency: "USD", + status: "SUCCESS", + settlementDisplayAmount: "-10.00", + }, + { + settlementAmount: -1200, + settlementCurrency: "USD", + status: "SUCCESS", + settlementDisplayAmount: "-12.00", + }, +] + +export const btcPaymentInUSDCurrency = [ + { + settlementCurrency: "BTC", + status: "SUCCESS", + settlementDisplayAmount: "-5.00", + }, +] diff --git a/dev/BUCK b/dev/BUCK index 74a452881f..ea8d62efe7 100644 --- a/dev/BUCK +++ b/dev/BUCK @@ -87,3 +87,13 @@ sh_binary( name = "stoppable-trigger", main = "bin/run-stoppable-trigger.sh", ) + +sh_binary( + name = "add-test-users-with-usernames", + main = "bin/add-test-users-with-usernames.sh", +) + +sh_binary( + name = "fund-user", + main = "bin/fund-user.sh", +) \ No newline at end of file diff --git a/dev/Tiltfile b/dev/Tiltfile index 35c97d9665..8aeae18264 100644 --- a/dev/Tiltfile +++ b/dev/Tiltfile @@ -61,6 +61,8 @@ local_resource( "api-keys", "svix", "svix-pg", + "add-test-users-with-usernames", + "fund-user", ], links = [ link("http://localhost:3001", "dashboard"), @@ -162,6 +164,32 @@ local_resource( ] ) +local_resource( + name='add-test-users-with-usernames', + labels = ['test'], + cmd='buck2 run //dev:add-test-users-with-usernames', + allow_parallel = True, + resource_deps = [ + "oathkeeper", + "kratos", + "api", + ] +) + +local_resource( + name='fund-user', + labels = ['test'], + cmd='buck2 run //dev:fund-user', + allow_parallel = True, + resource_deps = [ + "oathkeeper", + "kratos", + "api", + "init-test-user" + ] +) + + consent_target = "//apps/consent:dev" if is_ci: consent_target = '//apps/consent:consent' diff --git a/dev/bin/add-test-users-with-usernames.sh b/dev/bin/add-test-users-with-usernames.sh index dcb4700d56..e0f4080cdd 100755 --- a/dev/bin/add-test-users-with-usernames.sh +++ b/dev/bin/add-test-users-with-usernames.sh @@ -31,7 +31,7 @@ echo "Starting main execution" echo "Logging in user $user_a" auth_token_a=$(login_user "${user_a}") -echo "Auth token for $user_a: $auth_token_a" +echo "Auth token for $user_a: $auth_token_a" echo "Logging in user $user_b" auth_token_b=$(login_user "${user_b}") @@ -45,4 +45,4 @@ update_username "$auth_token_a" "$user_a_username" update_username "$auth_token_b" "$user_b_username" update_username "$auth_token_c" "$user_c_username" -echo "Username update process completed +echo "Username update process completed" diff --git a/dev/bin/fund-user.sh b/dev/bin/fund-user.sh new file mode 100755 index 0000000000..38b610f6bb --- /dev/null +++ b/dev/bin/fund-user.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# set -e +# set -x + +echo "Setting up DEV_DIR variable" +DEV_DIR="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")" +source "${DEV_DIR}/helpers/auth.sh" +source "${DEV_DIR}/helpers/cli.sh" +source "${DEV_DIR}/helpers/onchain.sh" + +user_phone="+16505554350" +token="$(login_user "${user_phone}")" +echo "Fetching wallets for account" + +echo "Funding wallets" +fund_user_onchain "$token" "USD" +fund_user_onchain "$token" "BTC" diff --git a/dev/helpers/common.sh b/dev/helpers/common.sh new file mode 100644 index 0000000000..9da2badc7b --- /dev/null +++ b/dev/helpers/common.sh @@ -0,0 +1,23 @@ +retry() { + local attempts=$1 + shift + local delay=$1 + shift + local i + + for ((i = 0; i < attempts; i++)); do + if [[ "${BATS_TEST_DIRNAME}" = "" ]]; then + "$@" + else + run "$@" + fi + + if [[ "$status" -eq 0 ]]; then + return 0 + fi + sleep "$delay" + done + + echo "Command \"$*\" failed $attempts times. Output: $output" + false +} diff --git a/dev/helpers/gql/on-chain-address-create.gql b/dev/helpers/gql/on-chain-address-create.gql new file mode 100644 index 0000000000..b8992d2763 --- /dev/null +++ b/dev/helpers/gql/on-chain-address-create.gql @@ -0,0 +1,8 @@ +mutation onChainAddressCreate($input: OnChainAddressCreateInput!) { + onChainAddressCreate(input: $input) { + address + errors { + message + } + } +} diff --git a/dev/helpers/gql/transactions.gql b/dev/helpers/gql/transactions.gql new file mode 100644 index 0000000000..5955d7a311 --- /dev/null +++ b/dev/helpers/gql/transactions.gql @@ -0,0 +1,66 @@ +query transactions($walletIds: [WalletId], $first: Int, $after: String) { + me { + defaultAccount { + defaultWallet { + id + } + transactions(walletIds: $walletIds, first: $first, after: $after) { + ...TransactionList + } + } + } +} + +fragment TransactionList on TransactionConnection { + pageInfo { + hasNextPage + } + edges { + cursor + node { + __typename + id + status + direction + memo + createdAt + settlementAmount + settlementFee + settlementDisplayAmount + settlementDisplayFee + settlementDisplayCurrency + settlementCurrency + settlementPrice { + base + offset + } + initiationVia { + __typename + ... on InitiationViaIntraLedger { + counterPartyWalletId + counterPartyUsername + } + ... on InitiationViaLn { + paymentHash + paymentRequest + } + ... on InitiationViaOnChain { + address + } + } + settlementVia { + __typename + ... on SettlementViaIntraLedger { + counterPartyWalletId + counterPartyUsername + } + ... on SettlementViaLn { + preImage + } + ... on SettlementViaOnChain { + transactionHash + } + } + } + } +} diff --git a/dev/helpers/gql/wallets-for-account.gql b/dev/helpers/gql/wallets-for-account.gql new file mode 100644 index 0000000000..4679226643 --- /dev/null +++ b/dev/helpers/gql/wallets-for-account.gql @@ -0,0 +1,13 @@ +query me { + me { + defaultAccount { + id + wallets { + id + walletCurrency + balance + pendingIncomingBalance + } + } + } +} diff --git a/dev/helpers/onchain.sh b/dev/helpers/onchain.sh new file mode 100644 index 0000000000..916f9cd225 --- /dev/null +++ b/dev/helpers/onchain.sh @@ -0,0 +1,65 @@ +DEV_DIR="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")" +source "${DEV_DIR}/helpers/gql.sh" + + +check_for_onchain_initiated_settled() { + local token_name=$1 + local wallet_id=$2 + local first=${3:-"1"} + + variables=$( + jq -n \ + --argjson first "$first" \ + '{"first": $first}' + ) + transactions="$(exec_graphql "$token_name" "transactions" "$variables")" + echo "$transactions" +} + + +retry() { + local attempts=$1 + shift + local delay=$1 + shift + local i + + for ((i = 0; i < attempts; i++)); do + run "$@" + + if [[ "$status" -eq 0 ]]; then + return 0 + fi + sleep "$delay" + done + + echo "Command \"$*\" failed $attempts times. Output: $output" + false +} + +fund_user_onchain() { + local token=$1 + local wallet_currency=$2 + local btc_amount_in_btc=${3:-"0.01"} + + response="$(exec_graphql "$token" "wallets-for-account")" + wallet_id=$(echo "$response" | jq -r --arg wc "$wallet_currency" '.data.me.defaultAccount.wallets[] | select(.walletCurrency == $wc) .id') + + echo "Creating variables for GraphQL query for :====> $wallet_id wallet ID i.e :===> $wallet_currency" + variables=$( + jq -n \ + --arg wallet_id "$wallet_id" \ + '{input: {walletId: $wallet_id}}' + ) + echo "Executing GraphQL query for on-chain address creation" + response=$(exec_graphql "$token" 'on-chain-address-create' "$variables") + echo "Parsing address from the response" + address=$(echo "$response" | jq -r '.data.onChainAddressCreate.address') + [[ "${address}" != "null" ]] || exit 1 + + echo "Sending BTC to address: $address" + bitcoin_signer_cli -generate 101 + bitcoin_signer_cli sendtoaddress "$address" "$btc_amount_in_btc" + bitcoin_signer_cli -generate 101 + check_for_onchain_initiated_settled $token $wallet_id +} From b8aaf8dc559ce68b309a66eefdf72d0a2de7ea0a Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Sun, 14 Jan 2024 17:53:07 +0530 Subject: [PATCH 02/12] chore: misc changes in test --- .../{index.cy.ts => batch-payments.cy.ts} | 3 +- apps/dashboard/cypress/e2e/e2e.cy.ts | 1 + apps/dashboard/cypress/support/commands.ts | 5 +- .../cypress/support/gql/get-transactions.gql | 16 ----- apps/dashboard/cypress/support/test-data.ts | 3 +- dev/Tiltfile | 3 +- dev/helpers/onchain.sh | 68 +++++++------------ 7 files changed, 35 insertions(+), 64 deletions(-) rename apps/dashboard/cypress/e2e/batch-payments/{index.cy.ts => batch-payments.cy.ts} (94%) delete mode 100644 apps/dashboard/cypress/support/gql/get-transactions.gql diff --git a/apps/dashboard/cypress/e2e/batch-payments/index.cy.ts b/apps/dashboard/cypress/e2e/batch-payments/batch-payments.cy.ts similarity index 94% rename from apps/dashboard/cypress/e2e/batch-payments/index.cy.ts rename to apps/dashboard/cypress/e2e/batch-payments/batch-payments.cy.ts index a41c934868..d24b8bf4e0 100644 --- a/apps/dashboard/cypress/e2e/batch-payments/index.cy.ts +++ b/apps/dashboard/cypress/e2e/batch-payments/batch-payments.cy.ts @@ -13,7 +13,7 @@ describe("CSV Upload Component Test", () => { cy.visit("/batch-payments") }) - it("uploads a CSV file via input and checks transactions", () => { + it("Batch Payments Test", () => { cy.get("[data-testid=csv-upload-input]").selectFile("cypress/fixtures/template.csv") cy.get("[data-testid=confirm-batch-payments-btn]").click() cy.get("[data-testid=batch-payments-modal-message]").should( @@ -37,7 +37,6 @@ describe("CSV Upload Component Test", () => { }) expectedTransactions.forEach((expectedTransaction) => { - // Exclude the special case transactions if ( !btcPaymentInUSDCurrency.some( (btcTx) => diff --git a/apps/dashboard/cypress/e2e/e2e.cy.ts b/apps/dashboard/cypress/e2e/e2e.cy.ts index b61ad20636..fe7d3f4e9c 100644 --- a/apps/dashboard/cypress/e2e/e2e.cy.ts +++ b/apps/dashboard/cypress/e2e/e2e.cy.ts @@ -1,3 +1,4 @@ /* eslint-disable import/no-unassigned-import */ import "./api-keys/api-keys.cy" import "./callback/callback.cy" +import "./batch-payments/batch-payments.cy" diff --git a/apps/dashboard/cypress/support/commands.ts b/apps/dashboard/cypress/support/commands.ts index 998bcad38e..d01aa62e1d 100644 --- a/apps/dashboard/cypress/support/commands.ts +++ b/apps/dashboard/cypress/support/commands.ts @@ -1,4 +1,5 @@ /// +import { CORE_URL } from "./test-data" type Transaction = { settlementAmount: number @@ -50,7 +51,7 @@ Cypress.Commands.add("loginAndGetToken", (phone, code) => { cy.flushRedis() cy.request({ method: "POST", - url: "http://localhost:4455/auth/phone/login", + url: `${CORE_URL}/auth/phone/login`, body: { phone, code, @@ -64,7 +65,7 @@ Cypress.Commands.add("loginAndGetToken", (phone, code) => { Cypress.Commands.add("getTransactions", (authToken, numberOfTransactions) => { cy.request({ method: "POST", - url: "http://localhost:4455/graphql", + url: `${CORE_URL}/graphql`, headers: { "Authorization": `Bearer ${authToken}`, "Content-Type": "application/json", diff --git a/apps/dashboard/cypress/support/gql/get-transactions.gql b/apps/dashboard/cypress/support/gql/get-transactions.gql deleted file mode 100644 index e2193dfa0a..0000000000 --- a/apps/dashboard/cypress/support/gql/get-transactions.gql +++ /dev/null @@ -1,16 +0,0 @@ -query GetFirstTransactions($first: Int!) { - me { - defaultAccount { - transactions(first: $first) { - edges { - node { - settlementAmount - settlementCurrency - status - settlementDisplayAmount - } - } - } - } - } -} diff --git a/apps/dashboard/cypress/support/test-data.ts b/apps/dashboard/cypress/support/test-data.ts index 810c3af51c..d82bc8f2ba 100644 --- a/apps/dashboard/cypress/support/test-data.ts +++ b/apps/dashboard/cypress/support/test-data.ts @@ -4,9 +4,10 @@ export const testData = { CALLBACK_URL: "https://www.google.com/", PHONE: "+16505554350", CODE: "000000", - CORE_URL: "http://localhost:4455", } +export const CORE_URL = "http://localhost:4455" + export const expectedTransactions = [ { settlementAmount: -100, diff --git a/dev/Tiltfile b/dev/Tiltfile index 8aeae18264..b4f2175583 100644 --- a/dev/Tiltfile +++ b/dev/Tiltfile @@ -185,7 +185,8 @@ local_resource( "oathkeeper", "kratos", "api", - "init-test-user" + "init-test-user", + "init-onchain" ] ) diff --git a/dev/helpers/onchain.sh b/dev/helpers/onchain.sh index 916f9cd225..6e5d1781e6 100644 --- a/dev/helpers/onchain.sh +++ b/dev/helpers/onchain.sh @@ -2,41 +2,6 @@ DEV_DIR="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")" source "${DEV_DIR}/helpers/gql.sh" -check_for_onchain_initiated_settled() { - local token_name=$1 - local wallet_id=$2 - local first=${3:-"1"} - - variables=$( - jq -n \ - --argjson first "$first" \ - '{"first": $first}' - ) - transactions="$(exec_graphql "$token_name" "transactions" "$variables")" - echo "$transactions" -} - - -retry() { - local attempts=$1 - shift - local delay=$1 - shift - local i - - for ((i = 0; i < attempts; i++)); do - run "$@" - - if [[ "$status" -eq 0 ]]; then - return 0 - fi - sleep "$delay" - done - - echo "Command \"$*\" failed $attempts times. Output: $output" - false -} - fund_user_onchain() { local token=$1 local wallet_currency=$2 @@ -51,15 +16,34 @@ fund_user_onchain() { --arg wallet_id "$wallet_id" \ '{input: {walletId: $wallet_id}}' ) - echo "Executing GraphQL query for on-chain address creation" + response=$(exec_graphql "$token" 'on-chain-address-create' "$variables") - echo "Parsing address from the response" address=$(echo "$response" | jq -r '.data.onChainAddressCreate.address') [[ "${address}" != "null" ]] || exit 1 - echo "Sending BTC to address: $address" - bitcoin_signer_cli -generate 101 - bitcoin_signer_cli sendtoaddress "$address" "$btc_amount_in_btc" - bitcoin_signer_cli -generate 101 - check_for_onchain_initiated_settled $token $wallet_id + bitcoin_cli sendtoaddress "$address" "$btc_amount_in_btc" + bitcoin_cli -generate 4 + + variables=$( + jq -n \ + --argjson first "1" \ + '{"first": $first}' + ) + for i in {1..60}; do + response=$(exec_graphql "$token" 'transactions' "$variables") + echo "$response" + jq_query='.data.me.defaultAccount.transactions.edges[] | select(.node.initiationVia.address == $address) .node' + transaction_info=$(echo $response \ + | jq -r --arg address "$address" "$jq_query") + + settled_status=$(echo "$transaction_info" | jq -r ".status") + settled_currency=$(echo "$transaction_info" | jq -r ".settlementCurrency") + + if [[ "${settled_status}" == "SUCCESS" && "${settled_currency}" == "$wallet_currency" ]]; then + echo "Transaction successful with correct settlement currency" + break + fi + + sleep 1 + done } From a9c3271761cef5868dc9d3a63167edd9f3e87e4c Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Tue, 16 Jan 2024 09:59:22 +0530 Subject: [PATCH 03/12] chore: update deps --- .../cypress/e2e/batch-payments/batch-payments.cy.ts | 5 +++++ dev/Tiltfile | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/dashboard/cypress/e2e/batch-payments/batch-payments.cy.ts b/apps/dashboard/cypress/e2e/batch-payments/batch-payments.cy.ts index d24b8bf4e0..8b9dbc75ed 100644 --- a/apps/dashboard/cypress/e2e/batch-payments/batch-payments.cy.ts +++ b/apps/dashboard/cypress/e2e/batch-payments/batch-payments.cy.ts @@ -15,7 +15,12 @@ describe("CSV Upload Component Test", () => { it("Batch Payments Test", () => { cy.get("[data-testid=csv-upload-input]").selectFile("cypress/fixtures/template.csv") + + cy.get("[data-testid=confirm-batch-payments-btn]").should("exist") + cy.get("[data-testid=confirm-batch-payments-btn]").should("be.visible") + cy.get("[data-testid=confirm-batch-payments-btn]").should("not.be.disabled") cy.get("[data-testid=confirm-batch-payments-btn]").click() + cy.get("[data-testid=batch-payments-modal-message]").should( "contain.text", "Batch Payment Completed", diff --git a/dev/Tiltfile b/dev/Tiltfile index b4f2175583..742a2de140 100644 --- a/dev/Tiltfile +++ b/dev/Tiltfile @@ -185,8 +185,8 @@ local_resource( "oathkeeper", "kratos", "api", - "init-test-user", - "init-onchain" + "init-onchain", + "init-user" ] ) From 317872d06c3bf05614e17057f9df943d84e03ea5 Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Tue, 16 Jan 2024 11:02:39 +0530 Subject: [PATCH 04/12] chore: misc changes --- .../e2e/batch-payments/batch-payments.cy.ts | 7 +++--- dev/BUCK | 2 +- dev/Tiltfile | 2 +- dev/bin/fund-user.sh | 1 - dev/helpers/common.sh | 23 ------------------- dev/helpers/onchain.sh | 7 ++++++ 6 files changed, 13 insertions(+), 29 deletions(-) delete mode 100644 dev/helpers/common.sh diff --git a/apps/dashboard/cypress/e2e/batch-payments/batch-payments.cy.ts b/apps/dashboard/cypress/e2e/batch-payments/batch-payments.cy.ts index 8b9dbc75ed..7cade7d66b 100644 --- a/apps/dashboard/cypress/e2e/batch-payments/batch-payments.cy.ts +++ b/apps/dashboard/cypress/e2e/batch-payments/batch-payments.cy.ts @@ -4,7 +4,7 @@ import { btcPaymentInUSDCurrency, } from "../../support/test-data" -describe("CSV Upload Component Test", () => { +describe("Batch payments test", () => { beforeEach(() => { cy.viewport(1920, 1080) cy.setCookie("next-auth.session-token", testData.NEXT_AUTH_SESSION_TOKEN, { @@ -20,11 +20,12 @@ describe("CSV Upload Component Test", () => { cy.get("[data-testid=confirm-batch-payments-btn]").should("be.visible") cy.get("[data-testid=confirm-batch-payments-btn]").should("not.be.disabled") cy.get("[data-testid=confirm-batch-payments-btn]").click() - + cy.get("[data-testid=batch-payments-modal-message]").should( - "contain.text", + "have.text", "Batch Payment Completed", ) + cy.loginAndGetToken(testData.PHONE, testData.CODE).then((token) => { const authToken = token cy.getTransactions(authToken, 4).then((transactions) => { diff --git a/dev/BUCK b/dev/BUCK index ea8d62efe7..00fca6d337 100644 --- a/dev/BUCK +++ b/dev/BUCK @@ -96,4 +96,4 @@ sh_binary( sh_binary( name = "fund-user", main = "bin/fund-user.sh", -) \ No newline at end of file +) diff --git a/dev/Tiltfile b/dev/Tiltfile index 742a2de140..e9743dc38d 100644 --- a/dev/Tiltfile +++ b/dev/Tiltfile @@ -186,7 +186,7 @@ local_resource( "kratos", "api", "init-onchain", - "init-user" + "init-test-user", ] ) diff --git a/dev/bin/fund-user.sh b/dev/bin/fund-user.sh index 38b610f6bb..74f52b131a 100755 --- a/dev/bin/fund-user.sh +++ b/dev/bin/fund-user.sh @@ -5,7 +5,6 @@ echo "Setting up DEV_DIR variable" DEV_DIR="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")" source "${DEV_DIR}/helpers/auth.sh" -source "${DEV_DIR}/helpers/cli.sh" source "${DEV_DIR}/helpers/onchain.sh" user_phone="+16505554350" diff --git a/dev/helpers/common.sh b/dev/helpers/common.sh deleted file mode 100644 index 9da2badc7b..0000000000 --- a/dev/helpers/common.sh +++ /dev/null @@ -1,23 +0,0 @@ -retry() { - local attempts=$1 - shift - local delay=$1 - shift - local i - - for ((i = 0; i < attempts; i++)); do - if [[ "${BATS_TEST_DIRNAME}" = "" ]]; then - "$@" - else - run "$@" - fi - - if [[ "$status" -eq 0 ]]; then - return 0 - fi - sleep "$delay" - done - - echo "Command \"$*\" failed $attempts times. Output: $output" - false -} diff --git a/dev/helpers/onchain.sh b/dev/helpers/onchain.sh index 6e5d1781e6..be7785c370 100644 --- a/dev/helpers/onchain.sh +++ b/dev/helpers/onchain.sh @@ -1,5 +1,6 @@ DEV_DIR="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")" source "${DEV_DIR}/helpers/gql.sh" +source "${DEV_DIR}/helpers/cli.sh" fund_user_onchain() { @@ -29,6 +30,7 @@ fund_user_onchain() { --argjson first "1" \ '{"first": $first}' ) + local success=false for i in {1..60}; do response=$(exec_graphql "$token" 'transactions' "$variables") echo "$response" @@ -41,9 +43,14 @@ fund_user_onchain() { if [[ "${settled_status}" == "SUCCESS" && "${settled_currency}" == "$wallet_currency" ]]; then echo "Transaction successful with correct settlement currency" + success=true break fi sleep 1 done + + if [[ $success != true ]]; then + echo "Failed to fund user" + fi } From 1d846a51ebffc60ce8990fff298742b221ade77f Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Tue, 16 Jan 2024 11:42:21 +0530 Subject: [PATCH 05/12] chore: remove logs --- dev/helpers/onchain.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/dev/helpers/onchain.sh b/dev/helpers/onchain.sh index be7785c370..e3213071eb 100644 --- a/dev/helpers/onchain.sh +++ b/dev/helpers/onchain.sh @@ -33,7 +33,6 @@ fund_user_onchain() { local success=false for i in {1..60}; do response=$(exec_graphql "$token" 'transactions' "$variables") - echo "$response" jq_query='.data.me.defaultAccount.transactions.edges[] | select(.node.initiationVia.address == $address) .node' transaction_info=$(echo $response \ | jq -r --arg address "$address" "$jq_query") From cc321cebb40d5f1eef55929e1d7b15c76176646d Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Tue, 16 Jan 2024 14:05:53 +0530 Subject: [PATCH 06/12] chore: update deps --- dev/Tiltfile | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/Tiltfile b/dev/Tiltfile index e9743dc38d..a30f7fb24c 100644 --- a/dev/Tiltfile +++ b/dev/Tiltfile @@ -187,6 +187,7 @@ local_resource( "api", "init-onchain", "init-test-user", + "api-trigger", ] ) From 48b42f2f18aff78e5215b2744b05fb6741083f15 Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Tue, 16 Jan 2024 16:06:29 +0530 Subject: [PATCH 07/12] chore: update deps and added waiting time' --- dev/Tiltfile | 2 ++ dev/bin/fund-user.sh | 1 + 2 files changed, 3 insertions(+) diff --git a/dev/Tiltfile b/dev/Tiltfile index a30f7fb24c..074aca6721 100644 --- a/dev/Tiltfile +++ b/dev/Tiltfile @@ -188,6 +188,8 @@ local_resource( "init-onchain", "init-test-user", "api-trigger", + "stablesats", + "price", ] ) diff --git a/dev/bin/fund-user.sh b/dev/bin/fund-user.sh index 74f52b131a..5c2f0434a5 100755 --- a/dev/bin/fund-user.sh +++ b/dev/bin/fund-user.sh @@ -12,5 +12,6 @@ token="$(login_user "${user_phone}")" echo "Fetching wallets for account" echo "Funding wallets" +sleep 20 fund_user_onchain "$token" "USD" fund_user_onchain "$token" "BTC" From af8dae9c531cd1794e4f6a883f8b8e232b932c1d Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Tue, 16 Jan 2024 18:50:01 +0530 Subject: [PATCH 08/12] chore: adding more deps --- dev/Tiltfile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dev/Tiltfile b/dev/Tiltfile index 074aca6721..b6b03c986c 100644 --- a/dev/Tiltfile +++ b/dev/Tiltfile @@ -190,6 +190,14 @@ local_resource( "api-trigger", "stablesats", "price", + + "trigger", + "apollo-router", + "mongodb-migrate", + "price-history", + "price-history-migrate", + "svix", + "svix-pg", ] ) From f49042b211cfee4329888d0c998d74a6d99fe23c Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Tue, 16 Jan 2024 19:16:29 +0530 Subject: [PATCH 09/12] chore: exit if user is not funded --- dev/Tiltfile | 8 -------- dev/helpers/onchain.sh | 1 + 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/dev/Tiltfile b/dev/Tiltfile index b6b03c986c..074aca6721 100644 --- a/dev/Tiltfile +++ b/dev/Tiltfile @@ -190,14 +190,6 @@ local_resource( "api-trigger", "stablesats", "price", - - "trigger", - "apollo-router", - "mongodb-migrate", - "price-history", - "price-history-migrate", - "svix", - "svix-pg", ] ) diff --git a/dev/helpers/onchain.sh b/dev/helpers/onchain.sh index e3213071eb..e669990d40 100644 --- a/dev/helpers/onchain.sh +++ b/dev/helpers/onchain.sh @@ -51,5 +51,6 @@ fund_user_onchain() { if [[ $success != true ]]; then echo "Failed to fund user" + exit 1 fi } From 41213b558612f2aa565030848c8855a9fb68ef9b Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Tue, 16 Jan 2024 20:28:05 +0530 Subject: [PATCH 10/12] chore: adding response log --- dev/helpers/onchain.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/helpers/onchain.sh b/dev/helpers/onchain.sh index e669990d40..d4dce59896 100644 --- a/dev/helpers/onchain.sh +++ b/dev/helpers/onchain.sh @@ -50,7 +50,7 @@ fund_user_onchain() { done if [[ $success != true ]]; then - echo "Failed to fund user" + echo "Failed to fund user: response ==> $response" exit 1 fi } From 817593890ca3bd2297090e159097d8bd14380baa Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Tue, 16 Jan 2024 22:14:07 +0530 Subject: [PATCH 11/12] chore: adding load wallet --- dev/bin/fund-user.sh | 1 - dev/helpers/onchain.sh | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dev/bin/fund-user.sh b/dev/bin/fund-user.sh index 5c2f0434a5..74f52b131a 100755 --- a/dev/bin/fund-user.sh +++ b/dev/bin/fund-user.sh @@ -12,6 +12,5 @@ token="$(login_user "${user_phone}")" echo "Fetching wallets for account" echo "Funding wallets" -sleep 20 fund_user_onchain "$token" "USD" fund_user_onchain "$token" "BTC" diff --git a/dev/helpers/onchain.sh b/dev/helpers/onchain.sh index d4dce59896..f521d08496 100644 --- a/dev/helpers/onchain.sh +++ b/dev/helpers/onchain.sh @@ -22,8 +22,11 @@ fund_user_onchain() { address=$(echo "$response" | jq -r '.data.onChainAddressCreate.address') [[ "${address}" != "null" ]] || exit 1 - bitcoin_cli sendtoaddress "$address" "$btc_amount_in_btc" - bitcoin_cli -generate 4 + + bitcoin_cli -regtest loadwallet "outside" + bitcoin_cli -regtest listwallets + bitcoin_cli -regtest sendtoaddress "$address" "$btc_amount_in_btc" + bitcoin_cli -regtest -generate 4 variables=$( jq -n \ From 0f64084591a884a96a5cf9cc1a4812b2719daa64 Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Tue, 16 Jan 2024 22:37:05 +0530 Subject: [PATCH 12/12] chore: linux EOL --- apps/dashboard/cypress/fixtures/template.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dashboard/cypress/fixtures/template.csv b/apps/dashboard/cypress/fixtures/template.csv index a526b53f39..088c09c2fa 100644 --- a/apps/dashboard/cypress/fixtures/template.csv +++ b/apps/dashboard/cypress/fixtures/template.csv @@ -2,4 +2,4 @@ username,amount,currency,wallet,memo test_user_a,12,USD,USD,Testing to send 12 USD test_user_b,10,USD,USD,Testing to send 10 USD test_user_c,5,USD,BTC,Testing to send 5 USD -test_user_a,100,SATS,BTC,Testing to send 100 SATS \ No newline at end of file +test_user_a,100,SATS,BTC,Testing to send 100 SATS