refactor(engine): share strict native financial views (CL18)
This commit is contained in:
parent
580a6de75c
commit
03518c8ae4
9 changed files with 252 additions and 99 deletions
|
|
@ -250,6 +250,90 @@ describe('stateless native financial transaction contract', () => {
|
|||
parseFinancialTransactionResult(JSON.stringify(reordered), identity)
|
||||
).not.toThrow();
|
||||
});
|
||||
it('rejects nested unknown, missing and null configuration fields through both native hosts', () => {
|
||||
const mutations: Array<(value: any) => void> = [
|
||||
value => {
|
||||
value.risk.ledger.riskSession.extra = true;
|
||||
},
|
||||
value => {
|
||||
delete value.risk.ledger.riskSession.calendarRevision;
|
||||
},
|
||||
value => {
|
||||
value.risk.ledger.riskSession.calendarRevision = null;
|
||||
},
|
||||
value => {
|
||||
value.owners[0].extra = true;
|
||||
},
|
||||
value => {
|
||||
delete value.owners[0].mode;
|
||||
},
|
||||
value => {
|
||||
value.owners[0].mode = null;
|
||||
},
|
||||
];
|
||||
for (const mutate of mutations) {
|
||||
const bad = structuredClone(config);
|
||||
mutate(bad);
|
||||
expect(() =>
|
||||
stageFinancialTransaction(
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
kind: 'initialize',
|
||||
identity,
|
||||
config: bad,
|
||||
})
|
||||
)
|
||||
).toThrow();
|
||||
expect(
|
||||
() =>
|
||||
new FinancialReplaySession(
|
||||
JSON.stringify({
|
||||
...nativeReplayLoad,
|
||||
config: { ...nativeReplayLoad.config, matching: bad },
|
||||
})
|
||||
)
|
||||
).toThrow();
|
||||
}
|
||||
});
|
||||
it('requires explicit null checkpoint fields and rejects nested receipt additions', () => {
|
||||
const { request, result } = marked();
|
||||
// The untouched initialized checkpoint has a required null cursor.
|
||||
expect(request.checkpoint.cursor).toBeNull();
|
||||
expect(() => stageFinancialTransaction(JSON.stringify(request))).not.toThrow();
|
||||
const omitted = structuredClone(request) as any;
|
||||
delete omitted.checkpoint.cursor;
|
||||
expect(() => stageFinancialTransaction(JSON.stringify(omitted))).toThrow(
|
||||
'missing financial transaction fields'
|
||||
);
|
||||
|
||||
const retry = { ...request, checkpoint: result.checkpoint };
|
||||
expect(retry.checkpoint.receipts[0]).toMatchObject({
|
||||
outcome: { effects: [{ Risk: { outcome: { remaining: null } } }] },
|
||||
});
|
||||
const mutations: Array<(value: any) => void> = [
|
||||
value => {
|
||||
value.checkpoint.receipts[0].outcome.effects[0].Risk.outcome.extra = true;
|
||||
},
|
||||
value => {
|
||||
delete value.checkpoint.receipts[0].outcome.effects[0].Risk.outcome.remaining;
|
||||
},
|
||||
value => {
|
||||
value.checkpoint.receipts[0].outcome.effects[0].Risk.outcome.disposition = null;
|
||||
},
|
||||
];
|
||||
for (const mutate of mutations) {
|
||||
const bad = structuredClone(retry);
|
||||
mutate(bad);
|
||||
expect(() => stageFinancialTransaction(JSON.stringify(bad))).toThrow();
|
||||
}
|
||||
const replay = parseFinancialTransactionResult(
|
||||
stageFinancialTransaction(JSON.stringify(retry)),
|
||||
identity
|
||||
);
|
||||
expect(replay.view).toEqual(result.view);
|
||||
expect(replay.checkpoint).toEqual(result.checkpoint);
|
||||
expect(replay.journal).toEqual([]);
|
||||
});
|
||||
it('validates initialized metadata and rejects operator/legacy/malformed native requests', () => {
|
||||
const result = initialized();
|
||||
const bad = structuredClone(result);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue