textmachine/platform/docs/p8-review/axis1-money/a1-usage-overflow.sh

15 lines
1 KiB
Bash
Executable file

#!/usr/bin/env bash
# A1/money. /v0/usage answers a percentage outside the contract's 0..100 because the share is
# computed as int64 `balance * 100 / granted` and `balance * 100` overflows above ~$92.2 billion.
# The wire answer also flips to state:"low", which is the warning shown to an account that is nearly
# out of money.
set -eu
BASE="${BASE:?stand root}"; URL="${URL:-http://127.0.0.1:8101}"; U="${U:?user id}"
J="$BASE/jar.txt"
echo "-- before"; curl -s --noproxy '*' -b "$J" "$URL/v0/usage"; echo
"$BASE/tmplatformctl" grant --user "$U" --usd 100000000000 --note "a1 overflow probe" --key a1-ovf
echo "-- after a \$100,000,000,000 grant"; curl -s --noproxy '*' -b "$J" "$URL/v0/usage"; echo
# observed: before {"state":"ok","remaining_percent":96,"halt_reason":null}
# after {"state":"low","remaining_percent":-84,"halt_reason":null}
# contract: docs/architecture/14-api-contract/openapi.yaml, Usage.remaining_percent minimum 0 maximum 100
"$BASE/tmplatformctl" adjust --user "$U" --usd -100000000000 --note "undo" --key a1-ovf-undo