Skip to content

Commit

Permalink
Merge pull request #5 from tigerbeetle/fix-exercises-pass-without-cha…
Browse files Browse the repository at this point in the history
…nges

Fix exercises that pass without changes
  • Loading branch information
emschwartz authored Jul 8, 2024
2 parents c12c45d + 4bcfb91 commit 90f24a0
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 39 deletions.
12 changes: 6 additions & 6 deletions exercises/010_batch_limits.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ tb "${create_account_batch%, };"

create_transfer_batch="create_transfers "
for ((i=0; i<8191; i++)); do
create_transfer_batch+="id=$((100000 + i))
debit_account_id=$((100000 + i))
credit_account_id=$((100000 + (1 + i) % 8190))
amount=100
code=10
ledger=80, "
create_transfer_batch+="id=$((1000 + i)) \
debit_account_id=$((100000 + i)) \
credit_account_id=$((100000 + (1 + i) % 8190)) \
amount=1 \
code=10 \
ledger=100, "
done

tb "${create_transfer_batch%, };"
Expand Down
3 changes: 1 addition & 2 deletions exercises/031_rate_limiting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ tb "create_transfers id=31000 debit_account_id=3100 credit_account_id=3101 amoun
TIMEOUT=???
for ((i=1; i<=11; i++)); do
id=$((31000 + i))
output=$(tb "create_transfers id=${id} debit_account_id=3101 credit_account_id=3100 amount=1 timeout=${TIMEOUT} ledger=310 code=10 flags=pending;")
echo "$output"
tb "create_transfers id=${id} debit_account_id=3101 credit_account_id=3100 amount=1 timeout=${TIMEOUT} ledger=310 code=10 flags=pending;"
done
# The last of these transfers will fail because the user has exceeded the rate limit.

Expand Down
3 changes: 1 addition & 2 deletions exercises/032_rate_limiting_bandwidth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ for ((i=1; i<=11; i++)); do
id=$((32000 + i))
# What should the amount be?
amount=???
output=$(tb "create_transfers id=${id} debit_account_id=3201 credit_account_id=3200 amount=${amount} timeout=60 ledger=320 code=10 flags=pending;")
echo "$output"
tb "create_transfers id=${id} debit_account_id=3201 credit_account_id=3200 amount=${amount} timeout=60 ledger=320 code=10 flags=pending;"
done

# As before, if you want to test that the balance resets, you can uncomment the following lines to sleep for 60 seconds before creating the last transfer.
Expand Down
5 changes: 2 additions & 3 deletions exercises/033_rate_limiting_money.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ tb "create_transfers id=33000 debit_account_id=3300 credit_account_id=3301 amoun
for ((i=1; i<=11; i++)); do
id=$((33002 + (i * 2)))
# What flags should these two transfers have? (Hint: they aren't the same.)
output=$(tb "create_transfers id=${id} debit_account_id=3301 credit_account_id=3300 amount=10 ledger=$USD_LEDGER code=10 flags=???,
id=$((id + 1)) debit_account_id=3303 credit_account_id=3302 amount=10 timeout=60 ledger=$RATE_LIMITING_LEDGER code=10 flags=???;")
echo "$output"
tb "create_transfers id=${id} debit_account_id=3301 credit_account_id=3300 amount=10 ledger=$USD_LEDGER code=10 flags=???,
id=$((id + 1)) debit_account_id=3303 credit_account_id=3302 amount=10 timeout=60 ledger=$RATE_LIMITING_LEDGER code=10 flags=???;"
done
# The last two of these transfers will fail because the user has exceeded the rate limit.

Expand Down
8 changes: 4 additions & 4 deletions patches/010_batch_limits.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/exercises/010_batch_limits.sh b/exercises/010_batch_limits.sh
index d5ff13b..e277a5d 100755
index 4d6372b..bc28aea 100755
--- a/exercises/010_batch_limits.sh
+++ b/exercises/010_batch_limits.sh
@@ -20,7 +20,7 @@ tb "${create_account_batch%, };"
Expand All @@ -8,6 +8,6 @@ index d5ff13b..e277a5d 100755
create_transfer_batch="create_transfers "
-for ((i=0; i<8191; i++)); do
+for ((i=0; i<8190; i++)); do
create_transfer_batch+="id=$((100000 + i))
debit_account_id=$((100000 + i))
credit_account_id=$((100000 + (1 + i) % 8190))
create_transfer_batch+="id=$((1000 + i)) \
debit_account_id=$((100000 + i)) \
credit_account_id=$((100000 + (1 + i) % 8190)) \
6 changes: 3 additions & 3 deletions patches/013_lookup_accounts.patch
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
diff --git a/exercises/013_lookup_accounts.sh b/exercises/013_lookup_accounts.sh
index 27e438d..2efd78f 100755
index aef124f..9032d4b 100755
--- a/exercises/013_lookup_accounts.sh
+++ b/exercises/013_lookup_accounts.sh
@@ -19,7 +19,7 @@ tb "lookup_accounts id=1300, id=1301;"
@@ -18,7 +18,7 @@ tb "lookup_accounts id=1300, id=1301;"

# Can you create another transfer so that account 1300 ends up with a net debit balance of 70?
# (Hint: the debits_posted will remain at 100, but the credits_posted will increase to 30.)
# Can you create another transfer so that account 1300 ends up with debits_posted of 70?
-tb "create_transfers id=13001 debit_account_id=??? credit_account_id=??? amount=30 ledger=130 code=10;"
+tb "create_transfers id=13001 debit_account_id=1301 credit_account_id=1300 amount=30 ledger=130 code=10;"

Expand Down
2 changes: 1 addition & 1 deletion patches/017_asset_scale.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/exercises/017_asset_scale.sh b/exercises/017_asset_scale.sh
index 7080c56..c4ddc1c 100755
index 130a718..e711b73 100755
--- a/exercises/017_asset_scale.sh
+++ b/exercises/017_asset_scale.sh
@@ -10,7 +10,7 @@ tb "create_accounts id=1700 code=10 ledger=170,
Expand Down
10 changes: 6 additions & 4 deletions patches/031_rate_limiting.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
diff --git a/exercises/031_rate_limiting.sh b/exercises/031_rate_limiting.sh
index ab84362..93c993e 100755
index d32f976..88f5f76 100755
--- a/exercises/031_rate_limiting.sh
+++ b/exercises/031_rate_limiting.sh
@@ -13,7 +13,7 @@ tb "create_transfers id=31000 debit_account_id=3100 credit_account_id=3101 amoun
@@ -13,8 +13,8 @@ tb "create_transfers id=31000 debit_account_id=3100 credit_account_id=3101 amoun

# Now, each time the user makes a request, we'll create a pending transfer with a timeout to temporarily debit the user's account.
# How long should the timeout be? (Hint: the timeout is an interval in seconds.)
-TIMEOUT=???
-for ((i=1; i<=11; i++)); do
+TIMEOUT=60
for ((i=1; i<=11; i++)); do
+for ((i=1; i<=10; i++)); do
id=$((31000 + i))
output=$(tb "create_transfers id=${id} debit_account_id=3101 credit_account_id=3100 amount=1 timeout=${TIMEOUT} ledger=310 code=10 flags=pending;")
tb "create_transfers id=${id} debit_account_id=3101 credit_account_id=3100 amount=1 timeout=${TIMEOUT} ledger=310 code=10 flags=pending;"
done
14 changes: 9 additions & 5 deletions patches/032_rate_limiting_bandwidth.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
diff --git a/exercises/032_rate_limiting_bandwidth.sh b/exercises/032_rate_limiting_bandwidth.sh
index b280c54..d4d8df8 100755
index dedb290..14338f7 100755
--- a/exercises/032_rate_limiting_bandwidth.sh
+++ b/exercises/032_rate_limiting_bandwidth.sh
@@ -15,7 +15,7 @@ tb "create_transfers id=32000 debit_account_id=3200 credit_account_id=3201 amoun
for ((i=1; i<=11; i++)); do
@@ -12,10 +12,10 @@ tb "create_accounts id=3200 code=10 ledger=320,
tb "create_transfers id=32000 debit_account_id=3200 credit_account_id=3201 amount=10000000 ledger=320 code=10;"

# Let's say that the user is sending requests that are 1 MB each.
-for ((i=1; i<=11; i++)); do
+for ((i=1; i<=10; i++)); do
id=$((32000 + i))
# What should the amount be?
- amount=???
+ amount=1000000
output=$(tb "create_transfers id=${id} debit_account_id=3201 credit_account_id=3200 amount=${amount} timeout=60 ledger=320 code=10 flags=pending;")
echo "$output"
tb "create_transfers id=${id} debit_account_id=3201 credit_account_id=3200 amount=${amount} timeout=60 ledger=320 code=10 flags=pending;"
done

20 changes: 12 additions & 8 deletions patches/033_rate_limiting_money.patch
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
diff --git a/exercises/033_rate_limiting_money.sh b/exercises/033_rate_limiting_money.sh
index c4da8b2..c078640 100755
index 1b4ff82..d5067ab 100755
--- a/exercises/033_rate_limiting_money.sh
+++ b/exercises/033_rate_limiting_money.sh
@@ -22,8 +22,8 @@ tb "create_transfers id=33000 debit_account_id=3300 credit_account_id=3301 amoun
for ((i=1; i<=11; i++)); do
@@ -19,11 +19,11 @@ tb "create_accounts id=3300 code=10 ledger=$USD_LEDGER,
tb "create_transfers id=33000 debit_account_id=3300 credit_account_id=3301 amount=10000 ledger=$USD_LEDGER code=10,
id=33001 debit_account_id=3302 credit_account_id=3303 amount=100 ledger=$RATE_LIMITING_LEDGER code=10;"

-for ((i=1; i<=11; i++)); do
+for ((i=1; i<=10; i++)); do
id=$((33002 + (i * 2)))
# What flags should these two transfers have? (Hint: they aren't the same.)
- output=$(tb "create_transfers id=${id} debit_account_id=3301 credit_account_id=3300 amount=10 ledger=$USD_LEDGER code=10 flags=???,
- id=$((id + 1)) debit_account_id=3303 credit_account_id=3302 amount=10 timeout=60 ledger=$RATE_LIMITING_LEDGER code=10 flags=???;")
+ output=$(tb "create_transfers id=${id} debit_account_id=3301 credit_account_id=3300 amount=10 ledger=$USD_LEDGER code=10 flags=linked,
+ id=$((id + 1)) debit_account_id=3303 credit_account_id=3302 amount=10 timeout=60 ledger=$RATE_LIMITING_LEDGER code=10 flags=pending;")
echo "$output"
- tb "create_transfers id=${id} debit_account_id=3301 credit_account_id=3300 amount=10 ledger=$USD_LEDGER code=10 flags=???,
- id=$((id + 1)) debit_account_id=3303 credit_account_id=3302 amount=10 timeout=60 ledger=$RATE_LIMITING_LEDGER code=10 flags=???;"
+ tb "create_transfers id=${id} debit_account_id=3301 credit_account_id=3300 amount=10 ledger=$USD_LEDGER code=10 flags=linked,
+ id=$((id + 1)) debit_account_id=3303 credit_account_id=3302 amount=10 timeout=60 ledger=$RATE_LIMITING_LEDGER code=10 flags=pending;"
done
# The last two of these transfers will fail because the user has exceeded the rate limit.

2 changes: 1 addition & 1 deletion tools/tb_function.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function tb() {
# The one exception is if an account or transfer already exists, it will return the "exists" error.
# We treat the "exists" error as a successful operation here.
while IFS= read -r line; do
if [[ $line =~ ^Fail|Cannot && $line != *"Result.exists." && $line != *"Result.linked_event_failed." ]]; then
if [[ $line =~ Fail|Cannot|panic && $line != *"Result.exists." && $line != *"Result.linked_event_failed." ]]; then
exit 1
fi
done <<< "$output"
Expand Down

0 comments on commit 90f24a0

Please sign in to comment.