grin/core/tests/vec_backend.rs

68 lines
1.7 KiB
Rust
Raw Normal View History

// Copyright 2021 The Grin Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
mod common;
use self::core::core::pmmr::{ReadablePMMR, VecBackend, PMMR};
use crate::common::TestElem;
use grin_core as core;
#[test]
fn leaf_pos_and_idx_iter_test() {
let elems = [
TestElem([0, 0, 0, 1]),
TestElem([0, 0, 0, 2]),
TestElem([0, 0, 0, 3]),
TestElem([0, 0, 0, 4]),
TestElem([0, 0, 0, 5]),
];
let mut backend = VecBackend::new();
let mut pmmr = PMMR::new(&mut backend);
for x in &elems {
pmmr.push(x).unwrap();
}
assert_eq!(
vec![0, 1, 2, 3, 4],
pmmr.leaf_idx_iter(0).collect::<Vec<_>>()
);
assert_eq!(
Fixmmr part2 (#3666) * use 0-based positions in methods pmmr_leaf_to_insertion_index and bintree_postorder_height; add round_up_to_leaf_pos method * use 0-based positions in method insertion_to_pmmr_index * use 0-based positions in method is_leaf * use 0-based positions in method family() * use 0-based positions in method is_left_sibling * use 0-based positions in method family_branch * use 0-based positions in methods bintree_{left,right}most * use 0-based positions in method bintree_pos_iter * use 0-based positions in method bintree_range * use 0-based positions in method bintree_leaf_pos_iter * rename last_pos in MMR related structs to size * use 0-based positions in method prune * use 0-based positions in method push and apply_output return value * use 0-based position argument of method merkle_proof * use 0-based outputs in method pmmr::peaks * fix peaks() code comments * refix peaks() code comments * use 0-based positions in method get_peak_from_file * use 0-based positions in methods get_data_from_file * use 0-based positions in methods get_from_file * use 0-based positions in methods get_data * use 0-based positions in methods get_hash * use 0-based positions in method peak_path * use 0-based positions in method bag_the_rhs * use 0-based positions in method Backend::remove * use 0-based positions in method leaf_pos_iter * use 0-based positions in method self.LeafSet::includes * use 0-based positions in methods self.LeafSet::{add,remove} * use 0-based positions in methods is_pruned,is_pruned_root,is_compacted * use 0-based positions in methods PruneList::append * use 0-based positions in methods append_pruned_subtree * use 0-based positions in method calculate_next_leaf_shift * use 0-based positions in method append_single * use 0-based positions in method calculate_next_shift * use 0-based positions in method segment_pos_range * use 0-based positions in method reconstruct_root * use 0-based positions in method validate_with * use 0-based positions in method validate * rename size (formerly last_pos) to mmr_size * use 0-based positions in Segment's hash_pos and leaf_pos * minimize use of saturating_sub(1) and rename some pos/idx to size * use 0-based positions in methods get_output_pos * use 0-based positions in method get_unspent_output_at * use 0-based positions in method get_header_hash * use 0-based positions in methods MerkleProof::verify{,_consume} * use 0-based positions in method cleanup_subtree * don't allow 0 in prunelist bitmap * use 0-based positions in methods get_{,leaf_}shift * rename some 1-based pos to pos1; identify TODO * Address yeastplume's PR review comments
2021-11-26 14:25:10 +03:00
vec![0, 1, 3, 4, 7],
pmmr.leaf_pos_iter().collect::<Vec<_>>()
);
}
#[test]
fn leaf_pos_and_idx_iter_hash_only_test() {
let elems = [
TestElem([0, 0, 0, 1]),
TestElem([0, 0, 0, 2]),
TestElem([0, 0, 0, 3]),
TestElem([0, 0, 0, 4]),
TestElem([0, 0, 0, 5]),
];
let mut backend = VecBackend::new_hash_only();
let mut pmmr = PMMR::new(&mut backend);
for x in &elems {
pmmr.push(x).unwrap();
}
assert_eq!(
vec![0, 1, 2, 3, 4],
pmmr.leaf_idx_iter(0).collect::<Vec<_>>()
);
assert_eq!(
Fixmmr part2 (#3666) * use 0-based positions in methods pmmr_leaf_to_insertion_index and bintree_postorder_height; add round_up_to_leaf_pos method * use 0-based positions in method insertion_to_pmmr_index * use 0-based positions in method is_leaf * use 0-based positions in method family() * use 0-based positions in method is_left_sibling * use 0-based positions in method family_branch * use 0-based positions in methods bintree_{left,right}most * use 0-based positions in method bintree_pos_iter * use 0-based positions in method bintree_range * use 0-based positions in method bintree_leaf_pos_iter * rename last_pos in MMR related structs to size * use 0-based positions in method prune * use 0-based positions in method push and apply_output return value * use 0-based position argument of method merkle_proof * use 0-based outputs in method pmmr::peaks * fix peaks() code comments * refix peaks() code comments * use 0-based positions in method get_peak_from_file * use 0-based positions in methods get_data_from_file * use 0-based positions in methods get_from_file * use 0-based positions in methods get_data * use 0-based positions in methods get_hash * use 0-based positions in method peak_path * use 0-based positions in method bag_the_rhs * use 0-based positions in method Backend::remove * use 0-based positions in method leaf_pos_iter * use 0-based positions in method self.LeafSet::includes * use 0-based positions in methods self.LeafSet::{add,remove} * use 0-based positions in methods is_pruned,is_pruned_root,is_compacted * use 0-based positions in methods PruneList::append * use 0-based positions in methods append_pruned_subtree * use 0-based positions in method calculate_next_leaf_shift * use 0-based positions in method append_single * use 0-based positions in method calculate_next_shift * use 0-based positions in method segment_pos_range * use 0-based positions in method reconstruct_root * use 0-based positions in method validate_with * use 0-based positions in method validate * rename size (formerly last_pos) to mmr_size * use 0-based positions in Segment's hash_pos and leaf_pos * minimize use of saturating_sub(1) and rename some pos/idx to size * use 0-based positions in methods get_output_pos * use 0-based positions in method get_unspent_output_at * use 0-based positions in method get_header_hash * use 0-based positions in methods MerkleProof::verify{,_consume} * use 0-based positions in method cleanup_subtree * don't allow 0 in prunelist bitmap * use 0-based positions in methods get_{,leaf_}shift * rename some 1-based pos to pos1; identify TODO * Address yeastplume's PR review comments
2021-11-26 14:25:10 +03:00
vec![0, 1, 3, 4, 7],
pmmr.leaf_pos_iter().collect::<Vec<_>>()
);
}