मुख्य सामग्री पर जाएं
कुछ प्रकार के tests के लिए time के माध्यम से skip करना उपयोगी है। यह Virtual Environments पर उपलब्ध 2 Admin RPC methods पर निर्भर करके संभव है: evm_setNextBlockTimestamp और evm_setNextBlockTimestamp

सही समय प्राप्त करना

एक transaction या eth_call के execution के दौरान एक contract के अंदर block.timestamp को access किया जाता है, तो value इस पर निर्भर करेगी कि target block (latest या pending) block है या नहीं:
  • pending block के लिए: block.timestamp == time.now() + adjustment_offset। यह time-adjustment methods द्वारा adjusted current time को दर्शाता है।
  • latest block के लिए: block.timestamp == latest_block.timestamp। यह सबसे हाल ही में mined block का timestamp है।
adjustment_offset time-adjustment methods से आता है:
  1. evm_setNextBlockTimestamp: अगले block के लिए timestamp पर time को skip करता है: adjustment_offset = timestamp - time.now()
  2. evm_increaseTime: time को एक relative amount से आगे बढ़ाता है। adjustment_offset += increase_value

उदाहरण

एक offset से time बढ़ाएं

showLineNumbers

pending block के लिए timestamp सेट करें

showLineNumbers