0
0
Blockchain / Solidityprogramming~10 mins

Assertion patterns in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to assert that the transaction was successful.

Blockchain / Solidity
assert transaction.status == [1]
Drag options to blanks, or click blank then click option'
AFalse
BTrue
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using False instead of True
Using 0 or None which do not represent success
2fill in blank
medium

Complete the code to assert the balance increased by the expected amount.

Blockchain / Solidity
assert new_balance == old_balance + [1]
Drag options to blanks, or click blank then click option'
Afee
Bgas
Cnonce
Damount
Attempts:
3 left
💡 Hint
Common Mistakes
Using fee or gas which are costs, not amounts received
Using nonce which is unrelated to balance
3fill in blank
hard

Fix the error in the assertion that checks the event log contains the expected event.

Blockchain / Solidity
assert [1] in transaction.events
Drag options to blanks, or click blank then click option'
Aevent_log
Btransaction.event
Cexpected_event
Dtransaction.logs
Attempts:
3 left
💡 Hint
Common Mistakes
Using transaction.event which is not a valid attribute
Using event_log or transaction.logs which may not exist
4fill in blank
hard

Fill both blanks to assert the smart contract's state variable equals the expected value after the call.

Blockchain / Solidity
assert contract.[1] == [2]
Drag options to blanks, or click blank then click option'
AstateVariable
BexpectedValue
CactualValue
Dbalance
Attempts:
3 left
💡 Hint
Common Mistakes
Using actualValue which is not defined
Using balance which is unrelated here
5fill in blank
hard

Fill all three blanks to assert the transaction reverted with the expected error message.

Blockchain / Solidity
with pytest.raises([1]) as excinfo:
    contract.call_function()
assert [2] in str(excinfo.[3])
Drag options to blanks, or click blank then click option'
AVirtualMachineError
B"revert"
Cvalue
Dmessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong exception type
Checking wrong attribute of excinfo
Missing quotes around 'revert'