mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-14 06:02:36 +03:00
Basic tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
ignorePatterns: ['.eslintrc.js'],
|
ignorePatterns: ['.eslintrc.js'],
|
||||||
|
include: ['jest.config.ts'],
|
||||||
env: {
|
env: {
|
||||||
browser: true,
|
browser: true,
|
||||||
es2021: true,
|
es2021: true,
|
||||||
|
|||||||
27
jest.config.ts
Normal file
27
jest.config.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import type { Config } from '@jest/types';
|
||||||
|
|
||||||
|
const config: Config.InitialOptions = {
|
||||||
|
verbose: true,
|
||||||
|
preset: 'ts-jest',
|
||||||
|
testRegex: "src/.*\\.test\\.ts$",
|
||||||
|
moduleFileExtensions: [
|
||||||
|
"ts",
|
||||||
|
"tsx",
|
||||||
|
"js",
|
||||||
|
"jsx",
|
||||||
|
"json",
|
||||||
|
"node"
|
||||||
|
],
|
||||||
|
testEnvironment: 'node',
|
||||||
|
transform: {
|
||||||
|
"^.+\\.tsx?$": "ts-jest"
|
||||||
|
},
|
||||||
|
rootDir: ".",
|
||||||
|
globals: {
|
||||||
|
"ts-jest": {
|
||||||
|
"tsconfig": "tsconfig.json"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setupFiles: ["dotenv/config"]
|
||||||
|
};
|
||||||
|
export default config;
|
||||||
3384
package-lock.json
generated
3384
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@@ -8,10 +8,10 @@
|
|||||||
"start": "npm run build-ts && node lib/index.js",
|
"start": "npm run build-ts && node lib/index.js",
|
||||||
"develop": "concurrently -i -k -p \"[{name}]\" -n \"Node,TypeScript\" -c \"yellow.bold,cyan.bold\" \"yarn watch-js\" \"yarn watch-ts\"",
|
"develop": "concurrently -i -k -p \"[{name}]\" -n \"Node,TypeScript\" -c \"yellow.bold,cyan.bold\" \"yarn watch-js\" \"yarn watch-ts\"",
|
||||||
"clean": "rimraf lib/*",
|
"clean": "rimraf lib/*",
|
||||||
"build-ts": "npm run typechain:generate-types && tsc --skipLibCheck",
|
"build-ts": "npm run typechain:generate-types && tsc -p tsconfig.build.json --skipLibCheck",
|
||||||
"watch-ts": "npm run typechain:generate-types && tsc -w --skipLibCheck",
|
"watch-ts": "npm run typechain:generate-types && tsc -w --skipLibCheck",
|
||||||
"watch-js": "nodemon lib/index.js",
|
"watch-js": "nodemon lib/index.js",
|
||||||
"test": "exit 0",
|
"test": "jest",
|
||||||
"coverage": "jest --coverage",
|
"coverage": "jest --coverage",
|
||||||
"lint:eslint": "eslint ./src --ext .ts,.js,.tsx,.jsx",
|
"lint:eslint": "eslint ./src --ext .ts,.js,.tsx,.jsx",
|
||||||
"lint:eslint:fix": "eslint ./src --ext .ts,.js,.tsx,.jsx --fix",
|
"lint:eslint:fix": "eslint ./src --ext .ts,.js,.tsx,.jsx --fix",
|
||||||
@@ -37,6 +37,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@typechain/ethers-v5": "^10.0.0",
|
"@typechain/ethers-v5": "^10.0.0",
|
||||||
"@types/csprng": "^0.1.2",
|
"@types/csprng": "^0.1.2",
|
||||||
|
"@types/jest": "^27.4.1",
|
||||||
"@types/node": "^17.0.23",
|
"@types/node": "^17.0.23",
|
||||||
"@types/node-fetch": "^2.6.1",
|
"@types/node-fetch": "^2.6.1",
|
||||||
"@types/socket.io-client": "1.4.33",
|
"@types/socket.io-client": "1.4.33",
|
||||||
@@ -45,11 +46,14 @@
|
|||||||
"@typescript-eslint/eslint-plugin": "^5.16.0",
|
"@typescript-eslint/eslint-plugin": "^5.16.0",
|
||||||
"@typescript-eslint/parser": "^5.16.0",
|
"@typescript-eslint/parser": "^5.16.0",
|
||||||
"concurrently": "^7.0.0",
|
"concurrently": "^7.0.0",
|
||||||
|
"dotenv": "^16.0.0",
|
||||||
"eslint": "^8.12.0",
|
"eslint": "^8.12.0",
|
||||||
"eslint-config-airbnb-base": "^15.0.0",
|
"eslint-config-airbnb-base": "^15.0.0",
|
||||||
"eslint-plugin-import": "^2.25.4",
|
"eslint-plugin-import": "^2.25.4",
|
||||||
"husky": "^7.0.4",
|
"husky": "^7.0.4",
|
||||||
"jest": "^27.5.1",
|
"jest": "^27.5.1",
|
||||||
|
"ts-jest": "^27.1.4",
|
||||||
|
"ts-node": "^10.7.0",
|
||||||
"typechain": "^8.0.0",
|
"typechain": "^8.0.0",
|
||||||
"typescript": "^4.5.3"
|
"typescript": "^4.5.3"
|
||||||
},
|
},
|
||||||
@@ -73,4 +77,4 @@
|
|||||||
"files": [
|
"files": [
|
||||||
"lib/**/*"
|
"lib/**/*"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
46
src/__tests__/deposit.test.ts
Normal file
46
src/__tests__/deposit.test.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { Wallet } from 'ethers';
|
||||||
|
import initOrionUnit from '../initOrionUnit';
|
||||||
|
import OrionUnit from '../OrionUnit';
|
||||||
|
import crypto from "crypto";
|
||||||
|
|
||||||
|
let wallet: Wallet;
|
||||||
|
let orionUnit: OrionUnit;
|
||||||
|
|
||||||
|
jest.setTimeout(15000);
|
||||||
|
beforeAll(() => {
|
||||||
|
orionUnit = initOrionUnit('0x61', 'testing');
|
||||||
|
if(!process.env.PRIVATE_KEY) throw new Error('PRIVATE_KEY env variable is not defined');
|
||||||
|
wallet = new Wallet(process.env.PRIVATE_KEY)
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Deposit', () => {
|
||||||
|
|
||||||
|
test('Deposit 0.00000001 ORN', () => {
|
||||||
|
return expect(orionUnit.exchange.deposit({
|
||||||
|
amount: 0.00000001,
|
||||||
|
asset: 'ORN',
|
||||||
|
signer: wallet,
|
||||||
|
})).resolves.toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Deposit -3 ORN', () => {
|
||||||
|
const amount = -3;
|
||||||
|
return expect(orionUnit.exchange.deposit({
|
||||||
|
amount,
|
||||||
|
asset: 'ORN',
|
||||||
|
signer: wallet,
|
||||||
|
})).rejects.toThrowError(`Amount '${amount.toString()}' should be greater than 0`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Deposit unknown asset', () => {
|
||||||
|
const random = crypto.randomBytes(10).toString('hex').toUpperCase();
|
||||||
|
console.log(random);
|
||||||
|
return expect(orionUnit.exchange.deposit({
|
||||||
|
amount: 0.00000001,
|
||||||
|
asset: random,
|
||||||
|
signer: wallet,
|
||||||
|
})).rejects.toThrowError(`Asset '${random}' not found`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export {};
|
||||||
17
src/__tests__/orionUnit.test.ts
Normal file
17
src/__tests__/orionUnit.test.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import initOrionUnit from '../initOrionUnit';
|
||||||
|
import OrionUnit from '../OrionUnit';
|
||||||
|
|
||||||
|
describe('OrionUnit', () => {
|
||||||
|
test('OrionUnit init is defined', () => {
|
||||||
|
const orionUnit = initOrionUnit('0x61', 'testing');
|
||||||
|
expect(orionUnit).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('OrionUnit is instance of OrionUnit', () => {
|
||||||
|
|
||||||
|
const orionUnit = initOrionUnit('0x61', 'testing');
|
||||||
|
expect(orionUnit).toBeInstanceOf(OrionUnit);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export {};
|
||||||
55
src/__tests__/swapMarket.test.ts
Normal file
55
src/__tests__/swapMarket.test.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import { Wallet } from 'ethers';
|
||||||
|
import initOrionUnit from '../initOrionUnit';
|
||||||
|
import OrionUnit from '../OrionUnit';
|
||||||
|
|
||||||
|
let wallet: Wallet;
|
||||||
|
let orionUnit: OrionUnit;
|
||||||
|
|
||||||
|
jest.setTimeout(15000);
|
||||||
|
beforeAll(() => {
|
||||||
|
orionUnit = initOrionUnit('0x61', 'testing');
|
||||||
|
if(!process.env.PRIVATE_KEY) throw new Error('PRIVATE_KEY env variable is not defined');
|
||||||
|
wallet = new Wallet(process.env.PRIVATE_KEY)
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Swap market', () => {
|
||||||
|
|
||||||
|
test('Too low amount', async () => {
|
||||||
|
expect(orionUnit.exchange.swapMarket({
|
||||||
|
amount: 0.00001,
|
||||||
|
signer: wallet,
|
||||||
|
type: 'exactReceive',
|
||||||
|
assetIn: 'ORN',
|
||||||
|
assetOut: 'USDT',
|
||||||
|
feeAsset: 'USDT',
|
||||||
|
slippagePercent: 1
|
||||||
|
})).rejects.toThrowError(/^Amount is too low/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Swap STEVE -> JOBS', async () => {
|
||||||
|
const swap = await orionUnit.exchange.swapMarket({
|
||||||
|
amount: 100,
|
||||||
|
signer: wallet,
|
||||||
|
type: 'exactReceive',
|
||||||
|
assetIn: 'STEVE',
|
||||||
|
assetOut: 'JOBS',
|
||||||
|
feeAsset: 'USDT',
|
||||||
|
slippagePercent: 1
|
||||||
|
});
|
||||||
|
expect(swap).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Swap empty assetIn', async () => {
|
||||||
|
return expect(orionUnit.exchange.swapMarket({
|
||||||
|
amount: 100,
|
||||||
|
signer: wallet,
|
||||||
|
type: 'exactReceive',
|
||||||
|
assetIn: '',
|
||||||
|
assetOut: 'JOBS',
|
||||||
|
feeAsset: 'USDT',
|
||||||
|
slippagePercent: 1
|
||||||
|
})).rejects.toThrowError('AssetIn can not be empty');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export {};
|
||||||
27
src/__tests__/withdraw.test.ts
Normal file
27
src/__tests__/withdraw.test.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { Wallet } from 'ethers';
|
||||||
|
import initOrionUnit from '../initOrionUnit';
|
||||||
|
import OrionUnit from '../OrionUnit';
|
||||||
|
|
||||||
|
let wallet: Wallet;
|
||||||
|
let orionUnit: OrionUnit;
|
||||||
|
|
||||||
|
jest.setTimeout(15000);
|
||||||
|
beforeAll(() => {
|
||||||
|
orionUnit = initOrionUnit('0x61', 'testing');
|
||||||
|
if(!process.env.PRIVATE_KEY) throw new Error('PRIVATE_KEY env variable is not defined');
|
||||||
|
wallet = new Wallet(process.env.PRIVATE_KEY)
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Withdraw', () => {
|
||||||
|
|
||||||
|
test('Withdraw 0.00001 ORN', () => {
|
||||||
|
return expect(orionUnit.exchange.withdraw({
|
||||||
|
amount: 0.00001,
|
||||||
|
asset: 'ORN',
|
||||||
|
signer: wallet,
|
||||||
|
})).resolves.toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export {};
|
||||||
8
tsconfig.build.json
Normal file
8
tsconfig.build.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig",
|
||||||
|
"exclude": [
|
||||||
|
"**/*.test.*",
|
||||||
|
"**/__mocks__/*",
|
||||||
|
"**/__tests__/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
{
|
{
|
||||||
"include": [
|
"include": [
|
||||||
"src"
|
"src",
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules",
|
"node_modules",
|
||||||
"**/__tests__/*",
|
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
@@ -32,11 +31,15 @@
|
|||||||
"module": "CommonJS", /* Specify what module code is generated. */
|
"module": "CommonJS", /* Specify what module code is generated. */
|
||||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||||
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||||
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
|
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
|
||||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
"types": [
|
||||||
|
"node",
|
||||||
|
"jest"
|
||||||
|
],
|
||||||
|
/* Specify type package names to be included without being referenced in a source file. */
|
||||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||||
"resolveJsonModule": true, /* Enable importing .json files */
|
"resolveJsonModule": true, /* Enable importing .json files */
|
||||||
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
|
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
|
||||||
|
|||||||
Reference in New Issue
Block a user