Skip to content
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

fix(upgrade.test.ts): minting from a clean state #2402

Merged
merged 54 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
e3c26c6
CI test
benceharomi Jul 3, 2024
01e0d46
Merge branch 'main' into bh/ci-test
benceharomi Jul 4, 2024
ec1a1c1
Merge branch 'main' into bh/ci-test
benceharomi Jul 4, 2024
d5d2273
Merge branch 'main' into bh/ci-test
benceharomi Jul 5, 2024
b015bd7
nonce logs
benceharomi Jul 5, 2024
ac40e25
unneeded allowance approval
benceharomi Jul 5, 2024
d2b02db
Merge branch 'main' into bh/ci-test
benceharomi Jul 5, 2024
12b62b4
Revert "unneeded allowance approval"
benceharomi Jul 5, 2024
f8ae7f3
approval change
benceharomi Jul 5, 2024
7c32b6e
nonce override for approve
benceharomi Jul 5, 2024
ab387b7
approval process change
benceharomi Jul 5, 2024
20648d8
fix
benceharomi Jul 5, 2024
df2c6c8
lint: unused var
benceharomi Jul 5, 2024
2c5fb55
Merge branch 'main' into bh/ci-test
benceharomi Jul 5, 2024
f2c31c4
removing debug logs
benceharomi Jul 5, 2024
0c14806
Merge branch 'main' into bh/ci-test
benceharomi Jul 5, 2024
d30a974
Merge branch 'main' into bh/ci-test
benceharomi Jul 8, 2024
7691382
running only upgrade tests
benceharomi Jul 8, 2024
fb65d9c
debug logs
benceharomi Jul 8, 2024
31e165e
mintToWallet fix
benceharomi Jul 8, 2024
36be6b2
Revert "debug logs"
benceharomi Jul 8, 2024
029ae93
skipping zk_toolbox tests
benceharomi Jul 8, 2024
16f21f2
Merge branch 'main' into bh/ci-test-2
benceharomi Jul 9, 2024
712073d
Merge branch 'main' into bh/ci-test-2
benceharomi Jul 9, 2024
73ab11d
logs added for debugging
benceharomi Jul 9, 2024
0af08b2
manually setting gasLimit and gasPrice
benceharomi Jul 10, 2024
c0fddee
Merge branch 'main' into bh/ci-test-2
benceharomi Jul 10, 2024
73fc271
fix: from address added to estimateGas
benceharomi Jul 10, 2024
0d12611
Merge branch 'main' into bh/ci-test-2
benceharomi Jul 10, 2024
3c36e77
Merge remote-tracking branch 'origin/main' into bh/ci-test-2
benceharomi Jul 11, 2024
ac26300
Revert "running only upgrade tests"
benceharomi Jul 11, 2024
6bf8ec0
Revert "skipping zk_toolbox tests"
benceharomi Jul 11, 2024
1c184ea
Revert "logs added for debugging"
benceharomi Jul 11, 2024
fd32b95
Merge remote-tracking branch 'origin/main' into bh/ci-test-2
benceharomi Jul 11, 2024
8a994b4
Merge branch 'main' into bh/ci-test-2
benceharomi Jul 11, 2024
791a0fe
Merge branch 'main' into bh/ci-test-2
benceharomi Jul 12, 2024
89dd80f
Merge branch 'main' into bh/ci-test-2
benceharomi Jul 12, 2024
a18bf3b
Merge branch 'main' into bh/ci-test-2
benceharomi Jul 23, 2024
eab33ed
Revert "fix: from address added to estimateGas"
benceharomi Jul 23, 2024
e4042ca
Revert "manually setting gasLimit and gasPrice"
benceharomi Jul 23, 2024
7b0a318
Merge branch 'main' into bh/ci-test-2
benceharomi Jul 24, 2024
36a3484
Merge branch 'main' into bh/ci-test-2
benceharomi Aug 8, 2024
9d256f7
Merge branch 'main' into bh/ci-test-2
benceharomi Aug 8, 2024
51cfada
Merge branch 'main' into bh/ci-test-2
benceharomi Aug 8, 2024
44a9113
Merge branch 'main' into bh/ci-test-2
benceharomi Aug 8, 2024
1b22902
Merge branch 'main' into bh/ci-test-2
benceharomi Aug 9, 2024
a0a0588
Merge branch 'main' into bh/ci-test-2
benceharomi Aug 9, 2024
95b2deb
Merge branch 'main' into bh/ci-test-2
benceharomi Aug 9, 2024
b10b5b5
Merge branch 'main' into bh/ci-test-2
benceharomi Aug 12, 2024
4b7aa51
Merge branch 'main' into bh/ci-test-2
benceharomi Aug 13, 2024
9fe92e4
Merge branch 'main' into bh/ci-test-2
benceharomi Aug 13, 2024
d1a58e3
test(erc20.test.ts): deposit with max balance test cleanup
benceharomi Aug 13, 2024
e1bd2ca
Merge branch 'main' into bh/ci-test-2
benceharomi Aug 15, 2024
60204a9
Merge branch 'main' into bh/ci-test-2
benceharomi Aug 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions core/tests/ts-integration/tests/erc20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ describe('ERC20 contract checks', () => {
let testMaster: TestMaster;
let alice: zksync.Wallet;
let bob: zksync.Wallet;
let isETHBasedChain: boolean;
let baseTokenAddress: string;
let tokenDetails: Token;
let aliceErc20: zksync.Contract;

Expand All @@ -23,6 +25,10 @@ describe('ERC20 contract checks', () => {
alice = testMaster.mainAccount();
bob = testMaster.newEmptyAccount();

// Get the information about base token address directly from the L2.
baseTokenAddress = await alice._providerL2().getBaseTokenContractAddress();
isETHBasedChain = baseTokenAddress == zksync.utils.ETH_ADDRESS_IN_CONTRACTS;

tokenDetails = testMaster.environment().erc20Token;
aliceErc20 = new zksync.Contract(tokenDetails.l2Address, zksync.utils.IERC20, alice);
});
Expand Down Expand Up @@ -207,48 +213,47 @@ describe('ERC20 contract checks', () => {
});

test('Can perform a deposit with precalculated max value', async () => {
const baseTokenAddress = await alice._providerL2().getBaseTokenContractAddress();
const isETHBasedChain = baseTokenAddress == zksync.utils.ETH_ADDRESS_IN_CONTRACTS;
if (!isETHBasedChain) {
// approving whole base token balance
const baseTokenDetails = testMaster.environment().baseToken;
const baseTokenMaxAmount = await alice.getBalanceL1(baseTokenDetails.l1Address);
await (await alice.approveERC20(baseTokenDetails.l1Address, baseTokenMaxAmount)).wait();
}

// Approving the needed allowance to ensure that the user has enough funds.
const maxAmount = await alice.getBalanceL1(tokenDetails.l1Address);
await (await alice.approveERC20(tokenDetails.l1Address, maxAmount)).wait();
// depositing the max amount: the whole balance of the token
const tokenDepositAmount = await alice.getBalanceL1(tokenDetails.l1Address);

// approving the needed allowance for the deposit
await (await alice.approveERC20(tokenDetails.l1Address, tokenDepositAmount)).wait();

// fee of the deposit in ether
const depositFee = await alice.getFullRequiredDepositFee({
token: tokenDetails.l1Address
});

// checking if alice has enough funds to pay the fee
const l1Fee = depositFee.l1GasLimit * (depositFee.maxFeePerGas! || depositFee.gasPrice!);
const l2Fee = depositFee.baseCost;
const aliceETHBalance = await alice.getBalanceL1();

if (aliceETHBalance < l1Fee + l2Fee) {
throw new Error('Not enough ETH to perform a deposit');
const aliceBalance = await alice.getBalanceL1();
if (aliceBalance < l1Fee + l2Fee) {
throw new Error('Not enough balance to pay the fee');
}

const l2ERC20BalanceChange = await shouldChangeTokenBalances(tokenDetails.l2Address, [
{ wallet: alice, change: maxAmount }
]);

const overrides: ethers.Overrides = depositFee.gasPrice
? { gasPrice: depositFee.gasPrice }
: {
maxFeePerGas: depositFee.maxFeePerGas,
maxPriorityFeePerGas: depositFee.maxPriorityFeePerGas
};
overrides.gasLimit = depositFee.l1GasLimit;
const depositOp = await alice.deposit({
// deposit handle with the precalculated max amount
const depositHandle = await alice.deposit({
token: tokenDetails.l1Address,
amount: maxAmount,
amount: tokenDepositAmount,
l2GasLimit: depositFee.l2GasLimit,
overrides
approveBaseERC20: true,
approveERC20: true,
overrides: depositFee
});
await expect(depositOp).toBeAccepted([l2ERC20BalanceChange]);

// checking the l2 balance change
const l2TokenBalanceChange = await shouldChangeTokenBalances(tokenDetails.l2Address, [
{ wallet: alice, change: tokenDepositAmount }
]);
await expect(depositHandle).toBeAccepted([l2TokenBalanceChange]);
});

afterAll(async () => {
Expand Down
11 changes: 8 additions & 3 deletions core/tests/upgrade-test/tests/upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('Upgrade test', function () {

if (!zksync.utils.isAddressEq(baseToken, zksync.utils.ETH_ADDRESS_IN_CONTRACTS)) {
await (await tester.syncWallet.approveERC20(baseToken, ethers.MaxUint256)).wait();
await mintToWallet(baseToken, tester.syncWallet, depositAmount * 10n);
await mintToAddress(baseToken, tester.ethWallet, tester.syncWallet.address, depositAmount * 10n);
}

const firstDepositHandle = await tester.syncWallet.deposit({
Expand Down Expand Up @@ -575,10 +575,15 @@ function prepareGovernanceCalldata(to: string, data: BytesLike): UpgradeCalldata
};
}

async function mintToWallet(baseTokenAddress: zksync.types.Address, ethersWallet: ethers.Wallet, amountToMint: bigint) {
async function mintToAddress(
baseTokenAddress: zksync.types.Address,
ethersWallet: ethers.Wallet,
addressToMintTo: string,
amountToMint: bigint
) {
const l1Erc20ABI = ['function mint(address to, uint256 amount)'];
const l1Erc20Contract = new ethers.Contract(baseTokenAddress, l1Erc20ABI, ethersWallet);
await (await l1Erc20Contract.mint(ethersWallet.address, amountToMint)).wait();
await (await l1Erc20Contract.mint(addressToMintTo, amountToMint)).wait();
}

const SEMVER_MINOR_VERSION_MULTIPLIER = 4294967296;
Expand Down
Loading