Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: separate out and disable keychain integration tests #15

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { assets } from './fixtures/assets'

import { KeyIdentifier, createKeyIdentifierForExodus } from '../key-identifier'

describe('KeyIdentifier', () => {
it('should fail on incorrect construction', () => {
const failures = [
{
derivationAlgorithm: 'BIP32',
asset: assets.ethereum,
},
{
derivationPath: "m/44'/60'/0'/0/0",
asset: assets.ethereum,
},
{
asset: assets.ethereum,
},
{
derivationAlgorithm: 0,
asset: assets.ethereum,
derivationPath: "m/44'/60'/0'/0/0",
},
{
derivationAlgorithm: 'BIP32',
asset: assets.ethereum,
derivationPath: 0,
},
{
derivationAlgorithm: 'BIP32',
asset: assets.ethereum,
derivationPath: "m/44'/60'/0'/0/0dddd",
},
{
derivationAlgorithm: 'BIP32',
asset: assets.ethereum,
derivationPath: "m\\44'/60'/0'/0/0",
},
{
derivationAlgorithm: 'BIP32',
asset: assets.ethereum,
derivationPath: "m44'/60'/0'/0/0",
},
]

const failuresAsFunctions = failures.map((failure) => () => {
return new KeyIdentifier(failure)
})
failuresAsFunctions.forEach((failureFunc) => {
expect(failureFunc).toThrow()
})
})

it('validates KeyIdentifier-likes', () => {
const valid = [
new KeyIdentifier({
derivationAlgorithm: 'BIP32',
assetName: 'ethereum',
derivationPath: "m/44'/60'/0'/0/0",
}),
new KeyIdentifier({
derivationAlgorithm: 'SLIP10',
assetName: 'solana',
derivationPath: "m/44'/501'/0'",
}),
{
derivationAlgorithm: 'BIP32',
assetName: 'ethereum',
derivationPath: "m/44'/60'/0'/0/0",
},
]

const invalid = [
{
derivationAlgorithm: 'BIP32',
assetName: 'ethereum',
},
]

valid.forEach((item) => expect(KeyIdentifier.validate(item)).toEqual(true))
invalid.forEach((item) => expect(KeyIdentifier.validate(item)).toEqual(false))
})

describe('.compare()', () => {
it('should return true when equal', () => {
const keyIdA = new KeyIdentifier({
derivationAlgorithm: 'BIP32',
assetName: 'ethereum',
derivationPath: "m/44'/60'/0'/0/0",
})

const keyIdB = new KeyIdentifier({
derivationAlgorithm: 'BIP32',
assetName: 'ethereum',
derivationPath: "m/44'/60'/0'/0/0",
})

expect(KeyIdentifier.compare(keyIdA, keyIdB)).toBe(true)
})

it('should return false when not equal', () => {
const keyIdA = new KeyIdentifier({
derivationAlgorithm: 'BIP32',
assetName: 'ethereum',
derivationPath: "m/44'/60'/0'/0/0",
})

const keyIdB = new KeyIdentifier({
derivationAlgorithm: 'BIP32',
assetName: 'ethereum',
derivationPath: "m/44'/60'/0'/0/1",
})

expect(KeyIdentifier.compare(keyIdA, keyIdB)).toBe(false)
expect(KeyIdentifier.compare('not-an-object', keyIdB)).toBe(false)
})
})
})

describe('createKeyIdentifierForExodus', () => {
it('should work', () => {
expect(() => createKeyIdentifierForExodus({ exoType: 'FUSION' })).not.toThrow()
})

it('should throw when incorrect exoType', async () => {
expect(() => createKeyIdentifierForExodus({ exoType: 'INVALID' })).toThrow()
})
})
41 changes: 3 additions & 38 deletions features/keychain/module/__tests__/key-identifier.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { assets } from './fixtures/assets'

import { KeyIdentifier, createKeyIdentifierForExodus } from '../key-identifier'

describe('KeyIdentifier', () => {
Expand All @@ -9,61 +7,28 @@ describe('KeyIdentifier', () => {
undefined,
{},
// Missing parameters
{
derivationAlgorithm: 'BIP32',
asset: assets.ethereum,
},
{
derivationPath: "m/44'/60'/0'/0/0",
asset: assets.ethereum,
},

mvayngrib marked this conversation as resolved.
Show resolved Hide resolved
{
derivationAlgorithm: 'BIP32',
},
{
derivationPath: "m/44'/60'/0'/0/0",
},
{
asset: assets.ethereum,
},

// Incorrect types
{
derivationAlgorithm: 0,
asset: assets.ethereum,
derivationPath: "m/44'/60'/0'/0/0",
},
{
derivationAlgorithm: 'BIP32',
assetName: 0,
derivationPath: "m/44'/60'/0'/0/0",
},
{
derivationAlgorithm: 'BIP32',
asset: assets.ethereum,
derivationPath: 0,
},

// Non-existing assetNames
// {
// derivationAlgorithm: 'BIP32',
// asset: { name: 'i-do-not-exist' },
// derivationPath: `m/44'/60'/0'/0/0`,
// },
// Incorrect paths
{
derivationAlgorithm: 'BIP32',
asset: assets.ethereum,
derivationPath: "m/44'/60'/0'/0/0dddd",
},
{
derivationAlgorithm: 'BIP32',
asset: assets.ethereum,
derivationPath: "m\\44'/60'/0'/0/0",
},
{
derivationAlgorithm: 'BIP32',
asset: assets.ethereum,
derivationPath: "m44'/60'/0'/0/0",
},
]

const failuresAsFunctions = failures.map((failure) => () => {
Expand Down
9 changes: 2 additions & 7 deletions features/keychain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"scripts": {
"lint": "eslint . --ignore-path ../../.gitignore",
"lint:fix": "yarn lint --fix",
"test": "jest"
"test": "jest",
"todo:reenable:test:integration": "jest --testMatch='**/*.integration-test.js'"
},
"dependencies": {
"@exodus/atoms": "^6.0.1",
Expand All @@ -44,12 +45,6 @@
"p-defer": "^4.0.0"
},
"devDependencies": {
"@exodus/assets": "latest",
"@exodus/cardano-lib": "^2.0.3",
"@exodus/ethereum-lib": "^3.3.6",
"@exodus/solana-lib": "^1.3.11",
"@exodus/solana-meta": "^1.0.2",
"@exodus/storage-memory": "^2.1.1",
"bip39": "2.6.0",
"eslint": "^8.44.0",
"events": "^3.3.0",
Expand Down
1 change: 1 addition & 0 deletions package.json
mvayngrib marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"packageManager": "[email protected]",
"dependencies": {
"@exodus/migrate": "^1.5.3",
"delay": "^5.0.0",
mvayngrib marked this conversation as resolved.
Show resolved Hide resolved
"global": "^4.4.0"
}
}
Loading
Loading