Skip to content

Commit

Permalink
chore: align current_miniblock, current_batch, current_timestamp to p…
Browse files Browse the repository at this point in the history
…oint to the latest entities (#135)

* normalize current_miniblock, current_batch, and current_timestamp to have latest values

* fix compute_hash to use miniblock number

* add tests for mine_empty_blocks

* merge main

* fix test, remove println!

* fix tests

* rename to BlockContext
  • Loading branch information
nbaztec authored Sep 28, 2023
1 parent 3f8c893 commit f19fe6c
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 80 deletions.
6 changes: 3 additions & 3 deletions e2e-tests/test/evm-apis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("evm_increaseTime", function () {
to: userWallet.address,
value: ethers.utils.parseEther("0.1"),
});
expectedTimestamp += 1; // New transaction will add a second block
expectedTimestamp += 2; // New transaction will add two blocks

// Assert
const newBlockTimestamp = (await provider.getBlock("latest")).timestamp;
Expand All @@ -60,7 +60,7 @@ describe("evm_setNextBlockTimestamp", function () {
to: userWallet.address,
value: ethers.utils.parseEther("0.1"),
});
expectedTimestamp += 1; // New transaction will add a second block
expectedTimestamp += 2; // New transaction will add two blocks

// Assert
const newBlockTimestamp = (await provider.getBlock("latest")).timestamp;
Expand All @@ -84,7 +84,7 @@ describe("evm_setTime", function () {
to: userWallet.address,
value: ethers.utils.parseEther("0.1"),
});
expectedTimestamp += 1; // New transaction will add a second block
expectedTimestamp += 2; // New transaction will add two blocks

// Assert
const newBlockTimestamp = (await provider.getBlock("latest")).timestamp;
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/test/hardhat-apis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("hardhat_mine", function () {
const latestBlock = await provider.getBlock("latest");
expect(latestBlock.number).to.equal(startingBlock.number + numberOfBlocks, "Block number mismatch");
expect(latestBlock.timestamp).to.equal(
startingTimestamp + (numberOfBlocks - 1) * intervalInSeconds * 1000,
startingTimestamp + (numberOfBlocks - 1) * intervalInSeconds * 1000 + 1,
"Timestamp mismatch"
);
});
Expand Down
4 changes: 2 additions & 2 deletions src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ mod tests {
.expect("block exists");

assert_eq!(start_block.number + 1, current_block.number);
assert_eq!(start_block.timestamp + 1000, current_block.timestamp);
assert_eq!(start_block.timestamp + 1, current_block.timestamp);

let result = evm.evm_mine().await.expect("evm_mine");
assert_eq!(&result, "0x0");
Expand All @@ -478,6 +478,6 @@ mod tests {
.expect("block exists");

assert_eq!(start_block.number + 2, current_block.number);
assert_eq!(start_block.timestamp + 2000, current_block.timestamp);
assert_eq!(start_block.timestamp + 2, current_block.timestamp);
}
}
6 changes: 3 additions & 3 deletions src/hardhat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ mod tests {
.expect("block exists");

assert_eq!(start_block.number + 1, current_block.number);
assert_eq!(start_block.timestamp + 1000, current_block.timestamp);
assert_eq!(start_block.timestamp + 1, current_block.timestamp);
let result = hardhat
.hardhat_mine(None, None)
.await
Expand All @@ -330,7 +330,7 @@ mod tests {
.expect("block exists");

assert_eq!(start_block.number + 2, current_block.number);
assert_eq!(start_block.timestamp + 2000, current_block.timestamp);
assert_eq!(start_block.timestamp + 2, current_block.timestamp);
}

#[tokio::test]
Expand All @@ -347,7 +347,7 @@ mod tests {

let num_blocks = 5;
let interval = 3;
let start_timestamp = start_block.timestamp + 1_000;
let start_timestamp = start_block.timestamp + 1;

let result = hardhat
.hardhat_mine(Some(U64::from(num_blocks)), Some(U64::from(interval)))
Expand Down
Loading

0 comments on commit f19fe6c

Please sign in to comment.