Skip to content

Commit

Permalink
Merge pull request #256 from RunOnFlux/test-creation-1
Browse files Browse the repository at this point in the history
Test creation 1
  • Loading branch information
TheTrunk authored Sep 17, 2024
2 parents c92796d + 7423df9 commit d59c4bb
Show file tree
Hide file tree
Showing 13 changed files with 3,699 additions and 461 deletions.
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ dist-ssr
*.sw?

package-lock.json
yarn.lock
yarn.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"test": "nyc --reporter=lcov ts-mocha -p tsconfig.test.json -r tsconfig-paths/register -r ignore-styles tests/**/*.spec.ts",
"lint": "eslint ./src ./public",
"lint:fix": "eslint ./src ./public --fix",
"type-check": "tsc",
Expand Down Expand Up @@ -59,6 +60,8 @@
"@types/react-dom": "~18.3.0",
"@types/react-redux": "~7.1.33",
"@types/react-router-dom": "~5.3.3",
"@types/chai": "~4.3.17",
"@types/mocha": "~10.0.7",
"@typescript-eslint/eslint-plugin": "~8.1.0",
"@typescript-eslint/parser": "~8.1.0",
"@vitejs/plugin-react-swc": "~3.7.0",
Expand All @@ -69,11 +72,20 @@
"eslint-plugin-react-hooks": "~4.6.2",
"eslint-plugin-react-refresh": "~0.4.9",
"globals": "~15.9.0",
"mocha": "~10.7.3",
"prettier": "~3.3.3",
"tsx": "~4.17.0",
"typescript": "~5.5.4",
"typescript-eslint": "~8.1.0",
"vite": "~5.4.1"
"vite": "~5.4.1",
"nyc": "~17.0.0",
"ts-mocha": "~10.0.0",
"chai": "~4.4.1",
"sinon": "~18.0.0",
"node-mocks-http": "~1.15.1",
"mock-browser": "~0.92.14",
"ignore-styles": "~5.0.1",
"tsconfig-paths": "~4.2.0"
},
"engines": {
"node": ">=20"
Expand Down
85 changes: 85 additions & 0 deletions tests/lib/balances.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* eslint-disable @typescript-eslint/no-unused-expressions */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck test suite
import chai from 'chai';
import { describe, it } from 'mocha';

import {
fetchAddressBalance,
fetchAddressTokenBalances,
} from '../../src/lib/balances';

const { expect, assert } = chai;

describe('Balances Lib', function () {
describe('Verifies balances', function () {
it('should return fetchAddressBalance data when value is flux', async function () {
const res = await fetchAddressBalance(
't1ex3ZyD2gYqztumQpgG6uPDGK5iHFY6aEd',
'flux',
);
expect(res).to.not.be.null;
expect(res).to.not.be.undefined;
expect(res.unconfirmed).to.not.be.null;
expect(res.unconfirmed).to.not.be.undefined;
expect(res.totalTransactions).to.not.be.null;
expect(res.totalTransactions).to.not.be.undefined;
assert.equal(res.address, 't1ex3ZyD2gYqztumQpgG6uPDGK5iHFY6aEd');
});

it('should return fetchAddressBalance data when value is blockbook type', async function () {
const res = await fetchAddressBalance(
'bitcoincash:qzq4ehw7h3jgcx5tx687zyunfk6pm9hcrys4u3tvhl',
'bch',
);
expect(res).to.not.be.null;
expect(res).to.not.be.undefined;
expect(res.unconfirmed).to.not.be.null;
expect(res.unconfirmed).to.not.be.undefined;
expect(res.totalTransactions).to.not.be.null;
expect(res.totalTransactions).to.not.be.undefined;
assert.equal(
res.address,
'bitcoincash:qzq4ehw7h3jgcx5tx687zyunfk6pm9hcrys4u3tvhl',
);
});

it('should return fetchAddressBalance data when value is evm type', async function () {
const res = await fetchAddressBalance(
'0x8092557902BA4dE6f83a7E27e14b8F0bF8ADFeA1',
'sepolia',
);
expect(res).to.not.be.null;
expect(res).to.not.be.undefined;
expect(res.unconfirmed).to.not.be.null;
expect(res.unconfirmed).to.not.be.undefined;
expect(res.confirmed).to.not.be.null;
expect(res.confirmed).to.not.be.undefined;
assert.equal(res.address, '0x8092557902BA4dE6f83a7E27e14b8F0bF8ADFeA1');
});

it('should return fetchAddressTokenBalances data when value is invalid', async function () {
await fetchAddressTokenBalances(
't1ex3ZyD2gYqztumQpgG6uPDGK5iHFY6aEd',
'flux',
[],
).catch((r) => {
assert.equal(r, 'Error: Only EVM chains support token balances');
});
});

it('should return fetchAddressTokenBalances data when value is evm type', async function () {
const res = await fetchAddressTokenBalances(
'0x8092557902BA4dE6f83a7E27e14b8F0bF8ADFeA1',
'sepolia',
['0x8092557902BA4dE6f83a7E27e14b8F0bF8ADFeA1'],
);
expect(res[0]).to.not.be.null;
expect(res[0]).to.not.be.undefined;
expect(res[0].contract).to.not.be.null;
expect(res[0].contract).to.not.be.undefined;
expect(res[0].balance).to.not.be.null;
expect(res[0].balance).to.not.be.undefined;
});
});
});
30 changes: 30 additions & 0 deletions tests/lib/blockheight.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable @typescript-eslint/no-unused-expressions */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck test suite
import chai from 'chai';
import { getBlockheight } from '../../src/lib/blockheight';
import { describe, it } from 'mocha';

const { expect } = chai;

describe('Currency Lib', function () {
describe('Verifies currency', function () {
it('should return data when value is valid evm', async function () {
const res = await getBlockheight('eth');
expect(res).to.not.be.null;
expect(res).to.not.be.undefined;
});

it('should return data when value is valid', async function () {
const res = await getBlockheight('flux');
expect(res).to.not.be.null;
expect(res).to.not.be.undefined;
});

it('should return data when value is valid blockbook', async function () {
const res = await getBlockheight('bch');
expect(res).to.not.be.null;
expect(res).to.not.be.undefined;
});
});
});
Loading

0 comments on commit d59c4bb

Please sign in to comment.