|
1 | 1 | import type { AccountSigner } from '@metamask/7715-permission-types';
|
2 |
| -import { Messenger } from '@metamask/base-controller'; |
| 2 | +import { Messenger, deriveStateFromMetadata } from '@metamask/base-controller'; |
3 | 3 | import type { HandleSnapRequest, HasSnap } from '@metamask/snaps-controllers';
|
4 | 4 | import type { SnapId } from '@metamask/snaps-sdk';
|
5 | 5 | import type { Hex } from '@metamask/utils';
|
@@ -379,6 +379,80 @@ describe('GatorPermissionsController', () => {
|
379 | 379 | expect(controller.state.isGatorPermissionsEnabled).toBe(true);
|
380 | 380 | });
|
381 | 381 | });
|
| 382 | + |
| 383 | + describe('metadata', () => { |
| 384 | + it('includes expected state in debug snapshots', () => { |
| 385 | + const controller = new GatorPermissionsController({ |
| 386 | + messenger: getMessenger(), |
| 387 | + }); |
| 388 | + |
| 389 | + expect( |
| 390 | + deriveStateFromMetadata( |
| 391 | + controller.state, |
| 392 | + controller.metadata, |
| 393 | + 'anonymous', |
| 394 | + ), |
| 395 | + ).toMatchInlineSnapshot(`Object {}`); |
| 396 | + }); |
| 397 | + |
| 398 | + it('includes expected state in state logs', () => { |
| 399 | + const controller = new GatorPermissionsController({ |
| 400 | + messenger: getMessenger(), |
| 401 | + }); |
| 402 | + |
| 403 | + expect( |
| 404 | + deriveStateFromMetadata( |
| 405 | + controller.state, |
| 406 | + controller.metadata, |
| 407 | + 'includeInStateLogs', |
| 408 | + ), |
| 409 | + ).toMatchInlineSnapshot(` |
| 410 | + Object { |
| 411 | + "gatorPermissionsMapSerialized": "{\\"native-token-stream\\":{},\\"native-token-periodic\\":{},\\"erc20-token-stream\\":{},\\"erc20-token-periodic\\":{},\\"other\\":{}}", |
| 412 | + "gatorPermissionsProviderSnapId": "@metamask/gator-permissions-snap", |
| 413 | + "isFetchingGatorPermissions": false, |
| 414 | + "isGatorPermissionsEnabled": false, |
| 415 | + } |
| 416 | + `); |
| 417 | + }); |
| 418 | + |
| 419 | + it('persists expected state', () => { |
| 420 | + const controller = new GatorPermissionsController({ |
| 421 | + messenger: getMessenger(), |
| 422 | + }); |
| 423 | + |
| 424 | + expect( |
| 425 | + deriveStateFromMetadata( |
| 426 | + controller.state, |
| 427 | + controller.metadata, |
| 428 | + 'persist', |
| 429 | + ), |
| 430 | + ).toMatchInlineSnapshot(` |
| 431 | + Object { |
| 432 | + "gatorPermissionsMapSerialized": "{\\"native-token-stream\\":{},\\"native-token-periodic\\":{},\\"erc20-token-stream\\":{},\\"erc20-token-periodic\\":{},\\"other\\":{}}", |
| 433 | + "isGatorPermissionsEnabled": false, |
| 434 | + } |
| 435 | + `); |
| 436 | + }); |
| 437 | + |
| 438 | + it('exposes expected state to UI', () => { |
| 439 | + const controller = new GatorPermissionsController({ |
| 440 | + messenger: getMessenger(), |
| 441 | + }); |
| 442 | + |
| 443 | + expect( |
| 444 | + deriveStateFromMetadata( |
| 445 | + controller.state, |
| 446 | + controller.metadata, |
| 447 | + 'usedInUi', |
| 448 | + ), |
| 449 | + ).toMatchInlineSnapshot(` |
| 450 | + Object { |
| 451 | + "gatorPermissionsMapSerialized": "{\\"native-token-stream\\":{},\\"native-token-periodic\\":{},\\"erc20-token-stream\\":{},\\"erc20-token-periodic\\":{},\\"other\\":{}}", |
| 452 | + } |
| 453 | + `); |
| 454 | + }); |
| 455 | + }); |
382 | 456 | });
|
383 | 457 |
|
384 | 458 | /**
|
|
0 commit comments