-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7d9e73
commit 2d6b2da
Showing
5 changed files
with
177 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { expect } from "chai"; | ||
import { getTestProvider } from "../helpers/utils"; | ||
import { Wallet } from "zksync-web3"; | ||
import { RichAccounts } from "../helpers/constants"; | ||
import { ethers } from "ethers"; | ||
|
||
const provider = getTestProvider(); | ||
|
||
// TODO: Investigate why deploying a smart contract after this crashes the bootloader/VM | ||
xdescribe("evm_mine", function () { | ||
it("Should mine one block", async function () { | ||
// Arrange | ||
const startingBlock = await provider.getBlock("latest"); | ||
|
||
// Act | ||
await provider.send("evm_mine", []); | ||
|
||
// Assert | ||
const latestBlock = await provider.getBlock("latest"); | ||
expect(latestBlock.number).to.equal(startingBlock.number + 1); | ||
}); | ||
}); | ||
|
||
describe("evm_increaseTime", function () { | ||
it("Should increase current timestamp of the node", async function () { | ||
// Arrange | ||
const timeIncreaseInSeconds = 13; | ||
let expectedTimestamp = (await provider.getBlock("latest")).timestamp; | ||
expectedTimestamp += timeIncreaseInSeconds * 1000; | ||
const wallet = new Wallet(RichAccounts[0].PrivateKey, provider); | ||
const userWallet = Wallet.createRandom().connect(provider); | ||
|
||
// Act | ||
await provider.send("evm_increaseTime", [timeIncreaseInSeconds]); | ||
|
||
await wallet.sendTransaction({ | ||
to: userWallet.address, | ||
value: ethers.utils.parseEther("0.1"), | ||
}); | ||
expectedTimestamp += 1; // New transaction will increase timestamp by 1 | ||
|
||
// Assert | ||
const currentBlockTimestamp = (await provider.getBlock("latest")).timestamp; | ||
expect(currentBlockTimestamp).to.equal(expectedTimestamp); | ||
}); | ||
}); | ||
|
||
describe("evm_setNextBlockTimestamp", function () { | ||
it("Should set current timestamp of the node to specific value", async function () { | ||
// Arrange | ||
const timeIncreaseInMS = 123; | ||
let newTimestamp = (await provider.getBlock("latest")).timestamp; | ||
newTimestamp += timeIncreaseInMS; | ||
const wallet = new Wallet(RichAccounts[0].PrivateKey, provider); | ||
const userWallet = Wallet.createRandom().connect(provider); | ||
|
||
// Act | ||
await provider.send("evm_setNextBlockTimestamp", [newTimestamp]); | ||
|
||
await wallet.sendTransaction({ | ||
to: userWallet.address, | ||
value: ethers.utils.parseEther("0.1"), | ||
}); | ||
|
||
// Assert | ||
const currentBlockTimestamp = (await provider.getBlock("latest")).timestamp; | ||
expect(currentBlockTimestamp).to.equal(newTimestamp); | ||
}); | ||
}); | ||
|
||
describe("evm_setTime", function () { | ||
it("Should set current timestamp of the node to specific value", async function () { | ||
// Arrange | ||
const timeIncreaseInMS = 123; | ||
let newTimestamp = (await provider.getBlock("latest")).timestamp; | ||
newTimestamp += timeIncreaseInMS; | ||
const wallet = new Wallet(RichAccounts[0].PrivateKey, provider); | ||
const userWallet = Wallet.createRandom().connect(provider); | ||
|
||
// Act | ||
await provider.send("evm_setTime", [newTimestamp]); | ||
|
||
await wallet.sendTransaction({ | ||
to: userWallet.address, | ||
value: ethers.utils.parseEther("0.1"), | ||
}); | ||
|
||
// Assert | ||
const currentBlockTimestamp = (await provider.getBlock("latest")).timestamp; | ||
expect(currentBlockTimestamp).to.equal(newTimestamp); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { expect } from "chai"; | ||
import { getTestProvider } from "../helpers/utils"; | ||
import { Wallet } from "zksync-web3"; | ||
import { RichAccounts } from "../helpers/constants"; | ||
import { ethers } from "ethers"; | ||
import { TransactionRequest } from "zksync-web3/build/src/types"; | ||
|
||
const provider = getTestProvider(); | ||
|
||
interface Fee { | ||
gas_limit: ethers.BigNumber; | ||
gas_per_pubdata_limit: ethers.BigNumber; | ||
max_fee_per_gas: ethers.BigNumber; | ||
max_priority_fee_per_gas: ethers.BigNumber; | ||
} | ||
|
||
describe("zks_estimateFee", function () { | ||
it("Should return fee estimation data for transfer of 1 ETH", async function () { | ||
// Arrange | ||
const wallet = new Wallet(RichAccounts[0].PrivateKey, provider); | ||
const userWallet = Wallet.createRandom().connect(provider); | ||
const transaction: TransactionRequest = { | ||
from: wallet.address, | ||
to: userWallet.address, | ||
value: ethers.utils.parseEther("1")._hex, | ||
}; | ||
|
||
// Act | ||
const response: Fee = await provider.send("zks_estimateFee", [transaction]); | ||
|
||
// Assert | ||
expect( | ||
ethers.BigNumber.from(response.gas_limit).eq( | ||
ethers.BigNumber.from("1228893") | ||
) | ||
).to.true; | ||
expect( | ||
ethers.BigNumber.from(response.gas_per_pubdata_limit).eq( | ||
ethers.BigNumber.from("4080") | ||
) | ||
).to.true; | ||
expect( | ||
ethers.BigNumber.from(response.max_fee_per_gas).eq( | ||
ethers.BigNumber.from("250000000") | ||
) | ||
).to.true; | ||
expect( | ||
ethers.BigNumber.from(response.max_priority_fee_per_gas).eq( | ||
ethers.BigNumber.from("0") | ||
) | ||
).to.true; | ||
}); | ||
}); | ||
|
||
describe("zks_getTokenPrice", function () { | ||
it("Should return fake token Price for ETH", async function () { | ||
// Arrange | ||
const ethAddress = "0x0000000000000000000000000000000000000000"; | ||
|
||
// Act | ||
const response: string = await provider.send("zks_getTokenPrice", [ethAddress]); | ||
|
||
// Assert | ||
expect(response).to.equal("1500"); | ||
}); | ||
}); |