Skip to content
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

Skip empty Script transaction #284

Merged
merged 3 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/interpreter/executors/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
39 changes: 39 additions & 0 deletions tests/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params)
.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);
Expand Down