2021-02-12 16:25:58 +01:00
|
|
|
import { isPrefixedFormattedHexString } from '../../../shared/modules/network.utils';
|
2020-01-09 04:34:58 +01:00
|
|
|
import {
|
Close window after opening fullscreen (#6966)
* Add background environment type
The `getEnvironmentType` method now checks for the background
environment as well, instead of returning 'notification' for that case.
Instead of adding another regex for the background path, the regexes
for each environment have been replaced with the URL constructor[0].
This is the standard method of parsing URLs, and is available in all
supported browsers.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/URL
* Add note regarding a missing manifest permission
The `url` parameter to `tabs.query(...)` requires the `tabs` permission,
and will be ignored otherwise. We are missing this permission, so that
call does not work.
* Close window after opening full screen
The browser behaviour when opening a new tab differs between Chrome and
Firefox. In the case of a popup, Chrome will close the popup whereas
Firefox will leave it open. In the case of the notification window,
Chrome will move the new tab to the foreground, whereas Firefox will
leave the notification window in the foreground when opening a new tab.
We always want to close the current UI (popup or notification) when
switching to a full-screen view. The only exception to this is when the
switch is triggered from the background, which has no UI.
Closes #6513, #6685
2019-08-08 16:50:32 +02:00
|
|
|
ENVIRONMENT_TYPE_POPUP,
|
|
|
|
ENVIRONMENT_TYPE_NOTIFICATION,
|
|
|
|
ENVIRONMENT_TYPE_FULLSCREEN,
|
|
|
|
ENVIRONMENT_TYPE_BACKGROUND,
|
2021-11-06 01:28:44 +01:00
|
|
|
PLATFORM_FIREFOX,
|
|
|
|
PLATFORM_OPERA,
|
|
|
|
PLATFORM_CHROME,
|
|
|
|
PLATFORM_EDGE,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../shared/constants/app';
|
2023-01-06 18:14:50 +01:00
|
|
|
import {
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionStatus,
|
|
|
|
TransactionType,
|
|
|
|
TransactionEnvelopeType,
|
2023-01-06 18:14:50 +01:00
|
|
|
} from '../../../shared/constants/transaction';
|
|
|
|
import {
|
|
|
|
deferredPromise,
|
|
|
|
getEnvironmentType,
|
|
|
|
getPlatform,
|
|
|
|
formatTxMetaForRpcResult,
|
|
|
|
} from './util';
|
2017-08-04 20:36:27 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
describe('app utils', () => {
|
|
|
|
describe('getEnvironmentType', () => {
|
|
|
|
it('should return popup type', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/popup.html',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(environmentType).toStrictEqual(ENVIRONMENT_TYPE_POPUP);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
Close window after opening fullscreen (#6966)
* Add background environment type
The `getEnvironmentType` method now checks for the background
environment as well, instead of returning 'notification' for that case.
Instead of adding another regex for the background path, the regexes
for each environment have been replaced with the URL constructor[0].
This is the standard method of parsing URLs, and is available in all
supported browsers.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/URL
* Add note regarding a missing manifest permission
The `url` parameter to `tabs.query(...)` requires the `tabs` permission,
and will be ignored otherwise. We are missing this permission, so that
call does not work.
* Close window after opening full screen
The browser behaviour when opening a new tab differs between Chrome and
Firefox. In the case of a popup, Chrome will close the popup whereas
Firefox will leave it open. In the case of the notification window,
Chrome will move the new tab to the foreground, whereas Firefox will
leave the notification window in the foreground when opening a new tab.
We always want to close the current UI (popup or notification) when
switching to a full-screen view. The only exception to this is when the
switch is triggered from the background, which has no UI.
Closes #6513, #6685
2019-08-08 16:50:32 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should return notification type', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/notification.html',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(environmentType).toStrictEqual(ENVIRONMENT_TYPE_NOTIFICATION);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
Close window after opening fullscreen (#6966)
* Add background environment type
The `getEnvironmentType` method now checks for the background
environment as well, instead of returning 'notification' for that case.
Instead of adding another regex for the background path, the regexes
for each environment have been replaced with the URL constructor[0].
This is the standard method of parsing URLs, and is available in all
supported browsers.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/URL
* Add note regarding a missing manifest permission
The `url` parameter to `tabs.query(...)` requires the `tabs` permission,
and will be ignored otherwise. We are missing this permission, so that
call does not work.
* Close window after opening full screen
The browser behaviour when opening a new tab differs between Chrome and
Firefox. In the case of a popup, Chrome will close the popup whereas
Firefox will leave it open. In the case of the notification window,
Chrome will move the new tab to the foreground, whereas Firefox will
leave the notification window in the foreground when opening a new tab.
We always want to close the current UI (popup or notification) when
switching to a full-screen view. The only exception to this is when the
switch is triggered from the background, which has no UI.
Closes #6513, #6685
2019-08-08 16:50:32 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should return fullscreen type for home.html', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/home.html',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(environmentType).toStrictEqual(ENVIRONMENT_TYPE_FULLSCREEN);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
Close window after opening fullscreen (#6966)
* Add background environment type
The `getEnvironmentType` method now checks for the background
environment as well, instead of returning 'notification' for that case.
Instead of adding another regex for the background path, the regexes
for each environment have been replaced with the URL constructor[0].
This is the standard method of parsing URLs, and is available in all
supported browsers.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/URL
* Add note regarding a missing manifest permission
The `url` parameter to `tabs.query(...)` requires the `tabs` permission,
and will be ignored otherwise. We are missing this permission, so that
call does not work.
* Close window after opening full screen
The browser behaviour when opening a new tab differs between Chrome and
Firefox. In the case of a popup, Chrome will close the popup whereas
Firefox will leave it open. In the case of the notification window,
Chrome will move the new tab to the foreground, whereas Firefox will
leave the notification window in the foreground when opening a new tab.
We always want to close the current UI (popup or notification) when
switching to a full-screen view. The only exception to this is when the
switch is triggered from the background, which has no UI.
Closes #6513, #6685
2019-08-08 16:50:32 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should return background type', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/_generated_background_page.html',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(environmentType).toStrictEqual(ENVIRONMENT_TYPE_BACKGROUND);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
Close window after opening fullscreen (#6966)
* Add background environment type
The `getEnvironmentType` method now checks for the background
environment as well, instead of returning 'notification' for that case.
Instead of adding another regex for the background path, the regexes
for each environment have been replaced with the URL constructor[0].
This is the standard method of parsing URLs, and is available in all
supported browsers.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/URL
* Add note regarding a missing manifest permission
The `url` parameter to `tabs.query(...)` requires the `tabs` permission,
and will be ignored otherwise. We are missing this permission, so that
call does not work.
* Close window after opening full screen
The browser behaviour when opening a new tab differs between Chrome and
Firefox. In the case of a popup, Chrome will close the popup whereas
Firefox will leave it open. In the case of the notification window,
Chrome will move the new tab to the foreground, whereas Firefox will
leave the notification window in the foreground when opening a new tab.
We always want to close the current UI (popup or notification) when
switching to a full-screen view. The only exception to this is when the
switch is triggered from the background, which has no UI.
Closes #6513, #6685
2019-08-08 16:50:32 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should return the correct type for a URL with a hash fragment', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/popup.html#hash',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(environmentType).toStrictEqual(ENVIRONMENT_TYPE_POPUP);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
Close window after opening fullscreen (#6966)
* Add background environment type
The `getEnvironmentType` method now checks for the background
environment as well, instead of returning 'notification' for that case.
Instead of adding another regex for the background path, the regexes
for each environment have been replaced with the URL constructor[0].
This is the standard method of parsing URLs, and is available in all
supported browsers.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/URL
* Add note regarding a missing manifest permission
The `url` parameter to `tabs.query(...)` requires the `tabs` permission,
and will be ignored otherwise. We are missing this permission, so that
call does not work.
* Close window after opening full screen
The browser behaviour when opening a new tab differs between Chrome and
Firefox. In the case of a popup, Chrome will close the popup whereas
Firefox will leave it open. In the case of the notification window,
Chrome will move the new tab to the foreground, whereas Firefox will
leave the notification window in the foreground when opening a new tab.
We always want to close the current UI (popup or notification) when
switching to a full-screen view. The only exception to this is when the
switch is triggered from the background, which has no UI.
Closes #6513, #6685
2019-08-08 16:50:32 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should return the correct type for a URL with query parameters', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/popup.html?param=foo',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(environmentType).toStrictEqual(ENVIRONMENT_TYPE_POPUP);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
Close window after opening fullscreen (#6966)
* Add background environment type
The `getEnvironmentType` method now checks for the background
environment as well, instead of returning 'notification' for that case.
Instead of adding another regex for the background path, the regexes
for each environment have been replaced with the URL constructor[0].
This is the standard method of parsing URLs, and is available in all
supported browsers.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/URL
* Add note regarding a missing manifest permission
The `url` parameter to `tabs.query(...)` requires the `tabs` permission,
and will be ignored otherwise. We are missing this permission, so that
call does not work.
* Close window after opening full screen
The browser behaviour when opening a new tab differs between Chrome and
Firefox. In the case of a popup, Chrome will close the popup whereas
Firefox will leave it open. In the case of the notification window,
Chrome will move the new tab to the foreground, whereas Firefox will
leave the notification window in the foreground when opening a new tab.
We always want to close the current UI (popup or notification) when
switching to a full-screen view. The only exception to this is when the
switch is triggered from the background, which has no UI.
Closes #6513, #6685
2019-08-08 16:50:32 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should return the correct type for a URL with query parameters and a hash fragment', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/popup.html?param=foo#hash',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(environmentType).toStrictEqual(ENVIRONMENT_TYPE_POPUP);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2017-08-04 20:36:27 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
describe('isPrefixedFormattedHexString', () => {
|
|
|
|
it('should return true for valid hex strings', () => {
|
|
|
|
expect(isPrefixedFormattedHexString('0x1')).toStrictEqual(true);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString('0xa')).toStrictEqual(true);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(
|
2020-11-03 00:41:28 +01:00
|
|
|
isPrefixedFormattedHexString('0xabcd1123fae909aad87452'),
|
2021-12-06 17:40:39 +01:00
|
|
|
).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should return false for invalid hex strings', () => {
|
|
|
|
expect(isPrefixedFormattedHexString('0x')).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString('0x0')).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString('0x01')).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString(' 0x1')).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString('0x1 ')).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString('0x1afz')).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString('z')).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString(2)).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString(['0x1'])).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString()).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2021-11-06 01:28:44 +01:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
describe('getPlatform', () => {
|
|
|
|
let userAgent, setBrowserSpecificWindow;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
userAgent = jest.spyOn(window.navigator, 'userAgent', 'get');
|
|
|
|
|
|
|
|
setBrowserSpecificWindow = (browser) => {
|
|
|
|
switch (browser) {
|
|
|
|
case 'firefox': {
|
|
|
|
userAgent.mockReturnValue(
|
2021-11-06 01:28:44 +01:00
|
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0',
|
2021-12-06 17:40:39 +01:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'edge': {
|
|
|
|
userAgent.mockReturnValue(
|
2021-11-06 01:28:44 +01:00
|
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Edg/95.0.1020.30',
|
2021-12-06 17:40:39 +01:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'opera': {
|
|
|
|
userAgent.mockReturnValue(
|
2021-11-06 01:28:44 +01:00
|
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36 OPR/80.0.4170.63',
|
2021-12-06 17:40:39 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
userAgent.mockReturnValue(
|
2021-11-06 01:28:44 +01:00
|
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36',
|
2021-12-06 17:40:39 +01:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2021-11-06 01:28:44 +01:00
|
|
|
}
|
2021-12-06 17:40:39 +01:00
|
|
|
};
|
|
|
|
});
|
2021-11-06 01:28:44 +01:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should detect Firefox', () => {
|
2021-11-06 01:28:44 +01:00
|
|
|
setBrowserSpecificWindow('firefox');
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(getPlatform()).toStrictEqual(PLATFORM_FIREFOX);
|
2021-11-06 01:28:44 +01:00
|
|
|
});
|
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should detect Edge', () => {
|
2021-11-06 01:28:44 +01:00
|
|
|
setBrowserSpecificWindow('edge');
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(getPlatform()).toStrictEqual(PLATFORM_EDGE);
|
2021-11-06 01:28:44 +01:00
|
|
|
});
|
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should detect Opera', () => {
|
2021-11-06 01:28:44 +01:00
|
|
|
setBrowserSpecificWindow('opera');
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(getPlatform()).toStrictEqual(PLATFORM_OPERA);
|
2021-11-06 01:28:44 +01:00
|
|
|
});
|
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should detect Chrome', () => {
|
2021-11-06 01:28:44 +01:00
|
|
|
setBrowserSpecificWindow('chrome');
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(getPlatform()).toStrictEqual(PLATFORM_CHROME);
|
2021-11-06 01:28:44 +01:00
|
|
|
});
|
|
|
|
});
|
2022-11-24 14:32:05 +01:00
|
|
|
|
|
|
|
describe('deferredPromise', () => {
|
|
|
|
it('should allow rejecting a deferred Promise', async () => {
|
|
|
|
const { promise, reject } = deferredPromise();
|
|
|
|
|
|
|
|
reject(new Error('test'));
|
|
|
|
|
|
|
|
await expect(promise).rejects.toThrow('test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow resolving a deferred Promise', async () => {
|
|
|
|
const { promise, resolve } = deferredPromise();
|
|
|
|
|
|
|
|
resolve('test');
|
|
|
|
|
|
|
|
await expect(promise).resolves.toBe('test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should still be rejected after reject is called twice', async () => {
|
|
|
|
const { promise, reject } = deferredPromise();
|
|
|
|
|
|
|
|
reject(new Error('test'));
|
|
|
|
reject(new Error('different message'));
|
|
|
|
|
|
|
|
await expect(promise).rejects.toThrow('test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should still be rejected after resolve is called post-rejection', async () => {
|
|
|
|
const { promise, resolve, reject } = deferredPromise();
|
|
|
|
|
|
|
|
reject(new Error('test'));
|
|
|
|
resolve('different message');
|
|
|
|
|
|
|
|
await expect(promise).rejects.toThrow('test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should still be resolved after resolve is called twice', async () => {
|
|
|
|
const { promise, resolve } = deferredPromise();
|
|
|
|
|
|
|
|
resolve('test');
|
|
|
|
resolve('different message');
|
|
|
|
|
|
|
|
await expect(promise).resolves.toBe('test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should still be resolved after reject is called post-resolution', async () => {
|
|
|
|
const { promise, resolve, reject } = deferredPromise();
|
|
|
|
|
|
|
|
resolve('test');
|
|
|
|
reject(new Error('different message'));
|
|
|
|
|
|
|
|
await expect(promise).resolves.toBe('test');
|
|
|
|
});
|
|
|
|
});
|
2023-01-06 18:14:50 +01:00
|
|
|
|
|
|
|
describe('formatTxMetaForRpcResult', () => {
|
|
|
|
it('should correctly format the tx meta object (EIP-1559)', () => {
|
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2023-01-06 18:14:50 +01:00
|
|
|
txParams: {
|
|
|
|
from: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
|
|
|
to: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
maxFeePerGas: '0x77359400',
|
|
|
|
maxPriorityFeePerGas: '0x77359400',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
nonce: '0x4b',
|
|
|
|
},
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.simpleSend,
|
2023-01-06 18:14:50 +01:00
|
|
|
origin: 'other',
|
|
|
|
chainId: '0x5',
|
|
|
|
time: 1624408066355,
|
|
|
|
metamaskNetworkId: '5',
|
|
|
|
hash: '0x4bcb6cd6b182209585f8ad140260ddb35c81a575dd40f508d9767e652a9f60e7',
|
|
|
|
r: '0x4c3111e42ed5eec3dcecba1e234700f387e8693c373c61c3e54a762a26f1570e',
|
|
|
|
s: '0x18bfc4eeb7ebcfacc3bd59ea100a6834ea3265e65945dbec69aa2a06564fafff',
|
|
|
|
v: '0x29',
|
|
|
|
};
|
|
|
|
const expectedResult = {
|
|
|
|
accessList: null,
|
|
|
|
blockHash: null,
|
|
|
|
blockNumber: null,
|
|
|
|
from: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
gasPrice: '0x77359400',
|
|
|
|
hash: '0x4bcb6cd6b182209585f8ad140260ddb35c81a575dd40f508d9767e652a9f60e7',
|
|
|
|
input: '0x',
|
|
|
|
maxFeePerGas: '0x77359400',
|
|
|
|
maxPriorityFeePerGas: '0x77359400',
|
|
|
|
nonce: '0x4b',
|
|
|
|
r: '0x4c3111e42ed5eec3dcecba1e234700f387e8693c373c61c3e54a762a26f1570e',
|
|
|
|
s: '0x18bfc4eeb7ebcfacc3bd59ea100a6834ea3265e65945dbec69aa2a06564fafff',
|
|
|
|
to: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
transactionIndex: null,
|
|
|
|
type: '0x2',
|
|
|
|
v: '0x29',
|
|
|
|
value: '0x0',
|
|
|
|
};
|
|
|
|
const result = formatTxMetaForRpcResult(txMeta);
|
|
|
|
expect(result).toStrictEqual(expectedResult);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly format the tx meta object (non EIP-1559)', () => {
|
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
2023-01-18 15:47:29 +01:00
|
|
|
status: TransactionStatus.unapproved,
|
2023-01-06 18:14:50 +01:00
|
|
|
txParams: {
|
|
|
|
from: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
|
|
|
to: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
gasPrice: '0x77359400',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
nonce: '0x4b',
|
|
|
|
},
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionType.simpleSend,
|
2023-01-06 18:14:50 +01:00
|
|
|
origin: 'other',
|
|
|
|
chainId: '0x5',
|
|
|
|
time: 1624408066355,
|
|
|
|
metamaskNetworkId: '5',
|
|
|
|
hash: '0x4bcb6cd6b182209585f8ad140260ddb35c81a575dd40f508d9767e652a9f60e7',
|
|
|
|
r: '0x4c3111e42ed5eec3dcecba1e234700f387e8693c373c61c3e54a762a26f1570e',
|
|
|
|
s: '0x18bfc4eeb7ebcfacc3bd59ea100a6834ea3265e65945dbec69aa2a06564fafff',
|
|
|
|
v: '0x29',
|
|
|
|
};
|
|
|
|
const expectedResult = {
|
|
|
|
accessList: null,
|
|
|
|
blockHash: null,
|
|
|
|
blockNumber: null,
|
|
|
|
from: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
|
|
|
gas: '0x7b0d',
|
|
|
|
hash: '0x4bcb6cd6b182209585f8ad140260ddb35c81a575dd40f508d9767e652a9f60e7',
|
|
|
|
input: '0x',
|
|
|
|
gasPrice: '0x77359400',
|
|
|
|
nonce: '0x4b',
|
|
|
|
r: '0x4c3111e42ed5eec3dcecba1e234700f387e8693c373c61c3e54a762a26f1570e',
|
|
|
|
s: '0x18bfc4eeb7ebcfacc3bd59ea100a6834ea3265e65945dbec69aa2a06564fafff',
|
|
|
|
to: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
transactionIndex: null,
|
2023-01-18 15:47:29 +01:00
|
|
|
type: TransactionEnvelopeType.legacy,
|
2023-01-06 18:14:50 +01:00
|
|
|
v: '0x29',
|
|
|
|
value: '0x0',
|
|
|
|
};
|
|
|
|
const result = formatTxMetaForRpcResult(txMeta);
|
|
|
|
expect(result).toStrictEqual(expectedResult);
|
|
|
|
});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|