Skip to content

Commit

Permalink
chore: misc changes in test
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhart1o1 committed Jan 14, 2024
1 parent 4ffcc7b commit 45e25a7
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -37,7 +37,6 @@ describe("CSV Upload Component Test", () => {
})

expectedTransactions.forEach((expectedTransaction) => {
// Exclude the special case transactions
if (
!btcPaymentInUSDCurrency.some(
(btcTx) =>
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/cypress/e2e/e2e.cy.ts
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 3 additions & 2 deletions apps/dashboard/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference types="cypress" />
import { CORE_URL } from "./test-data"

type Transaction = {
settlementAmount: number
Expand Down Expand Up @@ -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,
Expand All @@ -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",
Expand Down
16 changes: 0 additions & 16 deletions apps/dashboard/cypress/support/gql/get-transactions.gql

This file was deleted.

3 changes: 2 additions & 1 deletion apps/dashboard/cypress/support/test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion dev/Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ local_resource(
"oathkeeper",
"kratos",
"api",
"init-test-user"
"init-test-user",
"init-onchain"
]
)

Expand Down
68 changes: 26 additions & 42 deletions dev/helpers/onchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

0 comments on commit 45e25a7

Please sign in to comment.