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

Insert test #328

Merged
merged 4 commits into from
Oct 24, 2023
Merged

Insert test #328

merged 4 commits into from
Oct 24, 2023

Conversation

richardpringle
Copy link
Contributor

  • Use leaf and branch constructors for Node
  • Clean up merkle tests
  • Add insert tests

I got a little carried away cleaning things up, but now it's a lot easier to add new tests

}

#[test]
fn insert_and_retrieve_multiple() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess I should explain why this is necessary, what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. I would also argue that the prior test should either be marked smoke or removed as it is fully tested by this test case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔, you're absolutely right, however, by the same argument, one could say that many unit tests are actually covered by integration tests and are therefore unnecessary.

There are three separate outcomes when looking at these tests together:

  1. both tests pass (everything works, hurray)
  2. the _multiple test fails and the other tests pass (something is wrong with multiple insertion specifically, it's probably something to do with splitting nodes)
  3. both tests fail (nothing is working)

And with that said, I've realized that this test needs to be altered as it would not cause a split, but I am going to do that in the next PR!

s.rehash();
s
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Constructors leaf and branch should be used instead of Node::new (deleted below), but when decoding an encoded node, we're left with the arbitrary NodeType in some places. This is an easy way to convert between types.

In general, there's a really bad pattern used here that doesn't work that well with Rust. Whatever needs to do the locking should wrap the types they need locked instead of having wrapper types with locks. So eventually, NodeType will be completely refactored into Node and only the Cache should manage locks. But that's all for another day.

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 get this comment into the code with a TODO

Copy link
Collaborator

@rkuris rkuris left a comment

Choose a reason for hiding this comment

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

Almost all nits, otherwise looks good.

firewood/src/merkle.rs Show resolved Hide resolved
firewood/src/merkle.rs Show resolved Hide resolved
firewood/src/merkle.rs Show resolved Hide resolved
}

#[test]
fn insert_and_retrieve_multiple() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. I would also argue that the prior test should either be marked smoke or removed as it is fully tested by this test case.

s.rehash();
s
}
}
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 get this comment into the code with a TODO

}

pub fn branch(
repeated_disk_adderss: usize,
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, haven't you ever heard of an adderss? 😅

firewood/src/merkle/node.rs Show resolved Hide resolved
firewood/src/merkle/partial_path.rs Outdated Show resolved Hide resolved
};

pub const TRIE_HASH_LEN: usize = 32;
const U64_TRIE_HASH_LEN: u64 = TRIE_HASH_LEN as u64;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure I love this. This is just because in some places we are using the wrong type, I think. I'd prefer usize over u64 and use that everywhere.

Copy link
Contributor Author

@richardpringle richardpringle Oct 24, 2023

Choose a reason for hiding this comment

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

You're not sure? I hate it haha... but I think it's better than what was there before. This is all due to some shale madness though. When shale finally only deals with usize, the compiler will help guide us through where changes need to be made and this code will disappear. At the very least, this const isn't pub, so the bad code is isolated.

firewood/src/merkle/trie_hash.rs Show resolved Hide resolved
richardpringle and others added 2 commits October 24, 2023 12:39
Co-authored-by: Ron Kuris <ron.kuris@avalabs.org>
Signed-off-by: Richard Pringle <rpring9@gmail.com>
@richardpringle richardpringle merged commit 854e801 into main Oct 24, 2023
5 checks passed
@richardpringle richardpringle deleted the insert-test branch October 24, 2023 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants