Skip to content

Commit

Permalink
Libs update + prettier formating
Browse files Browse the repository at this point in the history
  • Loading branch information
edolganov committed Aug 21, 2024
1 parent 00cdccd commit 8df2c4e
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 79 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ module.exports = {
'prettier',
],
rules: {
'@typescript-eslint/return-await': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/ban-tslint-comment': 'off', // caused by no way to remove this from generated code
'object-property-newline': [
Expand Down
33 changes: 26 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"dependencies": {
"ethers": "^6.13.2",
"smartypay-client-model": "^2.30.0"
"smartypay-client-model": "^2.34.0"
},
"devDependencies": {
"@types/jest": "^29.5.12",
Expand Down
70 changes: 37 additions & 33 deletions src/Web3Common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
*/

import { Web3Common } from './Web3Common';
import { Assets } from 'smartypay-client-model';
import { BigNumber, ethers } from 'ethers';
import { Assets, util } from 'smartypay-client-model';
import { ethers } from 'ethers';

describe('Web3Common', () => {
const address = '0x14186C8215985f33845722730c6382443Bf9EC65';
const randomAddress = '0x790ACC251534cb02975A0c61dA94D200bB5833A5'; // from https://vanity-eth.tk/

const zero = BigNumber.from(0);
const zero = util.bigMath.toBigNumber(0);

describe('toNumberFromHex', () => {
test('should be correct number', () => {
Expand All @@ -23,8 +23,12 @@ describe('Web3Common', () => {

describe('toHexString', () => {
test('should be correct hex', () => {
expect(Web3Common.toHexString(1)).toBe('0x01');
expect(Web3Common.toHexString(15)).toBe('0x0f');
expect(Web3Common.toHexString(0)).toBe('0x0');
expect(Web3Common.toHexString(1)).toBe('0x1');
expect(Web3Common.toHexString(15)).toBe('0xf');
expect(Web3Common.toHexString(16)).toBe('0x10');
expect(Web3Common.toHexString(255)).toBe('0xff');
expect(Web3Common.toHexString(256)).toBe('0x100');
});
});

Expand All @@ -37,70 +41,70 @@ describe('Web3Common', () => {
describe('getTokenBalance', () => {
test('should support btBUSD', async () => {
const doubleForm = await Web3Common.getTokenBalance(Assets.btBUSD, address);
const absoluteForm = ethers.utils.parseUnits(doubleForm, Assets.btBUSD.decimals);
expect(absoluteForm.gt(zero)).toBe(true);
const absoluteForm = ethers.parseUnits(doubleForm, Assets.btBUSD.decimals);
expect(util.bigMath.isGreaterThan(absoluteForm, zero)).toBe(true);
});

test('should support btMNXe', async () => {
const doubleForm = await Web3Common.getTokenBalance(Assets.btMNXe, address);
const absoluteForm = ethers.utils.parseUnits(doubleForm, Assets.btMNXe.decimals);
expect(absoluteForm.gt(zero)).toBe(true);
const absoluteForm = ethers.parseUnits(doubleForm, Assets.btMNXe.decimals);
expect(util.bigMath.isGreaterThan(absoluteForm, zero)).toBe(true);
});

test('should support btUSDTv2', async () => {
const doubleForm = await Web3Common.getTokenBalance(Assets.btUSDTv2, address);
const absoluteForm = ethers.utils.parseUnits(doubleForm, Assets.btUSDTv2.decimals);
expect(absoluteForm.gt(zero)).toBe(true);
const absoluteForm = ethers.parseUnits(doubleForm, Assets.btUSDTv2.decimals);
expect(util.bigMath.isGreaterThan(absoluteForm, zero)).toBe(true);
});

test('should support asUSDC', async () => {
const doubleForm = await Web3Common.getTokenBalance(Assets.asUSDC, address);
const absoluteForm = ethers.utils.parseUnits(doubleForm, Assets.asUSDC.decimals);
expect(absoluteForm.gt(zero)).toBe(true);
const absoluteForm = ethers.parseUnits(doubleForm, Assets.asUSDC.decimals);
expect(util.bigMath.isGreaterThan(absoluteForm, zero)).toBe(true);
});

test('should support asUSDT', async () => {
const doubleForm = await Web3Common.getTokenBalance(Assets.asUSDT, address);
const absoluteForm = ethers.utils.parseUnits(doubleForm, Assets.asUSDT.decimals);
expect(absoluteForm.gt(zero)).toBe(true);
const absoluteForm = ethers.parseUnits(doubleForm, Assets.asUSDT.decimals);
expect(util.bigMath.isGreaterThan(absoluteForm, zero)).toBe(true);
});

test('should support pmUSDC', async () => {
const doubleForm = await Web3Common.getTokenBalance(Assets.pmUSDC, address);
const absoluteForm = ethers.utils.parseUnits(doubleForm, Assets.pmUSDC.decimals);
expect(absoluteForm.gt(zero)).toBe(true);
test('should support paUSDC', async () => {
const doubleForm = await Web3Common.getTokenBalance(Assets.paUSDC, address);
const absoluteForm = ethers.parseUnits(doubleForm, Assets.paUSDC.decimals);
expect(util.bigMath.isGreaterThan(absoluteForm, zero)).toBe(true);
});

test('should support pmUSDT', async () => {
const doubleForm = await Web3Common.getTokenBalance(Assets.pmUSDT, address);
const absoluteForm = ethers.utils.parseUnits(doubleForm, Assets.pmUSDT.decimals);
expect(absoluteForm.gt(zero)).toBe(true);
test('should support paUSDT', async () => {
const doubleForm = await Web3Common.getTokenBalance(Assets.paUSDT, address);
const absoluteForm = ethers.parseUnits(doubleForm, Assets.paUSDT.decimals);
expect(util.bigMath.isGreaterThan(absoluteForm, zero)).toBe(true);
});

test('should support sUSDC', async () => {
const doubleForm = await Web3Common.getTokenBalance(Assets.sUSDC, address);
const absoluteForm = ethers.utils.parseUnits(doubleForm, Assets.sUSDC.decimals);
expect(absoluteForm.gt(zero)).toBe(true);
const absoluteForm = ethers.parseUnits(doubleForm, Assets.sUSDC.decimals);
expect(util.bigMath.isGreaterThan(absoluteForm, zero)).toBe(true);
});
});

describe('getTokenAllowance', () => {
test('should support btBUSD', async () => {
const doubleForm = await Web3Common.getTokenAllowance(Assets.btBUSD, address, randomAddress);
const absoluteForm = ethers.utils.parseUnits(doubleForm, Assets.btBUSD.decimals);
expect(absoluteForm.eq(zero)).toBe(true);
const absoluteForm = ethers.parseUnits(doubleForm, Assets.btBUSD.decimals);
expect(util.bigMath.isEqualTo(absoluteForm, zero)).toBe(true);
});

test('should support atUSDC', async () => {
const doubleForm = await Web3Common.getTokenAllowance(Assets.asUSDC, address, randomAddress);
const absoluteForm = ethers.utils.parseUnits(doubleForm, Assets.asUSDC.decimals);
expect(absoluteForm.eq(zero)).toBe(true);
const absoluteForm = ethers.parseUnits(doubleForm, Assets.asUSDC.decimals);
expect(util.bigMath.isEqualTo(absoluteForm, zero)).toBe(true);
});

test('should support pmUSDC', async () => {
const doubleForm = await Web3Common.getTokenAllowance(Assets.pmUSDC, address, randomAddress);
const absoluteForm = ethers.utils.parseUnits(doubleForm, Assets.pmUSDC.decimals);
expect(absoluteForm.eq(zero)).toBe(true);
test('should support paUSDC', async () => {
const doubleForm = await Web3Common.getTokenAllowance(Assets.paUSDC, address, randomAddress);
const absoluteForm = ethers.parseUnits(doubleForm, Assets.paUSDC.decimals);
expect(util.bigMath.isEqualTo(absoluteForm, zero)).toBe(true);
});
});
});
Loading

0 comments on commit 8df2c4e

Please sign in to comment.