Skip to content

Commit

Permalink
Upstream 0.17.3 (#82)
Browse files Browse the repository at this point in the history
fixed bug in load _dict
  • Loading branch information
dbaranovstonfi authored Aug 14, 2024
1 parent c5d5199 commit fd60fdf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tonlib"
version = "0.17.2"
version = "0.17.3"
edition = "2021"
description = "Rust SDK for The Open Network"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl Cell {
if dict_loader.key_bit_len() - pp.bit_len() == 0 {
let bytes = pp.get_value_as_bytes();
let key = dict_loader.extract_key(bytes.as_slice())?;
let offset = self.bit_len - parser.remaining_bits();
let offset = parser.remaining_bits();
let cell_slice = CellSlice::new_with_offset(self, offset)?;
let value = dict_loader.extract_value(&cell_slice)?;
map.insert(key, value);
Expand Down
35 changes: 35 additions & 0 deletions src/cell/dict_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,38 @@ where
self.bit_len
}
}

#[cfg(test)]
mod test {
use std::collections::HashMap;

use num_bigint::BigUint;

use crate::cell::{key_extractor_u8, value_extractor_uint, BagOfCells, GenericDictLoader};

#[test]
fn tmp() {
let dict_boc_str = "te6cckEBBgEAWgABGccNPKUADZm5MepOjMABAgHNAgMCASAEBQAnQAAAAAAAAAAAAAABMlF4tR2RgCAAJgAAAAAAAAAAAAABaFhaZZhr6AAAJgAAAAAAAAAAAAAAR8sYU4eC4AA1PIC5";
let dict_boc = BagOfCells::parse_base64(&dict_boc_str).unwrap();
let cell = dict_boc.single_root().unwrap();
let loader = GenericDictLoader::new(key_extractor_u8, value_extractor_uint, 8);
let result = cell
.reference(0)
.unwrap()
.load_generic_dict(&loader)
.unwrap();

let mut expected_result = HashMap::new();
expected_result.extend(
[
(0, BigUint::from(25965603044000000000u128)),
(1, BigUint::from(5173255344000000000u64)),
(2, BigUint::from(344883687000000000u64)),
]
.iter()
.cloned(),
);

assert_eq!(expected_result, result);
}
}

0 comments on commit fd60fdf

Please sign in to comment.