mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-21 00:19:49 +00:00
12d29e5b94
* Fix #1569 * Use common component for handling "to" address * If to address becomes invalid, hide contract interact explorer * Add IS_CONTRACT_INTERACTION mode - fix bugs related to contract interact * Bump shepherd version to fix bugs related to metamask + network switches * Update mycrypto link downloads * Update facebook link * Remove console log from checktx * Fix dollar sign on contract address in conf modal * Fix unchecksummed address for metamask signing * Cleanup unused classname * Update generate keystore file description to be correct * Add space to create new wallet banner * Remove extra variable * Do checksumming in library function instead of component * Clear state on address change
123 lines
3.4 KiB
TypeScript
123 lines
3.4 KiB
TypeScript
import { TypeKeys } from 'actions/transaction/constants';
|
|
import { gasPriceToBase } from 'libs/units';
|
|
import { fields, State } from 'reducers/transaction/fields';
|
|
import * as txActions from 'actions/transaction';
|
|
import BN from 'bn.js';
|
|
|
|
describe('fields reducer', () => {
|
|
const INITIAL_STATE: State = {
|
|
to: { raw: '', value: null },
|
|
data: { raw: '', value: null },
|
|
nonce: { raw: '', value: null },
|
|
value: { raw: '', value: null },
|
|
gasLimit: { raw: '21000', value: new BN(21000) },
|
|
gasPrice: { raw: '20', value: gasPriceToBase(20) }
|
|
};
|
|
const testPayload = { raw: 'test', value: null };
|
|
|
|
it('should handle TO_FIELD_SET', () => {
|
|
expect(fields(INITIAL_STATE, txActions.setToField(testPayload))).toEqual({
|
|
...INITIAL_STATE,
|
|
to: testPayload
|
|
});
|
|
});
|
|
|
|
it('should handle VALUE_FIELD_SET', () => {
|
|
expect(fields(INITIAL_STATE, txActions.setValueField(testPayload))).toEqual({
|
|
...INITIAL_STATE,
|
|
value: testPayload
|
|
});
|
|
});
|
|
|
|
it('should handle DATA_FIELD_SET', () => {
|
|
expect(fields(INITIAL_STATE, txActions.setDataField(testPayload))).toEqual({
|
|
...INITIAL_STATE,
|
|
data: testPayload
|
|
});
|
|
});
|
|
|
|
it('should handle GAS_LIMIT_FIELD_SET', () => {
|
|
expect(fields(INITIAL_STATE, txActions.setGasLimitField(testPayload))).toEqual({
|
|
...INITIAL_STATE,
|
|
gasLimit: testPayload
|
|
});
|
|
});
|
|
|
|
it('should handle NONCE_SET', () => {
|
|
expect(fields(INITIAL_STATE, txActions.setNonceField(testPayload))).toEqual({
|
|
...INITIAL_STATE,
|
|
nonce: testPayload
|
|
});
|
|
});
|
|
|
|
it('should handle GAS_PRICE_FIELD_SET', () => {
|
|
expect(fields(INITIAL_STATE, txActions.setGasPriceField(testPayload))).toEqual({
|
|
...INITIAL_STATE,
|
|
gasPrice: testPayload
|
|
});
|
|
});
|
|
|
|
it('should handle TOKEN_TO_ETHER_SWAP', () => {
|
|
const swapAction: txActions.SwapTokenToEtherAction = {
|
|
type: TypeKeys.TOKEN_TO_ETHER_SWAP,
|
|
payload: {
|
|
to: testPayload,
|
|
value: testPayload,
|
|
decimal: 1
|
|
}
|
|
};
|
|
expect(fields(INITIAL_STATE, swapAction)).toEqual({
|
|
...INITIAL_STATE,
|
|
to: testPayload,
|
|
value: testPayload
|
|
});
|
|
});
|
|
|
|
it('should handle ETHER_TO_TOKEN_SWAP', () => {
|
|
const swapAction: txActions.SwapEtherToTokenAction = {
|
|
type: TypeKeys.ETHER_TO_TOKEN_SWAP,
|
|
payload: {
|
|
to: testPayload,
|
|
data: testPayload,
|
|
tokenTo: testPayload,
|
|
tokenValue: testPayload,
|
|
decimal: 1
|
|
}
|
|
};
|
|
expect(fields(INITIAL_STATE, swapAction)).toEqual({
|
|
...INITIAL_STATE,
|
|
to: testPayload,
|
|
data: testPayload
|
|
});
|
|
});
|
|
|
|
it('should handle TOKEN_TO_TOKEN_SWAP', () => {
|
|
const swapAction: txActions.SwapTokenToTokenAction = {
|
|
type: TypeKeys.TOKEN_TO_TOKEN_SWAP,
|
|
payload: {
|
|
to: testPayload,
|
|
data: testPayload,
|
|
tokenValue: testPayload,
|
|
decimal: 1
|
|
}
|
|
};
|
|
expect(fields(INITIAL_STATE, swapAction)).toEqual({
|
|
...INITIAL_STATE,
|
|
to: testPayload,
|
|
data: testPayload
|
|
});
|
|
});
|
|
|
|
it('should reset', () => {
|
|
const resetAction: txActions.ResetTransactionSuccessfulAction = {
|
|
type: TypeKeys.RESET_SUCCESSFUL,
|
|
payload: { isContractInteraction: false }
|
|
};
|
|
const modifiedState: State = {
|
|
...INITIAL_STATE,
|
|
data: { raw: 'modified', value: null }
|
|
};
|
|
expect(fields(modifiedState, resetAction)).toEqual(INITIAL_STATE);
|
|
});
|
|
});
|