Assert a small operation’s before-and-after behavior.
LET’S PICTURE IT
A scoreboard test checks the starting score and exactly one legal update.
SEE IT FOR YOURSELF
A valid counter call, step by stepStep 1 / 4
This example begins with count zero and a request to call increment(). No real contract is deployed.
This example begins with count zero and a request to call increment(). No real contract is deployed.Execution follows the code’s input and permission rules. A website button is not the access-control mechanism.The function reads zero, calculates zero plus one, and writes one to persistent storage.The accepted state contains count one. Later reads can inspect it. Events are emitted only if the code implements them.
Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.
Deploy fresh state
Create a new PracticeCounter in the local fixture. Record which account deploys it because the constructor makes that account the owner.
Assert the initial condition
The counter should begin at zero. An initial-state assertion distinguishes a bad setup from a later increment failure.
Call from the intended account
As the owner, call increment once and assert count equals one. A second call should produce two rather than resetting the value.
Keep unrelated behavior separate
Authorization, event encoding and overflow boundaries deserve additional focused tests. One successful increment does not establish those properties.