33"""
44import argparse
55from collections import namedtuple
6+ import decimal
67from decimal import Decimal
78import sys
89from typing import Any , Dict , Optional
@@ -63,6 +64,11 @@ def main(c_args: argparse.Namespace) -> None:
6364
6465 remaining_days : int = p_rv .msg ["product" ]["coins" ]["remaining_days" ]
6566
67+ # What's the 'billing prediction' in the /product response?
68+ # We'll compare this later to ensure it matches what we find
69+ # when we calculate the cost to the user using the product charges.
70+ product_response_billing_prediction : Decimal = round (Decimal (p_rv .msg ["product" ]["coins" ]["billing_prediction" ]), 2 )
71+
6672 # Get the product's charges...
6773 pc_rv : AsApiRv = AsApi .get_product_charges (token , product_id = args .product )
6874 if not pc_rv .success :
@@ -140,6 +146,8 @@ def main(c_args: argparse.Namespace) -> None:
140146 additional_coins : Decimal = total_uncommitted_processing_coins + burn_rate_contribution
141147 predicted_total_coins : Decimal = total_coins
142148 zero : Decimal = Decimal ()
149+ calculated_billing_prediction : Decimal = Decimal ()
150+
143151 if remaining_days > 0 and burn_rate > zero :
144152
145153 predicted_total_coins += additional_coins
@@ -159,9 +167,20 @@ def main(c_args: argparse.Namespace) -> None:
159167 "Coins (Adjusted)" : f"{ p_ac .fc } + { p_ac .aac } = { p_ac .coins } " ,
160168 }
161169
170+ calculated_billing_prediction = p_ac .coins
171+
162172 # Now just pre-tty-print the invoice
163173 pprint (invoice )
164174
175+ console .log (f"Calculated billing prediction is { calculated_billing_prediction } " )
176+ console .log (f"Product response billing prediction is { product_response_billing_prediction } " )
177+
178+ if calculated_billing_prediction == product_response_billing_prediction :
179+ console .log (":white_check_mark: CORRECT - Billing predictions match" )
180+ else :
181+ console .log (":cross_mark: ERROR - Billing predictions do not match" )
182+ sys .exit (1 )
183+
165184
166185def _calculate_adjusted_coins (total_coins : Decimal ,
167186 allowance : Decimal ,
0 commit comments