Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
code review improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmurdoch committed May 31, 2022
1 parent fecfb6c commit bf9cfbd
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions src/chains/ethereum/ethereum/tests/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,28 @@ describe("provider", () => {
const options = provider.getOptions();
assert(options.miner.timestampIncrement, "clock");

const accounts = await provider.send("eth_accounts");
const tx = { from: accounts[0], gas: "0xfffff" };
const sentAfter = Math.floor(Date.now() / 1000);
const hash = await provider.request({
method: "eth_sendTransaction",
params: [tx]
});
const receipt = await provider.request({
method: "eth_getTransactionReceipt",
params: [hash]
const timeBeforeMiningBlock = Math.floor(Date.now() / 1000);
await provider.request({
method: "evm_mine",
params: []
});
assert.notStrictEqual(receipt, null);
const sentBefore = Math.floor(Date.now() / 1000);
const timeAfterMiningBlock = Math.floor(Date.now() / 1000);
const block = await provider.request({
method: "eth_getBlockByNumber",
params: [receipt.blockNumber, false]
params: ["latest", false]
});
// the `block.timestamp` can be the same as `sentAfter` and/or
// `sentBefore` because the precision of `block.timestamp` is 1 second
// (floored), and mining happens much quicker than 1 second.
// the `block.timestamp` can be the same as `timeBeforeMiningBlock` and/or
// `timeAfterMiningBlock` because the precision of `block.timestamp` is 1
// second (floored), and mining happens much quicker than 1 second.
assert(
parseInt(block.timestamp) >= sentAfter,
`block wasn't mined at the right time, should have been on or after ${sentAfter}, was ${parseInt(
parseInt(block.timestamp) >= timeBeforeMiningBlock,
`block wasn't mined at the right time, should have been on or after ${timeBeforeMiningBlock}, was ${parseInt(
block.timestamp
)}`
);
assert(
parseInt(block.timestamp) <= sentBefore,
`block wasn't mined at the right time, should have been on or before ${sentAfter}, was ${parseInt(
parseInt(block.timestamp) <= timeAfterMiningBlock,
`block wasn't mined at the right time, should have been on or before ${timeAfterMiningBlock}, was ${parseInt(
block.timestamp
)}`
);
Expand Down Expand Up @@ -121,7 +114,8 @@ describe("provider", () => {
await provider.disconnect();
await fakeMainnet.disconnect();
});
it("uses the `time` option for the first block even when when `timestampIncrement` is not 'clock' when forking", async () => {

it("uses the `time` option for the first block even when `timestampIncrement` is not 'clock' when forking", async () => {
const time = new Date("2019-01-01T00:00:00.000Z");
const timestampIncrement = 5;
const fakeMainnet = await getProvider({
Expand Down

0 comments on commit bf9cfbd

Please sign in to comment.