diff --git a/packages/snaps-controllers/src/interface/SnapInterfaceController.test.tsx b/packages/snaps-controllers/src/interface/SnapInterfaceController.test.tsx index 05400d3fdf..0bc19501d6 100644 --- a/packages/snaps-controllers/src/interface/SnapInterfaceController.test.tsx +++ b/packages/snaps-controllers/src/interface/SnapInterfaceController.test.tsx @@ -10,7 +10,10 @@ import { Link, Text, } from '@metamask/snaps-sdk/jsx'; -import { getJsxElementFromComponent } from '@metamask/snaps-utils'; +import { + getJsonSizeUnsafe, + getJsxElementFromComponent, +} from '@metamask/snaps-utils'; import { MOCK_SNAP_ID } from '@metamask/snaps-utils/test-utils'; import { @@ -20,6 +23,11 @@ import { } from '../test-utils'; import { SnapInterfaceController } from './SnapInterfaceController'; +jest.mock('@metamask/snaps-utils', () => ({ + ...jest.requireActual('@metamask/snaps-utils'), + getJsonSizeUnsafe: jest.fn().mockReturnValue(1), +})); + describe('SnapInterfaceController', () => { describe('createInterface', () => { it('can create a new interface', async () => { @@ -157,6 +165,11 @@ describe('SnapInterfaceController', () => { const controllerMessenger = getRestrictedSnapInterfaceControllerMessenger(rootMessenger); + jest + .mocked(getJsonSizeUnsafe) + .mockReturnValueOnce(1) + .mockReturnValueOnce(10_000_000); + /* eslint-disable-next-line no-new */ new SnapInterfaceController({ messenger: controllerMessenger, @@ -287,13 +300,14 @@ describe('SnapInterfaceController', () => { false, ); + jest.mocked(getJsonSizeUnsafe).mockReturnValueOnce(11_000_000); + /* eslint-disable-next-line no-new */ new SnapInterfaceController({ messenger: controllerMessenger, }); - const images = new Array(800_000).fill(image(``)); - const components = panel(images); + const components = panel([image(``)]); await expect( rootMessenger.call( @@ -311,13 +325,17 @@ describe('SnapInterfaceController', () => { false, ); + jest.mocked(getJsonSizeUnsafe).mockReturnValueOnce(11_000_000); + /* eslint-disable-next-line no-new */ new SnapInterfaceController({ messenger: controllerMessenger, }); const element = ( - {new Array(800_000).fill()} + + + ); await expect( @@ -660,6 +678,11 @@ describe('SnapInterfaceController', () => { const controllerMessenger = getRestrictedSnapInterfaceControllerMessenger(rootMessenger); + jest + .mocked(getJsonSizeUnsafe) + .mockReturnValueOnce(1) + .mockReturnValueOnce(11_000_000); + /* eslint-disable-next-line no-new */ new SnapInterfaceController({ messenger: controllerMessenger, @@ -670,8 +693,7 @@ describe('SnapInterfaceController', () => { children: [input({ name: 'bar' })], }); - const images = new Array(800_000).fill(image(``)); - const newContent = panel(images); + const newContent = panel([image('')]); const id = await rootMessenger.call( 'SnapInterfaceController:createInterface', @@ -694,6 +716,11 @@ describe('SnapInterfaceController', () => { const controllerMessenger = getRestrictedSnapInterfaceControllerMessenger(rootMessenger); + jest + .mocked(getJsonSizeUnsafe) + .mockReturnValueOnce(1) + .mockReturnValueOnce(11_000_000); + /* eslint-disable-next-line no-new */ new SnapInterfaceController({ messenger: controllerMessenger, @@ -708,7 +735,9 @@ describe('SnapInterfaceController', () => { ); const newElement = ( - {new Array(800_000).fill('} />)} + + '} /> + ); const id = await rootMessenger.call(