Changeset View
Changeset View
Standalone View
Standalone View
cashtab/src/validation/fixtures/vectors.js
// Copyright (c) 2024 The Bitcoin developers | // Copyright (c) 2024 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
// Test vectors for validation functions | // Test vectors for validation functions | ||||
import appConfig from 'config/app'; | import appConfig from 'config/app'; | ||||
import { CashtabSettings } from 'config/cashtabSettings'; | import { CashtabSettings } from 'config/cashtabSettings'; | ||||
import CashtabCache from 'config/CashtabCache'; | import CashtabCache from 'config/CashtabCache'; | ||||
import { mockCashtabCache } from 'helpers/fixtures/mocks'; | import { | ||||
import { validWallet } from 'validation/fixtures/mocks'; | mockCashtabCache, | ||||
mockCashtabCacheNoBlocks, | |||||
mockCashtabCache_pre_2_9_0, | |||||
} from 'helpers/fixtures/mocks'; | |||||
import { | |||||
validWalletJson, | |||||
validWalletJsonMultiPath, | |||||
} from 'validation/fixtures/mocks'; | |||||
import { walletWithXecAndTokens_pre_2_9_0 } from 'components/fixtures/mocks'; | |||||
import { toXec } from 'wallet'; | import { toXec } from 'wallet'; | ||||
import { cashtabWalletFromJSON } from 'helpers'; | |||||
const cloneObjectWithDeletedKey = (object, key) => { | const cloneObjectWithDeletedKey = (object, key) => { | ||||
const clonedObject = JSON.parse(JSON.stringify(object)); | const clonedObject = { ...object }; | ||||
delete clonedObject[key]; | delete clonedObject[key]; | ||||
return clonedObject; | return clonedObject; | ||||
}; | }; | ||||
export default { | export default { | ||||
shouldSendXecBeDisabled: { | shouldSendXecBeDisabled: { | ||||
expectedReturns: [ | expectedReturns: [ | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 827 Lines • ▼ Show 20 Lines | isValidCashtabCache: { | ||||
}, | }, | ||||
{ | { | ||||
description: | description: | ||||
'Returns false if there is not a map at tokens key', | 'Returns false if there is not a map at tokens key', | ||||
cashtabCache: { tokens: {} }, | cashtabCache: { tokens: {} }, | ||||
isValid: false, | isValid: false, | ||||
}, | }, | ||||
{ | { | ||||
description: 'Returns false for cashtabCache before 2.9.0', | |||||
cashtabCache: mockCashtabCache_pre_2_9_0, | |||||
isValid: false, | |||||
}, | |||||
{ | |||||
description: | |||||
'Returns false for current version cashtabCache if it is missing the unknown token id', | |||||
cashtabCache: { tokens: new Map() }, | |||||
isValid: false, | |||||
}, | |||||
{ | |||||
description: 'Returns true for current version cashtabCache', | description: 'Returns true for current version cashtabCache', | ||||
cashtabCache: mockCashtabCache, | cashtabCache: mockCashtabCache, | ||||
isValid: true, | isValid: true, | ||||
}, | }, | ||||
{ | { | ||||
description: | |||||
'Returns true for current version cashtabCache if blocks key is missing', | |||||
cashtabCache: mockCashtabCacheNoBlocks, | |||||
isValid: true, | |||||
}, | |||||
{ | |||||
description: 'Returns true for default cashtabCache', | description: 'Returns true for default cashtabCache', | ||||
cashtabCache: new CashtabCache(), | cashtabCache: new CashtabCache(), | ||||
isValid: true, | isValid: true, | ||||
}, | }, | ||||
], | ], | ||||
}, | }, | ||||
isValidCashtabWallet: { | isValidCashtabWallet: { | ||||
expectedReturns: [ | expectedReturns: [ | ||||
{ | { | ||||
description: 'Returns true for a valid Cashtab wallet', | description: 'Returns true for a valid Cashtab wallet', | ||||
wallet: validWallet, | wallet: cashtabWalletFromJSON(validWalletJson), | ||||
returned: true, | returned: true, | ||||
}, | }, | ||||
{ | { | ||||
description: | |||||
'Returns false for a JSON-loaded pre-2.9.0 Cashtab wallet', | |||||
wallet: cashtabWalletFromJSON(walletWithXecAndTokens_pre_2_9_0), | |||||
returned: false, | |||||
}, | |||||
{ | |||||
description: 'Returns false for a pre-2.9.0 Cashtab wallet', | |||||
wallet: walletWithXecAndTokens_pre_2_9_0, | |||||
returned: false, | |||||
}, | |||||
{ | |||||
description: 'Returns false if not an object', | description: 'Returns false if not an object', | ||||
wallet: 'a string', | wallet: 'a string', | ||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: | description: | ||||
'Returns false if false (used to indicate no wallet yet set)', | 'Returns false if false (used to indicate no wallet yet set)', | ||||
wallet: false, | wallet: false, | ||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: 'Returns false if wallet is missing state', | description: 'Returns false if wallet is missing state', | ||||
wallet: cloneObjectWithDeletedKey(validWallet, 'state'), | wallet: cloneObjectWithDeletedKey( | ||||
cashtabWalletFromJSON(validWalletJson), | |||||
'state', | |||||
), | |||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: 'Returns false if wallet is missing mnemonic', | description: 'Returns false if wallet is missing mnemonic', | ||||
wallet: cloneObjectWithDeletedKey(validWallet, 'mnemonic'), | wallet: cloneObjectWithDeletedKey( | ||||
cashtabWalletFromJSON(validWalletJson), | |||||
'mnemonic', | |||||
), | |||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: 'Returns false if wallet is missing name', | description: 'Returns false if wallet is missing name', | ||||
wallet: cloneObjectWithDeletedKey(validWallet, 'name'), | wallet: cloneObjectWithDeletedKey( | ||||
cashtabWalletFromJSON(validWalletJson), | |||||
'name', | |||||
), | |||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: 'Returns false if wallet is missing paths', | description: 'Returns false if wallet is missing paths', | ||||
wallet: cloneObjectWithDeletedKey(validWallet, 'paths'), | wallet: cloneObjectWithDeletedKey( | ||||
cashtabWalletFromJSON(validWalletJson), | |||||
'paths', | |||||
), | |||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: | description: | ||||
'Returns false if wallet is missing hash in path1899 path object', | 'Returns false if wallet is missing hash in path1899 path object', | ||||
wallet: { | wallet: { | ||||
...validWallet, | ...cashtabWalletFromJSON(validWalletJson), | ||||
paths: [ | paths: new Map([ | ||||
cloneObjectWithDeletedKey(validWallet.paths[0], 'hash'), | [ | ||||
1899, | |||||
{ | |||||
address: 'string', | |||||
wif: 'string', | |||||
}, | |||||
], | ], | ||||
]), | |||||
}, | }, | ||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: | description: | ||||
'Returns false if wallet is missing address in path1899 path object', | 'Returns false if wallet is missing address in path1899 path object', | ||||
wallet: { | wallet: { | ||||
...validWallet, | ...cashtabWalletFromJSON(validWalletJson), | ||||
paths: [ | paths: new Map([ | ||||
cloneObjectWithDeletedKey( | [ | ||||
validWallet.paths[0], | 1899, | ||||
'address', | { | ||||
), | hash: 'string', | ||||
wif: 'string', | |||||
}, | |||||
], | ], | ||||
]), | |||||
}, | }, | ||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: | description: | ||||
'Returns false if wallet is missing wif in path1899 path object', | 'Returns false if wallet is missing address in path1899 path object', | ||||
wallet: { | wallet: { | ||||
...validWallet, | ...cashtabWalletFromJSON(validWalletJson), | ||||
paths: [ | paths: new Map([ | ||||
cloneObjectWithDeletedKey(validWallet.paths[0], 'wif'), | [ | ||||
1899, | |||||
{ | |||||
address: 'string', | |||||
hash: 'string', | |||||
}, | |||||
], | ], | ||||
]), | |||||
}, | }, | ||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: 'Returns true for a multi-path wallet', | |||||
wallet: cashtabWalletFromJSON(validWalletJsonMultiPath), | |||||
returned: true, | |||||
}, | |||||
{ | |||||
description: | description: | ||||
'Returns false if wallet is missing wif in a secondary path object', | 'Returns false if wallet is missing wif in a secondary path object', | ||||
wallet: { | wallet: { | ||||
...validWallet, | ...cashtabWalletFromJSON(validWalletJson), | ||||
paths: [ | paths: new Map([ | ||||
{ ...validWallet.paths[0] }, | [ | ||||
1899, | |||||
{ | |||||
hash: 'string', | |||||
address: 'string', | |||||
wif: 'string', | |||||
}, | |||||
], | |||||
[ | |||||
145, | |||||
{ | { | ||||
...cloneObjectWithDeletedKey( | hash: 'string', | ||||
validWallet.paths[0], | address: 'string', | ||||
'wif', | |||||
), | |||||
path: 145, | |||||
}, | }, | ||||
], | ], | ||||
]), | |||||
}, | }, | ||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: 'Returns false if wallet has no path info objects', | description: 'Returns false if wallet has no path info objects', | ||||
wallet: { ...validWallet, paths: [] }, | wallet: { | ||||
...cashtabWalletFromJSON(validWalletJson), | |||||
paths: new Map(), | |||||
}, | |||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: 'Returns false if wallet.state is not an object', | description: 'Returns false if wallet.state is not an object', | ||||
wallet: { | wallet: { | ||||
...validWallet, | ...cashtabWalletFromJSON(validWalletJson), | ||||
state: 'string', | state: 'string', | ||||
}, | }, | ||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: 'Returns false if no balanceSats in wallet.state', | description: 'Returns false if no balanceSats in wallet.state', | ||||
wallet: { | wallet: { | ||||
...validWallet, | ...cashtabWalletFromJSON(validWalletJson), | ||||
state: cloneObjectWithDeletedKey( | state: { | ||||
validWallet.state, | ...cloneObjectWithDeletedKey( | ||||
cashtabWalletFromJSON(validWalletJson).state, | |||||
'balanceSats', | 'balanceSats', | ||||
), | ), | ||||
}, | }, | ||||
}, | |||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: 'Returns false if balances in wallet.state', | description: 'Returns false if balances in wallet.state', | ||||
wallet: { | wallet: { | ||||
...validWallet, | ...cashtabWalletFromJSON(validWalletJson), | ||||
state: { ...validWallet.state, balances: {} }, | state: { | ||||
...cashtabWalletFromJSON(validWalletJson).state, | |||||
balances: {}, | |||||
}, | |||||
}, | }, | ||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: 'Returns false if balanceSats is not a number', | description: 'Returns false if balanceSats is not a number', | ||||
wallet: { | wallet: { | ||||
...validWallet, | ...cashtabWalletFromJSON(validWalletJson), | ||||
state: { ...validWallet.state, balanceSats: '100' }, | state: { | ||||
...validWalletJson.state, | |||||
balanceSats: '100', | |||||
tokens: new Map(), | |||||
}, | |||||
}, | }, | ||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: 'Returns false if no slpUtxos in wallet.state', | description: 'Returns false if no slpUtxos in wallet.state', | ||||
wallet: { | wallet: { | ||||
...validWallet, | ...cashtabWalletFromJSON(validWalletJson), | ||||
state: cloneObjectWithDeletedKey( | state: cloneObjectWithDeletedKey( | ||||
validWallet.state, | cashtabWalletFromJSON(validWalletJson).state, | ||||
'slpUtxos', | 'slpUtxos', | ||||
), | ), | ||||
}, | }, | ||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: 'Returns false if no nonSlpUtxos in wallet.state', | description: 'Returns false if no nonSlpUtxos in wallet.state', | ||||
wallet: { | wallet: { | ||||
...validWallet, | ...cashtabWalletFromJSON(validWalletJson), | ||||
state: cloneObjectWithDeletedKey( | state: cloneObjectWithDeletedKey( | ||||
validWallet.state, | cashtabWalletFromJSON(validWalletJson).state, | ||||
'nonSlpUtxos', | 'nonSlpUtxos', | ||||
), | ), | ||||
}, | }, | ||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: 'Returns false if no tokens in wallet.state', | description: 'Returns false if no tokens in wallet.state', | ||||
wallet: { | wallet: { | ||||
...validWallet, | ...cashtabWalletFromJSON(validWalletJson), | ||||
state: cloneObjectWithDeletedKey( | state: cloneObjectWithDeletedKey( | ||||
validWallet.state, | cashtabWalletFromJSON(validWalletJson).state, | ||||
'tokens', | 'tokens', | ||||
), | ), | ||||
}, | }, | ||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: | description: | ||||
'Returns false if hydratedUtxoDetails is in wallet.state', | 'Returns false if hydratedUtxoDetails is in wallet.state', | ||||
wallet: { | wallet: { | ||||
...validWallet, | ...cashtabWalletFromJSON(validWalletJson), | ||||
state: { ...validWallet.state, hydratedUtxoDetails: [] }, | state: { | ||||
...cashtabWalletFromJSON(validWalletJson).state, | |||||
hydratedUtxoDetails: [], | |||||
}, | |||||
}, | }, | ||||
returned: false, | returned: false, | ||||
}, | }, | ||||
{ | { | ||||
description: | description: | ||||
'Returns false if slpBalancesAndUtxos is in wallet.state', | 'Returns false if slpBalancesAndUtxos is in wallet.state', | ||||
wallet: { | wallet: { | ||||
...validWallet, | ...cashtabWalletFromJSON(validWalletJson), | ||||
state: { ...validWallet.state, slpBalancesAndUtxos: [] }, | state: { | ||||
...cashtabWalletFromJSON(validWalletJson).state, | |||||
slpBalancesAndUtxos: [], | |||||
}, | |||||
}, | }, | ||||
returned: false, | returned: false, | ||||
}, | }, | ||||
], | ], | ||||
}, | }, | ||||
isValidXecSendAmount: { | isValidXecSendAmount: { | ||||
expectedReturns: [ | expectedReturns: [ | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 283 Lines • Show Last 20 Lines |