-
Notifications
You must be signed in to change notification settings - Fork 4
feat: init cli tests #99
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
base: develop
Are you sure you want to change the base?
Conversation
tests/base/testData/roles.data.ts
Outdated
| [ | ||
| ROLES.DEFAULT_ADMIN, | ||
| { | ||
| index: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why you dont use the index from Array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could build the map dynamically, but I don’t yet know the canonical way
to derive a role’s keccak from roleName .I tried a few approaches, but the keccak I compute still doesn’t match the contract’s value. If you point me to correct keccak function I can do like this:
const rolesArray = Object.values(ROLES);
export const PERMISSION_ROLES = new Map(
rolesArray.map((role, index) => [
role,
{
index,
keccak: utils.keccak256(utils.toUtf8Bytes(role)),
},
]),
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you want create keccak dinamaly, you can use like this:
import { keccak256, toHex } from 'viem';
const toRoleHash = (role: string) => keccak256(toHex(role));
export const PERMISSIONS_FUND_ROLE = 'vaults.Permissions.Fund';
const PERMISSIONS_FUND_ROLE_KECCAK = toRoleHash(PERMISSIONS_FUND_ROLE);But my question was why you need to store the index of an element in an array if the array itself already has one.
array.map((item, index <---) => {})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially, I couldn’t iterate the array and use the index directly because I didn’t have a way to compute the keccak hash on the fly.
In my case I couldn’t just iterate with
array.map((item, index) => …) and compute keccak(item) on the fly, because I have a couple of additional roles that don’t fit into the simple “keccak of role name” pattern (for example, DEFAULT_ADMIN='0x000000' and an extra STRANGER role, VAULT_OWNER_AND_NoMANAGER)
So I ended up going with a small lookup table of precomputed hashes instead:
const ROLE_KECCAKS: Record<RoleValue, Hex> = {
// e.g.
// DEFAULT_ADMIN: '0x...',
// STRANGER: '0x...',
// NODE_OPERATOR: '0x...',
// ...
};
export const PERMISSION_ROLES = new Map<RoleValue, RoleData>(
Object.values(ROLES).map((role, index) => [
role,
{
index,
keccak: ROLE_KECCAKS[role],
},
]),
);
This way I still get a nice indexed PERMISSION_ROLES map, but I’m not forced to derive every role’s hash in the same way — special cases like DEFAULT_ADMIN are handled naturally through the ROLE_KECCAKS mapping.
tests/base/tests/globalSetup.ts
Outdated
| defaultAdmin: roles.defaultAdmin.address, | ||
| nodeOperator: roles.nodeOperator.address, | ||
| nodeOperatorManager: roles.nodeOperatorManager.address, | ||
| confirmExpiry: 86_400, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
86400/100 - move to constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, but 86400 is correct value in seconds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to move both numbers into constants 86400 and 100
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already fixed
tests/base/tests/globalSetup.ts
Outdated
| }); | ||
| }); | ||
|
|
||
| // Look out "🧑🔧 Debugging Tip" point for debug in Readme.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could control the display of logs by configuring test runs rather than commenting them out in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn’t a test log but a quick debugging tip: during debug it's good point how to not execute globalBeforeAll every time. Just thought it can be usable. That’s why we point to the "Debugging Tip" section here.
Just removed it. The debug tip is still in README.md. Commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can display specific logs depending on the log level passed, instead of manually writing them in the right places or commenting them each time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got you, but anyway i removed it from comments. Currently stored only in README.md
tests/base/package.json
Outdated
| "@lidofinance/wallets-testing-wallets": "^1.39.0", | ||
| "@playwright/test": "^1.56.1", | ||
| "viem": "^2.39.3", | ||
| "zod": "^3.24.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need zod?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially, I used it for several required env variables, but in this case I can use it without Zod.
Removed.
# Conflicts: # package.json # tests/unit/bigInt.test.ts # tests/unit/calculate-health.test.ts # tests/unit/calculate-overview-v2.test.ts # tests/unit/csv-file.test.ts # tests/unit/lido-apr.test.ts # tests/unit/merkle-utils.test.ts # tests/unit/rebase-rewards.test.ts # tests/unit/snake-to-camel.test.ts # tests/unit/timestamp.test.ts
f7f8681 to
0cea950
Compare
cbd19cf to
536f25a
Compare
Description
Add Playwright test template for CLI.
lsv_cli_testsandsetup lsv_cli before allsetup lsv_cliruns once before all tests to configure thedefaultVault, preventing repeated vault creation and granting required roles for test reusedefaultVaultinstance with all permissions granted via thegrantRolefunctionCHAIN_IDneeds to be set; the suite uses a free public RPC with an optional override viaRPC_URLin.envtests/utils) →unitdirectoryglobalSetup) and a demosupplytest using defaultVaultCode Review Notes
Pay attention to the lint-ignore assertion here.
This is intentional because
process.env.VAULT_ADDRESSanddashboardAddress: process.env.DASHBOARD_ADDRESSare set dynamically inglobalSetup.ts.Since Playwright projects run in separate processes, environment variables (even static ones) can’t be shared.
To handle this, a sub-project runs once before all tests to establish shared state, and is not executed again afterwards.
Review the naming for the
basedirectory — it was created to separate existing unit tests.We might consider renaming
base→e2eto better reflect its purpose and keep a clear distinction fromunittests.Should we keep 1 wf file for checks or stay with separated
checks&&teststests/unit
are currently executed via the rootpackage.jsonusingyarn test` (Jest).We should decide whether to:
tests/base/package.json, oryarn test:e2e).The first option keeps responsibilities clear (unit vs e2e), while the second simplifies CI integration if we want a unified
yarn testentry point.Checklist