Skip to content

Commit b913f0c

Browse files
authored
Merge pull request #4700 from stacks-network/hotfix/expect-result
fix: .expect_result must try, regression from 2.4.0.1.0
2 parents 3262678 + 63bafb0 commit b913f0c

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

clarity/src/vm/contexts.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> {
13361336
self.global_context.begin();
13371337
let result = stx_transfer_consolidated(self, from, to, amount, memo);
13381338
match result {
1339-
Ok(value) => match value.clone().expect_result() {
1339+
Ok(value) => match value.clone().expect_result()? {
13401340
Ok(_) => {
13411341
self.global_context.commit()?;
13421342
Ok(value)
@@ -1962,8 +1962,14 @@ impl CallStack {
19621962

19631963
#[cfg(test)]
19641964
mod test {
1965+
use stacks_common::types::chainstate::StacksAddress;
1966+
use stacks_common::util::hash::Hash160;
1967+
19651968
use super::*;
19661969
use crate::vm::callables::DefineType;
1970+
use crate::vm::tests::{
1971+
test_epochs, tl_env_factory, MemoryEnvironmentGenerator, TopLevelMemoryEnvironmentGenerator,
1972+
};
19671973
use crate::vm::types::signatures::CallableSubtype;
19681974
use crate::vm::types::{FixedFunction, FunctionArg, FunctionType, StandardPrincipalData};
19691975

@@ -2119,6 +2125,35 @@ mod test {
21192125
assert_eq!(table[&p2][&t7], AssetMapEntry::Burn(35 + 36));
21202126
}
21212127

2128+
/// Test the stx-transfer consolidation tx invalidation
2129+
/// bug from 2.4.0.1.0-rc1
2130+
#[apply(test_epochs)]
2131+
fn stx_transfer_consolidate_regr_24010(
2132+
epoch: StacksEpochId,
2133+
mut tl_env_factory: TopLevelMemoryEnvironmentGenerator,
2134+
) {
2135+
let mut env = tl_env_factory.get_env(epoch);
2136+
let u1 = StacksAddress {
2137+
version: 0,
2138+
bytes: Hash160([1; 20]),
2139+
};
2140+
let u2 = StacksAddress {
2141+
version: 0,
2142+
bytes: Hash160([2; 20]),
2143+
};
2144+
// insufficient balance must be a non-includable transaction. it must error here,
2145+
// not simply rollback the tx and squelch the error as includable.
2146+
let e = env
2147+
.stx_transfer(
2148+
&PrincipalData::from(u1.clone()),
2149+
&PrincipalData::from(u2.clone()),
2150+
1000,
2151+
&BuffData::empty(),
2152+
)
2153+
.unwrap_err();
2154+
assert_eq!(e.to_string(), "Interpreter(InsufficientBalance)");
2155+
}
2156+
21222157
#[test]
21232158
fn test_canonicalize_contract_context() {
21242159
let trait_id = TraitIdentifier::new(

clarity/src/vm/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl MemoryEnvironmentGenerator {
149149

150150
pub struct TopLevelMemoryEnvironmentGenerator(MemoryBackingStore);
151151
impl TopLevelMemoryEnvironmentGenerator {
152-
fn get_env(&mut self, epoch: StacksEpochId) -> OwnedEnvironment {
152+
pub fn get_env(&mut self, epoch: StacksEpochId) -> OwnedEnvironment {
153153
let owned_env = OwnedEnvironment::new(self.0.as_clarity_db(), epoch);
154154
owned_env
155155
}

0 commit comments

Comments
 (0)