Skip to content

Commit

Permalink
[Sep-24] Add tests for pending_, completed and `stellar_transacti…
Browse files Browse the repository at this point in the history
…on_id` (#117)

* [Sep-24] Add tests for 'pending_' and 'completed' transaction

* [Sep-24] Add tests for 'stellar_transaction_id' fetching

* Add fields descriptions

* Clean up

* transaction.id should always be a 'string'

* Bump version number

* Bump to version 0.6.0 instead

* More clarity on transaction schema definition

* Move schemas around

* Make it clear Sep-24 config file is optional

* Only display the 'Upload Customer Files' button when it's needed

* Fix 'accordian => accordion' typo

* Display proper error msg when Sep-24 config object is missing

* Rename Sep-24 account params and make publicKey optional
  • Loading branch information
CassioMG authored Aug 1, 2023
1 parent 9f0f325 commit 7edba13
Show file tree
Hide file tree
Showing 16 changed files with 1,309 additions and 278 deletions.
2 changes: 1 addition & 1 deletion @stellar/anchor-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stellar/anchor-tests",
"version": "0.5.12",
"version": "0.6.0",
"description": "stellar-anchor-tests is a library and command line interface for testing Stellar anchors.",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion @stellar/anchor-tests/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const command = yargs
type: "string",
requiresArg: true,
description:
"A relative or absolute file path to JSON file containing the configuration required for SEP 6, 12, & 31.",
"A relative or absolute file path to JSON file containing the configuration used by SEP 6, 12, 24, 31 & 38.",
},
})
.check((argv: any) => {
Expand Down
8 changes: 3 additions & 5 deletions @stellar/anchor-tests/src/helpers/sep10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export const postChallengeFailureModes: Record<string, Failure> = {
};

export async function getChallenge(
clientKeypair: Keypair,
accountAddress: string,
webAuthEndpoint: string,
networkPassphrase: string,
result: Result,
Expand All @@ -228,9 +228,7 @@ export async function getChallenge(
return;
}
const getAuthCall: NetworkCall = {
request: new Request(
webAuthEndpoint + `?account=${clientKeypair.publicKey()}`,
),
request: new Request(webAuthEndpoint + `?account=${accountAddress}`),
};
result.networkCalls.push(getAuthCall);
try {
Expand Down Expand Up @@ -301,7 +299,7 @@ export async function postChallenge(
): Promise<string | void> {
if (!challenge) {
challenge = (await getChallenge(
clientKeypair,
clientKeypair.publicKey(),
webAuthEndpoint,
networkPassphrase,
result,
Expand Down
75 changes: 75 additions & 0 deletions @stellar/anchor-tests/src/helpers/sep24.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Request } from "node-fetch";

import { Result, NetworkCall, Failure } from "../types";
import { makeRequest } from "./request";

export const invalidTransactionSchema: Failure = {
name: "invalid transaction schema",
text(args: any): string {
return (
"The response body returned does not comply with the schema defined for the /transaction endpoint. " +
"The errors returned from the schema validation:\n\n" +
`${args.errors}.`
);
},
links: {
"Transaction Schema":
"https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0024.md#single-historical-transaction",
},
};

export const unexpectedTransactionStatus: Failure = {
name: "unexpected transaction status",
text(args: any): string {
return `Unexpected transaction status. Expected '${args.expected}' but received '${args.received}' instead.`;
},
};

export const missingConfigFile: Failure = {
name: "missing config file",
text(args: any): string {
return `The ${args.sep} configuration object is missing. Please make sure to upload a config file containing a ${args.sep} configuration object in order for this test to run.`;
},
};

export const invalidConfigFile: Failure = {
name: "invalid config file",
text(args: any): string {
return "The UPLOAD CONFIG file has some issues:\n\n" + `${args.errors}.`;
},
};

export const fetchTransaction = async ({
transferServerUrl,
transactionId,
stellarTransactionId,
authToken,
result,
}: {
transferServerUrl: string;
transactionId?: string;
stellarTransactionId?: string;
authToken: string;
result: Result;
}) => {
const idQuery = stellarTransactionId
? `stellar_transaction_id=${stellarTransactionId}`
: `id=${transactionId}`;

const getTransactionCall: NetworkCall = {
request: new Request(transferServerUrl + `/transaction?${idQuery}`, {
headers: {
Authorization: `Bearer ${authToken}`,
},
}),
};
result.networkCalls.push(getTransactionCall);
const response = await makeRequest(
getTransactionCall,
200,
result,
"application/json",
);

return response;
};
28 changes: 28 additions & 0 deletions @stellar/anchor-tests/src/schemas/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ export const sep12ConfigSchema = {
required: ["customers", "createCustomer", "deleteCustomer"],
};

export const sep24ConfigSchema = {
type: "object",
properties: {
account: {
type: "object",
minProperties: 1,
},
depositPendingTransaction: {
type: "object",
minProperties: 2,
},
depositCompletedTransaction: {
type: "object",
minProperties: 3,
},
withdrawPendingUserTransferStartTransaction: {
type: "object",
minProperties: 7,
},
withdrawCompletedTransaction: {
type: "object",
minProperties: 3,
},
},
required: [],
};

export const sep31ConfigSchema = {
type: "object",
properties: {
Expand Down Expand Up @@ -108,6 +135,7 @@ export const sepConfigSchema = {
properties: {
"6": sep6ConfigSchema,
"12": sep12ConfigSchema,
"24": sep24ConfigSchema,
"31": sep31ConfigSchema,
"38": sep38ConfigSchema,
},
Expand Down
Loading

0 comments on commit 7edba13

Please sign in to comment.