Modern UI contract: bank read and bank.commit
The bank read lists account, fixed deposit, credit line, investments, the 12 stocks with their price history and the offered funds as Money. bank.commit moves money to or from the fixed deposit and buys or sells shares and fund units through the desk's own checks. Credits follow; the stock tip draws a random number and will be a quote.request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
43ae1ab510
commit
a1590a34ef
3 files changed
+84
-1
No files matched your search
@@ -213,6 +213,28 @@ int main(int argc, char** argv) {
|
||||
"messageType")) == "error" && modern::save_stream(session.state()) == kept && rev == before_training + 1,
|
||||
"training over the limit refused without change");
|
||||
}
|
||||
// bank: read, fixed deposit, a share, a refused withdrawal
|
||||
{
|
||||
const J bank = session.ui_read(O{{"kind", "bank"}}, rev);
|
||||
const J& accounts = at(at(bank, "data"), "accounts");
|
||||
const auto* stocks = at(at(bank, "data"), "stocks").array();
|
||||
check(s(at(bank, "messageType")) == "snapshot" && stocks && stocks->size() == 12, "bank read");
|
||||
const std::string deposit_before = s(at(at(accounts, "deposit"), "minor"));
|
||||
const uint64_t before_bank = rev;
|
||||
const J done = session.ui_command(cmd("request:b1", "bank.commit",
|
||||
O{{"action", "deposit"}, {"amount", O{{"minor", "10000000"}, {"currency", "EUR"}, {"minorUnits", 2}}}}), rev);
|
||||
const J after = session.ui_read(O{{"kind", "bank"}}, rev);
|
||||
check(s(at(done, "messageType")) == "command_result" && rev == before_bank + 1 &&
|
||||
std::stoll(s(at(at(at(at(after, "data"), "accounts"), "deposit"), "minor"))) ==
|
||||
std::stoll(deposit_before) + 10000000, "100000 euros to the fixed deposit");
|
||||
const J share = session.ui_command(cmd("request:b2", "bank.commit", O{{"action", "buy"}, {"assetId", "stock:0"}, {"count", 1}}), rev);
|
||||
check(s(at(share, "messageType")) == "command_result" && rev == before_bank + 2, "one share bought");
|
||||
const auto kept = modern::save_stream(session.state());
|
||||
const J refused = session.ui_command(cmd("request:b3", "bank.commit",
|
||||
O{{"action", "withdraw"}, {"amount", O{{"minor", "99999999900"}, {"currency", "EUR"}, {"minorUnits", 2}}}}), rev);
|
||||
check(s(at(refused, "messageType")) == "error" && modern::save_stream(session.state()) == kept && rev == before_bank + 2,
|
||||
"withdrawal above the deposit refused without change");
|
||||
}
|
||||
} catch (const std::exception& ex) {
|
||||
std::fprintf(stderr, "FAIL: %s\n", ex.what());
|
||||
return 1;
|
||||
|
||||
Reference in new issue
Block a user