Challenge - 5 Problems
Bug Buster
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a smart contract function without testing
Consider this simple smart contract function that transfers tokens. What will be the output when calling
transfer(50) if the sender has only 30 tokens?Blockchain / Solidity
contract Token {
mapping(address => uint) balances;
function transfer(uint amount) public returns (string memory) {
if (balances[msg.sender] >= amount) {
balances[msg.sender] -= amount;
return "Transfer successful";
} else {
return "Insufficient balance";
}
}
}Attempts:
2 left
💡 Hint
Think about what happens if the sender does not have enough tokens.
✗ Incorrect
The function checks if the sender's balance is enough. Since the sender has only 30 tokens but tries to transfer 50, the condition fails and the function returns "Insufficient balance".
🧠 Conceptual
intermediate1:30remaining
Why is testing important in blockchain development?
Which of the following best explains why testing smart contracts before deployment is crucial?
Attempts:
2 left
💡 Hint
Think about the nature of blockchain transactions and immutability.
✗ Incorrect
Smart contracts are immutable once deployed, so bugs cannot be fixed easily. Bugs can cause permanent loss of funds or unintended behavior, making testing essential.
🔧 Debug
advanced2:30remaining
Identify the bug causing incorrect token balance update
This smart contract function is supposed to transfer tokens from sender to receiver. What is the bug causing incorrect balances after transfer?
Blockchain / Solidity
function transfer(address to, uint amount) public {
require(balances[msg.sender] >= amount, "Not enough tokens");
balances[to] += amount;
balances[msg.sender] -= amount;
}Attempts:
2 left
💡 Hint
Consider what happens if the receiver's balance is very large before adding amount.
✗ Incorrect
Without checking for overflow, adding amount to receiver's balance can wrap around causing incorrect balances. This is a common bug in smart contracts.
📝 Syntax
advanced1:30remaining
Syntax error in smart contract function
Which option contains the correct syntax for a Solidity function that returns the balance of an address?
Attempts:
2 left
💡 Hint
Think about the function type that reads state without modifying it.
✗ Incorrect
The function reads the contract state without modifying it, so it must be marked as 'view'. Option B is correct syntax. Option B misses 'view', C uses 'pure' which disallows state access, D misses visibility and parentheses.
🚀 Application
expert3:00remaining
Effect of missing tests on deployed smart contract
A developer deployed a smart contract without thorough testing. After deployment, a bug caused incorrect token transfers. What is the most likely consequence?
Attempts:
2 left
💡 Hint
Remember that smart contracts are immutable once deployed on mainnet.
✗ Incorrect
Smart contracts on blockchain are immutable. Bugs cannot be fixed by patching the contract. Users may lose tokens permanently, and fixing requires redeploying a new contract and migrating users.