From 1e3c4627ed5f79ee892233e50d58ed53fee4e45b Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Thu, 25 Jan 2024 17:25:21 -0300 Subject: [PATCH 01/15] change contracts submodule --- contracts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts b/contracts index 79f4c20c2c58..42a6f2658fda 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit 79f4c20c2c58c2134823e15a9dda38137af0d03d +Subproject commit 42a6f2658fda9feef14e41e3db578f2c9c2f746e From a499871aac1747e5b998f05bf815bfb4618807ea Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Thu, 25 Jan 2024 17:25:39 -0300 Subject: [PATCH 02/15] remove test context restrictions --- .../tests/ts-integration/src/context-owner.ts | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/core/tests/ts-integration/src/context-owner.ts b/core/tests/ts-integration/src/context-owner.ts index ac9a6a9e4741..b7dec6238f4f 100644 --- a/core/tests/ts-integration/src/context-owner.ts +++ b/core/tests/ts-integration/src/context-owner.ts @@ -241,7 +241,7 @@ export class TestContextOwner { const gasPrice = await scaledGasPrice(this.mainEthersWallet); // Deposit L2 tokens (if needed). Depositing ETH with current native implementation is not supported. - if (!l2ETHAmountToDeposit.isZero() && !this.env.nativeErc20Testing) { + if (!l2ETHAmountToDeposit.isZero()) { // Given that we've already sent a number of transactions, // we have to correctly send nonce. const depositHandle = this.mainSyncWallet @@ -341,23 +341,17 @@ export class TestContextOwner { this.reporter.startAction(`Distributing tokens on L2`); let l2startNonce = await this.mainSyncWallet.getTransactionCount(); - // All the promises we send in this function. - const l2TxPromises: Promise[] = []; - // ETH transfers. - if (!this.env.nativeErc20Testing) { - const ethPromises = await sendTransfers( - zksync.utils.ETH_ADDRESS, - this.mainSyncWallet, - wallets, - L2_ETH_PER_ACCOUNT, - l2startNonce, - undefined, - this.reporter - ); - l2startNonce += l2TxPromises.length; - l2TxPromises.push(...ethPromises); - } + const l2TxPromises = await sendTransfers( + zksync.utils.ETH_ADDRESS, + this.mainSyncWallet, + wallets, + L2_ETH_PER_ACCOUNT, + l2startNonce, + undefined, + this.reporter + ); + l2startNonce += l2TxPromises.length; // ERC20 transfers. const l2TokenAddress = await this.mainSyncWallet.l2TokenAddress(this.env.erc20Token.l1Address); From 879c7998c45a5a3f83b6f2f22a3f005e93dfb2dc Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Fri, 26 Jan 2024 16:37:23 -0300 Subject: [PATCH 03/15] deposit eth in context owner --- core/tests/ts-integration/src/context-owner.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/tests/ts-integration/src/context-owner.ts b/core/tests/ts-integration/src/context-owner.ts index b7dec6238f4f..93d94f9e56af 100644 --- a/core/tests/ts-integration/src/context-owner.ts +++ b/core/tests/ts-integration/src/context-owner.ts @@ -246,11 +246,12 @@ export class TestContextOwner { // we have to correctly send nonce. const depositHandle = this.mainSyncWallet .deposit({ - to: this.mainEthersWallet.address, - approveERC20: true, - token: this.env.erc20Token.l1Address, + token: zksync.utils.ETH_ADDRESS, amount: l2ETHAmountToDeposit, - refundRecipient: this.mainEthersWallet.address + overrides: { + nonce: nonce++, + gasPrice + } }) .then((tx) => { const amount = ethers.utils.formatEther(l2ETHAmountToDeposit); From 69813294ebeab12523f918e1db3579034adb73df Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Mon, 29 Jan 2024 11:10:10 +0100 Subject: [PATCH 04/15] add non native token integration test --- .../tests/non-native-erc20-deposit.test.ts | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts diff --git a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts new file mode 100644 index 000000000000..187211721cfd --- /dev/null +++ b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts @@ -0,0 +1,56 @@ +/** + * This suite contains tests checking default ERC-20 contract behavior. + */ + +import { TestMaster } from '../src/index'; +import { Token } from '../src/types'; +import { shouldChangeTokenBalances, shouldOnlyTakeFee } from '../src/modifiers/balance-checker'; + +import * as zksync from 'zksync-web3'; +import { BigNumber, utils as etherUtils } from 'ethers'; +import * as ethers from 'ethers'; +import { scaledGasPrice, waitUntilBlockFinalized } from '../src/helpers'; +import { L2_ETH_PER_ACCOUNT } from '../src/context-owner'; + +describe('ERC20 contract checks', () => { + let testMaster: TestMaster; + let alice: zksync.Wallet; + let bob: zksync.Wallet; + let tokenDetails: Token; + let aliceErc20: zksync.Contract; + + beforeAll(async () => { + testMaster = TestMaster.getInstance(__filename); + alice = testMaster.mainAccount(); + bob = testMaster.newEmptyAccount(); + + tokenDetails = testMaster.environment().erc20Token; + aliceErc20 = new zksync.Contract(tokenDetails.l2Address, zksync.utils.IERC20, alice); + }); + + + test('Can perform a deposit', async () => { + const amount = 1; + const gasPrice = scaledGasPrice(alice); + + const initialTokenBalance = await alice.getBalanceL1(tokenDetails.l1Address); + await alice.deposit({ + token: tokenDetails.l1Address, + amount, + approveERC20: true, + approveOverrides: { + gasPrice + }, + overrides: { + gasPrice + } + }); + + const finalTokenBalance = await alice.getBalanceL1(tokenDetails.l1Address); + expect(finalTokenBalance.sub(initialTokenBalance)).toEqual(amount); + }); + + afterAll(async () => { + await testMaster.deinitialize(); + }); +}); From 6420aa7483ccaac08c2bcd1b0219248d21fc0df7 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Mon, 29 Jan 2024 11:12:38 +0100 Subject: [PATCH 05/15] apply fmt --- .../tests/non-native-erc20-deposit.test.ts | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts index 187211721cfd..28d4e535c0ce 100644 --- a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts +++ b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts @@ -28,23 +28,22 @@ describe('ERC20 contract checks', () => { aliceErc20 = new zksync.Contract(tokenDetails.l2Address, zksync.utils.IERC20, alice); }); - test('Can perform a deposit', async () => { const amount = 1; const gasPrice = scaledGasPrice(alice); const initialTokenBalance = await alice.getBalanceL1(tokenDetails.l1Address); await alice.deposit({ - token: tokenDetails.l1Address, - amount, - approveERC20: true, - approveOverrides: { - gasPrice - }, - overrides: { - gasPrice - } - }); + token: tokenDetails.l1Address, + amount, + approveERC20: true, + approveOverrides: { + gasPrice + }, + overrides: { + gasPrice + } + }); const finalTokenBalance = await alice.getBalanceL1(tokenDetails.l1Address); expect(finalTokenBalance.sub(initialTokenBalance)).toEqual(amount); From dcb066894f48922fd06e56d78a0442846617a957 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Wed, 31 Jan 2024 14:07:21 +0100 Subject: [PATCH 06/15] wip in tests --- .../tests/non-native-erc20-deposit.test.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts index 28d4e535c0ce..e4cf5312ecbb 100644 --- a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts +++ b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts @@ -33,19 +33,26 @@ describe('ERC20 contract checks', () => { const gasPrice = scaledGasPrice(alice); const initialTokenBalance = await alice.getBalanceL1(tokenDetails.l1Address); - await alice.deposit({ + const deposit = await alice.deposit({ + l2GasLimit: 500_000, token: tokenDetails.l1Address, amount, approveERC20: true, approveOverrides: { - gasPrice + gasPrice, + gasLimit: 5_000_000, }, overrides: { - gasPrice + gasPrice, + gasLimit: 5_000_000, } }); + await deposit.waitFinalize(); + const finalTokenBalance = await alice.getBalanceL1(tokenDetails.l1Address); + console.log('initialTokenBalance', initialTokenBalance.toString()); + console.log('finalTokenBalance', finalTokenBalance.toString()); expect(finalTokenBalance.sub(initialTokenBalance)).toEqual(amount); }); From d565b30f988da776d8197dd879c55339fc429a2c Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Thu, 1 Feb 2024 15:59:41 +0100 Subject: [PATCH 07/15] try different l2 addresses --- .../tests/non-native-erc20-deposit.test.ts | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts index e4cf5312ecbb..92e53b2d91ae 100644 --- a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts +++ b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts @@ -29,9 +29,11 @@ describe('ERC20 contract checks', () => { }); test('Can perform a deposit', async () => { - const amount = 1; + const amount = 555; const gasPrice = scaledGasPrice(alice); + // L1 Deposit + const initialTokenBalance = await alice.getBalanceL1(tokenDetails.l1Address); const deposit = await alice.deposit({ l2GasLimit: 500_000, @@ -53,7 +55,35 @@ describe('ERC20 contract checks', () => { const finalTokenBalance = await alice.getBalanceL1(tokenDetails.l1Address); console.log('initialTokenBalance', initialTokenBalance.toString()); console.log('finalTokenBalance', finalTokenBalance.toString()); - expect(finalTokenBalance.sub(initialTokenBalance)).toEqual(amount); + + // L2 Deposit Finalize + const l2ERC20Bridge = (await alice.getL2BridgeContracts()).erc20; + const finalizeDeposit = await l2ERC20Bridge['finalizeDeposit(address,address,address,uint256,bytes)'](alice.address, alice.address, tokenDetails.l1Address, amount, '0x') + console.log('wait finalize', await finalizeDeposit.wait()); + + + // L2 balance with address trough l1 address + const l2TokenAddress = await (await alice.getL1BridgeContracts()).erc20['l2TokenAddress(address)'](tokenDetails.l1Address); + const l2BalanceThroughL1Bridge = await alice.getBalance(l2TokenAddress); + console.log('address: l2BalanceThroughL1Bridge with l1 address', l2BalanceThroughL1Bridge.toString()); + console.log('l2BalanceThroughL1Bridge with l1 address', l2BalanceThroughL1Bridge.toString()); + + // L2 balance with l1 address + const l2Balance = await alice.getBalance(tokenDetails.l1Address); + console.log('[ADDRESS] l2Balance with l1 address', tokenDetails.l1Address.toString()); + console.log('l2Balance with l1 address', l2Balance.toString()); + + // L2 balance with l2 address + const l2Balance2 = await alice.getBalance(tokenDetails.l2Address); + console.log('[ADDRESS] l2Balance with l2 address', tokenDetails.l2Address.toString()); + console.log('l2Balance with l2 address', l2Balance2.toString()); + + // L2 balance with l2 address + const aliceL2Balance = await alice.getBalance(aliceErc20.address); + console.log('[ADDRESS] alice l2Balance with l2 address', aliceErc20.address.toString()); + console.log('alice l2Balance with l2 address', aliceL2Balance.toString()); + + expect(initialTokenBalance.sub(finalTokenBalance)).toEqual(BigNumber.from(amount)); }); afterAll(async () => { From c5953d82e08069796d5e4416def3643b07a6d808 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Thu, 1 Feb 2024 19:52:10 +0100 Subject: [PATCH 08/15] try different l2 addresses --- .../tests/non-native-erc20-deposit.test.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts index 92e53b2d91ae..1314a61cf0c1 100644 --- a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts +++ b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts @@ -42,11 +42,11 @@ describe('ERC20 contract checks', () => { approveERC20: true, approveOverrides: { gasPrice, - gasLimit: 5_000_000, + gasLimit: 5_000_000 }, overrides: { gasPrice, - gasLimit: 5_000_000, + gasLimit: 5_000_000 } }); @@ -58,12 +58,19 @@ describe('ERC20 contract checks', () => { // L2 Deposit Finalize const l2ERC20Bridge = (await alice.getL2BridgeContracts()).erc20; - const finalizeDeposit = await l2ERC20Bridge['finalizeDeposit(address,address,address,uint256,bytes)'](alice.address, alice.address, tokenDetails.l1Address, amount, '0x') + const finalizeDeposit = await l2ERC20Bridge['finalizeDeposit(address,address,address,uint256,bytes)']( + alice.address, + alice.address, + tokenDetails.l1Address, + amount, + '0x' + ); console.log('wait finalize', await finalizeDeposit.wait()); - // L2 balance with address trough l1 address - const l2TokenAddress = await (await alice.getL1BridgeContracts()).erc20['l2TokenAddress(address)'](tokenDetails.l1Address); + const l2TokenAddress = await ( + await alice.getL1BridgeContracts() + ).erc20['l2TokenAddress(address)'](tokenDetails.l1Address); const l2BalanceThroughL1Bridge = await alice.getBalance(l2TokenAddress); console.log('address: l2BalanceThroughL1Bridge with l1 address', l2BalanceThroughL1Bridge.toString()); console.log('l2BalanceThroughL1Bridge with l1 address', l2BalanceThroughL1Bridge.toString()); From 1dd94b9ecfca710567675331ef5191c31d01ea33 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Fri, 2 Feb 2024 14:38:31 +0100 Subject: [PATCH 09/15] add l2bridge query --- .../ts-integration/tests/non-native-erc20-deposit.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts index 1314a61cf0c1..19dc1d0de8d0 100644 --- a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts +++ b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts @@ -67,6 +67,14 @@ describe('ERC20 contract checks', () => { ); console.log('wait finalize', await finalizeDeposit.wait()); + const l2Bridge = (await alice.getL2BridgeContracts()).erc20; + console.log('l2Bridge', l2Bridge); + // L2 balance with address trough l2 bridge address + const l2TokenAddressWithL2Bridge = await l2Bridge['l2TokenAddress(address)'](tokenDetails.l1Address); + const l2BalanceThroughL2Bridge = await alice.getBalance(l2TokenAddressWithL2Bridge); + console.log('[ADDRESS] l2TokenAddressWithL2Bridge: ', l2TokenAddressWithL2Bridge); + console.log('l2BalanceThroughL2Bridge with l2 bridge address', l2BalanceThroughL2Bridge.toString()); + // L2 balance with address trough l1 address const l2TokenAddress = await ( await alice.getL1BridgeContracts() From 99d6cef0a73ea78b8eb3878b682a424d0144e8dc Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Fri, 2 Feb 2024 19:12:46 +0100 Subject: [PATCH 10/15] wip --- .../tests/non-native-erc20-deposit.test.ts | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts index 19dc1d0de8d0..a97ee459aa8a 100644 --- a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts +++ b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts @@ -29,7 +29,7 @@ describe('ERC20 contract checks', () => { }); test('Can perform a deposit', async () => { - const amount = 555; + const amount = BigNumber.from(555); const gasPrice = scaledGasPrice(alice); // L1 Deposit @@ -50,7 +50,7 @@ describe('ERC20 contract checks', () => { } }); - await deposit.waitFinalize(); + await deposit.waitL1Commit(); const finalTokenBalance = await alice.getBalanceL1(tokenDetails.l1Address); console.log('initialTokenBalance', initialTokenBalance.toString()); @@ -67,36 +67,34 @@ describe('ERC20 contract checks', () => { ); console.log('wait finalize', await finalizeDeposit.wait()); - const l2Bridge = (await alice.getL2BridgeContracts()).erc20; - console.log('l2Bridge', l2Bridge); // L2 balance with address trough l2 bridge address - const l2TokenAddressWithL2Bridge = await l2Bridge['l2TokenAddress(address)'](tokenDetails.l1Address); + const l2TokenAddressWithL2Bridge = await l2ERC20Bridge.l2TokenAddress(tokenDetails.l1Address, {}); const l2BalanceThroughL2Bridge = await alice.getBalance(l2TokenAddressWithL2Bridge); console.log('[ADDRESS] l2TokenAddressWithL2Bridge: ', l2TokenAddressWithL2Bridge); - console.log('l2BalanceThroughL2Bridge with l2 bridge address', l2BalanceThroughL2Bridge.toString()); + console.log('[BALANCE] l2BalanceThroughL2Bridge with l2 bridge address', l2BalanceThroughL2Bridge.toString()); // L2 balance with address trough l1 address const l2TokenAddress = await ( await alice.getL1BridgeContracts() ).erc20['l2TokenAddress(address)'](tokenDetails.l1Address); const l2BalanceThroughL1Bridge = await alice.getBalance(l2TokenAddress); - console.log('address: l2BalanceThroughL1Bridge with l1 address', l2BalanceThroughL1Bridge.toString()); - console.log('l2BalanceThroughL1Bridge with l1 address', l2BalanceThroughL1Bridge.toString()); + console.log('[ADDRESS] l2BalanceThroughL1Bridge with l1 address', l2BalanceThroughL1Bridge.toString()); + console.log('[BALANCE] l2BalanceThroughL1Bridge with l1 address', l2BalanceThroughL1Bridge.toString()); // L2 balance with l1 address const l2Balance = await alice.getBalance(tokenDetails.l1Address); console.log('[ADDRESS] l2Balance with l1 address', tokenDetails.l1Address.toString()); - console.log('l2Balance with l1 address', l2Balance.toString()); + console.log('[BALANCE] l2Balance with l1 address', l2Balance.toString()); // L2 balance with l2 address const l2Balance2 = await alice.getBalance(tokenDetails.l2Address); console.log('[ADDRESS] l2Balance with l2 address', tokenDetails.l2Address.toString()); - console.log('l2Balance with l2 address', l2Balance2.toString()); + console.log('[BALANCE] l2Balance with l2 address', l2Balance2.toString()); // L2 balance with l2 address const aliceL2Balance = await alice.getBalance(aliceErc20.address); console.log('[ADDRESS] alice l2Balance with l2 address', aliceErc20.address.toString()); - console.log('alice l2Balance with l2 address', aliceL2Balance.toString()); + console.log('[BALANCE] alice l2Balance with l2 address', aliceL2Balance.toString()); expect(initialTokenBalance.sub(finalTokenBalance)).toEqual(BigNumber.from(amount)); }); From 38c095004ffeb5a58b1887f4a6ea954e4a1f6f1e Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Mon, 5 Feb 2024 16:44:43 +0100 Subject: [PATCH 11/15] clean up --- .../tests/non-native-erc20-deposit.test.ts | 65 +++++++++++-------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts index a97ee459aa8a..053a3702a266 100644 --- a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts +++ b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts @@ -29,16 +29,17 @@ describe('ERC20 contract checks', () => { }); test('Can perform a deposit', async () => { + const tokenAddress = '0xF12131d79e026D9882d22e4556706496Bdc287E8'; const amount = BigNumber.from(555); const gasPrice = scaledGasPrice(alice); // L1 Deposit - - const initialTokenBalance = await alice.getBalanceL1(tokenDetails.l1Address); + const initialTokenBalance = await alice.getBalanceL1(tokenAddress); const deposit = await alice.deposit({ l2GasLimit: 500_000, - token: tokenDetails.l1Address, + token: tokenAddress, amount, + to: alice.address, approveERC20: true, approveOverrides: { gasPrice, @@ -52,7 +53,7 @@ describe('ERC20 contract checks', () => { await deposit.waitL1Commit(); - const finalTokenBalance = await alice.getBalanceL1(tokenDetails.l1Address); + const finalTokenBalance = await alice.getBalanceL1(tokenAddress); console.log('initialTokenBalance', initialTokenBalance.toString()); console.log('finalTokenBalance', finalTokenBalance.toString()); @@ -61,41 +62,53 @@ describe('ERC20 contract checks', () => { const finalizeDeposit = await l2ERC20Bridge['finalizeDeposit(address,address,address,uint256,bytes)']( alice.address, alice.address, - tokenDetails.l1Address, + tokenAddress, amount, '0x' ); - console.log('wait finalize', await finalizeDeposit.wait()); - // L2 balance with address trough l2 bridge address - const l2TokenAddressWithL2Bridge = await l2ERC20Bridge.l2TokenAddress(tokenDetails.l1Address, {}); - const l2BalanceThroughL2Bridge = await alice.getBalance(l2TokenAddressWithL2Bridge); - console.log('[ADDRESS] l2TokenAddressWithL2Bridge: ', l2TokenAddressWithL2Bridge); - console.log('[BALANCE] l2BalanceThroughL2Bridge with l2 bridge address', l2BalanceThroughL2Bridge.toString()); + const finalizeDepositWait = await finalizeDeposit.wait(); + console.log('finalizeDepositWait', finalizeDepositWait); + + // Token amount should be deposited to the account in the L2 side. + + /// Try through alice.l2TokenAddress + const aliceL2TokenAddress = await alice.l2TokenAddress(tokenAddress); + console.log('[ADDRESS] aliceL2TokenAddress', aliceL2TokenAddress); + const aliceBalanceThroughAliceL2TokenAddress = await alice.getBalance(aliceL2TokenAddress); + console.log( + '[BALANCE] aliceBalanceThroughAliceL2TokenAddress', + aliceBalanceThroughAliceL2TokenAddress.toString() + ); - // L2 balance with address trough l1 address + /// Try through l2ERC20Bridge.l2TokenAddress call opt 1 + // const l2TokenAddressL2Bridge = await ( + // await alice.getL2BridgeContracts() + // ).erc20['l2TokenAddress(address)'](tokenAddress); + // const l2BalanceThroughL2Bridge = await alice.getBalance(l2TokenAddressL2Bridge); + // console.log('[ADDRESS] l2BalanceThroughL2Bridge with l1 address', l2BalanceThroughL2Bridge.toString()); + // console.log('[BALANCE] l2BalanceThroughL2Bridge with l1 address', l2BalanceThroughL2Bridge.toString()); + + /// Try through l2ERC20Bridge.l2TokenAddress call opt 2 + // // L2 balance with address trough l2 bridge address + // const l2TokenAddressWithL2Bridge = await l2ERC20Bridge.l2TokenAddress(tokenAddress, {}); + // const l2BalanceThroughL2Bridge = await alice.getBalance(l2TokenAddressWithL2Bridge); + // console.log('[ADDRESS] l2TokenAddressWithL2Bridge: ', l2TokenAddressWithL2Bridge); + // console.log('[BALANCE] l2BalanceThroughL2Bridge with l2 bridge address', l2BalanceThroughL2Bridge.toString()); + + /// Try through l1ERC20Bridge.l2TokenAddress call const l2TokenAddress = await ( await alice.getL1BridgeContracts() - ).erc20['l2TokenAddress(address)'](tokenDetails.l1Address); + ).erc20['l2TokenAddress(address)'](tokenAddress); const l2BalanceThroughL1Bridge = await alice.getBalance(l2TokenAddress); console.log('[ADDRESS] l2BalanceThroughL1Bridge with l1 address', l2BalanceThroughL1Bridge.toString()); console.log('[BALANCE] l2BalanceThroughL1Bridge with l1 address', l2BalanceThroughL1Bridge.toString()); - // L2 balance with l1 address - const l2Balance = await alice.getBalance(tokenDetails.l1Address); - console.log('[ADDRESS] l2Balance with l1 address', tokenDetails.l1Address.toString()); + /// Try through same address than L1 call + const l2Balance = await alice.getBalance(tokenAddress); + console.log('[ADDRESS] l2Balance with l1 address', tokenAddress.toString()); console.log('[BALANCE] l2Balance with l1 address', l2Balance.toString()); - // L2 balance with l2 address - const l2Balance2 = await alice.getBalance(tokenDetails.l2Address); - console.log('[ADDRESS] l2Balance with l2 address', tokenDetails.l2Address.toString()); - console.log('[BALANCE] l2Balance with l2 address', l2Balance2.toString()); - - // L2 balance with l2 address - const aliceL2Balance = await alice.getBalance(aliceErc20.address); - console.log('[ADDRESS] alice l2Balance with l2 address', aliceErc20.address.toString()); - console.log('[BALANCE] alice l2Balance with l2 address', aliceL2Balance.toString()); - expect(initialTokenBalance.sub(finalTokenBalance)).toEqual(BigNumber.from(amount)); }); From 6f73c4b9692368aa64bff8449e0254b13db9e1f3 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Mon, 5 Feb 2024 17:53:12 +0100 Subject: [PATCH 12/15] add nonNative tokens for testing, remove l2gasLimit from test --- core/tests/ts-integration/src/env.ts | 14 +++++++++++ core/tests/ts-integration/src/types.ts | 4 ++++ .../tests/non-native-erc20-deposit.test.ts | 24 ++++++++++++------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/core/tests/ts-integration/src/env.ts b/core/tests/ts-integration/src/env.ts index 8857f40d4bb7..46aaffc0e940 100644 --- a/core/tests/ts-integration/src/env.ts +++ b/core/tests/ts-integration/src/env.ts @@ -103,6 +103,13 @@ export async function loadTestEnvironment(): Promise { ethers.getDefaultProvider(l1NodeUrl) ).l2TokenAddress(weth.address); + const nonNativeToken = tokens.find((token: { symbol: string }) => token.symbol == 'MLTT')!; + const nonNativeTokenL2Address = await new zksync.Wallet( + mainWalletPK, + new zksync.Provider(l2NodeUrl), + ethers.getDefaultProvider(l1NodeUrl) + ).l2TokenAddress(nonNativeToken.address); + return { network, mainWalletPK, @@ -124,6 +131,13 @@ export async function loadTestEnvironment(): Promise { l1Address: weth.address, l2Address: l2WethAddress }, + nonNativeToken: { + name: nonNativeToken.name, + symbol: nonNativeToken.symbol, + decimals: nonNativeToken.decimals, + l1Address: nonNativeToken.address, + l2Address: nonNativeTokenL2Address + }, nativeErc20Testing }; } diff --git a/core/tests/ts-integration/src/types.ts b/core/tests/ts-integration/src/types.ts index cde7bf09eded..be24ada40182 100644 --- a/core/tests/ts-integration/src/types.ts +++ b/core/tests/ts-integration/src/types.ts @@ -53,6 +53,10 @@ export interface TestEnvironment { * Flag indicating whether the tests are being run against the native ERC20 implementation. */ nativeErc20Testing: boolean; + /** + * Non native ERC20 token. + */ + nonNativeToken: Token; } /** diff --git a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts index 053a3702a266..17d2cd97dde4 100644 --- a/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts +++ b/core/tests/ts-integration/tests/non-native-erc20-deposit.test.ts @@ -17,6 +17,7 @@ describe('ERC20 contract checks', () => { let alice: zksync.Wallet; let bob: zksync.Wallet; let tokenDetails: Token; + let nonNativeToken: Token; let aliceErc20: zksync.Contract; beforeAll(async () => { @@ -25,33 +26,37 @@ describe('ERC20 contract checks', () => { bob = testMaster.newEmptyAccount(); tokenDetails = testMaster.environment().erc20Token; + nonNativeToken = testMaster.environment().nonNativeToken; aliceErc20 = new zksync.Contract(tokenDetails.l2Address, zksync.utils.IERC20, alice); }); test('Can perform a deposit', async () => { - const tokenAddress = '0xF12131d79e026D9882d22e4556706496Bdc287E8'; + const tokenAddress = nonNativeToken.l1Address; + // const tokenAddress = tokenDetails.l1Address; const amount = BigNumber.from(555); const gasPrice = scaledGasPrice(alice); + const nativeToken = '0xD47a77a7A93c099a451a2c269ea5fB35238dC52c' + + // The non native token address should be different than the native token address. + expect(tokenAddress != tokenDetails.l1Address); // L1 Deposit const initialTokenBalance = await alice.getBalanceL1(tokenAddress); const deposit = await alice.deposit({ - l2GasLimit: 500_000, token: tokenAddress, amount, to: alice.address, approveERC20: true, approveOverrides: { - gasPrice, - gasLimit: 5_000_000 + gasPrice }, overrides: { - gasPrice, - gasLimit: 5_000_000 + gasPrice } - }); + }, + nativeToken); - await deposit.waitL1Commit(); + await deposit.waitFinalize(); const finalTokenBalance = await alice.getBalanceL1(tokenAddress); console.log('initialTokenBalance', initialTokenBalance.toString()); @@ -71,7 +76,8 @@ describe('ERC20 contract checks', () => { console.log('finalizeDepositWait', finalizeDepositWait); // Token amount should be deposited to the account in the L2 side. - + console.log('l2BridgeAddress', l2ERC20Bridge.address); + /// Try through alice.l2TokenAddress const aliceL2TokenAddress = await alice.l2TokenAddress(tokenAddress); console.log('[ADDRESS] aliceL2TokenAddress', aliceL2TokenAddress); From 0017e9c3666317cd8c631ec70f4398305fe1ba9e Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Thu, 8 Feb 2024 12:26:25 +0100 Subject: [PATCH 13/15] fix missing msg.value to amount --- infrastructure/local-setup-preparation/src/index.ts | 2 +- sdk/zksync-rs/src/ethereum/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/local-setup-preparation/src/index.ts b/infrastructure/local-setup-preparation/src/index.ts index a8f7bbb56f07..4d09742f16f8 100644 --- a/infrastructure/local-setup-preparation/src/index.ts +++ b/infrastructure/local-setup-preparation/src/index.ts @@ -44,8 +44,8 @@ async function depositWithRichAccounts() { // deposit method from wallet requires a running server contract.requestL2Transaction( wallet.address, - 0, AMOUNT_TO_DEPOSIT, + overrides.value, '0x', DEPOSIT_L2_GAS_LIMIT, utils.REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT, diff --git a/sdk/zksync-rs/src/ethereum/mod.rs b/sdk/zksync-rs/src/ethereum/mod.rs index 29ebf48218d3..473112acb4d9 100644 --- a/sdk/zksync-rs/src/ethereum/mod.rs +++ b/sdk/zksync-rs/src/ethereum/mod.rs @@ -403,7 +403,7 @@ impl EthereumProvider { ( contract_address, l2_value, - 0, + value, calldata, gas_limit, L1_TO_L2_GAS_PER_PUBDATA, From f3384a0f45aaa3aed78883add56e857edb72ef53 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Thu, 8 Feb 2024 14:44:02 +0100 Subject: [PATCH 14/15] update submodule --- contracts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts b/contracts index 42a6f2658fda..474df7f5aac3 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit 42a6f2658fda9feef14e41e3db578f2c9c2f746e +Subproject commit 474df7f5aac3206f46d54d23d1d89849d7ca0137 From 3c01c7c2d4c0d0d6bd35ac43ffd3f81123cdc9f0 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Thu, 8 Feb 2024 16:50:31 +0100 Subject: [PATCH 15/15] update submodule --- contracts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts b/contracts index 474df7f5aac3..3b2b9650b96e 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit 474df7f5aac3206f46d54d23d1d89849d7ca0137 +Subproject commit 3b2b9650b96ed7d72452ab7e38def434e2b3f1e2