0
0
Blockchain / Solidityprogramming~20 mins

Why testing prevents costly bugs in Blockchain / Solidity - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bug Buster
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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";
        }
    }
}
A"Insufficient balance"
B"Transfer failed due to gas limit"
CTransaction reverts with error
D"Transfer successful"
Attempts:
2 left
💡 Hint
Think about what happens if the sender does not have enough tokens.
🧠 Conceptual
intermediate
1:30remaining
Why is testing important in blockchain development?
Which of the following best explains why testing smart contracts before deployment is crucial?
ABecause bugs in smart contracts can cause irreversible financial loss
BBecause testing increases the speed of blockchain transactions
CBecause smart contracts can be easily updated after deployment
DBecause testing reduces the size of the blockchain
Attempts:
2 left
💡 Hint
Think about the nature of blockchain transactions and immutability.
🔧 Debug
advanced
2: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;
}
AThe order of updating balances is wrong; sender balance should be reduced before receiver is increased
BThe function lacks a return statement indicating success or failure
CThe function does not check for overflow when increasing receiver balance
DThe require statement should check if receiver has enough tokens
Attempts:
2 left
💡 Hint
Consider what happens if the receiver's balance is very large before adding amount.
📝 Syntax
advanced
1:30remaining
Syntax error in smart contract function
Which option contains the correct syntax for a Solidity function that returns the balance of an address?
Afunction getBalance(address user) public returns (uint) { return balances[user]; }
Bfunction getBalance(address user) public view returns (uint) { return balances[user]; }
Cfunction getBalance(address user) public pure returns (uint) { return balances[user]; }
Dfunction getBalance(address user) returns uint { return balances[user]; }
Attempts:
2 left
💡 Hint
Think about the function type that reads state without modifying it.
🚀 Application
expert
3: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?
AThe developer can easily patch the contract and fix the bug immediately
BThe bug will only affect test networks and not the main blockchain
CThe blockchain network will automatically detect and correct the bug
DUsers may lose tokens permanently and the bug cannot be fixed without redeploying
Attempts:
2 left
💡 Hint
Remember that smart contracts are immutable once deployed on mainnet.