Smart contract unit test

If you run unit testing, you will receive an error due to the incorrect data type. The solution here would be to change all string data types to a bytes data type. Then, owing to a deprecation warning, you should change the way you call methods in a smart contract.

Ultimately, your unit test, which is located in tests/test_greeter.py, should look like this:

def test_greeter(chain):    greeter, _ = chain.provider.get_or_deploy_contract('Greeter')    greeting = greeter.functions.greet().call()    assert greeting == b'Hello'def test_custom_greeting(chain):    greeter, _ = chain.provider.get_or_deploy_contract('Greeter')    set_txn_hash = greeter.functions.setGreeting(b'Guten Tag').transact()    chain.wait.for_receipt(set_txn_hash) greeting ...

Get Hands-On Blockchain for Python Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.