Challenge - 5 Problems
Blockchain Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple smart contract test
Consider this Solidity test snippet using Hardhat framework. What will be the output printed by the test runner?
Blockchain / Solidity
describe('SimpleStorage', function () { it('should store and retrieve the value', async function () { const SimpleStorage = await ethers.getContractFactory('SimpleStorage'); const storage = await SimpleStorage.deploy(); await storage.deployed(); await storage.store(42); const value = await storage.retrieve(); console.log('Stored value:', value.toString()); }); });
Attempts:
2 left
💡 Hint
Remember that retrieve() returns a BigNumber and toString() converts it to a string.
✗ Incorrect
The contract stores 42, retrieve returns a BigNumber representing 42, and toString() converts it to '42'. So the console prints 'Stored value: 42'.
❓ Predict Output
intermediate1:30remaining
Test case result for failing assertion
What will happen when running this test case in a blockchain test framework?
Blockchain / Solidity
it('should fail when value is incorrect', async function () { const value = 10; assert.equal(value, 20, 'Value should be 20'); });
Attempts:
2 left
💡 Hint
assert.equal compares two values and throws if they differ.
✗ Incorrect
The assertion compares 10 and 20, which are not equal, so the test fails with the given message.
🔧 Debug
advanced2:30remaining
Identify the error in this test case
This test case is supposed to check if a transaction reverts. What error will it produce when run?
Blockchain / Solidity
it('should revert on invalid input', async function () { await expect(contract.doSomething(0)).to.be.revertedWith('Invalid input'); });
Attempts:
2 left
💡 Hint
Check if the testing framework supports the 'revertedWith' matcher.
✗ Incorrect
If the chai matchers for blockchain are not imported, 'revertedWith' is undefined causing a TypeError.
❓ Predict Output
advanced3:00remaining
Output of asynchronous test with event listening
What will this test print to the console when run?
Blockchain / Solidity
it('should emit event on action', async function () { const tx = await contract.performAction(); const receipt = await tx.wait(); const event = receipt.events.find(e => e.event === 'ActionPerformed'); console.log('Event data:', event.args[0].toString()); });
Attempts:
2 left
💡 Hint
TransactionReceipt in ethers.js has 'logs' property, not 'events'.
✗ Incorrect
In ethers.js, TransactionReceipt does not have an 'events' property (it has 'logs'). receipt.events is undefined, so receipt.events.find throws TypeError.
🚀 Application
expert1:30remaining
Number of test cases needed for full coverage
A smart contract function has 3 independent boolean inputs. How many test cases are needed to cover all input combinations?
Attempts:
2 left
💡 Hint
Each boolean can be true or false independently.
✗ Incorrect
With 3 booleans, total combinations are 2^3 = 8.