-
Notifications
You must be signed in to change notification settings - Fork 0
test: quint spec for stf #15
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
Open
tac0turtle
wants to merge
11
commits into
main
Choose a base branch
from
marko/quint_trial
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a6e2ccd
add quint spec for stf
tac0turtle 304bfe5
regenerate specs
tac0turtle a450801
add some more
tac0turtle bee32ce
redo specs
tac0turtle ab8bd1d
simplify
tac0turtle a8e2aae
erge branch 'main' into marko/quint_trial
tac0turtle 4e156a3
quality
tac0turtle 61c89af
dedup
tac0turtle cb0dc79
fix and use quint connect
tac0turtle 51c60eb
quint connect migration
tac0turtle e200886
Merge branch 'main' into marko/quint_trial
tac0turtle 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| #![allow(dead_code)] | ||
|
|
||
| use borsh::{BorshDeserialize, BorshSerialize}; | ||
| use evolve_core::runtime_api::ACCOUNT_IDENTIFIER_PREFIX; | ||
| use evolve_core::{ | ||
| AccountCode, AccountId, Environment, ErrorCode, InvokableMessage, InvokeResponse, ReadonlyKV, | ||
| SdkResult, | ||
| }; | ||
| use evolve_stf::gas::StorageGasConfig; | ||
| use evolve_stf_traits::{ | ||
| AccountsCodeStorage, BeginBlocker, EndBlocker, PostTxExecution, StateChange, TxValidator, | ||
| WritableKV, | ||
| }; | ||
| use hashbrown::HashMap; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Shared test message (used by core and post-tx conformance tests) | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| #[derive(Clone, Debug, BorshSerialize, BorshDeserialize)] | ||
| pub struct TestMsg { | ||
| pub key: Vec<u8>, | ||
| pub value: Vec<u8>, | ||
| pub fail_after_write: bool, | ||
| } | ||
|
|
||
| impl InvokableMessage for TestMsg { | ||
| const FUNCTION_IDENTIFIER: u64 = 1; | ||
| const FUNCTION_IDENTIFIER_NAME: &'static str = "test_msg"; | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Noop STF components | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| pub struct NoopBegin<B>(std::marker::PhantomData<B>); | ||
|
|
||
| impl<B> Default for NoopBegin<B> { | ||
| fn default() -> Self { | ||
| Self(std::marker::PhantomData) | ||
| } | ||
| } | ||
|
|
||
| impl<B> BeginBlocker<B> for NoopBegin<B> { | ||
| fn begin_block(&self, _block: &B, _env: &mut dyn Environment) {} | ||
| } | ||
|
|
||
| #[derive(Default)] | ||
| pub struct NoopEnd; | ||
|
|
||
| impl EndBlocker for NoopEnd { | ||
| fn end_block(&self, _env: &mut dyn Environment) {} | ||
| } | ||
|
|
||
| pub struct NoopValidator<T>(std::marker::PhantomData<T>); | ||
|
|
||
| impl<T> Default for NoopValidator<T> { | ||
| fn default() -> Self { | ||
| Self(std::marker::PhantomData) | ||
| } | ||
| } | ||
|
|
||
| impl<T> TxValidator<T> for NoopValidator<T> { | ||
| fn validate_tx(&self, _tx: &T, _env: &mut dyn Environment) -> SdkResult<()> { | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| pub struct NoopPostTx<T>(std::marker::PhantomData<T>); | ||
|
|
||
| impl<T> Default for NoopPostTx<T> { | ||
| fn default() -> Self { | ||
| Self(std::marker::PhantomData) | ||
| } | ||
| } | ||
|
|
||
| impl<T> PostTxExecution<T> for NoopPostTx<T> { | ||
| fn after_tx_executed( | ||
| _tx: &T, | ||
| _gas_consumed: u64, | ||
| _tx_result: &SdkResult<InvokeResponse>, | ||
| _env: &mut dyn Environment, | ||
| ) -> SdkResult<()> { | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // In-memory storage and code store | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| pub struct CodeStore { | ||
| codes: HashMap<String, Box<dyn AccountCode>>, | ||
| } | ||
|
|
||
| impl Default for CodeStore { | ||
| fn default() -> Self { | ||
| Self { | ||
| codes: HashMap::new(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl CodeStore { | ||
| pub fn new() -> Self { | ||
| Self::default() | ||
| } | ||
| pub fn add_code(&mut self, code: impl AccountCode + 'static) { | ||
| self.codes.insert(code.identifier(), Box::new(code)); | ||
| } | ||
| } | ||
|
|
||
| impl AccountsCodeStorage for CodeStore { | ||
| fn with_code<F, R>(&self, identifier: &str, f: F) -> Result<R, ErrorCode> | ||
| where | ||
| F: FnOnce(Option<&dyn AccountCode>) -> R, | ||
| { | ||
| Ok(f(self.codes.get(identifier).map(|c| c.as_ref()))) | ||
| } | ||
| fn list_identifiers(&self) -> Vec<String> { | ||
| self.codes.keys().cloned().collect() | ||
| } | ||
| } | ||
|
|
||
| #[derive(Default)] | ||
| pub struct InMemoryStorage { | ||
| pub data: HashMap<Vec<u8>, Vec<u8>>, | ||
| } | ||
|
|
||
| impl ReadonlyKV for InMemoryStorage { | ||
| fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, ErrorCode> { | ||
| Ok(self.data.get(key).cloned()) | ||
| } | ||
| } | ||
|
|
||
| impl WritableKV for InMemoryStorage { | ||
| fn apply_changes(&mut self, changes: Vec<StateChange>) -> Result<(), ErrorCode> { | ||
| for change in changes { | ||
| match change { | ||
| StateChange::Set { key, value } => { | ||
| self.data.insert(key, value); | ||
| } | ||
| StateChange::Remove { key } => { | ||
| self.data.remove(&key); | ||
| } | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Helpers | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| pub fn account_code_key(account: AccountId) -> Vec<u8> { | ||
| let mut out = vec![ACCOUNT_IDENTIFIER_PREFIX]; | ||
| out.extend_from_slice(&account.as_bytes()); | ||
| out | ||
| } | ||
|
|
||
| pub fn default_gas_config() -> StorageGasConfig { | ||
| StorageGasConfig { | ||
| storage_get_charge: 1, | ||
| storage_set_charge: 1, | ||
| storage_remove_charge: 1, | ||
| } | ||
| } | ||
|
|
||
| pub fn register_account(storage: &mut InMemoryStorage, account: AccountId, code_id: &str) { | ||
| use evolve_core::Message; | ||
| let id = code_id.to_string(); | ||
| storage.data.insert( | ||
| account_code_key(account), | ||
| Message::new(&id).unwrap().into_bytes().unwrap(), | ||
| ); | ||
| } | ||
|
|
||
| pub fn extract_account_storage( | ||
| storage: &InMemoryStorage, | ||
| account: AccountId, | ||
| ) -> HashMap<Vec<u8>, Vec<u8>> { | ||
| let prefix = account.as_bytes(); | ||
| let mut result = HashMap::new(); | ||
| for (key, value) in &storage.data { | ||
| if key.len() >= prefix.len() && key[..prefix.len()] == prefix { | ||
| result.insert(key[prefix.len()..].to_vec(), value.clone()); | ||
| } | ||
| } | ||
| result | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Use ordered maps in this shared harness.
CodeStore,InMemoryStorage, and the storage helper return types are allHashMap-based.list_identifiers()already exposes that iteration order directly, so the conformance harness is still carrying nondeterminism in the one place it should be deterministic.♻️ Minimal refactor
As per coding guidelines, "Use BTreeMap or BTreeSet instead of HashMap or HashSet to maintain deterministic iteration order".
Also applies to: 185-220, 272-302
🤖 Prompt for AI Agents