Skip to content

Add asset FK#1774

Open
DRadmir wants to merge 2 commits intomainfrom
1723-add-reference-to-assetrecord-for-core-models
Open

Add asset FK#1774
DRadmir wants to merge 2 commits intomainfrom
1723-add-reference-to-assetrecord-for-core-models

Conversation

@DRadmir
Copy link
Contributor

@DRadmir DRadmir commented Mar 6, 2026

Introduce DB.mockWithChains to pre-seed AssetStore for tests and update test cases to use it. Add foreign key references to AssetRecord on chain columns in AccountRecord, NodeRecord and NodeSelectedRecord to enforce referential integrity, and adjust migration ordering so AccountRecord is created after AssetRecord. Update WalletConnectorSigner.mock to seed the DB with chains derived from provided wallets.

  • Test

Close: #1723

@DRadmir DRadmir self-assigned this Mar 6, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances database integrity by implementing foreign key constraints between chain-related records and the AssetRecord, ensuring data consistency. Concurrently, it refactors the testing infrastructure by introducing a dedicated utility for pre-populating chain data, which simplifies test setup and improves the reliability of tests involving chain-specific assets.

Highlights

  • Database Integrity: Established foreign key constraints on the 'chain' columns in AccountRecord, NodeRecord, and NodeSelectedRecord to reference AssetRecord, enforcing referential integrity.
  • Migration Order Adjustment: Adjusted the database migration order to ensure AssetRecord is created before AccountRecord, resolving potential dependency issues for foreign key creation.
  • Test Utility Enhancement: Introduced a new static function, DB.mockWithChains, to pre-seed the AssetStore with specified chain assets, streamlining test setup.
  • Test Case Updates: Updated numerous test cases across WalletConnectorSignerTests, ConnectionsStoreTests, and WalletIdMigrationTests to utilize the new DB.mockWithChains utility for more consistent and accurate testing environments.
  • WalletConnectorSigner Mocking: Enhanced WalletConnectorSigner.mock to dynamically seed the database with chains derived from the wallets provided to the mock function.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • Features/WalletConnector/Tests/WalletConnectorSignerTests.swift
    • Updated test database initialization to use DB.mockWithChains for chain-specific data.
  • Packages/Store/Sources/Migrations.swift
    • Reordered the creation of AssetRecord before AccountRecord in the initial database migration.
  • Packages/Store/Sources/Models/AccountRecord.swift
    • Added a foreign key constraint on the 'chain' column referencing AssetRecord.
  • Packages/Store/Sources/Models/NodeRecord.swift
    • Added a foreign key constraint on the 'chain' column referencing AssetRecord.
  • Packages/Store/Sources/Models/NodeSelectedRecord.swift
    • Added a foreign key constraint on the 'chain' column referencing AssetRecord.
  • Packages/Store/TestKit/DB+StoreTestKit.swift
    • Introduced mockWithChains static function to DB for initializing a database with specified chain assets.
  • Packages/Store/Tests/StoreTests/ConnectionsStoreTests.swift
    • Modified test setup to use DB.mockWithChains for database initialization.
  • Packages/Store/Tests/StoreTests/WalletIdMigrationTests.swift
    • Updated test database initialization in various tests to use DB.mockWithChains with relevant chains.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces foreign key constraints to enhance database integrity by ensuring AccountRecord, NodeRecord, and NodeSelectedRecord reference valid assets. The migration order is correctly updated to accommodate these dependencies. A new test helper, DB.mockWithChains, is added to simplify test setup, and existing tests are updated to use it, which is a solid improvement. The changes are logical and well-executed. I have one suggestion to make the new test helper more robust in handling errors.

static func mockWithChains(_ chains: [Chain] = [.bitcoin]) -> DB {
let db = Self.mock()
let assetStore = AssetStore(db: db)
try? assetStore.add(assets: chains.map { .mock(asset: .mock(id: $0.assetId)) })
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using try? here can obscure errors during test setup, making debugging more difficult. If assetStore.add fails, the test will proceed with an incorrectly configured database, likely causing a less obvious failure later. It's better for the test setup to fail immediately and explicitly. Using try! is a good option here, as it will crash the test with a clear error if the asset addition fails, which is desirable for setup code that is not expected to fail.

Suggested change
try? assetStore.add(assets: chains.map { .mock(asset: .mock(id: $0.assetId)) })
try! assetStore.add(assets: chains.map { .mock(asset: .mock(id: $0.assetId)) })

@DRadmir DRadmir force-pushed the 1723-add-reference-to-assetrecord-for-core-models branch 2 times, most recently from cfe2fa4 to 82bc578 Compare March 6, 2026 12:45
Introduce DB.mockWithChains to pre-seed AssetStore for tests and update test cases to use it. Add foreign key references to AssetRecord on chain columns in AccountRecord, NodeRecord and NodeSelectedRecord to enforce referential integrity, and adjust migration ordering so AccountRecord is created after AssetRecord. Update WalletConnectorSigner.mock to seed the DB with chains derived from provided wallets.
@DRadmir DRadmir force-pushed the 1723-add-reference-to-assetrecord-for-core-models branch from 82bc578 to 8c0527e Compare March 6, 2026 13:07
@DRadmir DRadmir marked this pull request as ready for review March 10, 2026 05:52
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.

Add reference to AssetRecord for core models

1 participant