Skip to content

Commit 80c75e6

Browse files
authored
Merge pull request #11 from tigerbeetle/tobi/fix_bunch
Fix multiple small issues.
2 parents f79e60f + f6e7ea4 commit 80c75e6

10 files changed

+63
-42
lines changed

exercises/014_get_account_balances.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ tb "create_transfers id=14000 debit_account_id=1400 credit_account_id=1401 amoun
1616
id=14002 debit_account_id=1400 credit_account_id=1401 amount=100 ledger=140 code=10;"
1717

1818
# Uh oh! We're trying to look up historical balances for an account that doesn't have history enabled.
19-
tb "get_account_balances account_id=1401;"
19+
output=$(tb "get_account_balances account_id=1401;")
20+
if [[ "$output" == *"No balances were found"* ]]; then
21+
exit 1
22+
fi

exercises/024_two_phase_transfers.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tb "create_transfers id=24000 debit_account_id=2400 credit_account_id=2401 amoun
1919
tb "lookup_accounts id=2400, id=2401;"
2020

2121
# Now we can execute or "post" the transfer:
22-
tb "create_transfers id=24000 pending_id=24000 flags=post_pending_transfer;"
22+
tb "create_transfers id=24000 pending_id=24000 amount=200 flags=post_pending_transfer;"
2323

2424
# Uh oh! That doesn't work. The second transfer is a separate transfer so it needs its own unique ID.
2525

@@ -30,7 +30,7 @@ tb "create_transfers id=24003 pending_id=??? flags=???;"
3030
# Finally, we can look up the accounts again to see their final balances:
3131
tb "lookup_accounts id=2400, id=2401;"
3232

33-
# Note that we don't need to specify the debit_account_id, credit_account_id, amount, ledger, or code
33+
# Note that we don't need to specify the debit_account_id, credit_account_id, ledger, or code
3434
# for the transfers that post or void pending transfers.
3535
# We could if we wanted to -- but they need to be the same as in the pending transfer
3636
# (with the exception of the `amount`, which we'll explain in another exercise).

exercises/025_two_phase_transfers_timeout.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ sleep 2
2121

2222
# Now, we'll try to post both transfers.
2323
# Can you fix this request to post both transfers?
24-
output=$(tb "create_transfers id=25002 pending_id=??? flags=post_pending_transfer,
25-
id=25003 pending_id=25001 flags=???;")
24+
output=$(tb "create_transfers id=25002 pending_id=??? amount=200 flags=post_pending_transfer,
25+
id=25003 pending_id=25001 amount=100 flags=???;")
2626
echo "$output"
2727

2828
# Notice that the first transfer returns an error because the pending transfer already timed out.

exercises/026_two_phase_transfers_partial.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ tb "create_transfers id=26000 debit_account_id=2600 credit_account_id=2601 amoun
1414
id=26002 debit_account_id=2600 credit_account_id=2601 amount=100 ledger=260 code=10 flags=pending;"
1515

1616
# Now, we'll post them -- but we're going to specify different amounts:
17-
output=$(tb "create_transfers id=26003 pending_id=26000 amount=0 flags=post_pending_transfer,
18-
id=26004 pending_id=26001 amount=200 flags=post_pending_transfer,
19-
id=26005 pending_id=26002 amount=200 flags=post_pending_transfer;")
17+
output=$(tb "create_transfers id=26003 pending_id=26000 amount=500 flags=post_pending_transfer,
18+
id=26004 pending_id=26001 amount=200 flags=post_pending_transfer,
19+
id=26005 pending_id=26002 amount=200 flags=post_pending_transfer;")
2020

2121
# Uh oh! That didn't work!
22-
# The first transfer is actually okay -- specifying an amount of 0 means the full amount is posted.
22+
# The first transfer is actually okay -- specifying the same amount as the pending transfer posts the full amount.
2323
# The second is also okay, because the amount is less than the pending transfer.
2424
# But that third transfer...
2525
# Can you fix it?

patches/010_batch_limits.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
diff --git a/exercises/010_batch_limits.sh b/exercises/010_batch_limits.sh
2-
index 4d6372b..bc28aea 100755
2+
index fa34cff..7f6a21c 100755
33
--- a/exercises/010_batch_limits.sh
44
+++ b/exercises/010_batch_limits.sh
55
@@ -20,7 +20,7 @@ tb "${create_account_batch%, };"
66
# Now let's do the same for transfers!
7-
7+
88
create_transfer_batch="create_transfers "
9-
-for ((i=0; i<8191; i++)); do
9+
-for ((i=0; i<8190; i++)); do
1010
+for ((i=0; i<8189; i++)); do
1111
create_transfer_batch+="id=$((1000 + i)) \
1212
debit_account_id=$((100000 + i)) \
13-
credit_account_id=$((100000 + (1 + i) % 8190)) \
13+
credit_account_id=$((100000 + (1 + i) % 8189)) \
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
diff --git a/exercises/014_get_account_balances.sh b/exercises/014_get_account_balances.sh
2-
index a4267e0..2392d08 100755
2+
index fe56825..43e3b41 100755
33
--- a/exercises/014_get_account_balances.sh
44
+++ b/exercises/014_get_account_balances.sh
5-
@@ -16,4 +16,4 @@ tb "create_transfers id=14000 debit_account_id=1400 credit_account_id=1401 amoun
5+
@@ -16,7 +16,7 @@ tb "create_transfers id=14000 debit_account_id=1400 credit_account_id=1401 amoun
66
id=14002 debit_account_id=1400 credit_account_id=1401 amount=100 ledger=140 code=10;"
7-
7+
88
# Uh oh! We're trying to look up historical balances for an account that doesn't have history enabled.
9-
-tb "get_account_balances account_id=1401;"
10-
+tb "get_account_balances account_id=1400;"
9+
-output=$(tb "get_account_balances account_id=1401;")
10+
+output=$(tb "get_account_balances account_id=1400;")
11+
if [[ "$output" == *"No balances were found"* ]]; then
12+
exit 1
13+
fi
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
diff --git a/exercises/024_two_phase_transfers.sh b/exercises/024_two_phase_transfers.sh
2-
index a340abd..8171019 100755
32
--- a/exercises/024_two_phase_transfers.sh
43
+++ b/exercises/024_two_phase_transfers.sh
5-
@@ -19,13 +19,13 @@ tb "create_transfers id=24000 debit_account_id=2400 credit_account_id=2401 amoun
4+
@@ -19,13 +19,13 @@
65
tb "lookup_accounts id=2400, id=2401;"
7-
6+
87
# Now we can execute or "post" the transfer:
9-
-tb "create_transfers id=24000 pending_id=24000 flags=post_pending_transfer;"
10-
+tb "create_transfers id=24002 pending_id=24000 flags=post_pending_transfer;"
11-
8+
-tb "create_transfers id=24000 pending_id=24000 amount=200 flags=post_pending_transfer;"
9+
+tb "create_transfers id=24002 pending_id=24000 amount=200 flags=post_pending_transfer;"
10+
1211
# Uh oh! That doesn't work. The second transfer is a separate transfer so it needs its own unique ID.
13-
12+
1413
# Can you fix this so that the second transfer is voided?
1514
# Hint: we need to use the `void_pending_transfer` flag.
1615
-tb "create_transfers id=24003 pending_id=??? flags=???;"
1716
+tb "create_transfers id=24003 pending_id=24001 flags=void_pending_transfer;"
18-
17+
1918
# Finally, we can look up the accounts again to see their final balances:
2019
tb "lookup_accounts id=2400, id=2401;"
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
diff --git a/exercises/025_two_phase_transfers_timeout.sh b/exercises/025_two_phase_transfers_timeout.sh
2-
index 9c66a93..8fa425e 100755
32
--- a/exercises/025_two_phase_transfers_timeout.sh
43
+++ b/exercises/025_two_phase_transfers_timeout.sh
5-
@@ -21,8 +21,8 @@ sleep 2
6-
4+
@@ -21,8 +21,8 @@
5+
76
# Now, we'll try to post both transfers.
87
# Can you fix this request to post both transfers?
9-
-output=$(tb "create_transfers id=25002 pending_id=??? flags=post_pending_transfer,
10-
- id=25003 pending_id=25001 flags=???;")
11-
+output=$(tb "create_transfers id=25002 pending_id=25000 flags=post_pending_transfer,
12-
+ id=25003 pending_id=25001 flags=post_pending_transfer;")
8+
-output=$(tb "create_transfers id=25002 pending_id=??? amount=200 flags=post_pending_transfer,
9+
- id=25003 pending_id=25001 amount=100 flags=???;")
10+
+output=$(tb "create_transfers id=25002 pending_id=25000 amount=200 flags=post_pending_transfer,
11+
+ id=25003 pending_id=25001 amount=100 flags=post_pending_transfer;")
1312
echo "$output"
14-
13+
1514
# Notice that the first transfer returns an error because the pending transfer already timed out.
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
diff --git a/exercises/026_two_phase_transfers_partial.sh b/exercises/026_two_phase_transfers_partial.sh
2-
index f3dcc0a..555d557 100755
32
--- a/exercises/026_two_phase_transfers_partial.sh
43
+++ b/exercises/026_two_phase_transfers_partial.sh
5-
@@ -16,7 +16,7 @@ tb "create_transfers id=26000 debit_account_id=2600 credit_account_id=2601 amoun
4+
@@ -16,7 +16,7 @@
65
# Now, we'll post them -- but we're going to specify different amounts:
7-
output=$(tb "create_transfers id=26003 pending_id=26000 amount=0 flags=post_pending_transfer,
8-
id=26004 pending_id=26001 amount=200 flags=post_pending_transfer,
9-
- id=26005 pending_id=26002 amount=200 flags=post_pending_transfer;")
10-
+ id=26005 pending_id=26002 amount=100 flags=post_pending_transfer;")
11-
6+
output=$(tb "create_transfers id=26003 pending_id=26000 amount=500 flags=post_pending_transfer,
7+
id=26004 pending_id=26001 amount=200 flags=post_pending_transfer,
8+
- id=26005 pending_id=26002 amount=200 flags=post_pending_transfer;")
9+
+ id=26005 pending_id=26002 amount=100 flags=post_pending_transfer;")
10+
1211
# Uh oh! That didn't work!
13-
# The first transfer is actually okay -- specifying an amount of 0 means the full amount is posted.
12+
# The first transfer is actually okay -- specifying the same amount as the pending transfer posts the full amount.

run.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,32 @@ source ./tools/terminal_format.sh
66
# Trap the script exit signal and send SIGINT to the server process
77
trap 'processes_descendents_kill $$' EXIT SIGHUP SIGINT SIGQUIT SIGTERM SIGKILL
88

9+
# Optional: skip ahead to a specific exercise number (e.g., ./run.sh 15)
10+
# Setup exercises (000-002) always run regardless.
11+
start_from=$((10#${1:-0}))
12+
13+
# Remove old data file to ensure a fresh start
14+
rm -f 0_0.tigerbeetle
15+
916
echo "${bold}Welcome to the Tigerlings exercises!${normal}"
1017
echo ""
1118
echo "This script will run each exercise and stop when it gets to a broken one."
1219
echo "Once you've fixed that exercise, run this script again to continue."
20+
if [ "$start_from" -gt 0 ]; then
21+
echo "Skipping ahead to exercise $start_from."
22+
fi
1323
echo ""
1424

1525
# Run each exercise
1626
for file in $(ls exercises/[0-9][0-9][0-9]*.sh | sort -n); do
27+
# Extract the exercise number from the filename
28+
exercise_num=$((10#$(echo "$file" | grep -o '[0-9]\{3\}' | head -1)))
29+
30+
# Always run setup exercises (000-002), skip others before start_from
31+
if [ "$exercise_num" -gt 2 ] && [ "$exercise_num" -lt "$start_from" ]; then
32+
continue
33+
fi
34+
1735
echo "${bold}Running exercise: ./$file${normal}"
1836

1937
if [ "$file" = "exercises/000_download.sh" ]; then

0 commit comments

Comments
 (0)