extend_ttl storage operations, you can use the TTL getter operation (get_ttl) in combination with manipulating the ledger sequence number. Note, that get_ttl function is only available for tests and only in Soroban SDK v21+.
Example
Follow along the example that tests TTL extensions. The example has extensive comments, this document just highlights the most important parts. We use a very simple contract that only extends an entry for every Soroban storage type:test.rs.
It’s a good idea to define the custom values of TTL-related network settings, since the defaults are defined by the SDK and aren’t immediately obvious for the reader of the tests:
test_extend_ttl_behavior test for the full scenario). First, we setup the data and ensure that the initial TTL values correspond to the network settings we’ve defined above:
env.as_contract(...) in order to access the contract’s storage.
Then we call the TTL extension operations and verify that they behave as expected, for example:
test_temp_entry_removal test for the full scenario):
test_persistent_entry_auto_restored test for the full scenario):
Testing TTL extension for other contract instances
Sometimes a contract may want to extend TTL of another contracts and/or their Wasm entries (usually that would happen in factory contracts). This logic may be covered in a similar fashion to the example above usingenv.deployer().get_contract_instance_ttl(&contract) to get TTL of any contract’s instance, and env.deployer().get_contract_code_ttl(&contract) to get TTL of any contract’s Wasm entry. You can find an example of using these functions in the SDK test suite.