Skip to content

Commit

Permalink
Merge branch 'dev' into create-token-api
Browse files Browse the repository at this point in the history
Signed-off-by: Kiran Pachhai <kiran@pachhai.com>
  • Loading branch information
kpachhai authored Feb 22, 2024
2 parents b3f9423 + 982bd26 commit b0f7a4b
Show file tree
Hide file tree
Showing 14 changed files with 2,565 additions and 2,619 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/run-eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Lint Snap Code

on: [push, pull_request]

jobs:
eslint:
name: Run ESLint For Snap
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
name: Check out source code

- uses: actions/setup-node@v2
name: Set up Node.js
with:
node-version: '18'
cache: 'yarn'
cache-dependency-path: packages/hedera-wallet-snap/packages/snap

- name: Install Dependencies in Subdirectory
run: yarn install
working-directory: ./packages/hedera-wallet-snap/packages/snap

- name: Run ESLint in Subdirectory
run: yarn lint
working-directory: ./packages/hedera-wallet-snap/packages/snap
27 changes: 27 additions & 0 deletions .github/workflows/run-jest-unit-snap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Run Hedera Pulse Snap Unit Tests

on: [push]

jobs:
eslint:
name: Run Hedera Pulse Snap Unit Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
name: Check out source code

- uses: actions/setup-node@v2
name: Set up Node.js
with:
node-version: '18'
cache: 'yarn'
cache-dependency-path: packages/hedera-wallet-snap/packages/snap

- name: Install Dependencies in Subdirectory
run: yarn install
working-directory: ./packages/hedera-wallet-snap/packages/snap

- name: Run Snap Unit Tests
run: yarn test
working-directory: ./packages/hedera-wallet-snap/packages/snap
2 changes: 1 addition & 1 deletion packages/hedera-wallet-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"eslint-plugin-jest": "^27.4.0",
"eslint-plugin-jsdoc": "^46.8.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-prettier": "5.0.0",
"prettier": "^3.0.3",
"prettier-plugin-packagejson": "^2.4.5",
"typescript": "^5.2.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/hedera-wallet-snap/packages/snap/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ module.exports = {
project: './tsconfig.eslint.json',
sourceType: 'module',
},
ignorePatterns: ['!.eslintrc.js', 'dist/', './postBuild.js'],
ignorePatterns: ['!.eslintrc.js', 'dist/', './postBuild.js','jest.config.js'],
};
2 changes: 1 addition & 1 deletion packages/hedera-wallet-snap/packages/snap/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ module.exports = {
testEnvironment: 'node',
testRegex: '.*\\.spec\\.ts$',
transformIgnorePatterns: [],
testTimeout: 120000
testTimeout: 120000,
};
3 changes: 2 additions & 1 deletion packages/hedera-wallet-snap/packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path .gitignore",
"serve": "mm-snap serve",
"start": "mm-snap --version && concurrently \"yarn build && yarn serve\" \"yarn watch\"",
"test": "jest --forceExit",
"test": "jest --forceExit --verbose",
"test:ci": "yarn test --silent",
"watch": "chokidar 'src/' -c 'yarn build'"
},
Expand All @@ -58,6 +58,7 @@
"@metamask/snaps-ui": "^1.0.1",
"bignumber.js": "^9.1.1",
"ethers": "^6.3.0",
"jest-mock": "^29.7.0",
"lodash": "^4.17.21",
"normalize-url": "^8.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ describe('CryptoUtils', () => {
});

it('should validate an Ethereum public key', () => {
const publicKey = '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
const publicKey =
'0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
mockedIsHexString.mockReturnValue(true);

const result = CryptoUtils.isValidEthereumPublicKey(publicKey);
Expand Down Expand Up @@ -62,7 +63,9 @@ describe('CryptoUtils', () => {

it('should throw an error for invalid hex strings', () => {
const hexString = 'abc';
expect(() => CryptoUtils.hexToUInt8Array(hexString)).toThrow('Invalid hex string');
expect(() => CryptoUtils.hexToUInt8Array(hexString)).toThrow(
'Invalid hex string',
);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-restricted-globals */
import { FetchUtils, FetchResponse } from '../FetchUtils';

global.fetch = jest.fn();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { StateUtils } from '../StateUtils';
import { WalletAccountState, WalletSnapState } from '../../types/state';

describe('StateUtils', () => {
describe('getEmptyAccountState', () => {
it('returns a deep clone of emptyAccountState', () => {
const state : WalletAccountState = StateUtils.getEmptyAccountState();
const state: WalletAccountState = StateUtils.getEmptyAccountState();
expect(state).toEqual({
keyStore: {
curve: 'ECDSA_SECP256K1',
Expand All @@ -17,14 +18,14 @@ describe('StateUtils', () => {

// Verify deep clone by mutation
state.keyStore.curve = 'ED25519';
const newState : WalletAccountState = StateUtils.getEmptyAccountState();
const newState: WalletAccountState = StateUtils.getEmptyAccountState();
expect(newState.keyStore.curve).toBe('ECDSA_SECP256K1');
});
});

describe('getInitialSnapState', () => {
it('returns a deep clone of initialSnapState', () => {
const snapState:WalletSnapState = StateUtils.getInitialSnapState();
const snapState: WalletSnapState = StateUtils.getInitialSnapState();
expect(snapState).toEqual({
currentAccount: {},
accountState: {},
Expand All @@ -41,7 +42,7 @@ describe('StateUtils', () => {

// Verify deep clone by mutation
snapState.snapConfig.dApp.disablePopups = true;
const newSnapState:WalletSnapState = StateUtils.getInitialSnapState();
const newSnapState: WalletSnapState = StateUtils.getInitialSnapState();
expect(newSnapState.snapConfig.dApp.disablePopups).toBe(false);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ describe('HederaWalletUtils', () => {
maxCost: 115.5, // (100 + 10) * 1.05
};

const result = TuumUtils.calculateHederaQueryFees(queryCost, serviceFeePercentage);
const result = TuumUtils.calculateHederaQueryFees(
queryCost,
serviceFeePercentage,
);

expect(result.serviceFeeToPay).toBeCloseTo(expected.serviceFeeToPay);
expect(result.maxCost).toBeCloseTo(expected.maxCost);
Expand All @@ -21,8 +24,8 @@ describe('HederaWalletUtils', () => {

describe('deductServiceFee', () => {
it('should call transferCrypto with correct parameters', async () => {
//note that jest is having issues with classes with nested includes
//since we're doing the instance refactor next going to leave this as-is
// note that jest is having issues with classes with nested includes
// since we're doing the instance refactor next going to leave this as-is
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('HederaWalletSnap', () => {

test('should convert a string representation of a timestamp to a UTC string', () => {
const timestamp = '1672444800'; // Equivalent to 2023-01-01T00:00:00Z
const expected = new Date(parseInt(timestamp) * 1000).toUTCString();
const expected = new Date(parseInt(timestamp, 10) * 1000).toUTCString();
expect(Utils.timestampToString(timestamp)).toBe(expected);
});

Expand Down
1 change: 1 addition & 0 deletions packages/hedera-wallet-snap/packages/snap/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"removeComments": true
},
"files": ["./json-typings.d.ts"],
"exclude": ["./jest.config.js"],
"include": ["src/**/*"]
}
Loading

0 comments on commit b0f7a4b

Please sign in to comment.