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: tests using the new env var #85

Merged
merged 6 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions core/tests/ts-integration/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,26 @@ export async function scaledGasPrice(wallet: ethers.Wallet | zksync.Wallet): Pro
// Increase by 40%.
return gasPrice.mul(140).div(100);
}

/**
* Returns if it is runnning in Validium Mode.
*
* @returns Boolean that indicates whether it is Validium mode.
*/
export async function getIsValidium(): Promise<boolean> {
const filePath = `${process.env.ZKSYNC_HOME}/etc/env/dev.env`;

try {
const fileContent = await fs.promises.readFile(filePath, 'utf-8');

const isValidiumMode = fileContent
.split('\n')
.map((line) => line.trim().split('='))
.find((pair) => pair[0] === 'VALIDIUM_MODE');

return isValidiumMode ? isValidiumMode[1] === 'true' : false;
} catch (error) {
console.error(`Error reading or parsing the config file ${filePath}:`, error);
return false; // Return a default value or handle the error as needed
}
}
13 changes: 5 additions & 8 deletions core/tests/ts-integration/tests/contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
*/

import { TestMaster } from '../src/index';
import { deployContract, getTestContract, waitForNewL1Batch } from '../src/helpers';
import { deployContract, getIsValidium, getTestContract, waitForNewL1Batch } from '../src/helpers';
import { shouldOnlyTakeFee } from '../src/modifiers/balance-checker';

import * as ethers from 'ethers';
import * as zksync from 'zksync-web3';
import { Provider } from 'zksync-web3';
import { RetryProvider } from '../src/retry-provider';

const SYSTEM_CONFIG = require(`${process.env.ZKSYNC_HOME}/contracts/SystemConfig.json`);

// TODO: Leave only important ones.
const contracts = {
counter: getTestContract('Counter'),
Expand Down Expand Up @@ -321,9 +319,8 @@ describe('Smart contract behavior checks', () => {
data: '0x'
});

// If L1_GAS_PER_PUBDATA_BYTE is zero it is assumed to be running in validium mode,
// there is no pubdata and the transaction will not be rejected.
if (SYSTEM_CONFIG['L1_GAS_PER_PUBDATA_BYTE'] > 0) {
// If it is running in validium mode, there is no pubdata and the transaction will not be rejected.
if (await getIsValidium()) {
await expect(
alice.sendTransaction({
to: alice.address,
Expand All @@ -332,7 +329,7 @@ describe('Smart contract behavior checks', () => {
factoryDeps: [bytecode]
}
})
).toBeRejected('not enough gas to publish compressed bytecodes');
);
} else {
await expect(
alice.sendTransaction({
Expand All @@ -342,7 +339,7 @@ describe('Smart contract behavior checks', () => {
factoryDeps: [bytecode]
}
})
);
).toBeRejected('not enough gas to publish compressed bytecodes');
}
});

Expand Down
11 changes: 5 additions & 6 deletions core/tests/ts-integration/tests/system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import * as ethers from 'ethers';
import { BigNumberish, BytesLike } from 'ethers';
import { serialize, hashBytecode } from 'zksync-web3/build/src/utils';
import { deployOnAnyLocalAddress, ForceDeployment } from '../src/system';
import { getTestContract } from '../src/helpers';
import { getIsValidium, getTestContract } from '../src/helpers';

const contracts = {
counter: getTestContract('Counter'),
events: getTestContract('Emitter')
};

const SYSTEM_CONFIG = require(`${process.env.ZKSYNC_HOME}/contracts/SystemConfig.json`);

describe('System behavior checks', () => {
let testMaster: TestMaster;
let alice: zksync.Wallet;
Expand Down Expand Up @@ -75,11 +73,12 @@ describe('System behavior checks', () => {
});

test('Should accept transactions with small gasPerPubdataByte', async () => {
const isValidium = await getIsValidium();
// The number "10" was chosen because we have a different error for lesser `smallGasPerPubdata`.
// In validium mode, this minimum value is "55"
const smallGasPerPubdata = SYSTEM_CONFIG['L1_GAS_PER_PUBDATA_BYTE'] > 0 ? 10 : 55;
const senderNonce =
SYSTEM_CONFIG['L1_GAS_PER_PUBDATA_BYTE'] > 0 ? await alice.getTransactionCount() : undefined;
const smallGasPerPubdata = isValidium ? 55 : 10;
// In validium mode, the nonce is not required.
const senderNonce = isValidium ? undefined : await alice.getTransactionCount();

// This tx should be accepted by the server, but would never be executed, so we don't wait for the receipt.
await alice.sendTransaction({
Expand Down
Loading