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

test: dual pxe tests #12

Merged
merged 10 commits into from
Feb 7, 2025
Merged

test: dual pxe tests #12

merged 10 commits into from
Feb 7, 2025

Conversation

xorsal
Copy link
Collaborator

@xorsal xorsal commented Feb 4, 2025

To run these tests you need to run two separate of the aztec sandboxes

  • First you need to run the sandbox normally
    aztec start --sandbox

  • Then you need to run a PXE instance pointing to the previously started sandbox:
    aztec start --port 8081 --pxe --pxe.nodeUrl=http://host.docker.internal:8080

Currently blocked because although I've sent the tokens to the escrow contract I'm unable to withdraw from it.

Summary by CodeRabbit

  • New Features
    • Launched an additional container service with configurable settings for improved resilience.
  • Tests
    • Expanded validation scenarios for token exchanges and escrow operations across multiple instances.
  • Chores
    • Streamlined the automated workflow to ensure clearer separation of environment setup and testing, with a defined job timeout for enhanced process efficiency.

ro run this test you'll need to run two separate of the aztec sandbox

First you need to run the sandbox normally
`aztec start --sandbox`,

then you need to run a PXE instance pointing to the previously started
sandbox:
`aztec start --port 8081 --pxe --pxe.nodeUrl=http://host.docker.internal:8080`
Comment on lines 614 to 616
// const transfer2Tx = await token.withWallet(bob).methods.transfer_to_private(bob.getAddress(), wad(5)).send().wait({
// debug: true
// })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transfer_to_private is public -> private, and bob has now a private balance (since Alice transfer is private->private), can change it for transfer_in_private(bob.getAddress(), bob.getAddress(), wad(5), 0) and test will pass

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was due to a confusion on my part but I think there's something weird happening regarding the available notes in each PXE. I'll review it and probably ask you to discuss it later.

expect(await token.methods.balance_of_private(address).simulate()).toBe(privateBalance);
};

const wad = (n: number = 1) => AMOUNT * BigInt(n);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wad is confusing, why not just use 10n instead of wad(10) -> 10 * 1000n?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would _amount(n: number = 1): BigInt be clearer? (added underscore to avoid conflicts with variables named amount)

but to answer your question, because:

  • centralized conversion, just pick a number and it will be converted to bigint without fuss (or don't and use default value)
  • short and expressive (although I agree it could have a name change!)
  • it's shorter than the multiplication expression

ci: override sandbox docker config to run a secondary PXE

---------

Co-authored-by: zorzal <zorzal@defi.sucks>
Copy link

coderabbitai bot commented Feb 6, 2025

📝 Walkthrough

Walkthrough

The pull request updates several key components. In the continuous integration workflow, the GitHub Actions configuration is modified to trigger on push and pull_request events for the main branch only, with an added 30-minute timeout for a specific job. The workflow now separates the Aztec version setup from starting the sandbox, which is launched using Docker Compose in the background, and introduces a dedicated step for executing JavaScript tests via Jest. In the container orchestration configuration, a new service named "alternative-pxe" is added, featuring Docker image details, environment variable settings, volume mounts, and service dependencies. Additionally, the test suite for the token contract is expanded with new functions for deploying token and escrow contracts, revised variable types, and additional tests that cover multi-PXE interactions, including scenarios for token minting, transferring, and balance verification.

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
src/token_contract/src/test/main.test.ts (3)

30-37: Function createPXE for dynamic multi-PXE.
Flexible approach for running PXE on distinct ports.

Consider adding a brief console or logger statement to output the final URL for easier debugging.


43-49: deployToken helper function with console.log.
Logging the contract address is helpful, though you may want to unify logs using a single shared logger instead of console.

-  console.log('Token contract deployed at', contract.address);
+  // For consistent logging:
+  // logger.info('Token contract deployed at', contract.address);

51-66: deployEscrow concurrent registration.
The approach using Promise.all is efficient.

• Consider calling computePartialAddress(escrowInstance) once outside the loop, since it is constant.
• Similarly, to keep logging consistent, you could integrate the existing logger instead of console.log.

.github/workflows/tests.yaml (3)

30-30: Trailing spaces detected.
Please remove trailing spaces to pass lint checks.

-            VERSION=0.72.1 aztec-up 
+            VERSION=0.72.1 aztec-up
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 30-30: trailing spaces

(trailing-spaces)


31-33: Splitting sandbox startup into a separate step.
Good approach for clarity.

Consider using “docker compose up -d” if you prefer a detached mode instead of backgrounding with an ampersand.


47-49: “Run nr tests” naming.
The short name “nr” might be ambiguous.

You could rename the step to “Run Noir tests” for clarity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a41733c and 9807057.

📒 Files selected for processing (3)
  • .github/workflows/tests.yaml (3 hunks)
  • docker-compose.override.yml (1 hunks)
  • src/token_contract/src/test/main.test.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.ts`: Review TypeScript files for adherence to the fo...

**/*.ts: Review TypeScript files for adherence to the following guidelines:
- Avoid over-abstraction; prioritize composition over inheritance.
- Use dependency injection and follow SOLID principles.
- Avoid any; use unknown when necessary.
- Use runtime type-checking for environment variables (e.g., Zod).
- Prevent circular dependencies with the internal module pattern.
- Libraries should have an external.ts file explicitly listing public exports.
- Use bigint as-is; cast to Number only when exposing values via APIs.
- Document all code with JSDoc.
- Encourage static async factory functions for constructors.

  • Avoid overly nitpicky feedback beyond these best practices.
  • src/token_contract/src/test/main.test.ts
`**/*.test.ts`: Review the unit test files with the followin...

**/*.test.ts: Review the unit test files with the following guidelines:
- Avoid using the word "should" in test descriptions.
- Ensure descriptive test names convey the intent of each test.
- Validate adherence to the Mocha/Chai/Jest/Vitest/Cypress test library best practices.

  • Be concise and avoid overly nitpicky feedback outside of these best practices.
  • src/token_contract/src/test/main.test.ts
🪛 YAMLlint (1.35.1)
.github/workflows/tests.yaml

[warning] 9-9: wrong indentation: expected 8 but found 6

(indentation)


[error] 30-30: trailing spaces

(trailing-spaces)


[error] 46-46: trailing spaces

(trailing-spaces)


[warning] 50-50: too many blank lines

(1 > 0) (empty-lines)

⏰ Context from checks skipped due to timeout of 300000ms (1)
  • GitHub Check: setup-and-run
🔇 Additional comments (13)
src/token_contract/src/test/main.test.ts (9)

1-1: New import for Transfer event looks good.
No issues detected. This import aligns with the test usage of Transfer.


15-18: Additional imports for Aztec features are correctly introduced.
These imports (AztecAddress, AccountWalletWithSecretKey, Wallet, and UniqueNote) support multi-PXE and private/public balance testing.


20-26: Added imports for account creation and key derivation.
These are appropriate libraries for testing flows involving derived keys and partial addresses.


27-29: Escrow contract imports.
Including EscrowContract and EscrowContractArtifact is consistent for testing escrow functionality.


39-41: Lightweight wrapper around createPXE.
setupSandbox simply delegates to createPXE. This is fine as a convenience method.


70-70: Type changed to AccountWalletWithSecretKey[].
This change makes sense for private note and secret-key-based operations.


90-90: Mapping wallet arrays to addresses.
This line properly captures each wallet’s complete address, no issues.


98-98: deployToken invoked in beforeEach.
Ensures each test runs with a freshly deployed contract.


437-704: Multi PXE and escrow test suite.
The new “describe('Multi PXE', ... )” block provides comprehensive coverage for multi-PXE interactions, public/private transfers, and escrow flows.

• Consider unifying logs with a shared logger.
• At line 524, a “wad” helper is used. A previous reviewer noted that the “wad” naming could be confusing.

• The escrow tests are nicely detailed; adding corner-case tests for multiple partial withdrawals or advanced edge scenarios could further strengthen coverage.

docker-compose.override.yml (1)

1-19: New alternative-pxe service definition.
Helps run an additional PXE instance for multi-PXE testing.

• Ensure the “LOG_LEVEL” variable’s syntax (with semicolon) works correctly.
• The “TODO” for health checks is important; consider implementing a proper readiness check so the container waits for the main sandbox.

.github/workflows/tests.yaml (3)

6-6: Pull request branch trigger restricted to 'main.'
Verify that removing the dev branch trigger is intentional.


10-10: Job timeout set to 30 minutes.
Ensure 30 minutes is sufficient for your growing test suite.


44-45: Dedicated “Run js tests” step.
This step is explicit and preserves clarity for integration tests.

@@ -405,3 +434,271 @@ describe('Token', () => {
expect(await token.methods.balance_of_private(bob.getAddress()).simulate()).toBe(AMOUNT);
}, 300_000);
});

describe('Multi PXE', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this one into perhaps:
from /src/token_contract/src/test
to /src/test/token_contract.test.ts
and move this part into /src/test/escrow_contract.test.ts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I planned to do it once I updated to the latest version of the escrow.
but yes, I agree on move it out of the token contract directory.

Copy link
Member

@wei3erHase wei3erHase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! 🚢

@xorsal xorsal merged commit 3d66aa6 into dev Feb 7, 2025
3 checks passed
@xorsal xorsal deleted the test/dual-pxe branch February 7, 2025 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants