0
0
Blockchain / Solidityprogramming~10 mins

Writing test cases 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 define a simple test case function.

Blockchain / Solidity
function test[1]() {
  // test logic here
}
Drag options to blanks, or click blank then click option'
ATest
BCase
CRun
DCheck
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic names like 'Run' or 'Check' instead of 'Test'.
2fill in blank
medium

Complete the code to assert that a smart contract function returns true.

Blockchain / Solidity
assert.equal(contract.[1](), true);
Drag options to blanks, or click blank then click option'
Arun
BisActive
Cexecute
Dtransfer
Attempts:
3 left
💡 Hint
Common Mistakes
Using functions that do not return booleans like 'transfer' or 'run'.
3fill in blank
hard

Fix the error in the test case to correctly check the balance after transfer.

Blockchain / Solidity
const balance = await contract.getBalance([1]);
assert.equal(balance.toNumber(), 100);
Drag options to blanks, or click blank then click option'
Aaccount
Breceiver
Caddress
Dsender
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic terms like 'sender' or 'account' that may not be defined.
4fill in blank
hard

Fill both blanks to write a test that checks if a transaction reverts with an error.

Blockchain / Solidity
await expect(contract.[1](100)).to.be.revertedWith([2]);
Drag options to blanks, or click blank then click option'
Atransfer
Bapprove
C'Insufficient balance'
D'Unauthorized'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong function names or error messages that don't match the test scenario.
5fill in blank
hard

Fill all three blanks to create a test that verifies an event is emitted with correct parameters.

Blockchain / Solidity
await expect(contract.[1](user, 50))
  .to.emit(contract, '[2]')
  .withArgs([3]);
Drag options to blanks, or click blank then click option'
Amint
BTransfer
Cuser, 50
DBurn
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong event names or incorrect event argument formats.