From 133fcd156d3d11cbdc4ffad1cfca3b814ace48b0 Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Tue, 2 Dec 2025 12:05:24 +0100 Subject: update bank with model and flow of talk --- pbt/ts/src/bank.test.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'pbt/ts/src/bank.test.ts') diff --git a/pbt/ts/src/bank.test.ts b/pbt/ts/src/bank.test.ts index 2944e4c..d750d05 100644 --- a/pbt/ts/src/bank.test.ts +++ b/pbt/ts/src/bank.test.ts @@ -1,5 +1,10 @@ import {toNullable} from 'fp-ts/lib/Option'; -import {Account, Operation, SimpleBank} from './bank'; +import { + Account, + Operation, + SimpleBank, + bankImplementationMatchesModel, +} from './bank'; import { Gen, Property, @@ -111,6 +116,32 @@ const correctBalance = }; describe('Bank Simulator', () => { + test('level-db bank conforms to model', async () => { + const prop = forall(genAccounts, async accounts => { + return property(genOperations(accounts), async ops => { + const levelBank = await withTempFile( + filename => new LevelBank(filename), + ).then(bank => bank.populateWith(accounts)); + + return bankImplementationMatchesModel(accounts)(levelBank)(ops); + }); + }); + + const result = await Property.run(prop); + + console.log(result); + console.log(JSON.stringify(result.counterexample)); + + expect(result.result).toBe('OK'); + }); + + // + // + // + // + // + // + test('can retrieve balance given account exists', async () => { const prop = forall(genAccounts, async accounts => { const api = new SimpleBank(accounts); -- cgit v1.3.1