From db6be1b695c007070552c9ae1e6e0855599bef8b Mon Sep 17 00:00:00 2001 From: Priyank <3169068+rdlrt@users.noreply.github.com> Date: Tue, 12 Sep 2023 10:37:08 +1000 Subject: [PATCH] Fixes discovered during schemathesis tests --- files/grest/rpc/account/account_addresses.sql | 8 +++----- files/grest/rpc/account/account_txs.sql | 4 ++-- files/grest/rpc/address/address_txs.sql | 4 ++-- files/grest/rpc/address/credential_txs.sql | 4 ++-- files/grest/rpc/assets/asset_addresses.sql | 2 +- files/grest/rpc/assets/asset_txs.sql | 1 + files/grest/rpc/assets/asset_utxos.sql | 5 ++--- files/grest/rpc/assets/policy_asset_addresses.sql | 2 +- files/grest/rpc/pool/pool_metadata.sql | 6 +++--- 9 files changed, 17 insertions(+), 19 deletions(-) diff --git a/files/grest/rpc/account/account_addresses.sql b/files/grest/rpc/account/account_addresses.sql index 5cf301e4..b3039088 100644 --- a/files/grest/rpc/account/account_addresses.sql +++ b/files/grest/rpc/account/account_addresses.sql @@ -28,9 +28,8 @@ BEGIN txo.stake_address_id, txo.id FROM tx_out AS txo - WHERE - txo.stake_address_id = ANY(sa_id_list) - AND tx_out.consumed_by_tx_in_id IS NULL + WHERE txo.stake_address_id = ANY(sa_id_list) + AND txo.consumed_by_tx_in_id IS NULL ) AS x ) @@ -55,8 +54,7 @@ BEGIN txo.stake_address_id, txo.id FROM tx_out AS txo - WHERE - txo.stake_address_id = ANY(sa_id_list) + WHERE txo.stake_address_id = ANY(sa_id_list) LIMIT (CASE WHEN _first_only IS TRUE THEN 1 ELSE NULL END) ) AS x ) diff --git a/files/grest/rpc/account/account_txs.sql b/files/grest/rpc/account/account_txs.sql index bcf8c76b..d44455a2 100644 --- a/files/grest/rpc/account/account_txs.sql +++ b/files/grest/rpc/account/account_txs.sql @@ -45,8 +45,8 @@ BEGIN FROM public.tx INNER JOIN public.block AS b ON b.id = tx.block_id WHERE tx.id = ANY(_tx_id_list) - AND block.block_no >= _after_block_height - ORDER BY block.block_no DESC; + AND b.block_no >= _after_block_height + ORDER BY b.block_no DESC; END; $$; diff --git a/files/grest/rpc/address/address_txs.sql b/files/grest/rpc/address/address_txs.sql index 743ea71f..a40fe57e 100644 --- a/files/grest/rpc/address/address_txs.sql +++ b/files/grest/rpc/address/address_txs.sql @@ -44,8 +44,8 @@ BEGIN FROM public.tx INNER JOIN public.block AS b ON b.id = tx.block_id WHERE tx.id = ANY(_tx_id_list) - AND block.block_no >= _after_block_height - ORDER BY block.block_no DESC; + AND b.block_no >= _after_block_height + ORDER BY b.block_no DESC; END; $$; diff --git a/files/grest/rpc/address/credential_txs.sql b/files/grest/rpc/address/credential_txs.sql index e3ad6a4e..780423d7 100644 --- a/files/grest/rpc/address/credential_txs.sql +++ b/files/grest/rpc/address/credential_txs.sql @@ -52,8 +52,8 @@ BEGIN FROM public.tx INNER JOIN public.block AS b ON b.id = tx.block_id WHERE tx.id = ANY(_tx_id_list) - AND block.block_no >= _after_block_height - ORDER BY block.block_no DESC; + AND b.block_no >= _after_block_height + ORDER BY b.block_no DESC; END; $$; diff --git a/files/grest/rpc/assets/asset_addresses.sql b/files/grest/rpc/assets/asset_addresses.sql index 8216671c..dd6d605d 100644 --- a/files/grest/rpc/assets/asset_addresses.sql +++ b/files/grest/rpc/assets/asset_addresses.sql @@ -45,7 +45,7 @@ BEGIN FROM ma_tx_out AS mto INNER JOIN tx_out AS txo ON txo.id = mto.tx_out_id WHERE mto.ident = _asset_id - AND tx_out.consumed_by_tx_in_id IS NULL + AND txo.consumed_by_tx_in_id IS NULL ) AS x GROUP BY x.address; END; diff --git a/files/grest/rpc/assets/asset_txs.sql b/files/grest/rpc/assets/asset_txs.sql index 01d950f2..8c426b8e 100644 --- a/files/grest/rpc/assets/asset_txs.sql +++ b/files/grest/rpc/assets/asset_txs.sql @@ -54,6 +54,7 @@ BEGIN GROUP BY ident, tx.hash, + txo.index::smallint, block.epoch_no, block.block_no, block.time diff --git a/files/grest/rpc/assets/asset_utxos.sql b/files/grest/rpc/assets/asset_utxos.sql index 8af487b3..9fd7ed86 100644 --- a/files/grest/rpc/assets/asset_utxos.sql +++ b/files/grest/rpc/assets/asset_utxos.sql @@ -97,9 +97,8 @@ BEGIN LEFT JOIN block AS b ON b.id = tx.block_id LEFT JOIN datum ON datum.id = tx_out.inline_datum_id LEFT JOIN script ON script.tx_id = tx_out.reference_script_id - LEFT JOIN _assets ON tx_out.id = _assets.id - WHERE mto.ident = ANY(_asset_id_list) - AND tx_out.consumed_by_tx_in_id IS NULL + INNER JOIN _assets ON tx_out.id = _assets.id + WHERE tx_out.consumed_by_tx_in_id IS NULL ; END; $$; diff --git a/files/grest/rpc/assets/policy_asset_addresses.sql b/files/grest/rpc/assets/policy_asset_addresses.sql index 5287b4a1..062310c2 100644 --- a/files/grest/rpc/assets/policy_asset_addresses.sql +++ b/files/grest/rpc/assets/policy_asset_addresses.sql @@ -33,7 +33,7 @@ BEGIN FROM _all_assets AS aa INNER JOIN ma_tx_out AS mto ON mto.ident = aa.id INNER JOIN tx_out AS txo ON txo.id = mto.tx_out_id - WHERE tx_out.consumed_by_tx_in_id IS NULL + WHERE txo.consumed_by_tx_in_id IS NULL ) AS x GROUP BY x.asset_name, diff --git a/files/grest/rpc/pool/pool_metadata.sql b/files/grest/rpc/pool/pool_metadata.sql index 83bc4a35..c919791c 100644 --- a/files/grest/rpc/pool/pool_metadata.sql +++ b/files/grest/rpc/pool/pool_metadata.sql @@ -17,8 +17,8 @@ BEGIN pic.meta_hash, pod.json, pic.pool_status - FROM grest.pool_hash AS ph - LEFT JOIN grest.pool_infor_cache AS pic ON ph.view = pic.pool_id_bech32 + FROM public.pool_hash AS ph + LEFT JOIN grest.pool_info_cache AS pic ON ph.view = pic.pool_id_bech32 LEFT JOIN public.pool_offline_data AS pod ON pod.pmr_id = pic.meta_id WHERE CASE @@ -26,7 +26,7 @@ BEGIN WHEN _pool_bech32_ids IS NOT NULL THEN pic.pool_id_bech32 = ANY(SELECT UNNEST(_pool_bech32_ids)) END ORDER BY - ph.view, + pic.pool_id_bech32, pic.tx_id DESC; END; $$;