Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avkos committed Jul 9, 2024
1 parent 42c7267 commit 3524fa8
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 21 deletions.
49 changes: 40 additions & 9 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,18 @@ export class ZkSyncPlugin extends Web3PluginBase {
* @param providerOrContextL2 - The provider or context for the L2 network
*/
constructor(
providerOrContextL2: web3Types.SupportedProviders<any> | Web3ContextInitOptions | string,
providerOrContextL2:
| string
| web3Types.SupportedProviders<any>
| Web3ContextInitOptions
| Web3ZkSyncL2,
) {
super(providerOrContextL2);
super(
providerOrContextL2 as
| string
| web3Types.SupportedProviders<any>
| Web3ContextInitOptions,
);
if (providerOrContextL2 instanceof Web3ZkSyncL2) {
this.L2 = providerOrContextL2;
} else {
Expand Down Expand Up @@ -165,8 +174,16 @@ export class ZkSyncPlugin extends Web3PluginBase {
constants.CONTRACT_DEPLOYER_ADDRESS,
this.L2,
),
L1MessengerContract: new Contract(IL1MessengerABI, constants.L1_MESSENGER_ADDRESS, this.L2),
NonceHolderContract: new Contract(INonceHolderABI, constants.NONCE_HOLDER_ADDRESS, this.L2),
L1MessengerContract: new Contract(
IL1MessengerABI,
constants.L1_MESSENGER_ADDRESS,
this.L2,
),
NonceHolderContract: new Contract(
INonceHolderABI,
constants.NONCE_HOLDER_ADDRESS,
this.L2,
),
L2BridgeContract: new Contract(IL2BridgeABI, l2SharedDefaultBridge, this.L2),
},
};
Expand Down Expand Up @@ -220,7 +237,9 @@ export class ZkSyncPlugin extends Web3PluginBase {
*/
get rpc(): RpcMethods {
if (!this._rpc) {
this._rpc = new RpcMethods(this.L2.requestManager as unknown as Web3RequestManager<unknown>);
this._rpc = new RpcMethods(
this.L2.requestManager as unknown as Web3RequestManager<unknown>,
);
}
return this._rpc;
}
Expand All @@ -235,8 +254,16 @@ export class ZkSyncPlugin extends Web3PluginBase {
* For example, if the L1 or L2 providers were changed from testnet to mainnet, this method should be called.
*/
public updateProviders(
contextL1: Web3ZkSyncL1 | web3Types.SupportedProviders<any> | Web3ContextInitOptions | string,
contextL2: Web3ZkSyncL2 | web3Types.SupportedProviders<any> | Web3ContextInitOptions | string,
contextL1:
| Web3ZkSyncL1
| web3Types.SupportedProviders<any>
| Web3ContextInitOptions
| string,
contextL2:
| Web3ZkSyncL2
| web3Types.SupportedProviders<any>
| Web3ContextInitOptions
| string,
) {
this.L1 = contextL1 instanceof Web3ZkSyncL1 ? contextL1 : new Web3ZkSyncL1(contextL1);
this.L2 = contextL2 instanceof Web3ZkSyncL2 ? contextL2 : new Web3ZkSyncL2(contextL2);
Expand Down Expand Up @@ -285,7 +312,9 @@ export class ZkSyncPlugin extends Web3PluginBase {
return l1Token;
}
} catch (e) {
throw new Error(`Error getting L1 address for token ${token}. ${JSON.stringify(e)}`);
throw new Error(
`Error getting L1 address for token ${token}. ${JSON.stringify(e)}`,
);
}
}

Expand All @@ -311,7 +340,9 @@ export class ZkSyncPlugin extends Web3PluginBase {
return l2WethToken;
}
} catch (e) {
throw new Error(`Error getting L2 address for token ${token}. ${JSON.stringify(e)}`);
throw new Error(
`Error getting L2 address for token ${token}. ${JSON.stringify(e)}`,
);
}
}

Expand Down
3 changes: 1 addition & 2 deletions test/integration/_wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ describe('wallet', () => {
const PRIVATE_KEY = (process.env.PRIVATE_KEY as string) || web3Accounts.create().privateKey;
const wallet = new ZKSyncWallet(PRIVATE_KEY, l2Provider, l1Provider);

it.only('should deposit', async () => {
console.log(wallet.getAddress());
it('should deposit', async () => {
const tx = await wallet.deposit({
token: ETH_ADDRESS,
to: wallet.getAddress(),
Expand Down
1 change: 1 addition & 0 deletions test/integration/mainnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('ZkSyncPlugin rpc mainnet tests', () => {

beforeAll(() => {
web3 = new Web3();
// @ts-ignore
web3.registerPlugin(new ZkSyncPlugin('https://mainnet.era.zksync.io'));
});

Expand Down
1 change: 1 addition & 0 deletions test/integration/rpc.mainnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('ZkSyncPlugin rpc mainnet tests', () => {

beforeAll(() => {
web3 = new Web3();
// @ts-ignore
web3.registerPlugin(new ZkSyncPlugin('https://mainnet.era.zksync.io'));
});

Expand Down
1 change: 1 addition & 0 deletions test/integration/rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('ZkSyncPlugin rpc tests', () => {

beforeAll(() => {
web3 = new Web3();
// @ts-ignore
web3.registerPlugin(new ZkSyncPlugin('https://sepolia.era.zksync.dev'));
});

Expand Down
4 changes: 3 additions & 1 deletion test/integration/zksync.contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('ZkSyncPlugin rpc tests', () => {

it('contracts only works after registering the plugin', async () => {
expect(zkSync.Contracts).rejects.toThrow();
// @ts-ignore
web3.registerPlugin(zkSync);

// after registering the plugin, the Contracts property should be without throwing an error
Expand All @@ -30,7 +31,8 @@ describe('ZkSyncPlugin rpc tests', () => {
// TODO: Need to check how to either get the actual contract address or how to call the proxy with now issues
// current error when calling the proxy is: "ContractExecutionError: Error happened while trying to execute a function inside a smart contract"
// related web3.js issue: https://github.com/web3/web3.js/issues/7143
contracts.L1.ZkSyncMainContract.options.address = '0x550cf73F4b50aA0DF0257f2D07630D48fA00f73a';
contracts.L1.ZkSyncMainContract.options.address =
'0x550cf73F4b50aA0DF0257f2D07630D48fA00f73a';

const contractName = await contracts.L1.ZkSyncMainContract.methods.getName().call();

Expand Down
1 change: 1 addition & 0 deletions test/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ZkSyncPlugin } from '../../src';
describe('ZkSyncPlugin tests', () => {
it('should register ZkSync plugin on Web3Context instance', () => {
const web3 = new Web3('http://some-rpc-url-l1.com');
// @ts-ignore
web3.registerPlugin(new ZkSyncPlugin('http://some-rpc-url-l2.com'));
expect(web3.zkSync).toBeDefined();
});
Expand Down
8 changes: 4 additions & 4 deletions test/unit/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Web3 } from 'web3';
import * as web3Accounts from 'web3-eth-accounts';
import type { types } from '../../src';
import { utils } from '../../src';
import { ADDRESS1, ADDRESS2 } from '../utils';
import { ADDRESS1, ADDRESS3 } from '../utils';
import * as constants from '../../src/constants';
import { getL2HashFromPriorityOp } from '../../src/utils';
import * as web3Types from '../../../web3.js/packages/web3-types';
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('utils', () => {
{
chainId: 270,
from: ADDRESS1,
to: ADDRESS2,
to: ADDRESS3,
value: 1_000_000,
},
'0x73a20167b8d23b610b058c05368174495adf7da3a4ed4a57eb6dbdeb1fafc24aaf87530d663a0d061f69bb564d2c6fb46ae5ae776bbd4bd2a2a4478b9cd1b42a',
Expand Down Expand Up @@ -227,7 +227,7 @@ describe('utils', () => {
maxPriorityFeePerGas: 0n,
maxFeePerGas: 0n,
gasLimit: 0n,
to: ADDRESS2,
to: ADDRESS3,
value: 1_000_000n,
data: '0x',
chainId: 270n,
Expand All @@ -254,7 +254,7 @@ describe('utils', () => {
maxPriorityFeePerGas: 0n,
maxFeePerGas: 0n,
gasLimit: 0n,
to: ADDRESS2,
to: ADDRESS3,
value: 0n,
data: '0x',
chainId: 270n,
Expand Down
12 changes: 7 additions & 5 deletions test/unit/web3zksync-l2.as.provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import type { Transaction } from 'web3-types';
import { ethRpcMethods } from 'web3-rpc-methods';

import { Web3ZkSyncL2 } from '../../src';
import { getPriorityOpResponse } from '../../lib/utils';
import { Web3ZkSyncL1 } from '../../lib';
import { PriorityL1OpResponse } from '../../src/types';

jest.mock('web3-rpc-methods');

Expand Down Expand Up @@ -44,12 +47,11 @@ describe('Web3ZkSyncL2 as a Provider', () => {

const txPromise = web3ZkSyncL2.sendRawTransaction(signed);

const priorityOpResponse = await web3ZkSyncL2.getPriorityOpResponse(
web3ZkSyncL2,
txPromise,
);
const priorityOpResponse = await getPriorityOpResponse(new Web3ZkSyncL1(), txPromise);
// 'The waitL1Commit function should be properly initialized'
expect(typeof priorityOpResponse.waitL1Commit).toEqual('function');
expect(typeof (priorityOpResponse as PriorityL1OpResponse).waitL1Commit).toEqual(
'function',
);
// 'The wait function should be properly initialized'
expect(typeof priorityOpResponse.wait).toBe('function');
// 'The waitFinalize function should be properly initialized'
Expand Down
2 changes: 2 additions & 0 deletions test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const ADDRESS1 = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049';
export const ADDRESS3 = '0xa61464658AfeAf65CccaaFD3a512b69A83B77618';

export const PRIVATE_KEY1 = '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110';
export const MNEMONIC1 =
'stuff slice staff easily soup parent arm payment cotton trade scatter struggle';
Expand Down

0 comments on commit 3524fa8

Please sign in to comment.