diff --git a/bats/core/api/invoices.bats b/bats/core/api/invoices.bats index 87523eaf790..e00355fc1e7 100644 --- a/bats/core/api/invoices.bats +++ b/bats/core/api/invoices.bats @@ -7,6 +7,7 @@ setup_file() { clear_cache create_user 'alice' + create_user 'bob' seed_invoices } @@ -69,29 +70,75 @@ seed_invoices() { [[ "$num_errors" == "0" ]] || exit 1 } -@test "invoices: adding multiple invoices with same external id fails" { - token_name='alice' - btc_wallet_name="$token_name.btc_wallet_id" - btc_amount="1000" +@test "invoices: adding multiple invoices with same external id fails for same account" { external_id="external-id-$RANDOM" + alice_btc_wallet_name="alice.btc_wallet_id" + alice_usd_wallet_name="alice.usd_wallet_id" + bob_btc_wallet_name="bob.btc_wallet_id" + bob_usd_wallet_name="bob.usd_wallet_id" + + btc_amount="1000" + usd_amount="20" + variables=$( jq -n \ - --arg wallet_id "$(read_value $btc_wallet_name)" \ + --arg wallet_id "$(read_value $alice_btc_wallet_name)" \ --arg amount "$btc_amount" \ --arg external_id "$external_id" \ '{input: {walletId: $wallet_id, amount: $amount, externalId: $external_id}}' ) - exec_graphql "$token_name" 'ln-invoice-create' "$variables" + exec_graphql 'alice' 'ln-invoice-create' "$variables" num_errors="$(graphql_output '.data.lnInvoiceCreate.errors | length')" [[ "$num_errors" == "0" ]] || exit 1 - exec_graphql "$token_name" 'ln-invoice-create' "$variables" + # Check 'alice' can't re-use externalId for same wallet + exec_graphql 'alice' 'ln-invoice-create' "$variables" invoice="$(graphql_output '.data.lnInvoiceCreate.invoice')" [[ "$invoice" == "null" ]] || exit 1 error_msg="$(graphql_output '.data.lnInvoiceCreate.errors[0].message')" [[ "${error_msg}" =~ "already exists" ]] || exit 1 + + # Check 'alice' can't re-use externalId for different wallet + variables=$( + jq -n \ + --arg wallet_id "$(read_value $alice_usd_wallet_name)" \ + --arg amount "$usd_amount" \ + --arg external_id "$external_id" \ + '{input: {walletId: $wallet_id, amount: $amount, externalId: $external_id}}' + ) + exec_graphql 'alice' 'ln-usd-invoice-create' "$variables" + invoice="$(graphql_output '.data.lnUsdInvoiceCreate.invoice')" + [[ "$invoice" == "null" ]] || exit 1 + error_msg="$(graphql_output '.data.lnUsdInvoiceCreate.errors[0].message')" + [[ "${error_msg}" =~ "already exists" ]] || exit 1 + + # Check 'bob' can re-use externalId once + variables=$( + jq -n \ + --arg wallet_id "$(read_value $bob_btc_wallet_name)" \ + --arg amount "$btc_amount" \ + --arg external_id "$external_id" \ + '{input: {walletId: $wallet_id, amount: $amount, externalId: $external_id}}' + ) + exec_graphql 'bob' 'ln-invoice-create' "$variables" + num_errors="$(graphql_output '.data.lnInvoiceCreate.errors | length')" + [[ "$num_errors" == "0" ]] || exit 1 + + # Check 'bob' cant re-use externalId again + variables=$( + jq -n \ + --arg wallet_id "$(read_value $bob_usd_wallet_name)" \ + --arg amount "$usd_amount" \ + --arg external_id "$external_id" \ + '{input: {walletId: $wallet_id, amount: $amount, externalId: $external_id}}' + ) + exec_graphql 'bob' 'ln-usd-invoice-create' "$variables" + invoice="$(graphql_output '.data.lnUsdInvoiceCreate.invoice')" + [[ "$invoice" == "null" ]] || exit 1 + error_msg="$(graphql_output '.data.lnUsdInvoiceCreate.errors[0].message')" + [[ "${error_msg}" =~ "already exists" ]] || exit 1 } @test "invoices: get invoices for account" {