Skip to content

Commit 48d3987

Browse files
authored
feat: Add new metadata properties to sample-controllers (#6471)
## Explanation The new metadata properties `includeInStateLogs` and `usedInUi` have been added to the sample controllers. ## References Relates to #6443 ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [x] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
1 parent 5d44962 commit 48d3987

File tree

5 files changed

+131
-2
lines changed

5 files changed

+131
-2
lines changed

packages/sample-controllers/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- `SampleGasPricesServiceFetchGasPricesAction`
2020
- `SampleGasPricesServiceMessenger`
2121
- Export `getDefaultPetnamesControllerState` ([#6168](https://github.com/MetaMask/core/pull/6168))
22+
- Add two new controller state metadata properties: `includeInStateLogs` and `usedInUi` ([#6471](https://github.com/MetaMask/core/pull/6471))
2223

2324
### Changed
2425

packages/sample-controllers/src/sample-gas-prices-controller.test.ts

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Messenger } from '@metamask/base-controller';
1+
import { Messenger, deriveStateFromMetadata } from '@metamask/base-controller';
22
import { SampleGasPricesController } from '@metamask/sample-controllers';
33
import type { SampleGasPricesControllerMessenger } from '@metamask/sample-controllers';
44

@@ -293,6 +293,68 @@ describe('SampleGasPricesController', () => {
293293
});
294294
});
295295
});
296+
297+
describe('metadata', () => {
298+
it('includes expected state in debug snapshots', async () => {
299+
await withController(({ controller }) => {
300+
expect(
301+
deriveStateFromMetadata(
302+
controller.state,
303+
controller.metadata,
304+
'anonymous',
305+
),
306+
).toMatchInlineSnapshot(`Object {}`);
307+
});
308+
});
309+
310+
it('includes expected state in state logs', async () => {
311+
await withController(({ controller }) => {
312+
expect(
313+
deriveStateFromMetadata(
314+
controller.state,
315+
controller.metadata,
316+
'includeInStateLogs',
317+
),
318+
).toMatchInlineSnapshot(`
319+
Object {
320+
"gasPricesByChainId": Object {},
321+
}
322+
`);
323+
});
324+
});
325+
326+
it('persists expected state', async () => {
327+
await withController(({ controller }) => {
328+
expect(
329+
deriveStateFromMetadata(
330+
controller.state,
331+
controller.metadata,
332+
'persist',
333+
),
334+
).toMatchInlineSnapshot(`
335+
Object {
336+
"gasPricesByChainId": Object {},
337+
}
338+
`);
339+
});
340+
});
341+
342+
it('exposes expected state to UI', async () => {
343+
await withController(({ controller }) => {
344+
expect(
345+
deriveStateFromMetadata(
346+
controller.state,
347+
controller.metadata,
348+
'usedInUi',
349+
),
350+
).toMatchInlineSnapshot(`
351+
Object {
352+
"gasPricesByChainId": Object {},
353+
}
354+
`);
355+
});
356+
});
357+
});
296358
});
297359

298360
/**

packages/sample-controllers/src/sample-gas-prices-controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ export type SampleGasPricesControllerState = {
6565
*/
6666
const gasPricesControllerMetadata = {
6767
gasPricesByChainId: {
68+
includeInStateLogs: true,
6869
persist: true,
6970
anonymous: false,
71+
usedInUi: true,
7072
},
7173
} satisfies StateMetadata<SampleGasPricesControllerState>;
7274

packages/sample-controllers/src/sample-petnames-controller.test.ts

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Messenger } from '@metamask/base-controller';
1+
import { Messenger, deriveStateFromMetadata } from '@metamask/base-controller';
22

33
import type { SamplePetnamesControllerMessenger } from './sample-petnames-controller';
44
import { SamplePetnamesController } from './sample-petnames-controller';
@@ -189,6 +189,68 @@ describe('SamplePetnamesController', () => {
189189
);
190190
});
191191
});
192+
193+
describe('metadata', () => {
194+
it('includes expected state in debug snapshots', async () => {
195+
await withController(({ controller }) => {
196+
expect(
197+
deriveStateFromMetadata(
198+
controller.state,
199+
controller.metadata,
200+
'anonymous',
201+
),
202+
).toMatchInlineSnapshot(`Object {}`);
203+
});
204+
});
205+
206+
it('includes expected state in state logs', async () => {
207+
await withController(({ controller }) => {
208+
expect(
209+
deriveStateFromMetadata(
210+
controller.state,
211+
controller.metadata,
212+
'includeInStateLogs',
213+
),
214+
).toMatchInlineSnapshot(`
215+
Object {
216+
"namesByChainIdAndAddress": Object {},
217+
}
218+
`);
219+
});
220+
});
221+
222+
it('persists expected state', async () => {
223+
await withController(({ controller }) => {
224+
expect(
225+
deriveStateFromMetadata(
226+
controller.state,
227+
controller.metadata,
228+
'persist',
229+
),
230+
).toMatchInlineSnapshot(`
231+
Object {
232+
"namesByChainIdAndAddress": Object {},
233+
}
234+
`);
235+
});
236+
});
237+
238+
it('exposes expected state to UI', async () => {
239+
await withController(({ controller }) => {
240+
expect(
241+
deriveStateFromMetadata(
242+
controller.state,
243+
controller.metadata,
244+
'usedInUi',
245+
),
246+
).toMatchInlineSnapshot(`
247+
Object {
248+
"namesByChainIdAndAddress": Object {},
249+
}
250+
`);
251+
});
252+
});
253+
});
192254
});
193255

194256
/**

packages/sample-controllers/src/sample-petnames-controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ export type SamplePetnamesControllerState = {
4141
*/
4242
const samplePetnamesControllerMetadata = {
4343
namesByChainIdAndAddress: {
44+
includeInStateLogs: true,
4445
persist: true,
4546
anonymous: false,
47+
usedInUi: true,
4648
},
4749
} satisfies StateMetadata<SamplePetnamesControllerState>;
4850

0 commit comments

Comments
 (0)