2020-01-30 20:34:45 +01:00
|
|
|
import assert from 'assert'
|
|
|
|
import {
|
|
|
|
unapprovedMessagesSelector,
|
|
|
|
transactionsSelector,
|
|
|
|
nonceSortedTransactionsSelector,
|
|
|
|
nonceSortedPendingTransactionsSelector,
|
|
|
|
nonceSortedCompletedTransactionsSelector,
|
|
|
|
submittedPendingTransactionsSelector,
|
|
|
|
} from '../transactions'
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Transaction Selectors', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('unapprovedMessagesSelector', function () {
|
|
|
|
it('returns eth sign msg from unapprovedMsgs', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const msg = {
|
|
|
|
id: 1,
|
|
|
|
msgParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
data: '0xData',
|
|
|
|
origin: 'origin',
|
|
|
|
},
|
|
|
|
time: 1,
|
|
|
|
status: 'unapproved',
|
|
|
|
type: 'eth_sign',
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
unapprovedMsgs: {
|
|
|
|
1: msg,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const msgSelector = unapprovedMessagesSelector(state)
|
|
|
|
|
|
|
|
assert(Array.isArray(msgSelector))
|
|
|
|
assert.deepEqual(msgSelector, [msg])
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('returns personal sign from unapprovedPersonalMsgsSelector', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const msg = {
|
|
|
|
id: 1,
|
|
|
|
msgParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
data: '0xData',
|
|
|
|
origin: 'origin',
|
|
|
|
},
|
|
|
|
time: 1,
|
|
|
|
status: 'unapproved',
|
|
|
|
type: 'personal_sign',
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
unapprovedPersonalMsgs: {
|
|
|
|
1: msg,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const msgSelector = unapprovedMessagesSelector(state)
|
|
|
|
|
|
|
|
assert(Array.isArray(msgSelector))
|
|
|
|
assert.deepEqual(msgSelector, [msg])
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('returns typed message from unapprovedTypedMessagesSelector', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const msg = {
|
|
|
|
id: 1,
|
|
|
|
msgParams: {
|
|
|
|
data: '0xData',
|
|
|
|
from: '0xAddress',
|
|
|
|
version: 'V3',
|
|
|
|
origin: 'origin',
|
|
|
|
},
|
|
|
|
time: 1,
|
|
|
|
status: 'unapproved',
|
|
|
|
type: 'eth_signTypedData',
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
unapprovedTypedMessages: {
|
|
|
|
1: msg,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const msgSelector = unapprovedMessagesSelector(state)
|
|
|
|
|
|
|
|
assert(Array.isArray(msgSelector))
|
|
|
|
assert.deepEqual(msgSelector, [msg])
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('transactionsSelector', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('selectedAddressTxList', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
featureFlags: {
|
|
|
|
showIncomingTransactions: false,
|
|
|
|
},
|
|
|
|
selectedAddressTxList: [
|
|
|
|
{
|
|
|
|
id: 0,
|
|
|
|
time: 0,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
time: 1,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const orderedTxlist = state.metamask.selectedAddressTxList.sort((a, b) => b.time - a.time)
|
|
|
|
|
|
|
|
const txSelector = transactionsSelector(state)
|
|
|
|
|
|
|
|
assert(Array.isArray(txSelector))
|
|
|
|
assert.deepEqual(txSelector, orderedTxlist)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('returns token tx from selectedAddressTxList when selectedTokenAddress is valid', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
featureFlags: {
|
|
|
|
showIncomingTransactions: false,
|
|
|
|
},
|
|
|
|
selectedTokenAddress: '0xToken',
|
|
|
|
selectedAddressTxList: [
|
|
|
|
{
|
|
|
|
id: 0,
|
|
|
|
time: 0,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xToken',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
time: 1,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xToken',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const orderedTxlist = state.metamask.selectedAddressTxList.sort((a, b) => b.time - a.time)
|
|
|
|
|
|
|
|
const txSelector = transactionsSelector(state)
|
|
|
|
|
|
|
|
assert(Array.isArray(txSelector))
|
|
|
|
assert.deepEqual(txSelector, orderedTxlist)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('nonceSortedTransactionsSelector', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('returns transaction group nonce sorted tx from from selectedTxList wit', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const tx1 = {
|
|
|
|
id: 0,
|
|
|
|
time: 0,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x0',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const tx2 = {
|
|
|
|
id: 1,
|
|
|
|
time: 1,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x1',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
featureFlags: {
|
|
|
|
showIncomingTransactions: false,
|
|
|
|
},
|
|
|
|
selectedAddressTxList: [
|
|
|
|
tx1,
|
|
|
|
tx2,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const expectedResult = [
|
|
|
|
{
|
|
|
|
nonce: '0x0',
|
|
|
|
transactions: [ tx1 ],
|
|
|
|
initialTransaction: tx1,
|
|
|
|
primaryTransaction: tx1,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nonce: '0x1',
|
|
|
|
transactions: [ tx2 ],
|
|
|
|
initialTransaction: tx2,
|
|
|
|
primaryTransaction: tx2,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
assert.deepEqual(nonceSortedTransactionsSelector(state), expectedResult)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Sorting Transactions Selectors', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const submittedTx = {
|
|
|
|
id: 0,
|
|
|
|
time: 0,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x0',
|
|
|
|
},
|
|
|
|
status: 'submitted',
|
|
|
|
}
|
|
|
|
|
|
|
|
const unapprovedTx = {
|
|
|
|
id: 1,
|
|
|
|
time: 1,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x1',
|
|
|
|
},
|
|
|
|
status: 'unapproved',
|
|
|
|
}
|
|
|
|
|
|
|
|
const approvedTx = {
|
|
|
|
id: 2,
|
|
|
|
time: 2,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x2',
|
|
|
|
},
|
|
|
|
status: 'approved',
|
|
|
|
}
|
|
|
|
|
|
|
|
const confirmedTx = {
|
|
|
|
id: 3,
|
|
|
|
time: 3,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x3',
|
|
|
|
},
|
|
|
|
status: 'confirmed',
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
featureFlags: {
|
|
|
|
showIncomingTransactions: false,
|
|
|
|
},
|
|
|
|
selectedAddressTxList: [
|
|
|
|
submittedTx,
|
|
|
|
unapprovedTx,
|
|
|
|
approvedTx,
|
|
|
|
confirmedTx,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('nonceSortedPendingTransactionsSelector', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const expectedResult = [
|
|
|
|
{
|
|
|
|
nonce: submittedTx.txParams.nonce,
|
|
|
|
transactions: [ submittedTx ],
|
|
|
|
initialTransaction: submittedTx,
|
|
|
|
primaryTransaction: submittedTx,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nonce: unapprovedTx.txParams.nonce,
|
|
|
|
transactions: [ unapprovedTx ],
|
|
|
|
initialTransaction: unapprovedTx,
|
|
|
|
primaryTransaction: unapprovedTx,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nonce: approvedTx.txParams.nonce,
|
|
|
|
transactions: [ approvedTx ],
|
|
|
|
initialTransaction: approvedTx,
|
|
|
|
primaryTransaction: approvedTx,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
assert.deepEqual(nonceSortedPendingTransactionsSelector(state), expectedResult)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('nonceSortedCompletedTransactionsSelector', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const expectedResult = [
|
|
|
|
{
|
|
|
|
nonce: confirmedTx.txParams.nonce,
|
|
|
|
transactions: [ confirmedTx ],
|
|
|
|
initialTransaction: confirmedTx,
|
|
|
|
primaryTransaction: confirmedTx,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
assert.deepEqual(nonceSortedCompletedTransactionsSelector(state), expectedResult)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('submittedPendingTransactionsSelector', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const expectedResult = [ submittedTx ]
|
|
|
|
assert.deepEqual(submittedPendingTransactionsSelector(state), expectedResult)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|