Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: hyperledger-iroha/iroha
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 211e782c5da91ec2b33c13da86e6fe012a1d2b6e
Choose a base ref
..
head repository: hyperledger-iroha/iroha
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a011f752a216856ef8f89d14882923b581c35115
Choose a head ref
Showing with 13 additions and 113 deletions.
  1. +12 −112 crates/iroha_core/src/smartcontracts/wasm.rs
  2. +1 −1 tests/events/data.rs
124 changes: 12 additions & 112 deletions crates/iroha_core/src/smartcontracts/wasm.rs
Original file line number Diff line number Diff line change
@@ -1665,7 +1665,7 @@ mod tests {
{memory_and_alloc}
;; Function which starts the smartcontract execution
(func (export "{main_fn_name}") (param)
(func (export "{main_fn_name}") (param i32)
(call $exec_fn (i32.const 0) (i32.const {isi_len}))
;; No use of return values
@@ -1711,7 +1711,7 @@ mod tests {
{memory_and_alloc}
;; Function which starts the smartcontract execution
(func (export "{main_fn_name}") (param)
(func (export "{main_fn_name}") (param i32)
(call $exec_fn (i32.const 0) (i32.const {isi_len}))
;; No use of return values
@@ -1757,14 +1757,21 @@ mod tests {
(module
;; Import host function to execute
(import "iroha" "{execute_fn_name}"
(func $exec_fn (param i32 i32)))
(func $exec_fn (param i32 i32) (result i32)))
{memory_and_alloc}
;; Function which starts the smartcontract execution
(func (export "{main_fn_name}") (param i32 i32)
(func (export "{main_fn_name}") (param i32)
(call $exec_fn (i32.const 0) (i32.const {isi1_end}))
(call $exec_fn (i32.const {isi1_end}) (i32.const {isi2_end}))))
;; No use of return value
drop
(call $exec_fn (i32.const {isi1_end}) (i32.const {isi2_end}))
;; No use of return value
drop))
"#,
main_fn_name = import::SMART_CONTRACT_MAIN,
execute_fn_name = export::EXECUTE_ISI,
@@ -1794,111 +1801,4 @@ mod tests {

Ok(())
}

#[test]
async fn instructions_not_allowed() -> Result<(), Error> {
let (authority, _authority_keypair) = gen_account_in("wonderland");
let kura = Kura::blank_kura_for_testing();
let query_handle = LiveQueryStore::start_test();
let state = State::new(world_with_test_account(&authority), kura, query_handle);

let isi_hex = {
let (new_authority, _new_authority_keypair) = gen_account_in("wonderland");
let register_isi = Register::account(Account::new(new_authority));
encode_hex(InstructionBox::from(register_isi))
};

let wat = format!(
r#"
(module
;; Import host function to execute
(import "iroha" "{execute_fn_name}"
(func $exec_fn (param i32 i32))
)
{memory_and_alloc}
;; Function which starts the smartcontract execution
(func (export "{main_fn_name}") (param i32 i32)
(call $exec_fn (i32.const 0) (i32.const {isi_len}))
)
)
"#,
main_fn_name = import::SMART_CONTRACT_MAIN,
execute_fn_name = export::EXECUTE_ISI,
memory_and_alloc = memory_and_alloc(&isi_hex),
isi_len = isi_hex.len() / 3,
);

let mut runtime = RuntimeBuilder::<state::SmartContract>::new().build()?;
let block_header = ValidBlock::new_dummy(&KeyPair::random().into_parts().1)
.as_ref()
.header();
let mut state_block = state.block(block_header);
let mut state_transaction = state_block.transaction();
let res = runtime.validate(&mut state_transaction, authority, wat, nonzero!(1_u64));
state_transaction.apply();
state_block.commit();

if let Error::ExportFnCall(ExportFnCallError::HostExecution(report)) =
res.expect_err("Execution should fail")
{
assert!(report
.to_string()
.starts_with("Transaction rejected due to insufficient authorisation"));
}

Ok(())
}

#[test]
async fn queries_not_allowed() -> Result<(), Error> {
let (authority, _authority_keypair) = gen_account_in("wonderland");
let kura = Kura::blank_kura_for_testing();
let query_handle = LiveQueryStore::start_test();
let state = State::new(world_with_test_account(&authority), kura, query_handle);
let query_hex = encode_hex(QueryRequest::Singular(
SingularQueryBox::FindExecutorDataModel(FindExecutorDataModel),
));

let wat = format!(
r#"
(module
;; Import host function to execute
(import "iroha" "{execute_fn_name}"
(func $exec_fn (param i32 i32) (result i32)))
{memory_and_alloc}
;; Function which starts the smartcontract execution
(func (export "{main_fn_name}") (param i32 i32)
(call $exec_fn (i32.const 0) (i32.const {isi_len}))
;; No use of return value
drop))
"#,
main_fn_name = import::SMART_CONTRACT_MAIN,
execute_fn_name = export::EXECUTE_QUERY,
memory_and_alloc = memory_and_alloc(&query_hex),
isi_len = query_hex.len() / 3,
);

let mut runtime = RuntimeBuilder::<state::SmartContract>::new().build()?;
let block_header = ValidBlock::new_dummy(&KeyPair::random().into_parts().1)
.as_ref()
.header();
let mut state_block = state.block(block_header);
let mut state_transaction = state_block.transaction();
let res = runtime.validate(&mut state_transaction, authority, wat, nonzero!(1_u64));
state_transaction.apply();
state_block.commit();

if let Error::ExportFnCall(ExportFnCallError::HostExecution(report)) =
res.expect_err("Execution should fail")
{
assert!(report.to_string().starts_with("All operations are denied"));
}

Ok(())
}
}
2 changes: 1 addition & 1 deletion tests/events/data.rs
Original file line number Diff line number Diff line change
@@ -119,7 +119,7 @@ async fn wasm_execution_should_produce_events() -> Result<()> {
{wasm_template}
;; Function which starts the smartcontract execution
(func (export "{main_fn_name}") (param)
(func (export "{main_fn_name}") (param i32)
{isi_calls}))
"#,
main_fn_name = "_iroha_smart_contract_main",