-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
SamvelRaja Sakthivel
authored and
SamvelRaja Sakthivel
committed
Aug 2, 2023
1 parent
fa94d0d
commit 87940db
Showing
8 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
"roots": [ | ||
"<rootDir>/src" | ||
], | ||
"testMatch": [ | ||
"**/tests/**/*.+(ts|tsx|js)", | ||
"**/?(*.)+(spec|test).+(ts|tsx|js)" | ||
], | ||
"transform": { | ||
"^.+\\.(ts|tsx)$": "ts-jest" | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,8 @@ | |
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write", | ||
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path .gitignore", | ||
"serve": "mm-snap serve", | ||
"start": "mm-snap watch" | ||
"start": "mm-snap watch", | ||
"test": "jest --coverage" | ||
}, | ||
"dependencies": { | ||
"@cosmjs/stargate": "^0.30.1", | ||
|
@@ -47,6 +48,7 @@ | |
"@metamask/eslint-config-nodejs": "^10.0.0", | ||
"@metamask/eslint-config-typescript": "^10.0.0", | ||
"@metamask/snaps-cli": "^0.32.2", | ||
"@types/jest": "^29.5.3", | ||
"@typescript-eslint/eslint-plugin": "^5.33.0", | ||
"@typescript-eslint/parser": "^5.33.0", | ||
"eslint": "^8.21.0", | ||
|
@@ -56,12 +58,14 @@ | |
"eslint-plugin-jsdoc": "^39.2.9", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"jest": "^29.6.2", | ||
"patch-package": "^7.0.0", | ||
"postinstall-postinstall": "^2.1.0", | ||
"prettier": "^2.2.1", | ||
"prettier-plugin-packagejson": "^2.2.11", | ||
"rimraf": "^3.0.2", | ||
"through2": "^4.0.2", | ||
"ts-jest": "^29.1.1", | ||
"typescript": "^4.7.4" | ||
}, | ||
"packageManager": "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Json, JsonRpcRequest } from "@metamask/snaps-types"; | ||
|
||
|
||
const output = { | ||
success: { | ||
getKey: { | ||
origin: 'test_mock', | ||
request: { | ||
id: "some_unique_id", | ||
jsonrpc: "2.0", | ||
method: 'getKey', | ||
params: { | ||
chainId: 'cosmoshub-4', | ||
}, | ||
} as unknown as JsonRpcRequest<Json[] | Record<string, Json>> | ||
} | ||
}, | ||
failure: { | ||
getKey: { | ||
origin: 'test_mock', | ||
request: { | ||
id: "some_unique_id", | ||
jsonrpc: "2.0", | ||
method: 'getKey', | ||
params: { | ||
chainId: 'cosmos', | ||
}, | ||
} as unknown as JsonRpcRequest<Json[] | Record<string, Json>> | ||
} | ||
} | ||
} | ||
|
||
export default output; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const output = { | ||
success: { | ||
getKey: { | ||
address: 'cosmos127jexdh5jx5tdqxt6z6dggfr5c6ffcwuamstpe', | ||
algo: 'secp256k1', | ||
bech32Address: 'cosmos127jexdh5jx5tdqxt6z6dggfr5c6ffcwuamstpe', | ||
isNanoLedger: false, | ||
name: 'Cosmos' | ||
} | ||
} | ||
} | ||
|
||
export default output; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
|
||
|
||
const snapMock:any = { | ||
success: { | ||
request: (params: any) => { | ||
if ( | ||
params.method === "snap_getBip44Entropy" | ||
) { | ||
return {"depth":2,"masterFingerprint":3507465413,"parentFingerprint":3845878817,"index":2147483766,"privateKey":"0x4072b5221f1526a0654c5ea97791476d70f1c09fa9e71e8812c3b9a097c829ad","publicKey":"0x04f9cc5a47a6497bd9b0dd069f8d12b50a3c2198354f0630371ba5bc34b8e67939dc541e975c8ea7c0e77630f92af9f862bd6203458735525d8715de7d7c590608","chainCode":"0xd2beb6b5262f8db0200551b45ebf22054ac7e31846fe64b953bffdfd4f1e1592","coin_type":118,"path":"m / bip32:44' / bip32:118'"}; | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export default snapMock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import onRPCRequest from '../index'; | ||
import snapMock from '../mocks/snap.mock'; | ||
import input from '../mocks/input.mock'; | ||
import output from '../mocks/output.mock'; | ||
import { JsonRpcRequest, OnRpcRequestHandler } from '@metamask/snaps-types'; | ||
|
||
test('GetKey for Invalid Chain ID', async () => { | ||
if(input.failure.getKey.request) { | ||
await expect(onRPCRequest(input.failure.getKey)).rejects.toThrow('Invalid chainId'); | ||
} | ||
|
||
}); | ||
|
||
test('GetKey for Valid Chain ID', async () => { | ||
(global as any).snap = snapMock.success; | ||
await expect(onRPCRequest(input.success.getKey)).resolves.toMatchObject(output.success.getKey) | ||
}); |