Skip to content

Commit 339818f

Browse files
committed
Add tests for recursive partial anonymizing function
Tests have been added to ensure that the anonymizing function works as expected when the return type omits properties from the top-level property state or from a nested object.
1 parent 9a67b9e commit 339818f

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/BaseControllerV2.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,67 @@ describe('getAnonymizedState', () => {
219219

220220
expect(anonymizedState).toEqual({ transactionHash: '4321x0' });
221221
});
222+
223+
it('should allow returning a partial object from an anonymizing function', () => {
224+
const anonymizeTransactionHash = (txMeta: { hash: string; value: number }) => {
225+
return { value: txMeta.value };
226+
};
227+
228+
const anonymizedState = getAnonymizedState(
229+
{
230+
txMeta: {
231+
hash: '0x123',
232+
value: 10,
233+
},
234+
},
235+
{
236+
txMeta: {
237+
anonymous: anonymizeTransactionHash,
238+
persist: false,
239+
},
240+
},
241+
);
242+
243+
expect(anonymizedState).toEqual({ txMeta: { value: 10 } });
244+
});
245+
246+
it('should allow returning a ntested partial object from an anonymizing function', () => {
247+
const anonymizeTransactionHash = (txMeta: {
248+
hash: string;
249+
value: number;
250+
history: { hash: string; value: number }[];
251+
}) => {
252+
return {
253+
history: txMeta.history.map((entry) => {
254+
return { value: entry.value };
255+
}),
256+
value: txMeta.value,
257+
};
258+
};
259+
260+
const anonymizedState = getAnonymizedState(
261+
{
262+
txMeta: {
263+
hash: '0x123',
264+
history: [
265+
{
266+
hash: '0x123',
267+
value: 9,
268+
},
269+
],
270+
value: 10,
271+
},
272+
},
273+
{
274+
txMeta: {
275+
anonymous: anonymizeTransactionHash,
276+
persist: false,
277+
},
278+
},
279+
);
280+
281+
expect(anonymizedState).toEqual({ txMeta: { history: [{ value: 9 }], value: 10 } });
282+
});
222283
});
223284

224285
describe('getPersistentState', () => {

0 commit comments

Comments
 (0)