Skip to content

test(fortuna): add unit tests for HashChainState #2698

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

Merged
merged 2 commits into from
May 17, 2025

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Add unit tests for HashChainState

This PR adds comprehensive unit tests for the HashChainState struct in the fortuna codebase. The tests cover:

  • Creating a new HashChainState with from_chain_at_offset
  • Revealing hashes for valid sequence numbers
  • Handling invalid sequence numbers (too small or too large)
  • Working with multiple hash chains at different offsets
  • Edge case of revealing at exactly the offset

Link to Devin run: https://app.devin.ai/sessions/28a349ec6b4245d197df7d831bcf1088
Requested by: Jayant Krishnamurthy

Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz>
Copy link

vercel bot commented May 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2025 6:02pm
component-library ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2025 6:02pm
entropy-debugger ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2025 6:02pm
entropy-explorer ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2025 6:02pm
insights ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2025 6:02pm
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2025 6:02pm
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2025 6:02pm

Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

}

#[test]
fn test_reveal_at_offset() -> Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

very similar to test_reveal_valid_sequence. not adding a lot of value

@@ -203,3 +203,87 @@ mod test {
run_hash_chain_test([0u8; 32], 100, 55);
}
}

#[cfg(test)]
mod hash_chain_state_test {
Copy link
Collaborator

Choose a reason for hiding this comment

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

any reason to have these in a separate mod?

#[test]
fn test_reveal_sequence_too_large() {
let chain = PebbleHashChain::new([0u8; 32], 10, 1);
let hash_chain_state = HashChainState::from_chain_at_offset(5, chain);
Copy link
Collaborator

Choose a reason for hiding this comment

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

not related to this PR but we should make this from_chain_at_offset function only for tests.

let chain2 = PebbleHashChain::new([1u8; 32], 10, 1);
let expected_hash2 = chain2.reveal_ith(3)?;

let mut hash_chain_state = HashChainState::from_chain_at_offset(5, chain1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's just construct the hash_chain_state directly from fields for better readability

let expected_hash2 = chain2.reveal_ith(3)?;

let mut hash_chain_state = HashChainState::from_chain_at_offset(5, chain1);
hash_chain_state.offsets.push(20);
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we also test this 20 boundary?

crate::state::{HashChainState, PebbleHashChain},
anyhow::Result,
};

Copy link
Collaborator

Choose a reason for hiding this comment

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

add some tests for overlapping PebbleHashChains.

Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz>
@jayantk jayantk merged commit f1969ce into main May 17, 2025
10 checks passed
@jayantk jayantk deleted the devin/1747414098-add-hash-chain-state-tests branch May 17, 2025 15:02
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