Skip to content

Commit

Permalink
chore: separate out and disable keychain integration tests (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvayngrib authored Jan 23, 2024
1 parent 8dfbc60 commit acd5eed
Show file tree
Hide file tree
Showing 7 changed files with 956 additions and 2,395 deletions.
128 changes: 128 additions & 0 deletions features/keychain/module/__tests__/key-identifier.integration-test.js
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,
},

{
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"packageManager": "yarn@3.2.2",
"dependencies": {
"@exodus/migrate": "^1.5.3",
"delay": "^5.0.0",
"global": "^4.4.0"
}
}
Loading

0 comments on commit acd5eed

Please sign in to comment.