2020-03-06 22:34:56 +01:00
|
|
|
import { strict as assert } from 'assert'
|
2020-11-07 08:38:12 +01:00
|
|
|
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'
|
2020-01-30 20:34:45 +01:00
|
|
|
import {
|
|
|
|
unapprovedMessagesSelector,
|
|
|
|
transactionsSelector,
|
|
|
|
nonceSortedTransactionsSelector,
|
|
|
|
nonceSortedPendingTransactionsSelector,
|
|
|
|
nonceSortedCompletedTransactionsSelector,
|
|
|
|
submittedPendingTransactionsSelector,
|
|
|
|
} from '../transactions'
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Transaction Selectors', function () {
|
|
|
|
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,
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.UNAPPROVED,
|
2020-01-30 20:34:45 +01:00
|
|
|
type: 'eth_sign',
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
unapprovedMsgs: {
|
|
|
|
1: msg,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const msgSelector = unapprovedMessagesSelector(state)
|
|
|
|
|
|
|
|
assert(Array.isArray(msgSelector))
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(msgSelector, [msg])
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
|
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,
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.UNAPPROVED,
|
2020-01-30 20:34:45 +01:00
|
|
|
type: 'personal_sign',
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
unapprovedPersonalMsgs: {
|
|
|
|
1: msg,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const msgSelector = unapprovedMessagesSelector(state)
|
|
|
|
|
|
|
|
assert(Array.isArray(msgSelector))
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(msgSelector, [msg])
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
|
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,
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.UNAPPROVED,
|
2020-01-30 20:34:45 +01:00
|
|
|
type: 'eth_signTypedData',
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
unapprovedTypedMessages: {
|
|
|
|
1: msg,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const msgSelector = unapprovedMessagesSelector(state)
|
|
|
|
|
|
|
|
assert(Array.isArray(msgSelector))
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(msgSelector, [msg])
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('transactionsSelector', function () {
|
2020-03-06 22:34:56 +01:00
|
|
|
it('selects the currentNetworkTxList', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
const state = {
|
|
|
|
metamask: {
|
2020-02-26 18:34:46 +01:00
|
|
|
provider: {
|
|
|
|
nickname: 'mainnet',
|
|
|
|
},
|
2020-01-30 20:34:45 +01:00
|
|
|
featureFlags: {
|
|
|
|
showIncomingTransactions: false,
|
|
|
|
},
|
2020-03-06 22:34:56 +01:00
|
|
|
selectedAddress: '0xAddress',
|
|
|
|
currentNetworkTxList: [
|
2020-01-30 20:34:45 +01:00
|
|
|
{
|
|
|
|
id: 0,
|
|
|
|
time: 0,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
time: 1,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const orderedTxList = state.metamask.currentNetworkTxList.sort(
|
|
|
|
(a, b) => b.time - a.time,
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-03-06 22:34:56 +01:00
|
|
|
const selectedTx = transactionsSelector(state)
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-03-06 22:34:56 +01:00
|
|
|
assert(Array.isArray(selectedTx))
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(selectedTx, orderedTxList)
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('nonceSortedTransactionsSelector', function () {
|
|
|
|
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: {
|
2020-02-26 18:34:46 +01:00
|
|
|
provider: {
|
|
|
|
nickname: 'mainnet',
|
|
|
|
},
|
2020-03-06 22:34:56 +01:00
|
|
|
selectedAddress: '0xAddress',
|
2020-01-30 20:34:45 +01:00
|
|
|
featureFlags: {
|
|
|
|
showIncomingTransactions: false,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
currentNetworkTxList: [tx1, tx2],
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const expectedResult = [
|
|
|
|
{
|
|
|
|
nonce: '0x0',
|
2020-08-19 18:27:05 +02:00
|
|
|
transactions: [tx1],
|
2020-01-30 20:34:45 +01:00
|
|
|
initialTransaction: tx1,
|
|
|
|
primaryTransaction: tx1,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nonce: '0x1',
|
2020-08-19 18:27:05 +02:00
|
|
|
transactions: [tx2],
|
2020-01-30 20:34:45 +01:00
|
|
|
initialTransaction: tx2,
|
|
|
|
primaryTransaction: tx2,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
nonceSortedTransactionsSelector(state),
|
|
|
|
expectedResult,
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
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',
|
|
|
|
},
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.SUBMITTED,
|
2020-01-30 20:34:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const unapprovedTx = {
|
|
|
|
id: 1,
|
|
|
|
time: 1,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x1',
|
|
|
|
},
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.UNAPPROVED,
|
2020-01-30 20:34:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const approvedTx = {
|
|
|
|
id: 2,
|
|
|
|
time: 2,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x2',
|
|
|
|
},
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.APPROVED,
|
2020-01-30 20:34:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const confirmedTx = {
|
|
|
|
id: 3,
|
|
|
|
time: 3,
|
|
|
|
txParams: {
|
|
|
|
from: '0xAddress',
|
|
|
|
to: '0xRecipient',
|
|
|
|
nonce: '0x3',
|
|
|
|
},
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
2020-01-30 20:34:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
2020-02-26 18:34:46 +01:00
|
|
|
provider: {
|
|
|
|
nickname: 'mainnet',
|
|
|
|
},
|
2020-03-06 22:34:56 +01:00
|
|
|
selectedAddress: '0xAddress',
|
2020-01-30 20:34:45 +01:00
|
|
|
featureFlags: {
|
|
|
|
showIncomingTransactions: false,
|
|
|
|
},
|
2020-03-06 22:34:56 +01:00
|
|
|
currentNetworkTxList: [
|
2020-01-30 20:34:45 +01:00
|
|
|
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,
|
2020-08-19 18:27:05 +02:00
|
|
|
transactions: [submittedTx],
|
2020-01-30 20:34:45 +01:00
|
|
|
initialTransaction: submittedTx,
|
|
|
|
primaryTransaction: submittedTx,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nonce: unapprovedTx.txParams.nonce,
|
2020-08-19 18:27:05 +02:00
|
|
|
transactions: [unapprovedTx],
|
2020-01-30 20:34:45 +01:00
|
|
|
initialTransaction: unapprovedTx,
|
|
|
|
primaryTransaction: unapprovedTx,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nonce: approvedTx.txParams.nonce,
|
2020-08-19 18:27:05 +02:00
|
|
|
transactions: [approvedTx],
|
2020-01-30 20:34:45 +01:00
|
|
|
initialTransaction: approvedTx,
|
|
|
|
primaryTransaction: approvedTx,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
nonceSortedPendingTransactionsSelector(state),
|
|
|
|
expectedResult,
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
|
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,
|
2020-08-19 18:27:05 +02:00
|
|
|
transactions: [confirmedTx],
|
2020-01-30 20:34:45 +01:00
|
|
|
initialTransaction: confirmedTx,
|
|
|
|
primaryTransaction: confirmedTx,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
nonceSortedCompletedTransactionsSelector(state),
|
|
|
|
expectedResult,
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('submittedPendingTransactionsSelector', function () {
|
2020-08-19 18:27:05 +02:00
|
|
|
const expectedResult = [submittedTx]
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
submittedPendingTransactionsSelector(state),
|
|
|
|
expectedResult,
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|