Cheat Functions
Here’s a structured documentation outline for the Komet cheat functions along with the explanations for each host function:
Komet Cheat Functions
In addition to the standard host functions provided by the Soroban host environment, Komet includes a set of custom host functions, known as Komet cheat functions. These cheat functions provide special abilities that normal contracts do not have and are required for testing purposes. They allow the test contract to manipulate the blockchain state to create controlled scenarios that would be otherwise difficult or impossible to test—for example, changing the ledger timestamp to simulate time-based contract behavior.
Below are the available Komet cheat functions:
kasmer_set_ledger_sequence
kasmer_set_ledger_sequence
Description: This function lets us manually set the ledger sequence number, enabling tests for contract behaviors that depend on it—such as evaluating TTLs for contract data
kasmer_set_ledger_timestamp
kasmer_set_ledger_timestamp
Description: This cheat function allows us to set the ledger timestamp. The timestamp represents the current time on the blockchain. By manipulating the timestamp, we can simulate how contracts behave after specific periods of time.
kasmer_create_contract
kasmer_create_contract
Description: This cheat function allows us to create a contract with a specified address and Wasm hash.
kasmer_address_from_bytes
kasmer_address_from_bytes
Description: This cheat function converts a byte array into a contract address.
Conclusion
These Komet cheat functions provide the ability to perform actions that are critical for testing smart contracts in Komet. By manipulating key aspects of the blockchain environment, such as the ledger sequence, timestamp, and contract creation, we can more easily simulate and test a wide range of scenarios that would be hard to reproduce in a standard contract execution environment.
Last updated