diff --git a/@stellar/anchor-tests/package.json b/@stellar/anchor-tests/package.json index 80595fe..c6c8b27 100644 --- a/@stellar/anchor-tests/package.json +++ b/@stellar/anchor-tests/package.json @@ -1,6 +1,6 @@ { "name": "@stellar/anchor-tests", - "version": "0.6.6", + "version": "0.6.7", "description": "stellar-anchor-tests is a library and command line interface for testing Stellar anchors.", "main": "./lib/index.js", "types": "./lib/index.d.ts", diff --git a/@stellar/anchor-tests/src/schemas/sep6.ts b/@stellar/anchor-tests/src/schemas/sep6.ts index 4f2ca5c..440cb58 100644 --- a/@stellar/anchor-tests/src/schemas/sep6.ts +++ b/@stellar/anchor-tests/src/schemas/sep6.ts @@ -1,5 +1,3 @@ -import { sep9Fields } from "./sep12"; - const fieldsSchema = { type: "object", additionalProperties: { @@ -90,23 +88,6 @@ export const infoSchema = { required: ["deposit", "withdraw", "fee", "transaction", "transactions"], }; -export const needsInfoResponseSchema = { - type: "object", - properties: { - type: { - type: "string", - pattern: "non_interactive_customer_info_needed", - }, - fields: { - type: "array", - items: { - type: "string", - enum: sep9Fields, - }, - }, - }, -}; - export const customerInfoStatusSchema = { type: "object", properties: { diff --git a/@stellar/anchor-tests/src/tests/sep6/deposit.ts b/@stellar/anchor-tests/src/tests/sep6/deposit.ts index 663c133..ac529d2 100644 --- a/@stellar/anchor-tests/src/tests/sep6/deposit.ts +++ b/@stellar/anchor-tests/src/tests/sep6/deposit.ts @@ -5,14 +5,11 @@ import { validate } from "jsonschema"; import { Test, Config, Result, NetworkCall } from "../../types"; import { makeRequest } from "../../helpers/request"; -import { postChallenge } from "../../helpers/sep10"; import { genericFailures, makeFailure } from "../../helpers/failure"; import { hasWebAuthEndpoint, returnsValidJwt } from "../sep10/tests"; -import { canCreateCustomer } from "../sep12/putCustomer"; import { hasTransferServerUrl } from "./toml"; import { assetCodeEnabledForDeposit, isCompliantWithSchema } from "./info"; import { - needsInfoResponseSchema, depositSuccessResponseSchema, customerInfoStatusSchema, } from "../../schemas/sep6"; @@ -289,94 +286,12 @@ const depositRejectsUnsupportedAssetCode: Test = { }; tests.push(depositRejectsUnsupportedAssetCode); -export const returnsProperSchemaForUnknownAccounts: Test = { - assertion: - "returns a needs info response for valid requests from unknown accounts", - sep: 6, - group: depositTestsGroup, - dependencies: depositRequiresAssetCode.dependencies, - context: { - expects: depositRequiresAssetCode.context.expects, - provides: { - sep6FieldsRequired: undefined, - }, - }, - failureModes: { - INVALID_SCHEMA: { - name: "invalid schema", - text(args: any): string { - return ( - "The response body returned does not comply with the schema defined for the /deposit endpoint. " + - "The errors returned from the schema validation:\n\n" + - `${args.errors}` - ); - }, - links: { - "Deposit Response": - "https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#2-customer-information-needed-non-interactive", - }, - }, - ...genericFailures, - }, - async run(config: Config): Promise { - if (!config.sepConfig || !config.sepConfig["6"]) - throw { message: "improperly configured" }; - const result: Result = { networkCalls: [] }; - const clientKeypair = Keypair.random(); - const token = await postChallenge( - clientKeypair, - this.context.expects.webAuthEndpoint, - this.context.expects.tomlObj.NETWORK_PASSPHRASE, - result, - ); - const headers = this.context.expects.authRequired - ? { - headers: { - Authorization: `Bearer ${token}`, - }, - } - : {}; - const callParams = new URLSearchParams({ - asset_code: config.assetCode, - account: clientKeypair.publicKey(), - ...config.sepConfig["6"].deposit.transactionFields, - }); - const getDepositCall: NetworkCall = { - request: new Request( - this.context.expects.sep6TransferServerUrl + - depositEndpoint + - `?${callParams.toString()}`, - { ...headers }, - ), - }; - result.networkCalls.push(getDepositCall); - const responseBody = await makeRequest( - getDepositCall, - 403, - result, - "application/json", - ); - if (!responseBody) return result; - const validatorResult = validate(responseBody, needsInfoResponseSchema); - if (validatorResult.errors.length !== 0) { - result.failure = makeFailure(this.failureModes.INVALID_SCHEMA, { - errors: validatorResult.errors.join("\n"), - }); - return result; - } - this.context.provides.sep6FieldsRequired = responseBody.fields; - return result; - }, -}; -tests.push(returnsProperSchemaForUnknownAccounts); - export const returnsProperSchemaForKnownAccounts: Test = { - assertion: - "returns a success or customer info status response for valid requests from KYC'ed accounts", + assertion: "returns a success response for valid requests", sep: 6, group: depositTestsGroup, dependencies: (config: Config) => { - let resultDependencies = [canCreateCustomer]; + let resultDependencies: Test[] = []; if (depositRequiresAssetCode.dependencies) { let otherDependencies = diff --git a/@stellar/anchor-tests/src/tests/sep6/withdraw.ts b/@stellar/anchor-tests/src/tests/sep6/withdraw.ts index ef0c026..9e94993 100644 --- a/@stellar/anchor-tests/src/tests/sep6/withdraw.ts +++ b/@stellar/anchor-tests/src/tests/sep6/withdraw.ts @@ -5,14 +5,11 @@ import { validate } from "jsonschema"; import { Test, Config, Result, NetworkCall } from "../../types"; import { makeRequest } from "../../helpers/request"; -import { postChallenge } from "../../helpers/sep10"; import { genericFailures, makeFailure } from "../../helpers/failure"; import { hasWebAuthEndpoint, returnsValidJwt } from "../sep10/tests"; -import { canCreateCustomer } from "../sep12/putCustomer"; import { hasTransferServerUrl } from "./toml"; import { assetCodeEnabledForWithdraw, isCompliantWithSchema } from "./info"; import { - needsInfoResponseSchema, withdrawSuccessResponseSchema, customerInfoStatusSchema, } from "../../schemas/sep6"; @@ -335,106 +332,12 @@ const withdrawRejectsUnsupportedAssetCode: Test = { }; tests.push(withdrawRejectsUnsupportedAssetCode); -export const returnsProperSchemaForUnknownAccounts: Test = { - assertion: - "returns a needs info response for valid requests from unknown accounts", - sep: 6, - group: withdrawTestsGroup, - dependencies: withdrawRequiresAssetCode.dependencies, - context: { - expects: withdrawRequiresAssetCode.context.expects, - provides: { - sep6FieldsRequired: undefined, - }, - }, - failureModes: { - INVALID_SCHEMA: { - name: "invalid schema", - text(args: any): string { - return ( - "The response body returned does not comply with the schema defined for the /withdraw endpoint. " + - "The errors returned from the schema validation:\n\n" + - `${args.errors}` - ); - }, - links: { - "Withdraw Schema": - "https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#2-customer-information-needed-non-interactive", - }, - }, - ...genericFailures, - }, - async run(config: Config): Promise { - if ( - !config.sepConfig || - !config.sepConfig["6"] || - !config.assetCode || - !config.sepConfig["6"].withdraw.types - ) - throw { message: "improperly configured" }; - const result: Result = { networkCalls: [] }; - const clientKeypair = Keypair.random(); - const token = await postChallenge( - clientKeypair, - this.context.expects.webAuthEndpoint, - this.context.expects.tomlObj.NETWORK_PASSPHRASE, - result, - ); - const headers = this.context.expects.authRequired - ? { - headers: { - Authorization: `Bearer ${token}`, - }, - } - : {}; - const withdrawInfo = - this.context.expects.sep6InfoObj.withdraw[config.assetCode]; - const withdrawType = Object.keys(withdrawInfo.types)[0]; - const withdrawTypeFields = - config.sepConfig["6"].withdraw.types[withdrawType].transactionFields || - {}; - const callParams = new URLSearchParams({ - asset_code: config.assetCode, - account: clientKeypair.publicKey(), - type: withdrawType, - ...withdrawTypeFields, - }); - const getWithdrawCall: NetworkCall = { - request: new Request( - this.context.expects.sep6TransferServerUrl + - withdrawEndpoint + - `?${callParams.toString()}`, - { ...headers }, - ), - }; - result.networkCalls.push(getWithdrawCall); - const responseBody = await makeRequest( - getWithdrawCall, - 403, - result, - "application/json", - ); - if (!responseBody) return result; - const validatorResult = validate(responseBody, needsInfoResponseSchema); - if (validatorResult.errors.length !== 0) { - result.failure = makeFailure(this.failureModes.INVALID_SCHEMA, { - errors: validatorResult.errors.join("\n"), - }); - return result; - } - this.context.provides.sep6FieldsRequired = responseBody.fields; - return result; - }, -}; -tests.push(returnsProperSchemaForUnknownAccounts); - export const returnsProperSchemaForKnownAccounts: Test = { - assertion: - "returns a success or customer info status response for valid requests from KYC'ed accounts", + assertion: "returns a success response for valid requests", sep: 6, group: withdrawTestsGroup, dependencies: (config: Config) => { - let resultDependencies = [canCreateCustomer]; + let resultDependencies: Test[] = []; if (withdrawRequiresAssetCode.dependencies) { let otherDependencies = diff --git a/server/package.json b/server/package.json index bdde9d2..44b0e23 100644 --- a/server/package.json +++ b/server/package.json @@ -30,6 +30,6 @@ "winston": "^3.3.3" }, "peerDependencies": { - "@stellar/anchor-tests": "0.6.6" + "@stellar/anchor-tests": "0.6.7" } }