1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

Consolidate selector tests (#8510)

This commit is contained in:
Erik Marks 2020-05-05 07:05:16 -07:00 committed by GitHub
parent 79d9209473
commit 0a584a3a0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 82 additions and 323 deletions

View File

@ -109,7 +109,7 @@
"chainId": "4",
"isEns": false,
"memo": "",
"name": ""
"name": "Address Book Account 1"
}
}
},

View File

@ -1,88 +0,0 @@
import assert from 'assert'
import * as selectors from '../../../../ui/app/selectors'
import mockState from '../../../data/mock-state.json'
describe('Selectors', function () {
describe('#getSelectedAddress', function () {
it('returns undefined if selectedAddress is undefined', function () {
assert.equal(selectors.getSelectedAddress({ metamask: {} }), undefined)
})
it('returns selectedAddress', function () {
const selectedAddress = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'
assert.equal(selectors.getSelectedAddress({ metamask: { selectedAddress } }), selectedAddress)
})
})
it('returns selected identity', function () {
assert.deepEqual(
selectors.getSelectedIdentity(mockState),
{
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
name: 'Test Account',
}
)
})
it('returns selected account', function () {
const account = selectors.getSelectedAccount(mockState)
assert.equal(account.balance, '0x0')
assert.equal(account.address, '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc')
})
it('returns selected token from first token list', function () {
const token = selectors.getSelectedToken(mockState)
assert.equal(token.address, '0x108cf70c7d384c552f42c07c41c0e1e46d77ea0d')
assert.equal(token.symbol, 'TEST')
assert.equal(token.decimals, '0')
})
describe('#getSelectedTokenExchangeRate', function () {
it('returns token exchange rate for first token', function () {
const tokenRate = selectors.getSelectedTokenExchangeRate(mockState)
assert.equal(tokenRate, '0.00039345803819379796')
})
})
it('returns conversionRate from state', function () {
assert.equal(selectors.conversionRateSelector(mockState), 556.12)
})
it('returns address book from state', function () {
const addressBook = selectors.getAddressBook(mockState)
assert.equal(addressBook[0].address, '0xc42edfcc21ed14dda456aa0756c153f7985d8813')
assert.equal(addressBook[0].name, '')
})
it('returns accounts with balance, address, and name from identity and accounts in state', function () {
const accountsWithSendEther = selectors.accountsWithSendEtherInfoSelector(mockState)
assert.equal(accountsWithSendEther.length, 2)
assert.equal(accountsWithSendEther[0].balance, '0x0')
assert.equal(accountsWithSendEther[0].address, '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc')
assert.equal(accountsWithSendEther[0].name, 'Test Account')
})
it('returns selected account with balance, address, and name from accountsWithSendEtherInfoSelector', function () {
const currentAccountwithSendEther = selectors.getCurrentAccountWithSendEtherInfo(mockState)
assert.equal(currentAccountwithSendEther.balance, '0x0')
assert.equal(currentAccountwithSendEther.address, '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc')
assert.equal(currentAccountwithSendEther.name, 'Test Account')
})
it('#getGasIsLoading', function () {
const gasIsLoading = selectors.getGasIsLoading(mockState)
assert.equal(gasIsLoading, false)
})
it('#getCurrentCurrency', function () {
const currentCurrency = selectors.getCurrentCurrency(mockState)
assert.equal(currentCurrency, 'usd')
})
it('#getTotalUnapprovedCount', function () {
const totalUnapprovedCount = selectors.getTotalUnapprovedCount(mockState)
assert.equal(totalUnapprovedCount, 1)
})
})

View File

@ -5,6 +5,7 @@ import {
approveTokenAmountAndToAddressSelector,
sendTokenTokenAmountAndToAddressSelector,
contractExchangeRateSelector,
conversionRateSelector,
} from '../confirm-transaction'
describe('Confirm Transaction Selector', function () {
@ -153,7 +154,14 @@ describe('Confirm Transaction Selector', function () {
it('returns contract exchange rate in metamask state based on confirm transaction txParams token recipient', function () {
assert.equal(contractExchangeRateSelector(state), 10)
})
})
describe('conversionRateSelector', function () {
it('returns conversionRate from state', function () {
const state = {
metamask: { conversionRate: 556.12 },
}
assert.equal(conversionRateSelector(state), 556.12)
})
})
})

View File

@ -1,226 +0,0 @@
export default {
'metamask': {
'isInitialized': true,
'isUnlocked': true,
'featureFlags': { 'sendHexData': true },
'rpcTarget': 'https://rawtestrpc.metamask.io/',
'identities': {
'0xfdea65c8e26263f6d9a1b5de9555d2931a33b825': {
'address': '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
'name': 'Send Account 1',
},
'0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb': {
'address': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
'name': 'Send Account 2',
},
'0x2f8d4a878cfa04a6e60d46362f5644deab66572d': {
'address': '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
'name': 'Send Account 3',
},
'0xd85a4b6a394794842887b8284293d69163007bbb': {
'address': '0xd85a4b6a394794842887b8284293d69163007bbb',
'name': 'Send Account 4',
},
},
'cachedBalances': {},
'currentBlockGasLimit': '0x4c1878',
'currentCurrency': 'USD',
'conversionRate': 1200.88200327,
'conversionDate': 1489013762,
'nativeCurrency': 'ETH',
'frequentRpcList': [],
'network': '3',
'accounts': {
'0xfdea65c8e26263f6d9a1b5de9555d2931a33b825': {
'code': '0x',
'balance': '0x47c9d71831c76efe',
'nonce': '0x1b',
'address': '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
},
'0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb': {
'code': '0x',
'balance': '0x37452b1315889f80',
'nonce': '0xa',
'address': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
},
'0x2f8d4a878cfa04a6e60d46362f5644deab66572d': {
'code': '0x',
'balance': '0x30c9d71831c76efe',
'nonce': '0x1c',
'address': '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
},
'0xd85a4b6a394794842887b8284293d69163007bbb': {
'code': '0x',
'balance': '0x0',
'nonce': '0x0',
'address': '0xd85a4b6a394794842887b8284293d69163007bbb',
},
},
'addressBook': {
'3': {
'0x06195827297c7a80a443b6894d3bdb8824b43896': {
'address': '0x06195827297c7a80a443b6894d3bdb8824b43896',
'chainId': '3',
'isEns': false,
'memo': '',
'name': 'Address Book Account 1',
},
},
},
'tokens': [
{
'address': '0x1a195821297c7a80a433b6894d3bdb8824b43896',
'decimals': 18,
'symbol': 'ABC',
},
{
'address': '0x8d6b81208414189a58339873ab429b6c47ab92d3',
'decimals': 4,
'symbol': 'DEF',
},
{
'address': '0xa42084c8d1d9a2198631988579bb36b48433a72b',
'decimals': 18,
'symbol': 'GHI',
},
],
'contractExchangeRates': {
'0x8d6b81208414189a58339873ab429b6c47ab92d3': 0.00039345803819379796,
'0xd8f6a2ffb0fc5952d16c9768b71cfd35b6399aa5': 0.00008189274407698049,
},
'transactions': {},
'currentNetworkTxList': [
{
'id': 'mockTokenTx1',
'txParams': {
'to': '0x8d6b81208414189a58339873ab429b6c47ab92d3',
},
'time': 1700000000000,
},
{
'id': 'mockTokenTx2',
'txParams': {
'to': '0xafaketokenaddress',
},
'time': 1600000000000,
},
{
'id': 'mockTokenTx3',
'txParams': {
'to': '0x8d6b81208414189a58339873ab429b6c47ab92d3',
},
'time': 1500000000000,
},
{
'id': 'mockEthTx1',
'txParams': {
'to': '0xd85a4b6a394794842887b8284293d69163007bbb',
},
'time': 1400000000000,
},
],
'selectedTokenAddress': '0x8d6b81208414189a58339873ab429b6c47ab92d3',
'unapprovedMsgs': {
'0xabc': { id: 'unapprovedMessage1', 'time': 1650000000000 },
'0xdef': { id: 'unapprovedMessage2', 'time': 1550000000000 },
'0xghi': { id: 'unapprovedMessage3', 'time': 1450000000000 },
},
'unapprovedMsgCount': 0,
'unapprovedPersonalMsgs': {},
'unapprovedPersonalMsgCount': 0,
'unapprovedDecryptMsgs': {},
'unapprovedDecryptMsgCount': 0,
'unapprovedEncryptionPublicKeyMsgs': {},
'unapprovedEncryptionPublicKeyMsgCount': 0,
'keyringTypes': [
'Simple Key Pair',
'HD Key Tree',
],
'keyrings': [
{
'type': 'HD Key Tree',
'accounts': [
'fdea65c8e26263f6d9a1b5de9555d2931a33b825',
'c5b8dbac4c1d3f152cdeb400e2313f309c410acb',
'2f8d4a878cfa04a6e60d46362f5644deab66572d',
],
},
{
'type': 'Simple Key Pair',
'accounts': [
'0xd85a4b6a394794842887b8284293d69163007bbb',
],
},
],
'selectedAddress': '0xd85a4b6a394794842887b8284293d69163007bbb',
'provider': {
'type': 'testnet',
},
'send': {
'gasLimit': '0xFFFF',
'gasPrice': '0xaa',
'gasTotal': '0xb451dc41b578',
'tokenBalance': 3434,
'from': {
'address': '0xabcdefg',
'balance': '0x5f4e3d2c1',
},
'to': '0x987fedabc',
'amount': '0x080',
'memo': '',
'errors': {
'someError': null,
},
'maxModeOn': false,
'editingTransactionId': 97531,
},
'unapprovedTxs': {
'4768706228115573': {
'id': 4768706228115573,
'time': 1487363153561,
'status': 'unapproved',
'gasMultiplier': 1,
'metamaskNetworkId': '3',
'txParams': {
'from': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
'to': '0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761',
'value': '0xde0b6b3a7640000',
'metamaskId': 4768706228115573,
'metamaskNetworkId': '3',
'gas': '0x5209',
},
'txFee': '17e0186e60800',
'txValue': 'de0b6b3a7640000',
'maxCost': 'de234b52e4a0800',
'gasPrice': '4a817c800',
},
},
'currentLocale': 'en',
recentBlocks: ['mockBlock1', 'mockBlock2', 'mockBlock3'],
},
'appState': {
'menuOpen': false,
'currentView': {
'name': 'accountDetail',
'detailView': null,
'context': '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
},
'accountDetail': {
'subview': 'transactions',
},
'modal': {
'modalState': {},
'previousModalState': {},
},
'isLoading': false,
'warning': null,
'scrollToBottom': false,
'forgottenPassword': null,
},
'identities': {},
'send': {
'fromDropdownOpen': false,
'toDropdownOpen': false,
'errors': { 'someError': null },
},
}

View File

@ -1,17 +1,52 @@
import assert from 'assert'
import { getAddressBook } from '../selectors'
import mockState from './selectors-test-data'
import * as selectors from '../selectors'
import mockState from '../../../../test/data/mock-state.json'
describe('selectors', function () {
describe('Selectors', function () {
describe('getAddressBook()', function () {
describe('#getSelectedAddress', function () {
it('returns undefined if selectedAddress is undefined', function () {
assert.equal(selectors.getSelectedAddress({ metamask: {} }), undefined)
})
it('returns selectedAddress', function () {
const selectedAddress = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'
assert.equal(selectors.getSelectedAddress({ metamask: { selectedAddress } }), selectedAddress)
})
})
it('returns selected identity', function () {
assert.deepEqual(
selectors.getSelectedIdentity(mockState),
{
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
name: 'Test Account',
}
)
})
it('returns selected account', function () {
const account = selectors.getSelectedAccount(mockState)
assert.equal(account.balance, '0x0')
assert.equal(account.address, '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc')
})
describe('#getSelectedTokenExchangeRate', function () {
it('returns token exchange rate for first token', function () {
const tokenRate = selectors.getSelectedTokenExchangeRate(mockState)
assert.equal(tokenRate, '0.00039345803819379796')
})
})
describe('#getAddressBook', function () {
it('should return the address book', function () {
assert.deepEqual(
getAddressBook(mockState),
selectors.getAddressBook(mockState),
[
{
'address': '0x06195827297c7a80a443b6894d3bdb8824b43896',
'chainId': '3',
'address': '0xc42edfcc21ed14dda456aa0756c153f7985d8813',
'chainId': '4',
'isEns': false,
'memo': '',
'name': 'Address Book Account 1',
@ -20,4 +55,34 @@ describe('selectors', function () {
)
})
})
it('returns accounts with balance, address, and name from identity and accounts in state', function () {
const accountsWithSendEther = selectors.accountsWithSendEtherInfoSelector(mockState)
assert.equal(accountsWithSendEther.length, 2)
assert.equal(accountsWithSendEther[0].balance, '0x0')
assert.equal(accountsWithSendEther[0].address, '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc')
assert.equal(accountsWithSendEther[0].name, 'Test Account')
})
it('returns selected account with balance, address, and name from accountsWithSendEtherInfoSelector', function () {
const currentAccountwithSendEther = selectors.getCurrentAccountWithSendEtherInfo(mockState)
assert.equal(currentAccountwithSendEther.balance, '0x0')
assert.equal(currentAccountwithSendEther.address, '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc')
assert.equal(currentAccountwithSendEther.name, 'Test Account')
})
it('#getGasIsLoading', function () {
const gasIsLoading = selectors.getGasIsLoading(mockState)
assert.equal(gasIsLoading, false)
})
it('#getCurrentCurrency', function () {
const currentCurrency = selectors.getCurrentCurrency(mockState)
assert.equal(currentCurrency, 'usd')
})
it('#getTotalUnapprovedCount', function () {
const totalUnapprovedCount = selectors.getTotalUnapprovedCount(mockState)
assert.equal(totalUnapprovedCount, 1)
})
})