Skip to content

Commit 36dbd3d

Browse files
committed
add metadata properties to ShieldController
1 parent fab0656 commit 36dbd3d

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

packages/shield-controller/src/ShieldController.test.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { deriveStateFromMetadata } from '@metamask/base-controller';
12
import type { TransactionControllerState } from '@metamask/transaction-controller';
23

34
import { ShieldController } from './ShieldController';
@@ -142,4 +143,68 @@ describe('ShieldController', () => {
142143
expect(backend.checkCoverage).toHaveBeenCalledWith(txMeta);
143144
});
144145
});
146+
147+
describe('metadata', () => {
148+
it('includes expected state in debug snapshots', () => {
149+
const { controller } = setup();
150+
151+
expect(
152+
deriveStateFromMetadata(
153+
controller.state,
154+
controller.metadata,
155+
'anonymous',
156+
),
157+
).toMatchInlineSnapshot(`Object {}`);
158+
});
159+
160+
it('includes expected state in state logs', async () => {
161+
const { controller } = setup();
162+
163+
expect(
164+
deriveStateFromMetadata(
165+
controller.state,
166+
controller.metadata,
167+
'includeInStateLogs',
168+
),
169+
).toMatchInlineSnapshot(`
170+
Object {
171+
"coverageResults": Object {},
172+
"orderedTransactionHistory": Array [],
173+
}
174+
`);
175+
});
176+
177+
it('persists expected state', async () => {
178+
const { controller } = setup();
179+
180+
expect(
181+
deriveStateFromMetadata(
182+
controller.state,
183+
controller.metadata,
184+
'persist',
185+
),
186+
).toMatchInlineSnapshot(`
187+
Object {
188+
"coverageResults": Object {},
189+
"orderedTransactionHistory": Array [],
190+
}
191+
`);
192+
});
193+
194+
it('exposes expected state to UI', async () => {
195+
const { controller } = setup();
196+
197+
expect(
198+
deriveStateFromMetadata(
199+
controller.state,
200+
controller.metadata,
201+
'usedInUi',
202+
),
203+
).toMatchInlineSnapshot(`
204+
Object {
205+
"coverageResults": Object {},
206+
}
207+
`);
208+
});
209+
});
145210
});

packages/shield-controller/src/ShieldController.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,16 @@ export type ShieldControllerMessenger = RestrictedMessenger<
101101
*/
102102
const metadata = {
103103
coverageResults: {
104+
includeInStateLogs: true,
104105
persist: true,
105106
anonymous: false,
107+
usedInUi: true,
106108
},
107109
orderedTransactionHistory: {
110+
includeInStateLogs: true,
108111
persist: true,
109112
anonymous: false,
113+
usedInUi: false,
110114
},
111115
};
112116

0 commit comments

Comments
 (0)