diff --git a/src/plugin.ts b/src/plugin.ts index 00fa899..6b9570e 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -96,11 +96,11 @@ export class ZkSyncPlugin extends Web3PluginBase { return ETH_ADDRESS; } else { const bridgeAddresses = await this.getDefaultBridgeAddresses(); - const l2WethBridge = this.getL2BridgeContract(bridgeAddresses.wethL2); + const l2Bridge = this.getL2BridgeContract(bridgeAddresses.erc20L2); try { - const l1WethToken = await l2WethBridge.methods.l1TokenAddress(token).call(); - if (l1WethToken !== ZERO_ADDRESS) { - return l1WethToken; + const l1Token = await l2Bridge.methods.l1TokenAddress(token).call(); + if (l1Token !== ZERO_ADDRESS) { + return l1Token; } } catch (e) { throw new Error( @@ -121,9 +121,9 @@ export class ZkSyncPlugin extends Web3PluginBase { return ETH_ADDRESS; } else { const bridgeAddresses = await this.getDefaultBridgeAddresses(); - const l2WethBridge = this.getL2BridgeContract(bridgeAddresses.wethL2); + const l2Bridge = this.getL2BridgeContract(bridgeAddresses.erc20L2); try { - const l2WethToken = await l2WethBridge.methods.l2TokenAddress(token).call(); + const l2WethToken = await l2Bridge.methods.l2TokenAddress(token).call(); if (l2WethToken !== ZERO_ADDRESS) { return l2WethToken; } diff --git a/test/fixtures.ts b/test/fixtures.ts index 01b80b8..f29387c 100644 --- a/test/fixtures.ts +++ b/test/fixtures.ts @@ -102,7 +102,7 @@ export const getBlockDetailsData = { output: { number: BigInt(1), l1BatchNumber: BigInt(1), - timestamp: BigInt(1701420713), + timestamp: 1701420713, l1TxCount: BigInt(4), l2TxCount: BigInt(0), rootHash: '0x086227fafad2bc4d08a122ebb690d958edcd43352d38d31646968480f496827c', diff --git a/test/index.test.ts b/test/index.test.ts index 2974c3e..c23ce91 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -1,12 +1,5 @@ -import { Web3, core } from 'web3'; -import { ZkSyncPlugin, ZERO_ADDRESS } from '../src'; - -const EXAMPLE_ERC20_TOKEN = { - address: '0xF38E1Ce18214DF71f4c2101eefA14dfC98000421', - l1Address: '0x0000000000000000000000000000000000000000', - l2Address: '0x6A910b989aC7BF30B1C359806F05Eae2992a465D', - decimals: 18, -}; +import { core } from 'web3'; +import { ZkSyncPlugin } from '../src'; describe('ZkSyncPlugin tests', () => { it('should register ZkSync plugin on Web3Context instance', () => { @@ -14,30 +7,4 @@ describe('ZkSyncPlugin tests', () => { web3Context.registerPlugin(new ZkSyncPlugin()); expect(web3Context.zkSync).toBeDefined(); }); - - describe('ZkSync Plugin method tests', () => { - let web3: Web3; - - beforeAll(() => { - web3 = new Web3('https://testnet.era.zksync.dev'); - web3.registerPlugin(new ZkSyncPlugin()); - }); - - it('should get bridge addresses', async () => { - const res = await web3.zkSync.getDefaultBridgeAddresses(); - - expect(res.erc20L1).toBe('0x927ddfcc55164a59e0f33918d13a2d559bc10ce7'); - expect(res.erc20L2).toBe('0x00ff932a6d70e2b8f1eb4919e1e09c1923e7e57b'); - expect(res.wethL1).toBe('0x0000000000000000000000000000000000000000'); - expect(res.wethL2).toBe('0x0000000000000000000000000000000000000000'); - }); - it.skip('should get L1 token address', async () => { - const res = await web3.zkSync.getL1Address(EXAMPLE_ERC20_TOKEN.address); - expect(res).toBe(ZERO_ADDRESS); - }); - it.skip('should get L2 token address', async () => { - const res = await web3.zkSync.getL2Address(EXAMPLE_ERC20_TOKEN.address); - expect(res).toBe(EXAMPLE_ERC20_TOKEN.l2Address); - }); - }); }); diff --git a/test/rpc.mainnet.test.ts b/test/rpc.mainnet.test.ts index bb0fc94..cca0192 100644 --- a/test/rpc.mainnet.test.ts +++ b/test/rpc.mainnet.test.ts @@ -7,6 +7,13 @@ import { getProofData, } from './fixtures'; +const EXAMPLE_ERC20_TOKEN = { + address: '0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4', + l1Address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', + l2Address: '0x40E56A95F440a07000e474e9E1a1385a5319334a', + decimals: 18, +}; + describe('ZkSyncPlugin rpc mainnet tests', () => { let web3: Web3; @@ -15,6 +22,23 @@ describe('ZkSyncPlugin rpc mainnet tests', () => { web3.registerPlugin(new ZkSyncPlugin()); }); + it('should get bridge addresses', async () => { + const res = await web3.zkSync.getDefaultBridgeAddresses(); + + expect(res.erc20L1).toBe('0x57891966931eb4bb6fb81430e6ce0a03aabde063'); + expect(res.erc20L2).toBe('0x11f943b2c77b743ab90f4a0ae7d5a4e7fca3e102'); + expect(res.wethL1).toBe('0x0000000000000000000000000000000000000000'); + expect(res.wethL2).toBe('0x0000000000000000000000000000000000000000'); + }); + it('should get L1 token address', async () => { + const res = await web3.zkSync.getL1Address(EXAMPLE_ERC20_TOKEN.address); + expect(res).toBe(EXAMPLE_ERC20_TOKEN.l1Address); + }); + it('should get L2 token address', async () => { + const res = await web3.zkSync.getL2Address(EXAMPLE_ERC20_TOKEN.address); + expect(res).toBe(EXAMPLE_ERC20_TOKEN.l2Address); + }); + it('getL2ToL1LogProof', async () => { const res = await web3.zkSync.rpc.getL2ToL1LogProof(getL2ToL1LogProofData.input); expect(res).toEqual(getL2ToL1LogProofData.output);