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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.