> loading_
# Walkthrough: Understanding the OOG error propagation fix in TIP20's is_initialized
#
# Before the fix, the is_initialized check looked something like this:
#
# fn is_initialized(contract_addr: Address) -> bool {
# // Attempt to read the initialization flag from storage
# match storage_read(contract_addr, INIT_SLOT) {
# Ok(value) => value != 0,
# Err(_) => false // <-- BUG: OOG errors land here too!
# }
# }
#
# The problem: Err(_) catches *all* errors, including OutOfGas.
# When gas runs out mid-read, the function returns false ("not initialized"),
# which lets initialization logic run again on an already-live contract.
#
# After the fix, OOG is explicitly propagated:
#
# fn is_initialized(contract_addr: Address) -> Result<bool, Error> {
# match storage_read(contract_addr, INIT_SLOT) {
# Ok(value) => Ok(value != 0),
# Err(Error::OutOfGas) => Err(Error::OutOfGas), // <-- Propagate OOG!
# Err(_) => Ok(false) // Other read failures still treat as uninitialized
# }
# }
#
# To test this in your own TIP20 contracts, simulate a low-gas call:
#
# #[test]
# fn test_oog_does_not_mask_initialization() {
# let contract = deploy_tip20_contract();
# initialize_contract(&contract);
#
# // Simulate a call with barely enough gas to enter is_initialized
# // but not enough to complete the storage read
# let result = call_with_gas_limit(
# &contract,
# "is_initialized",
# gas_limit: 200, // artificially low
# );
#
# // After the fix, this should return an OOG error,
# // NOT a successful `false` response
# assert!(result.is_err());
# assert_eq!(result.unwrap_err(), Error::OutOfGas);
#
# // Critically, a re-initialization attempt under low gas should also fail
# let reinit_result = call_with_gas_limit(
# &contract,
# "initialize",
# gas_limit: 200,
# );
# assert!(reinit_result.is_err()); // Must NOT succeed
# }
#
# Key takeaway: never use catch-all error handling around storage reads
# in initialization guards. OOG is not "data not found" — it's "I couldn't
# finish looking." Treating those the same is a security vulnerability.