Complete the code to define a simple test function that checks if a smart contract function returns the expected value.
def test_get_balance(): expected = 100 result = get_balance() assert result [1] expected
The test checks if the result equals the expected value using ==. This confirms the function works as intended.
Complete the code to simulate a transaction and check if the balance updates correctly.
def test_transaction(): initial_balance = 100 amount = 20 new_balance = initial_balance - [1] assert new_balance == 80
The code subtracts the amount from the initial_balance to get the new balance.
Fix the error in the test that checks if a smart contract function raises an exception on invalid input.
def test_invalid_input(): try: process_transaction(-10) except [1]: passed = True else: passed = False assert passed
The function should raise a ValueError when given a negative amount, so the test catches that exception.
Fill both blanks to create a dictionary comprehension that maps transaction IDs to their amounts, but only for amounts greater than 50.
transactions = {tx_id: amount for tx_id, amount in tx_list if amount [1] 50 and amount [2] 0}The comprehension filters amounts greater than 50 and greater than or equal to 0 to include valid transactions.
Fill all three blanks to create a dictionary comprehension that maps user addresses to their balances, but only include users with balances greater than zero.
user_balances = { [3].[1]: [3].[2] for [3] in users if [3].[2] > 0 }The comprehension uses user to get address and balance for each user, filtering for positive balances.