You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
216 lines
5.6 KiB
216 lines
5.6 KiB
4 years ago
|
import { addHexPrefixToObjectValues } from '../../../helpers/utils/util';
|
||
4 years ago
|
import { TOKEN_TRANSFER_FUNCTION_SIGNATURE } from '../send.constants';
|
||
7 years ago
|
|
||
4 years ago
|
import {
|
||
|
addressIsNew,
|
||
|
constructTxParams,
|
||
|
constructUpdatedTx,
|
||
|
} from './send-footer.utils';
|
||
|
|
||
|
jest.mock('ethereumjs-abi', () => ({
|
||
|
rawEncode: jest.fn((arr1, arr2) => {
|
||
4 years ago
|
return [...arr1, ...arr2];
|
||
7 years ago
|
}),
|
||
4 years ago
|
}));
|
||
7 years ago
|
|
||
4 years ago
|
describe('send-footer utils', () => {
|
||
|
describe('addHexPrefixToObjectValues()', () => {
|
||
|
it('should return a new object with the same properties with a 0x prefix', () => {
|
||
|
expect(
|
||
|
addHexPrefixToObjectValues({
|
||
|
prop1: '0x123',
|
||
|
prop2: '456',
|
||
|
prop3: 'x',
|
||
|
}),
|
||
|
).toStrictEqual({
|
||
|
prop1: '0x123',
|
||
|
prop2: '0x456',
|
||
|
prop3: '0xx',
|
||
|
});
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('addressIsNew()', () => {
|
||
|
it('should return false if the address exists in toAccounts', () => {
|
||
|
expect(
|
||
4 years ago
|
addressIsNew(
|
||
|
[{ address: '0xabc' }, { address: '0xdef' }, { address: '0xghi' }],
|
||
|
'0xdef',
|
||
|
),
|
||
4 years ago
|
).toStrictEqual(false);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should return true if the address does not exists in toAccounts', () => {
|
||
|
expect(
|
||
4 years ago
|
addressIsNew(
|
||
|
[{ address: '0xabc' }, { address: '0xdef' }, { address: '0xghi' }],
|
||
|
'0xxyz',
|
||
|
),
|
||
4 years ago
|
).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('constructTxParams()', () => {
|
||
|
it('should return a new txParams object with data if there data is given', () => {
|
||
|
expect(
|
||
6 years ago
|
constructTxParams({
|
||
|
data: 'someData',
|
||
5 years ago
|
sendToken: undefined,
|
||
6 years ago
|
to: 'mockTo',
|
||
|
amount: 'mockAmount',
|
||
|
from: 'mockFrom',
|
||
|
gas: 'mockGas',
|
||
|
gasPrice: 'mockGasPrice',
|
||
|
}),
|
||
4 years ago
|
).toStrictEqual({
|
||
|
data: '0xsomeData',
|
||
|
to: '0xmockTo',
|
||
|
value: '0xmockAmount',
|
||
|
from: '0xmockFrom',
|
||
|
gas: '0xmockGas',
|
||
|
gasPrice: '0xmockGasPrice',
|
||
|
});
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should return a new txParams object with value and to properties if there is no sendToken', () => {
|
||
|
expect(
|
||
7 years ago
|
constructTxParams({
|
||
5 years ago
|
sendToken: undefined,
|
||
7 years ago
|
to: 'mockTo',
|
||
|
amount: 'mockAmount',
|
||
|
from: 'mockFrom',
|
||
|
gas: 'mockGas',
|
||
|
gasPrice: 'mockGasPrice',
|
||
|
}),
|
||
4 years ago
|
).toStrictEqual({
|
||
|
data: undefined,
|
||
|
to: '0xmockTo',
|
||
|
value: '0xmockAmount',
|
||
|
from: '0xmockFrom',
|
||
|
gas: '0xmockGas',
|
||
|
gasPrice: '0xmockGasPrice',
|
||
|
});
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should return a new txParams object without a to property and a 0 value if there is a sendToken', () => {
|
||
|
expect(
|
||
7 years ago
|
constructTxParams({
|
||
5 years ago
|
sendToken: { address: '0x0' },
|
||
7 years ago
|
to: 'mockTo',
|
||
|
amount: 'mockAmount',
|
||
|
from: 'mockFrom',
|
||
|
gas: 'mockGas',
|
||
|
gasPrice: 'mockGasPrice',
|
||
|
}),
|
||
4 years ago
|
).toStrictEqual({
|
||
|
data: undefined,
|
||
|
value: '0x0',
|
||
|
from: '0xmockFrom',
|
||
|
gas: '0xmockGas',
|
||
|
gasPrice: '0xmockGasPrice',
|
||
|
});
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('constructUpdatedTx()', () => {
|
||
|
it('should return a new object with an updated txParams', () => {
|
||
7 years ago
|
const result = constructUpdatedTx({
|
||
|
amount: 'mockAmount',
|
||
|
editingTransactionId: '0x456',
|
||
|
from: 'mockFrom',
|
||
|
gas: 'mockGas',
|
||
|
gasPrice: 'mockGasPrice',
|
||
5 years ago
|
sendToken: false,
|
||
7 years ago
|
to: 'mockTo',
|
||
|
unapprovedTxs: {
|
||
|
'0x123': {},
|
||
|
'0x456': {
|
||
|
unapprovedTxParam: 'someOtherParam',
|
||
|
txParams: {
|
||
|
data: 'someData',
|
||
|
},
|
||
|
},
|
||
|
},
|
||
4 years ago
|
});
|
||
4 years ago
|
expect(result).toStrictEqual({
|
||
7 years ago
|
unapprovedTxParam: 'someOtherParam',
|
||
|
txParams: {
|
||
|
from: '0xmockFrom',
|
||
|
gas: '0xmockGas',
|
||
|
gasPrice: '0xmockGasPrice',
|
||
|
value: '0xmockAmount',
|
||
|
to: '0xmockTo',
|
||
|
data: '0xsomeData',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should not have data property if there is non in the original tx', () => {
|
||
7 years ago
|
const result = constructUpdatedTx({
|
||
|
amount: 'mockAmount',
|
||
|
editingTransactionId: '0x456',
|
||
|
from: 'mockFrom',
|
||
|
gas: 'mockGas',
|
||
|
gasPrice: 'mockGasPrice',
|
||
5 years ago
|
sendToken: false,
|
||
7 years ago
|
to: 'mockTo',
|
||
|
unapprovedTxs: {
|
||
|
'0x123': {},
|
||
|
'0x456': {
|
||
|
unapprovedTxParam: 'someOtherParam',
|
||
|
txParams: {
|
||
|
from: 'oldFrom',
|
||
|
gas: 'oldGas',
|
||
|
gasPrice: 'oldGasPrice',
|
||
|
},
|
||
|
},
|
||
|
},
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
expect(result).toStrictEqual({
|
||
7 years ago
|
unapprovedTxParam: 'someOtherParam',
|
||
|
txParams: {
|
||
|
from: '0xmockFrom',
|
||
|
gas: '0xmockGas',
|
||
|
gasPrice: '0xmockGasPrice',
|
||
|
value: '0xmockAmount',
|
||
|
to: '0xmockTo',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should have token property values if sendToken is truthy', () => {
|
||
7 years ago
|
const result = constructUpdatedTx({
|
||
|
amount: 'mockAmount',
|
||
|
editingTransactionId: '0x456',
|
||
|
from: 'mockFrom',
|
||
|
gas: 'mockGas',
|
||
|
gasPrice: 'mockGasPrice',
|
||
5 years ago
|
sendToken: {
|
||
7 years ago
|
address: 'mockTokenAddress',
|
||
|
},
|
||
|
to: 'mockTo',
|
||
|
unapprovedTxs: {
|
||
|
'0x123': {},
|
||
|
'0x456': {
|
||
|
unapprovedTxParam: 'someOtherParam',
|
||
|
txParams: {},
|
||
|
},
|
||
|
},
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
expect(result).toStrictEqual({
|
||
7 years ago
|
unapprovedTxParam: 'someOtherParam',
|
||
|
txParams: {
|
||
|
from: '0xmockFrom',
|
||
|
gas: '0xmockGas',
|
||
|
gasPrice: '0xmockGasPrice',
|
||
|
value: '0x0',
|
||
|
to: '0xmockTokenAddress',
|
||
|
data: `${TOKEN_TRANSFER_FUNCTION_SIGNATURE}ss56Tont`,
|
||
|
},
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|