|
1 | | -import { Messenger } from '@metamask/base-controller'; |
| 1 | +import { deriveStateFromMetadata, Messenger } from '@metamask/base-controller'; |
2 | 2 | import { |
3 | 3 | NetworkType, |
4 | 4 | convertHexToDecimal, |
@@ -2531,6 +2531,143 @@ describe('SmartTransactionsController', () => { |
2531 | 2531 | ); |
2532 | 2532 | }); |
2533 | 2533 | }); |
| 2534 | + |
| 2535 | + describe('metadata', () => { |
| 2536 | + it('includes expected state in debug snapshots', async () => { |
| 2537 | + await withController(({ controller }) => { |
| 2538 | + expect( |
| 2539 | + deriveStateFromMetadata( |
| 2540 | + controller.state, |
| 2541 | + controller.metadata, |
| 2542 | + 'anonymous', |
| 2543 | + ), |
| 2544 | + ).toMatchInlineSnapshot(` |
| 2545 | + { |
| 2546 | + "smartTransactionsState": { |
| 2547 | + "fees": { |
| 2548 | + "approvalTxFees": null, |
| 2549 | + "tradeTxFees": null, |
| 2550 | + }, |
| 2551 | + "feesByChainId": { |
| 2552 | + "0x1": { |
| 2553 | + "approvalTxFees": null, |
| 2554 | + "tradeTxFees": null, |
| 2555 | + }, |
| 2556 | + "0xaa36a7": { |
| 2557 | + "approvalTxFees": null, |
| 2558 | + "tradeTxFees": null, |
| 2559 | + }, |
| 2560 | + }, |
| 2561 | + "liveness": true, |
| 2562 | + "livenessByChainId": { |
| 2563 | + "0x1": true, |
| 2564 | + "0xaa36a7": true, |
| 2565 | + }, |
| 2566 | + "smartTransactions": { |
| 2567 | + "0x1": [], |
| 2568 | + }, |
| 2569 | + "userOptIn": null, |
| 2570 | + "userOptInV2": null, |
| 2571 | + }, |
| 2572 | + } |
| 2573 | + `); |
| 2574 | + }); |
| 2575 | + }); |
| 2576 | + |
| 2577 | + it('includes expected state in state logs', async () => { |
| 2578 | + await withController(({ controller }) => { |
| 2579 | + expect( |
| 2580 | + deriveStateFromMetadata( |
| 2581 | + controller.state, |
| 2582 | + controller.metadata, |
| 2583 | + 'includeInStateLogs', |
| 2584 | + ), |
| 2585 | + ).toMatchInlineSnapshot(` |
| 2586 | + { |
| 2587 | + "smartTransactionsState": { |
| 2588 | + "fees": { |
| 2589 | + "approvalTxFees": null, |
| 2590 | + "tradeTxFees": null, |
| 2591 | + }, |
| 2592 | + "feesByChainId": { |
| 2593 | + "0x1": { |
| 2594 | + "approvalTxFees": null, |
| 2595 | + "tradeTxFees": null, |
| 2596 | + }, |
| 2597 | + "0xaa36a7": { |
| 2598 | + "approvalTxFees": null, |
| 2599 | + "tradeTxFees": null, |
| 2600 | + }, |
| 2601 | + }, |
| 2602 | + "liveness": true, |
| 2603 | + "livenessByChainId": { |
| 2604 | + "0x1": true, |
| 2605 | + "0xaa36a7": true, |
| 2606 | + }, |
| 2607 | + "smartTransactions": { |
| 2608 | + "0x1": [], |
| 2609 | + }, |
| 2610 | + "userOptIn": null, |
| 2611 | + "userOptInV2": null, |
| 2612 | + }, |
| 2613 | + } |
| 2614 | + `); |
| 2615 | + }); |
| 2616 | + }); |
| 2617 | + |
| 2618 | + it('persists expected state', async () => { |
| 2619 | + await withController(({ controller }) => { |
| 2620 | + expect( |
| 2621 | + deriveStateFromMetadata( |
| 2622 | + controller.state, |
| 2623 | + controller.metadata, |
| 2624 | + 'persist', |
| 2625 | + ), |
| 2626 | + ).toMatchInlineSnapshot(`{}`); |
| 2627 | + }); |
| 2628 | + }); |
| 2629 | + |
| 2630 | + it('includes expected state in UI', async () => { |
| 2631 | + await withController(({ controller }) => { |
| 2632 | + expect( |
| 2633 | + deriveStateFromMetadata( |
| 2634 | + controller.state, |
| 2635 | + controller.metadata, |
| 2636 | + 'usedInUi', |
| 2637 | + ), |
| 2638 | + ).toMatchInlineSnapshot(` |
| 2639 | + { |
| 2640 | + "smartTransactionsState": { |
| 2641 | + "fees": { |
| 2642 | + "approvalTxFees": null, |
| 2643 | + "tradeTxFees": null, |
| 2644 | + }, |
| 2645 | + "feesByChainId": { |
| 2646 | + "0x1": { |
| 2647 | + "approvalTxFees": null, |
| 2648 | + "tradeTxFees": null, |
| 2649 | + }, |
| 2650 | + "0xaa36a7": { |
| 2651 | + "approvalTxFees": null, |
| 2652 | + "tradeTxFees": null, |
| 2653 | + }, |
| 2654 | + }, |
| 2655 | + "liveness": true, |
| 2656 | + "livenessByChainId": { |
| 2657 | + "0x1": true, |
| 2658 | + "0xaa36a7": true, |
| 2659 | + }, |
| 2660 | + "smartTransactions": { |
| 2661 | + "0x1": [], |
| 2662 | + }, |
| 2663 | + "userOptIn": null, |
| 2664 | + "userOptInV2": null, |
| 2665 | + }, |
| 2666 | + } |
| 2667 | + `); |
| 2668 | + }); |
| 2669 | + }); |
| 2670 | + }); |
2534 | 2671 | }); |
2535 | 2672 |
|
2536 | 2673 | type WithControllerCallback<ReturnValue> = ({ |
|
0 commit comments