2023-01-24 15:10:36 +01:00
|
|
|
import { BigNumber } from '@ethersproject/bignumber';
|
2022-07-01 15:58:35 +02:00
|
|
|
import { GAS_LIMITS } from '../../../shared/constants/gas';
|
|
|
|
import {
|
2023-01-18 15:47:29 +01:00
|
|
|
AssetType,
|
|
|
|
TokenStandard,
|
|
|
|
TransactionEnvelopeType,
|
2022-07-01 15:58:35 +02:00
|
|
|
} from '../../../shared/constants/transaction';
|
|
|
|
import { BURN_ADDRESS } from '../../../shared/modules/hexstring-utils';
|
|
|
|
import { getInitialSendStateWithExistingTxState } from '../../../test/jest/mocks';
|
|
|
|
import {
|
|
|
|
generateERC20TransferData,
|
|
|
|
generateERC721TransferData,
|
|
|
|
} from '../../pages/send/send.utils';
|
|
|
|
import { generateTransactionParams } from './helpers';
|
|
|
|
|
|
|
|
describe('Send Slice Helpers', () => {
|
|
|
|
describe('generateTransactionParams', () => {
|
|
|
|
it('should generate a txParams for a token transfer', () => {
|
|
|
|
const tokenDetails = {
|
|
|
|
address: '0xToken',
|
|
|
|
symbol: 'SYMB',
|
|
|
|
decimals: 18,
|
|
|
|
};
|
|
|
|
const txParams = generateTransactionParams(
|
|
|
|
getInitialSendStateWithExistingTxState({
|
|
|
|
fromAccount: {
|
|
|
|
address: '0x00',
|
|
|
|
},
|
|
|
|
amount: {
|
|
|
|
value: '0x1',
|
|
|
|
},
|
|
|
|
asset: {
|
2023-01-18 15:47:29 +01:00
|
|
|
type: AssetType.token,
|
2022-07-01 15:58:35 +02:00
|
|
|
balance: '0xaf',
|
|
|
|
details: tokenDetails,
|
|
|
|
},
|
|
|
|
recipient: {
|
|
|
|
address: BURN_ADDRESS,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
expect(txParams).toStrictEqual({
|
|
|
|
from: '0x00',
|
|
|
|
data: generateERC20TransferData({
|
|
|
|
toAddress: BURN_ADDRESS,
|
|
|
|
amount: '0x1',
|
|
|
|
sendToken: tokenDetails,
|
|
|
|
}),
|
|
|
|
to: '0xToken',
|
|
|
|
type: '0x0',
|
|
|
|
value: '0x0',
|
|
|
|
gas: '0x0',
|
|
|
|
gasPrice: '0x0',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
it('should generate a txParams for an NFT transfer', () => {
|
2022-07-01 15:58:35 +02:00
|
|
|
const txParams = generateTransactionParams(
|
|
|
|
getInitialSendStateWithExistingTxState({
|
|
|
|
fromAccount: {
|
|
|
|
address: '0x00',
|
|
|
|
},
|
|
|
|
amount: {
|
|
|
|
value: '0x1',
|
|
|
|
},
|
|
|
|
asset: {
|
2023-01-18 15:47:29 +01:00
|
|
|
type: AssetType.NFT,
|
2022-07-01 15:58:35 +02:00
|
|
|
balance: '0xaf',
|
|
|
|
details: {
|
|
|
|
address: '0xToken',
|
2023-01-18 15:47:29 +01:00
|
|
|
standard: TokenStandard.ERC721,
|
2023-01-24 15:10:36 +01:00
|
|
|
tokenId: BigNumber.from(15000).toString(),
|
2022-07-01 15:58:35 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
recipient: {
|
|
|
|
address: BURN_ADDRESS,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
expect(txParams).toStrictEqual({
|
|
|
|
from: '0x00',
|
|
|
|
data: generateERC721TransferData({
|
|
|
|
toAddress: BURN_ADDRESS,
|
|
|
|
fromAddress: '0x00',
|
2023-01-24 15:10:36 +01:00
|
|
|
tokenId: BigNumber.from(15000).toString(),
|
2022-07-01 15:58:35 +02:00
|
|
|
}),
|
|
|
|
to: '0xToken',
|
|
|
|
type: '0x0',
|
|
|
|
value: '0x0',
|
|
|
|
gas: '0x0',
|
|
|
|
gasPrice: '0x0',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should generate a txParams for a native legacy transaction', () => {
|
|
|
|
const txParams = generateTransactionParams(
|
|
|
|
getInitialSendStateWithExistingTxState({
|
|
|
|
fromAccount: {
|
|
|
|
address: '0x00',
|
|
|
|
},
|
|
|
|
amount: {
|
|
|
|
value: '0x1',
|
|
|
|
},
|
|
|
|
asset: {
|
2023-01-18 15:47:29 +01:00
|
|
|
type: AssetType.native,
|
2022-07-01 15:58:35 +02:00
|
|
|
balance: '0xaf',
|
|
|
|
details: null,
|
|
|
|
},
|
|
|
|
recipient: {
|
|
|
|
address: BURN_ADDRESS,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
expect(txParams).toStrictEqual({
|
|
|
|
from: '0x00',
|
|
|
|
data: undefined,
|
|
|
|
to: BURN_ADDRESS,
|
|
|
|
type: '0x0',
|
|
|
|
value: '0x1',
|
|
|
|
gas: '0x0',
|
|
|
|
gasPrice: '0x0',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should generate a txParams for a native fee market transaction', () => {
|
|
|
|
const txParams = generateTransactionParams({
|
|
|
|
...getInitialSendStateWithExistingTxState({
|
|
|
|
fromAccount: {
|
|
|
|
address: '0x00',
|
|
|
|
},
|
|
|
|
amount: {
|
|
|
|
value: '0x1',
|
|
|
|
},
|
|
|
|
asset: {
|
2023-01-18 15:47:29 +01:00
|
|
|
type: AssetType.native,
|
2022-07-01 15:58:35 +02:00
|
|
|
balance: '0xaf',
|
|
|
|
details: null,
|
|
|
|
},
|
|
|
|
recipient: {
|
|
|
|
address: BURN_ADDRESS,
|
|
|
|
},
|
|
|
|
gas: {
|
|
|
|
maxFeePerGas: '0x2',
|
|
|
|
maxPriorityFeePerGas: '0x1',
|
|
|
|
gasLimit: GAS_LIMITS.SIMPLE,
|
|
|
|
},
|
2023-01-18 15:47:29 +01:00
|
|
|
transactionType: TransactionEnvelopeType.feeMarket,
|
2022-07-01 15:58:35 +02:00
|
|
|
}),
|
|
|
|
eip1559support: true,
|
|
|
|
});
|
|
|
|
expect(txParams).toStrictEqual({
|
|
|
|
from: '0x00',
|
|
|
|
data: undefined,
|
|
|
|
to: BURN_ADDRESS,
|
|
|
|
type: '0x2',
|
|
|
|
value: '0x1',
|
|
|
|
gas: GAS_LIMITS.SIMPLE,
|
|
|
|
maxFeePerGas: '0x2',
|
|
|
|
maxPriorityFeePerGas: '0x1',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|