In this track: Build, test and reason
advanced · 4 MIN READ

Test access control

Exercise allowed callers and rejected callers.

LET’S PICTURE IT

An entrance test should try both the correct key and an unrelated key.

SEE IT FOR YOURSELF
A valid counter call, step by stepStep 1 / 4
A valid counter call, step by stepFunction requestincrement()No argumentsBefore executionstored count0A local teaching example with a defined starting stateIncoming callCheck function dispatchCheck coded conditionsRules passConditions passContinue executionA failed check can revert insteadCalculation0 + 1Result: 1Storage writecount = 1Persists if call succeedsCalculating a local value and storing it are separate stepsPersistent statecount1Later readGetter reports 1No new incrementState, logs and browser display have different roles

This example begins with count zero and a request to call increment(). No real contract is deployed.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Name the authorized role

For PracticeCounter, the deployment account is the owner. Keep that identity explicit in the test rather than relying on a runner’s unnamed default account.

Test the allowed path

The owner should be able to increment under the example’s rules. A test suite with only rejection tests can miss a function that blocks everyone.

Test an unrelated caller

A different local account should fail with the intended error. Assert that count remains unchanged after the rejected action.

Include role transitions where present

For mutable-role designs, test former owners, pending owners and transfer completion. PracticeCounter uses an immutable owner, so those transitions are not part of this toy interface.

Define the test

owner call → success and increment
unrelated account call → NotOwner(account)
after rejection → count unchanged

Test plans are framework-neutral unless labeled as complete Solidity or JavaScript. Use a local test environment and no real funds.

QUICK CHECK · NO PRESSURE

Should a rejected unauthorized call leave count changed?

Your progress stays in this browser.
Keep exploring the original referenceethereum.org ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.