forked from matter-labs/zksync-era
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kl factory - deposit tests #190
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6079c19
native erc20 deposit test
juan518munoz 70a1322
zk fmt
juan518munoz 577f26c
add test not enough balance
juan518munoz 1a93797
add L2_ETH_TOKEN_ADDRESS var
juan518munoz 1678b01
replace let with const
juan518munoz 16e33e9
fix suite wallet pk
juan518munoz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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
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,97 @@ | ||
/** | ||
* This suite contains tests checking default ERC-20 contract behavior. | ||
*/ | ||
|
||
import { TestMaster } from '../src/index'; | ||
import { Token } from '../src/types'; | ||
|
||
import * as zksync from 'zksync-ethers'; | ||
import { BigNumber } from 'ethers'; | ||
import * as ethers from 'ethers'; | ||
import { scaledGasPrice } from '../src/helpers'; | ||
|
||
describe('ERC20 contract checks', () => { | ||
let testMaster: TestMaster; | ||
let alice: zksync.Wallet; | ||
let baseTokenDetails: Token; | ||
let aliceBaseErc20: ethers.Contract; | ||
let chainId: ethers.BigNumberish; | ||
|
||
beforeAll(async () => { | ||
testMaster = TestMaster.getInstance(__filename); | ||
alice = testMaster.mainAccount(); | ||
chainId = process.env.CHAIN_ETH_ZKSYNC_NETWORK_ID!; | ||
|
||
baseTokenDetails = testMaster.environment().baseToken; | ||
aliceBaseErc20 = new ethers.Contract(baseTokenDetails.l1Address, zksync.utils.IERC20, alice._providerL1()); | ||
}); | ||
|
||
test('Can perform a deposit', async () => { | ||
const amount = 1; // 1 wei is enough. | ||
const gasPrice = scaledGasPrice(alice); | ||
|
||
const initialEthBalance = await alice.getBalanceL1(); | ||
const initialL1Balance = await alice.getBalanceL1(baseTokenDetails.l1Address); | ||
const initialL2Balance = await alice.getBalance(); | ||
|
||
const depositTx = await alice.deposit({ | ||
token: baseTokenDetails.l1Address, | ||
amount: amount, | ||
approveERC20: true, | ||
approveBaseERC20: true, | ||
approveBaseOverrides: { | ||
gasPrice | ||
}, | ||
approveOverrides: { | ||
gasPrice | ||
}, | ||
overrides: { | ||
gasPrice | ||
} | ||
}); | ||
const depositHash = depositTx.hash; | ||
await depositTx.wait(); | ||
|
||
const receipt = await alice._providerL1().getTransactionReceipt(depositHash); | ||
const fee = receipt.effectiveGasPrice.mul(receipt.gasUsed); | ||
|
||
// TODO: should all the following tests use strict equality? | ||
|
||
const finalEthBalance = await alice.getBalanceL1(); | ||
expect(initialEthBalance).bnToBeGt(finalEthBalance.add(fee)); // Fee should be taken from the ETH balance on L1. | ||
|
||
const finalL1Balance = await alice.getBalanceL1(baseTokenDetails.l1Address); | ||
expect(initialL1Balance).bnToBeGte(finalL1Balance.add(amount)); | ||
|
||
const finalL2Balance = await alice.getBalance(); | ||
expect(initialL2Balance).bnToBeLte(finalL2Balance.add(amount)); | ||
}); | ||
|
||
test('Not enough balance should revert', async () => { | ||
const amount = BigNumber.from('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'); | ||
const gasPrice = scaledGasPrice(alice); | ||
let errorMessage; | ||
|
||
await expect( | ||
alice.deposit({ | ||
token: baseTokenDetails.l1Address, | ||
amount: amount, | ||
approveERC20: true, | ||
approveBaseERC20: true, | ||
approveBaseOverrides: { | ||
gasPrice | ||
}, | ||
approveOverrides: { | ||
gasPrice | ||
}, | ||
overrides: { | ||
gasPrice | ||
} | ||
}) | ||
).toBeRejected(errorMessage); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testMaster.deinitialize(); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Care to explain bit more about this comment?
Do we have an issue for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon further inspecting how the testing works, it turns out that the individual wallet used for each test wasn't getting native erc20 funds needed, this is now done inside of
distributeL1BaseToken()
.