-
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 9 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,265 @@ | ||
| //! Conformance tests: replay Quint ITF traces for stf_call_depth.qnt. | ||
| //! | ||
| //! The Quint spec models nested do_exec calls with a call_stack. This | ||
| //! conformance test uses a RecursiveAccount that calls itself N times, | ||
| //! verifying that the real STF matches the spec's depth enforcement. | ||
| //! | ||
| //! Run: | ||
| //! `quint test --main=stf_call_depth specs/stf_call_depth.qnt --out-itf "specs/traces/out_{test}_{seq}.itf.json"` | ||
| //! `cargo test -p evolve_stf --test quint_call_depth_conformance` | ||
|
|
||
| use borsh::{BorshDeserialize, BorshSerialize}; | ||
| use evolve_core::{ | ||
| AccountCode, AccountId, BlockContext, Environment, EnvironmentQuery, FungibleAsset, | ||
| InvokableMessage, InvokeRequest, InvokeResponse, SdkResult, | ||
| }; | ||
| use evolve_stf::Stf; | ||
| use evolve_stf_traits::{Block as BlockTrait, Transaction}; | ||
| use serde::Deserialize; | ||
| use std::path::Path; | ||
|
|
||
| mod quint_common; | ||
| use quint_common::{ | ||
| find_single_trace_file, read_itf_trace, register_account, CodeStore, InMemoryStorage, | ||
| ItfBigInt, NoopBegin, NoopEnd, NoopPostTx, NoopValidator, | ||
| }; | ||
|
|
||
| #[derive(Deserialize)] | ||
| struct ItfTrace { | ||
| states: Vec<ItfState>, | ||
| } | ||
|
|
||
| #[derive(Deserialize)] | ||
| struct ItfState { | ||
| #[allow(dead_code)] | ||
| call_stack: Vec<ItfBigInt>, | ||
| last_result: ItfResult, | ||
| } | ||
|
|
||
| #[derive(Deserialize)] | ||
| struct ItfResult { | ||
| ok: bool, | ||
| #[allow(dead_code)] | ||
| err_code: ItfBigInt, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, BorshSerialize, BorshDeserialize)] | ||
| struct RecurseMsg { | ||
| remaining: u16, | ||
| } | ||
|
|
||
| impl InvokableMessage for RecurseMsg { | ||
| const FUNCTION_IDENTIFIER: u64 = 1; | ||
| const FUNCTION_IDENTIFIER_NAME: &'static str = "recurse"; | ||
| } | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| struct TestTx { | ||
| sender: AccountId, | ||
| recipient: AccountId, | ||
| request: InvokeRequest, | ||
| gas_limit: u64, | ||
| funds: Vec<FungibleAsset>, | ||
| } | ||
|
|
||
| impl Transaction for TestTx { | ||
| fn sender(&self) -> AccountId { | ||
| self.sender | ||
| } | ||
| fn recipient(&self) -> AccountId { | ||
| self.recipient | ||
| } | ||
| fn request(&self) -> &InvokeRequest { | ||
| &self.request | ||
| } | ||
| fn gas_limit(&self) -> u64 { | ||
| self.gas_limit | ||
| } | ||
| fn funds(&self) -> &[FungibleAsset] { | ||
| &self.funds | ||
| } | ||
| fn compute_identifier(&self) -> [u8; 32] { | ||
| [0u8; 32] | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone)] | ||
| struct TestBlock { | ||
| height: u64, | ||
| time: u64, | ||
| txs: Vec<TestTx>, | ||
| } | ||
|
|
||
| impl BlockTrait<TestTx> for TestBlock { | ||
| fn context(&self) -> BlockContext { | ||
| BlockContext::new(self.height, self.time) | ||
| } | ||
| fn txs(&self) -> &[TestTx] { | ||
| &self.txs | ||
| } | ||
| fn gas_limit(&self) -> u64 { | ||
| 1_000_000 | ||
| } | ||
| } | ||
|
|
||
| #[derive(Default)] | ||
| struct RecursiveAccount; | ||
|
|
||
| impl AccountCode for RecursiveAccount { | ||
| fn identifier(&self) -> String { | ||
| "recursive".to_string() | ||
| } | ||
| fn schema(&self) -> evolve_core::schema::AccountSchema { | ||
| evolve_core::schema::AccountSchema::new("RecursiveAccount", "recursive") | ||
| } | ||
| fn init( | ||
| &self, | ||
| _env: &mut dyn Environment, | ||
| _request: &InvokeRequest, | ||
| ) -> SdkResult<InvokeResponse> { | ||
| InvokeResponse::new(&()) | ||
| } | ||
| fn execute( | ||
| &self, | ||
| env: &mut dyn Environment, | ||
| request: &InvokeRequest, | ||
| ) -> SdkResult<InvokeResponse> { | ||
| let msg: RecurseMsg = request.get()?; | ||
| if msg.remaining == 0 { | ||
| return InvokeResponse::new(&()); | ||
| } | ||
| let next = RecurseMsg { | ||
| remaining: msg.remaining - 1, | ||
| }; | ||
| env.do_exec(env.whoami(), &InvokeRequest::new(&next)?, vec![])?; | ||
| InvokeResponse::new(&()) | ||
| } | ||
| fn query( | ||
| &self, | ||
| _env: &mut dyn EnvironmentQuery, | ||
| _request: &InvokeRequest, | ||
| ) -> SdkResult<InvokeResponse> { | ||
| InvokeResponse::new(&()) | ||
| } | ||
| } | ||
|
|
||
| const RECURSIVE_ACCOUNT: u64 = 100; | ||
| const TEST_SENDER: u64 = 200; | ||
|
|
||
| struct ConformanceCase { | ||
| test_name: &'static str, | ||
| requested_depth: u16, | ||
| expect_ok: bool, | ||
| } | ||
|
|
||
| fn known_test_cases() -> Vec<ConformanceCase> { | ||
| vec![ | ||
| ConformanceCase { | ||
| test_name: "singleCallTest", | ||
| requested_depth: 1, | ||
| expect_ok: true, | ||
| }, | ||
| ConformanceCase { | ||
| test_name: "nestedCallsTest", | ||
| requested_depth: 3, | ||
| expect_ok: true, | ||
| }, | ||
| ConformanceCase { | ||
| test_name: "returnUnwindsStackTest", | ||
| requested_depth: 2, | ||
| expect_ok: true, | ||
| }, | ||
| ConformanceCase { | ||
| test_name: "fullUnwindTest", | ||
| requested_depth: 2, | ||
| expect_ok: true, | ||
| }, | ||
| ConformanceCase { | ||
| test_name: "recursiveCallsTest", | ||
| requested_depth: 3, | ||
| expect_ok: true, | ||
| }, | ||
| ] | ||
| } | ||
|
|
||
| #[test] | ||
| fn quint_itf_call_depth_conformance() { | ||
| let traces_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../../specs/traces"); | ||
|
|
||
| let test_cases = known_test_cases(); | ||
| for case in &test_cases { | ||
| let trace_file = find_single_trace_file(&traces_dir, case.test_name); | ||
| let trace: ItfTrace = read_itf_trace(&trace_file); | ||
| let spec_state = trace | ||
| .states | ||
| .last() | ||
| .expect("trace must have at least one state"); | ||
| let spec_result = &spec_state.last_result; | ||
|
|
||
| assert_eq!( | ||
| spec_result.ok, case.expect_ok, | ||
| "{}: expected ok={} but trace says ok={}", | ||
| case.test_name, case.expect_ok, spec_result.ok | ||
| ); | ||
|
|
||
| let stf = Stf::new( | ||
| NoopBegin::<TestBlock>::default(), | ||
| NoopEnd, | ||
| NoopValidator::<TestTx>::default(), | ||
| NoopPostTx::<TestTx>::default(), | ||
| quint_common::default_gas_config(), | ||
| ); | ||
|
|
||
| let mut storage = InMemoryStorage::default(); | ||
| let mut codes = CodeStore::new(); | ||
| codes.add_code(RecursiveAccount); | ||
| register_account( | ||
| &mut storage, | ||
| AccountId::from_u64(RECURSIVE_ACCOUNT), | ||
| "recursive", | ||
| ); | ||
|
|
||
| let msg = RecurseMsg { | ||
| remaining: case.requested_depth, | ||
| }; | ||
| let tx = TestTx { | ||
| sender: AccountId::from_u64(TEST_SENDER), | ||
| recipient: AccountId::from_u64(RECURSIVE_ACCOUNT), | ||
| request: InvokeRequest::new(&msg).unwrap(), | ||
| gas_limit: 1_000_000, | ||
| funds: vec![], | ||
| }; | ||
| let block = TestBlock { | ||
| height: 1, | ||
| time: 0, | ||
| txs: vec![tx], | ||
| }; | ||
|
|
||
| let (real_result, _) = stf.apply_block(&storage, &codes, &block); | ||
| assert_eq!( | ||
| real_result.tx_results.len(), | ||
| 1, | ||
| "{}: expected one tx result", | ||
| case.test_name | ||
| ); | ||
|
|
||
| let real_ok = real_result.tx_results[0].response.is_ok(); | ||
| assert_eq!( | ||
| real_ok, case.expect_ok, | ||
| "{}: ok mismatch (real={real_ok}, expected={})", | ||
| case.test_name, case.expect_ok | ||
| ); | ||
|
|
||
| if !case.expect_ok { | ||
| let real_err = real_result.tx_results[0].response.as_ref().unwrap_err().id; | ||
| assert_eq!( | ||
| real_err, | ||
| evolve_stf::errors::ERR_CALL_DEPTH_EXCEEDED.id, | ||
| "{}: expected call depth error", | ||
| case.test_name | ||
| ); | ||
| } | ||
|
|
||
| eprintln!("PASS: {}", case.test_name); | ||
| } | ||
| } | ||
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.
Add a depth-exceeded case.
Every
ConformanceCasecurrently setsexpect_ok: true, so the branch at Lines 253-260 is dead and the suite never validates the actual call-depth boundary orERR_CALL_DEPTH_EXCEEDED. One failing trace/case is needed to make this file test depth enforcement rather than only successful recursion.Also applies to: 253-260
🤖 Prompt for AI Agents