Skip to content

Commit

Permalink
fix get l1 l2 addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
avkos committed Feb 6, 2024
1 parent d3a13c9 commit 1dd658f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 42 deletions.
12 changes: 6 additions & 6 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
37 changes: 2 additions & 35 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,10 @@
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', () => {
const web3Context = new core.Web3Context('http://127.0.0.1:8545');
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);
});
});
});
24 changes: 24 additions & 0 deletions test/rpc.mainnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit 1dd658f

Please sign in to comment.