मुख्य सामग्री पर जाएं
कुछ प्रकार के 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
VIRTUAL_TESTNET_RPC=https://YOUR-RPC-URL-HERE
curl -s -X POST \
  -H "Content-Type: application/json" \
  --data '{
    "jsonrpc": "2.0",
    "method": "evm_increaseTime",
    "params": ["0xe10"],
    "id": 2
  }' "$VIRTUAL_TESTNET_RPC"

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

showLineNumbers
VIRTUAL_TESTNET_RPC=https://YOUR-RPC-URL-HERE

# Get the current date in Unix timestamp format
current_date=$(date +%s)

# Use evm_setTime to set the block time to today (current timestamp)
curl -s -X POST \
  -H "Content-Type: application/json" \
  --data '{
    "jsonrpc": "2.0",
    "method": "evm_setNextBlockTimestamp",
    "params": ["'"$current_date"'"],
    "id": 3
  }' "$VIRTUAL_TESTNET_RPC"