Skip to content

Commit

Permalink
Move token-swap tests to mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
joncinque committed Nov 8, 2023
1 parent 7ac2472 commit 73bd10b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 43 deletions.
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions token-swap/js/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extension": ["ts"],
"node-option": ["experimental-specifier-resolution=node", "loader=ts-node/esm"],
"timeout": 100000
}
6 changes: 5 additions & 1 deletion token-swap/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"scripts": {
"build": "tsc -p tsconfig.json && tsc-esm -p tsconfig.json && tsc -p tsconfig.cjs.json",
"postbuild": "echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json && echo '{\"type\":\"module\"}' > dist/esm/package.json",
"test": "ts-node test/main.ts",
"test": "mocha test",
"start-with-test-validator": "start-server-and-test 'solana-test-validator --bpf-program SwapsVeCiPHMUAtzQWZw7RjsKjgCjhwU55QGu4U1Szw ../../target/deploy/spl_token_swap.so --reset --quiet' http://127.0.0.1:8899/health test",
"lint": "npm run pretty && eslint --max-warnings 0 .",
"lint:fix": "npm run pretty:fix && eslint . --fix",
Expand All @@ -49,10 +49,14 @@
"devDependencies": {
"@solana/spl-token": "workspace:*",
"@types/bn.js": "^5.1.0",
"@types/chai-as-promised": "^7.1.4",
"@types/chai": "^4.3.3",
"@types/mocha": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.31.0",
"eslint-plugin-import": "^2.22.0",
"mocha": "^10.1.0",
"prettier": "^3.0.0",
"start-server-and-test": "^2.0.0",
"ts-node": "^10.0.0",
Expand Down
37 changes: 37 additions & 0 deletions token-swap/js/test/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
createAccountAndSwapAtomic,
createTokenSwap,
swap,
depositAllTokenTypes,
withdrawAllTokenTypes,
depositSingleTokenTypeExactAmountIn,
withdrawSingleTokenTypeExactAmountOut,
} from './token-swap-test';
import {CurveType} from '../src';

describe('spl-token-swap instructions', () => {
it('executes properly', async () => {
// These test cases are designed to run sequentially and in the following order
console.log('Run test: createTokenSwap (constant price)');
const constantPrice = new Uint8Array(8);
constantPrice[0] = 1;
await createTokenSwap(CurveType.ConstantPrice, constantPrice);
console.log(
'Run test: createTokenSwap (constant product, used further in tests)',
);
await createTokenSwap(CurveType.ConstantProduct);
console.log('Run test: deposit all token types');
await depositAllTokenTypes();
console.log('Run test: withdraw all token types');
await withdrawAllTokenTypes();
console.log('Run test: swap');
await swap();
console.log('Run test: create account, approve, swap all at once');
await createAccountAndSwapAtomic();
console.log('Run test: deposit one exact amount in');
await depositSingleTokenTypeExactAmountIn();
console.log('Run test: withrdaw one exact amount out');
await withdrawSingleTokenTypeExactAmountOut();
console.log('Success\n');
});
});
42 changes: 0 additions & 42 deletions token-swap/js/test/main.ts

This file was deleted.

0 comments on commit 73bd10b

Please sign in to comment.