diff --git a/src/interpreter/executors/main.rs b/src/interpreter/executors/main.rs index dfa26e0b9d..a669275029 100644 --- a/src/interpreter/executors/main.rs +++ b/src/interpreter/executors/main.rs @@ -193,7 +193,23 @@ where // TODO set tree balance - let program = self.run_program(); + // `Interpreter` supports only `Create` and `Script` transactions. It is not `Create` -> + // it is `Script`. + let program = if !self + .transaction() + .as_script() + .expect("It should be `Script` transaction") + .script() + .is_empty() + { + self.run_program() + } else { + // Return `1` as successful execution. + let return_val = 1; + self.ret(return_val)?; + Ok(ProgramState::Return(return_val)) + }; + let gas_used = self .transaction() .limit() diff --git a/tests/flow.rs b/tests/flow.rs index 593c53819f..2d2f6b2692 100644 --- a/tests/flow.rs +++ b/tests/flow.rs @@ -10,6 +10,45 @@ use rand::{rngs::StdRng, Rng, SeedableRng}; const SET_STATUS_REG: usize = 0x29; +#[test] +fn can_execute_empty_script_transaction() { + let mut client = MemoryClient::default(); + + let gas_price = 0; + let gas_limit = 1_000_000; + let maturity = 0; + let height = 0; + let params = ConsensusParameters::DEFAULT; + + let empty_script = vec![]; + + let tx = Transaction::script( + gas_price, + gas_limit, + maturity, + empty_script, + vec![], + vec![], + vec![], + vec![], + ) + .into_checked(height, ¶ms) + .expect("failed to generate a checked tx"); + + let receipts = client.transact(tx); + + // Expect the correct receipt + assert_eq!(receipts.len(), 2); + assert!(matches!(receipts[0], Receipt::Return { val: 1, .. })); + assert!(matches!( + receipts[1], + Receipt::ScriptResult { + result: ScriptExecutionResult::Success, + .. + } + )); +} + #[test] fn code_copy() { let rng = &mut StdRng::seed_from_u64(2322u64);