Skip to content

Commit

Permalink
Commodity market (#498)
Browse files Browse the repository at this point in the history
* start commodity market

* set up form

* remove buy button

* tweaks

* start triggers

* trigger fixpoint loop

* iterations

* fix loop

* execute trade

* commodity market ddtest

* logging

* logging & tweaks

* update

* 'fix' missing writes

* tweak

* remove some logging

* add choose fn

* test the fuzzer
  • Loading branch information
vilterp authored Nov 24, 2024
1 parent daed9b8 commit 166f544
Show file tree
Hide file tree
Showing 14 changed files with 2,541 additions and 38 deletions.
1 change: 1 addition & 0 deletions apps/actors/systems/kvSync/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ function processLiveQueryUpdate(
updateMsg: LiveQueryUpdate
): ClientState {
const newData = { ...state.data };

for (const update of updateMsg.updates) {
const key = update.key;
switch (update.type) {
Expand Down
11 changes: 11 additions & 0 deletions apps/actors/systems/kvSync/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ export class MutationContextImpl implements MutationCtx {
return val.value;
}

scan(prefix: string): Json[] {
const out: Json[] = [];
for (const [key, values] of Object.entries(this.kvData)) {
if (key.startsWith(prefix)) {
const value = getVisibleValue(this.isTxnCommitted, this.kvData, key);
out.push(value.value);
}
}
return out;
}

write(key: string, value: Json) {
const [newKVData, writeOp] = doWrite(
this.kvData,
Expand Down
13 changes: 12 additions & 1 deletion apps/actors/systems/kvSync/ddTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { explore } from "../../explore";
import { mapObj } from "../../../../util/util";
import { counter } from "./examples/counter";
import { commodityMarket } from "./examples/commodityMarket";

export function kvSyncTests(writeResults: boolean): Suite {
return [
Expand All @@ -46,6 +47,16 @@ export function kvSyncTests(writeResults: boolean): Suite {
);
},
},
{
name: "commodityMarket",
test() {
runDDTestAtPath(
"apps/actors/systems/kvSync/examples/commodityMarket.dd.txt",
(inputs) => kvSyncTest(commodityMarket, inputs),
writeResults
);
},
},
];
}

Expand All @@ -56,7 +67,7 @@ function kvSyncTest(app: KVApp, testCases: string[]): TestOutput[] {
state: KVSyncState,
init: LoadedTickInitiator<KVSyncState, KVSyncMsg>
) => {
return update(app.mutations, state, init);
return update(app, state, init);
};

return testCases.map((testCase) => {
Expand Down
Loading

0 comments on commit 166f544

Please sign in to comment.