-
Notifications
You must be signed in to change notification settings - Fork 38
refactor!: replace Result with panic in stable-structures API #351
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
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
966a0bc
use write instead of safe_write
maksymar 36eced2
.
maksymar e9abb83
.
maksymar 28cca8d
.
maksymar 355c8c7
Merge branch 'main' into maksym/rm-grow-failed
maksymar 24f1a37
.
maksymar 760e03e
.
maksymar a0c589a
.
maksymar 9046736
.
maksymar 3bb1947
.
maksymar db04aba
.
maksymar 482bd50
.
maksymar 2b10343
fix tests
maksymar 63ad427
expect
maksymar afa39a4
.
maksymar 150b992
.
maksymar b7b5a3a
.
maksymar d08c455
.
maksymar 536baff
fmt
maksymar ba88029
add api_conformance_cell
maksymar 7466749
add api_conformance_log
maksymar a54abb5
cell
maksymar 8102ee3
Revert "cell"
maksymar 79324c5
fix fuzz build
maksymar 6ab72f6
cell
maksymar 32b647a
log
maksymar aa60ee5
.
maksymar 6933d29
Merge branch 'main' into maksym/rm-grow-failed
maksymar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,62 +1,56 @@ | ||
| use crate::cell::{Cell, ValueError}; | ||
| use crate::cell::Cell; | ||
| use crate::storable::Storable; | ||
| use crate::vec_mem::VectorMemory; | ||
| use crate::{Memory, RestrictedMemory, WASM_PAGE_SIZE}; | ||
|
|
||
| fn reload<T: Default + Storable, M: Memory>(c: Cell<T, M>) -> Cell<T, M> { | ||
| Cell::init(c.into_memory(), T::default()).unwrap() | ||
| Cell::init(c.into_memory(), T::default()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_cell_init() { | ||
| let mem = VectorMemory::default(); | ||
| let cell = Cell::init(mem, 1024u64).unwrap(); | ||
| let cell = Cell::init(mem, 1024u64); | ||
| assert_eq!(*cell.get(), 1024u64); | ||
| let mem = cell.into_memory(); | ||
| assert_ne!(mem.size(), 0); | ||
| let cell = Cell::init(mem, 0u64).unwrap(); | ||
| let cell = Cell::init(mem, 0u64); | ||
| assert_eq!(1024u64, *cell.get()); | ||
|
|
||
| // Check that Cell::new overwrites the contents unconditionally. | ||
| let cell = Cell::new(cell.into_memory(), 2048u64).unwrap(); | ||
| let cell = Cell::new(cell.into_memory(), 2048u64); | ||
| assert_eq!(2048u64, *cell.get()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_cell_init_empty() { | ||
| let mem = VectorMemory::default(); | ||
| let cell = Cell::init(mem, vec![]).unwrap(); | ||
| let cell = Cell::init(mem, vec![]); | ||
| assert_eq!(Vec::<u8>::new(), *cell.get()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_out_of_space() { | ||
| #[should_panic(expected = "ValueTooLarge { value_size: 65536 }")] | ||
| fn test_failure_out_of_space() { | ||
| let mem = RestrictedMemory::new(VectorMemory::default(), 0..1); | ||
| let data = [1u8; 100]; | ||
| let mut cell = Cell::new(mem, data.to_vec()).unwrap(); | ||
| let mut cell = Cell::new(mem, data.to_vec()); | ||
|
|
||
| assert_eq!(&data[..], &cell.get()[..]); | ||
|
|
||
| assert_eq!( | ||
| Err(ValueError::ValueTooLarge { | ||
| value_size: WASM_PAGE_SIZE, | ||
| }), | ||
| cell.set(vec![2u8; WASM_PAGE_SIZE as usize]) | ||
| ); | ||
|
|
||
| assert_eq!(&data[..], &cell.get()[..]); | ||
| cell.set(vec![2u8; WASM_PAGE_SIZE as usize]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_cell_grow_and_shrink() { | ||
| let mem = VectorMemory::default(); | ||
| let mut cell = Cell::init(mem, vec![1u8; 10]).unwrap(); | ||
| let mut cell = Cell::init(mem, vec![1u8; 10]); | ||
|
|
||
| cell.set(vec![2u8; 20]).unwrap(); | ||
| cell.set(vec![2u8; 20]); | ||
| let mut cell = reload(cell); | ||
| assert_eq!(&[2u8; 20][..], &cell.get()[..]); | ||
|
|
||
| cell.set(vec![3u8; 5]).unwrap(); | ||
| cell.set(vec![3u8; 5]); | ||
| let cell = reload(cell); | ||
| assert_eq!(&[3u8; 5][..], &cell.get()[..]); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.