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

chore: replaced friend for unit-test with mock #5054

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

vlntb
Copy link

@vlntb vlntb commented Jun 24, 2024

Improving unit-test that have to access class internals

Context of Change

Replacing friend relationship between tested class (STLedgerEntry) and unit-test (Invariants_test) in favour of using mock. The change has no functional impact.

Type of Change

  • Removed Invariants_test as a friend from STLedgerEntry.
  • Declared a mock class that avoids checking LedgerFormats on construction.
  • Made a dummy Nickname ledger entry to trigger an invalid ledger entry error.

API Impact

  • None

@vlntb vlntb changed the title replaced friend for unit-test with mock chore: replaced friend for unit-test with mock Jun 24, 2024

// Make a dummy Nickname ledger entry to trigger an invalid ledger entry error.
Keylet nickname = {static_cast<LedgerEntryType>(0x006e), sha512Half('n', A1, (*sle)[sfSequence] + 2)};
auto sleNew = std::reinterpret_pointer_cast<STLedgerEntry>(std::make_shared<STLedgerEntryMock>(nickname));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice idea! I'm honestly not sure if this is UB or not (I suspect it is, but I'd also need to look at what the rules are for type punning).

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.

None yet

2 participants