summaryrefslogtreecommitdiff
path: root/pbt/ts/src/bank.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'pbt/ts/src/bank.test.ts')
-rw-r--r--pbt/ts/src/bank.test.ts124
1 files changed, 60 insertions, 64 deletions
diff --git a/pbt/ts/src/bank.test.ts b/pbt/ts/src/bank.test.ts
index 021e4c6..a6b3e76 100644
--- a/pbt/ts/src/bank.test.ts
+++ b/pbt/ts/src/bank.test.ts
@@ -1,10 +1,10 @@
-import {toNullable} from 'fp-ts/lib/Option';
+import {toNullable} from 'fp-ts/lib/Option.js';
import {
Account,
Operation,
SimpleBank,
bankImplementationMatchesModel,
-} from './bank';
+} from './bank.js';
import {
Gen,
Property,
@@ -16,10 +16,11 @@ import {
listOf,
mapOf1 as nonEmptyMap,
property,
-} from './property';
+} from './property.js';
import Prando from 'prando';
-import {LevelBank} from './levelbank';
-import {withTempFile} from './fs';
+import {LevelBank} from './levelbank.js';
+import {withTempFile} from './fs.js';
+import {test, expect} from 'vitest';
const sampleAccounts: Account[] = [
'FR12345678901234',
@@ -116,83 +117,78 @@ const levelBankMatchFakeBank =
return true;
};
-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));
+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);
- });
+ return bankImplementationMatchesModel(accounts)(levelBank)(ops);
});
+ });
- const result = await Property.run(prop);
+ const result = await Property.run(prop);
- console.log(result);
- console.log(JSON.stringify(result.counterexample));
+ console.log(result);
+ console.log(JSON.stringify(result.counterexample));
- expect(result.result).toBe('OK');
- });
+ expect(result.result).toBe('OK');
+});
- //
- //
- //
- //
- //
- //
+//
+//
+//
+//
+//
+//
- test('in-mem bank conforms to model', async () => {
- const prop = forall(genAccounts, async accounts => {
- return property(genOperations(accounts), async ops => {
- const simpleBank = new SimpleBank(accounts);
+test('in-mem bank conforms to model', async () => {
+ const prop = forall(genAccounts, async accounts => {
+ return property(genOperations(accounts), async ops => {
+ const simpleBank = new SimpleBank(accounts);
- return bankImplementationMatchesModel(accounts)(simpleBank)(ops);
- });
+ return bankImplementationMatchesModel(accounts)(simpleBank)(ops);
});
+ });
- const result = await Property.run(prop);
+ const result = await Property.run(prop);
- console.log(result);
- console.log(JSON.stringify(result.counterexample));
+ console.log(result);
+ console.log(JSON.stringify(result.counterexample));
- expect(result.result).toBe('OK');
- });
+ expect(result.result).toBe('OK');
+});
- //
- //
- //
- //
- //
- //
+//
+//
+//
+//
+//
+//
- test('can retrieve balance given account exists', async () => {
- const prop = forall(genAccounts, async accounts => {
- const api = new SimpleBank(accounts);
- return property(keyValueOf(accounts), async ([accountNr, bal]) => {
- const retrieved = toNullable(await api.balance(accountNr));
- return Promise.resolve(retrieved === bal);
- });
+test('can retrieve balance given account exists', async () => {
+ const prop = forall(genAccounts, async accounts => {
+ const api = new SimpleBank(accounts);
+ return property(keyValueOf(accounts), async ([accountNr, bal]) => {
+ const retrieved = toNullable(await api.balance(accountNr));
+ return Promise.resolve(retrieved === bal);
});
-
- const result = await Property.run(prop);
-
- expect(result.result).toBe('OK');
});
- test('correctly update balance given a sequence of deposits and withdrawals', async () => {
- const prop = forall(genAccounts, accounts => {
- return property(
- genOperations(accounts),
- levelBankMatchFakeBank(accounts),
- );
- });
+ const result = await Property.run(prop);
- const result = await Property.run(prop);
+ expect(result.result).toBe('OK');
+});
- console.log(result);
- console.log(JSON.stringify(result.counterexample));
- expect(result.result).toBe('OK');
+test('correctly update balance given a sequence of deposits and withdrawals', async () => {
+ const prop = forall(genAccounts, accounts => {
+ return property(genOperations(accounts), levelBankMatchFakeBank(accounts));
});
+
+ const result = await Property.run(prop);
+
+ console.log(result);
+ console.log(JSON.stringify(result.counterexample));
+ expect(result.result).toBe('OK');
});