forked from fiatconnect/validate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
5,333 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
BASE_URL=https://cico-staging.bitmama.io | ||
OPENAPI_SPEC=../specification/swagger.yaml | ||
QUOTE_OUT_MOCK=quoteOutNigeriaCUSD | ||
FIAT_ACCOUNT_MOCK=accountNumberNigeria | ||
KYC_MOCK=personalDataAndDocumentsNigeria |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
OPENAPI_SPEC=../specification/swagger.yaml | ||
|
||
BASE_URL=https://alfajores.fc.alphafortress.com | ||
|
||
QUOTE_OUT_MOCK=quoteOutNigeriaCUSD | ||
|
||
|
||
# FIAT_ACCOUNT_MOCK=accountNumberNigeria | ||
# FIAT_ACCOUNT_MOCK=personalDataAndDocumentsNigeria | ||
FIAT_ACCOUNT_MOCK=ibanNumberAustria | ||
KYC_MOCK=personalDataAndDocumentsAustria |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
OPENAPI_SPEC=../specification/swagger.yaml | ||
|
||
BASE_URL=https://fiatconnect-sandbox.paychant.com/v1 | ||
|
||
QUOTE_OUT_MOCK=quoteOutNigeriaCUSD | ||
|
||
FIAT_ACCOUNT_MOCK=accountNumberNigeria | ||
KYC_MOCK=personalDataAndDocumentsNigeria | ||
|
||
CLIENT_API_KEY=<-------REMEMBER TO FILL ME IN--------> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 FiatConnect | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# validate | ||
|
||
FiatConnect Validate is a test suite for validating a FiatConnect-compliant API. | ||
|
||
While this may be useful in developing a FiatConnect-compliant API, it is still strongly recommended that | ||
Cash-In/Cash-Out providers follow best practices and write their own unit and integration tests specific to their | ||
implementations. | ||
|
||
## Developing | ||
|
||
``` | ||
yarn | ||
``` | ||
|
||
## Running | ||
|
||
Make sure you have a copy of the [FiatConnect OpenAPI spec](https://github.com/fiatconnect/specification/blob/main/swagger.yaml) | ||
on your device, since it is used for schema validation. | ||
|
||
Setup a config file (remember to customize): | ||
|
||
``` | ||
echo BASE_URL=https://some.api.fiatconnect.org > .env | ||
echo OPENAPI_SPEC=/path/to/swagger.yaml >> .env | ||
echo QUOTE_OUT_MOCK=quoteOutNigeriaCUSD | ||
echo FIAT_ACCOUNT_MOCK=accountNumberNigeria | ||
echo KYC_MOCK=personalDataAndDocumentsNigeria | ||
``` | ||
|
||
Alternatively, you may use a pre-defined environment. Note that you still may need to customize, for example by filling in | ||
client api keys. For example: | ||
|
||
``` | ||
cp .env.paychant .env | ||
``` | ||
|
||
Run all validation: | ||
|
||
``` | ||
yarn validate | ||
``` | ||
|
||
Run specific tests (see Jest documentation for | ||
[`--testNamePattern`](https://jestjs.io/docs/cli#--testnamepatternregex)). | ||
|
||
``` | ||
yarn validate --testNamePattern='quote' | ||
``` | ||
|
||
## Contributing | ||
|
||
If you see an opportunity to improve this repo, perhaps by increasing test coverage or making existing | ||
tests easier to debug, please open a pull request and tag `@fiatconnect-devs` in the | ||
[FiatConnect Discord channel](https://fiatconnect.org/contact). | ||
|
||
## Resources | ||
|
||
- [api-contract-validator](https://www.chaijs.com/plugins/api-contract-validator/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
watchman: false, | ||
moduleFileExtensions: ['ts', 'js', 'json'], | ||
transform: { | ||
'^.+\\.(ts)$': 'ts-jest', | ||
}, | ||
testPathIgnorePatterns: ['dist'], | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: 'tsconfig.json', | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "validate", | ||
"version": "0.0.1", | ||
"main": "index.js", | ||
"repository": "[email protected]:fiatconnect/validate.git", | ||
"author": "Valora Inc", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "tsc", | ||
"typecheck": "yarn build", | ||
"validate": "jest", | ||
"format": "prettier --loglevel error --write .", | ||
"format:check": "prettier --check .", | ||
"lint": "eslint --ext=.tsx,.ts,.json src/", | ||
"lint:fix": "yarn lint --fix" | ||
}, | ||
"prettier": "@valora/prettier-config", | ||
"devDependencies": { | ||
"@types/chai": "^4.3.1", | ||
"@types/jest": "^27.5.1", | ||
"@types/node": "^17.0.31", | ||
"@types/yargs": "^17.0.10", | ||
"@typescript-eslint/eslint-plugin": "^5.29.0", | ||
"@valora/eslint-config-typescript": "^1.0.0", | ||
"@valora/prettier-config": "^0.0.1", | ||
"eslint": "^8.18.0", | ||
"eslint-plugin-chai-expect": "^3.0.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jest": "^26.5.3", | ||
"eslint-plugin-react": "^7.30.0", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-plugin-react-native": "^4.0.0", | ||
"prettier": "^2.7.1", | ||
"ts-node": "^10.7.0", | ||
"typescript": "^4.6.4" | ||
}, | ||
"dependencies": { | ||
"@fiatconnect/fiatconnect-sdk": "^0.3.1", | ||
"@fiatconnect/fiatconnect-types": "^5.0.0", | ||
"api-contract-validator": "^2.2.8", | ||
"axios": "^0.27.2", | ||
"chai": "^4.3.6", | ||
"dotenv": "^16.0.0", | ||
"ethers": "^5.6.8", | ||
"jest": "^28.1.0", | ||
"ts-jest": "^28.0.2", | ||
"yargs": "^17.4.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import path from 'path' | ||
import { config } from './config' | ||
import { expect, use } from 'chai' | ||
import { chaiPlugin } from 'api-contract-validator' | ||
import { AxiosResponse } from 'axios' | ||
|
||
const apiDefinitionsPath = path.join(config.openapiSpec) | ||
use(chaiPlugin({ apiDefinitionsPath })) | ||
|
||
/** | ||
* Check that the response matches the API schema. | ||
* | ||
* Ignores /v1 prefix | ||
*/ | ||
export function checkResponseSchema(response: AxiosResponse) { | ||
if (response.request.path.slice(0, 3) === '/v1') { | ||
// removes /v1 prefix, total hack to get api schema matcher to work | ||
response.request.path = response.request.path.slice(3) | ||
} | ||
expect(response).to.have.status(200).and.to.matchApiSchema() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import yargs from 'yargs' | ||
import * as dotenv from 'dotenv' | ||
import path from 'path' | ||
import { MOCK_FIAT_ACCOUNTS } from './mock-data/fiat-account' | ||
import { MOCK_KYC } from './mock-data/kyc' | ||
import { Wallet } from 'ethers' | ||
import { MOCK_QUOTE } from './mock-data/quote' | ||
|
||
dotenv.config() | ||
|
||
export const config = yargs | ||
.env('') | ||
.option('test-private-key', { | ||
description: | ||
'Private key to use for testing. Should be a dummy/unused value. ' + | ||
'(Do NOT use a private key for an account with real funds!!) Defaults to randomly generated.', | ||
type: 'string', | ||
default: Wallet.createRandom().privateKey, | ||
}) | ||
.option('base-url', { | ||
description: 'Base URL for FiatConnect API', | ||
type: 'string', | ||
demandOption: true, | ||
}) | ||
.option('openapi-spec', { | ||
description: 'OpenAPI 2.0 specification file to test against', | ||
type: 'string', | ||
demandOption: true, | ||
coerce: (arg) => path.resolve(arg), | ||
}) | ||
.option('client-api-key', { | ||
description: 'Client API key', | ||
type: 'string', | ||
demandOption: false, | ||
}) | ||
.option('quote-out-mock', { | ||
description: | ||
'Mock data to use for a transfer out quote that should be offered', | ||
type: 'string', | ||
demandOption: true, | ||
example: 'quoteOutNigeriaCUSD', | ||
options: Object.keys(MOCK_QUOTE), | ||
}) | ||
.option('fiat-account-mock', { | ||
description: 'Fiat account mock data to use', | ||
type: 'string', | ||
demandOption: true, | ||
example: 'accountNumberNigeria', | ||
options: Object.keys(MOCK_FIAT_ACCOUNTS), | ||
}) | ||
.option('kyc-mock', { | ||
description: 'KYC mock data to use', | ||
type: 'string', | ||
demandOption: true, | ||
example: 'personalDataAndDocumentsNigeria', | ||
options: Object.keys(MOCK_KYC), | ||
}) | ||
.help() | ||
.parseSync() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const FIFTEEN_MINUTES_IN_MS = 1000 * 60 * 15 | ||
export const ALFAJORES_CHAIN_ID = 44787 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
FiatAccountSchema, | ||
FiatAccountType, | ||
PostFiatAccountRequestBody, | ||
} from '@fiatconnect/fiatconnect-types' | ||
|
||
const accountNumberNigeria: PostFiatAccountRequestBody<FiatAccountSchema.AccountNumber> = | ||
{ | ||
fiatAccountSchema: FiatAccountSchema.AccountNumber, | ||
data: { | ||
fiatAccountType: FiatAccountType.BankAccount, | ||
institutionName: 'UNITED BANK FOR AFRICA Lacaras', | ||
accountName: 'My UBA Account', | ||
accountNumber: '0123456789', | ||
country: 'NG', | ||
}, | ||
} | ||
|
||
const ibanNumberAustria: PostFiatAccountRequestBody<FiatAccountSchema.IBANNumber> = | ||
{ | ||
fiatAccountSchema: FiatAccountSchema.IBANNumber, | ||
data: { | ||
accountName: 'My Austrian Bank account', | ||
institutionName: 'Austrian Bank', | ||
country: 'AT', | ||
fiatAccountType: FiatAccountType.BankAccount, | ||
iban: 'mock-iban-number', | ||
}, | ||
} | ||
|
||
export const MOCK_FIAT_ACCOUNTS: Record< | ||
string, | ||
PostFiatAccountRequestBody<FiatAccountSchema> | ||
> = { accountNumberNigeria, ibanNumberAustria } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { KycSchema } from '@fiatconnect/fiatconnect-types' | ||
import { AddKycParams } from '@fiatconnect/fiatconnect-sdk' | ||
|
||
const personalDataAndDocumentsNigeria: AddKycParams<KycSchema.PersonalDataAndDocuments> = | ||
{ | ||
kycSchemaName: KycSchema.PersonalDataAndDocuments, | ||
data: { | ||
lastName: 'Bob', | ||
firstName: 'Alice', | ||
middleName: 'Foo', | ||
dateOfBirth: { | ||
day: '12', | ||
year: '1994', | ||
month: '4', | ||
}, | ||
address: { | ||
city: 'Lagos', | ||
address1: 'No 15', | ||
address2: 'string', | ||
postalCode: '100001', | ||
isoRegionCode: 'KD', | ||
isoCountryCode: 'NG', | ||
}, | ||
phoneNumber: '07037205555', | ||
selfieDocument: 'abc', | ||
identificationDocument: 'def', | ||
}, | ||
} | ||
|
||
const personalDataAndDocumentsAustria: AddKycParams<KycSchema.PersonalDataAndDocuments> = | ||
{ | ||
...personalDataAndDocumentsNigeria, | ||
data: { | ||
...personalDataAndDocumentsNigeria.data, | ||
address: { | ||
...personalDataAndDocumentsNigeria.data.address, | ||
isoCountryCode: 'AT', | ||
isoRegionCode: 'AT-5', // Salzburg | ||
}, | ||
}, | ||
} | ||
|
||
export const MOCK_KYC: Record<string, AddKycParams<KycSchema>> = { | ||
personalDataAndDocumentsNigeria, | ||
personalDataAndDocumentsAustria, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { | ||
CryptoType, | ||
FiatType, | ||
QuoteRequestQuery, | ||
} from '@fiatconnect/fiatconnect-types' | ||
|
||
const quoteOutNigeriaCUSD: QuoteRequestQuery = { | ||
cryptoType: CryptoType.cUSD, | ||
fiatType: FiatType.NGN, | ||
cryptoAmount: '10', | ||
country: 'NG', | ||
} | ||
|
||
export const MOCK_QUOTE: Record<string, QuoteRequestQuery> = { | ||
quoteOutNigeriaCUSD, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"include": ["src"], | ||
"exclude": ["node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"esModuleInterop": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"rootDirs": ["src", "validations"], | ||
"outDir": "dist", | ||
"baseUrl": "./", | ||
"sourceMap": true, | ||
"strict": true, | ||
"target": "es2017", | ||
"lib": ["es7", "es2017"], | ||
"skipLibCheck": true, | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.json", "validations/**/*.ts"], | ||
"exclude": ["node_modules/**/*"] | ||
} |
Oops, something went wrong.