From 9060b4c3483512ba84e8c16e3e795bf208038088 Mon Sep 17 00:00:00 2001 From: Evan Schwartz <3262610+emschwartz@users.noreply.github.com> Date: Mon, 8 Jul 2024 13:59:12 -0400 Subject: [PATCH 1/4] fix: patches broken by PR --- patches/013_lookup_accounts.patch | 6 +++--- patches/017_asset_scale.patch | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/patches/013_lookup_accounts.patch b/patches/013_lookup_accounts.patch index 7a3fb07..c5f3084 100644 --- a/patches/013_lookup_accounts.patch +++ b/patches/013_lookup_accounts.patch @@ -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;" diff --git a/patches/017_asset_scale.patch b/patches/017_asset_scale.patch index 79087cb..525f6f9 100644 --- a/patches/017_asset_scale.patch +++ b/patches/017_asset_scale.patch @@ -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, From 35e9a81ff95a2aa7ec94ee5e638493302eab602b Mon Sep 17 00:00:00 2001 From: Evan Schwartz <3262610+emschwartz@users.noreply.github.com> Date: Mon, 8 Jul 2024 14:54:12 -0400 Subject: [PATCH 2/4] fix: exercises that pass without changes --- exercises/010_batch_limits.sh | 12 ++++++------ exercises/031_rate_limiting.sh | 3 +-- exercises/032_rate_limiting_bandwidth.sh | 3 +-- exercises/033_rate_limiting_money.sh | 5 ++--- patches/010_batch_limits.patch | 8 ++++---- patches/031_rate_limiting.patch | 4 ++-- patches/032_rate_limiting_bandwidth.patch | 6 +++--- patches/033_rate_limiting_money.patch | 12 ++++++------ 8 files changed, 25 insertions(+), 28 deletions(-) diff --git a/exercises/010_batch_limits.sh b/exercises/010_batch_limits.sh index d5ff13b..4d6372b 100755 --- a/exercises/010_batch_limits.sh +++ b/exercises/010_batch_limits.sh @@ -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%, };" diff --git a/exercises/031_rate_limiting.sh b/exercises/031_rate_limiting.sh index ab84362..d32f976 100755 --- a/exercises/031_rate_limiting.sh +++ b/exercises/031_rate_limiting.sh @@ -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. diff --git a/exercises/032_rate_limiting_bandwidth.sh b/exercises/032_rate_limiting_bandwidth.sh index b280c54..dedb290 100755 --- a/exercises/032_rate_limiting_bandwidth.sh +++ b/exercises/032_rate_limiting_bandwidth.sh @@ -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. diff --git a/exercises/033_rate_limiting_money.sh b/exercises/033_rate_limiting_money.sh index c4da8b2..1b4ff82 100755 --- a/exercises/033_rate_limiting_money.sh +++ b/exercises/033_rate_limiting_money.sh @@ -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. diff --git a/patches/010_batch_limits.patch b/patches/010_batch_limits.patch index a97e1d9..115f5db 100644 --- a/patches/010_batch_limits.patch +++ b/patches/010_batch_limits.patch @@ -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%, };" @@ -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)) \ diff --git a/patches/031_rate_limiting.patch b/patches/031_rate_limiting.patch index 065dde7..d107f8f 100644 --- a/patches/031_rate_limiting.patch +++ b/patches/031_rate_limiting.patch @@ -1,5 +1,5 @@ diff --git a/exercises/031_rate_limiting.sh b/exercises/031_rate_limiting.sh -index ab84362..93c993e 100755 +index d32f976..9e28a6b 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 @@ -10,4 +10,4 @@ index ab84362..93c993e 100755 +TIMEOUT=60 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;") + tb "create_transfers id=${id} debit_account_id=3101 credit_account_id=3100 amount=1 timeout=${TIMEOUT} ledger=310 code=10 flags=pending;" diff --git a/patches/032_rate_limiting_bandwidth.patch b/patches/032_rate_limiting_bandwidth.patch index 693d5cc..b1e8287 100644 --- a/patches/032_rate_limiting_bandwidth.patch +++ b/patches/032_rate_limiting_bandwidth.patch @@ -1,5 +1,5 @@ diff --git a/exercises/032_rate_limiting_bandwidth.sh b/exercises/032_rate_limiting_bandwidth.sh -index b280c54..d4d8df8 100755 +index dedb290..6d50b1c 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 @@ -8,6 +8,6 @@ index b280c54..d4d8df8 100755 # 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 + diff --git a/patches/033_rate_limiting_money.patch b/patches/033_rate_limiting_money.patch index 7b69536..11cd62e 100644 --- a/patches/033_rate_limiting_money.patch +++ b/patches/033_rate_limiting_money.patch @@ -1,15 +1,15 @@ diff --git a/exercises/033_rate_limiting_money.sh b/exercises/033_rate_limiting_money.sh -index c4da8b2..c078640 100755 +index 1b4ff82..457e3dd 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 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. + From e57dbe22ff7b5e907473fce0e1bad85dfef184bf Mon Sep 17 00:00:00 2001 From: Evan Schwartz <3262610+emschwartz@users.noreply.github.com> Date: Mon, 8 Jul 2024 15:00:55 -0400 Subject: [PATCH 3/4] fix: patches should make tests pass --- patches/031_rate_limiting.patch | 8 +++++--- patches/032_rate_limiting_bandwidth.patch | 10 +++++++--- patches/033_rate_limiting_money.patch | 10 +++++++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/patches/031_rate_limiting.patch b/patches/031_rate_limiting.patch index d107f8f..62628a9 100644 --- a/patches/031_rate_limiting.patch +++ b/patches/031_rate_limiting.patch @@ -1,13 +1,15 @@ diff --git a/exercises/031_rate_limiting.sh b/exercises/031_rate_limiting.sh -index d32f976..9e28a6b 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)) tb "create_transfers id=${id} debit_account_id=3101 credit_account_id=3100 amount=1 timeout=${TIMEOUT} ledger=310 code=10 flags=pending;" + done diff --git a/patches/032_rate_limiting_bandwidth.patch b/patches/032_rate_limiting_bandwidth.patch index b1e8287..546df1c 100644 --- a/patches/032_rate_limiting_bandwidth.patch +++ b/patches/032_rate_limiting_bandwidth.patch @@ -1,9 +1,13 @@ diff --git a/exercises/032_rate_limiting_bandwidth.sh b/exercises/032_rate_limiting_bandwidth.sh -index dedb290..6d50b1c 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=??? diff --git a/patches/033_rate_limiting_money.patch b/patches/033_rate_limiting_money.patch index 11cd62e..8bebc95 100644 --- a/patches/033_rate_limiting_money.patch +++ b/patches/033_rate_limiting_money.patch @@ -1,9 +1,13 @@ diff --git a/exercises/033_rate_limiting_money.sh b/exercises/033_rate_limiting_money.sh -index 1b4ff82..457e3dd 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.) - tb "create_transfers id=${id} debit_account_id=3301 credit_account_id=3300 amount=10 ledger=$USD_LEDGER code=10 flags=???, From 4bcfb91b8f82cbbf53b76ec4ec297af19341d0a3 Mon Sep 17 00:00:00 2001 From: Evan Schwartz <3262610+emschwartz@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:26:35 -0400 Subject: [PATCH 4/4] fix: scripts should exit if a thread panics --- tools/tb_function.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tb_function.sh b/tools/tb_function.sh index 4eced8a..6504841 100755 --- a/tools/tb_function.sh +++ b/tools/tb_function.sh @@ -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"