Skip to content

Commit

Permalink
Merge branch 'main' into wasm_builder_flags
Browse files Browse the repository at this point in the history
  • Loading branch information
aoyako authored Dec 7, 2024
2 parents a10f446 + f32a775 commit 07cb9fe
Show file tree
Hide file tree
Showing 33 changed files with 1,194 additions and 795 deletions.
84 changes: 84 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,90 @@

## [Unreleased]

## [2.0.0-rc.1.0] - 2024-12-06

### Added

- implement query projections (#5242)
- use persistent executor (#5082)
- add listen timeouts to iroha cli (#5241)
- add /peers API endpoint to torii (#5235)
- address agnostic p2p (#5176)
- improve multisig utility and usability (#5027)
- protect `BasicAuth::password` from being printed (#5195)
- sort descending in `FindTransactions` query (#5190)
- introduce block header into every smart contract execution context (#5151)
- dynamic commit time based on view change index (#4957)
- define default permission set (#5075)
- add implementation of Niche for `Option<Box<R>>` (#5094)
- transaction and block predicates (#5025)
- report amount of remaining items in query (#5016)
- bounded discrete time (#4928)
- don't validate transactions inside WASM (#4995)
- add missing mathematical operations to `Numeric` (#4976)
- validate block sync messages (#4965)
- query filters (#4833)

### Changed

- simplify peer id parsing (#5228)
- move transaction error out of block payload (#5118)
- rename JsonString to Json (#5154)
- add client entity to smart contracts (#5073)
- leader as transaction ordering service (#4967)
- directly provide payload to WASM entrypoints (#5113)
- make kura drop old blocks from memory (#5103)
- use `ConstVec` for instructions in `Executable` (#5096)
- gossip txs at most once (#5079)
- reduce memory usage of `CommittedTransaction` (#5089)
- make query cursor errors more specific (#5086)
- make `PublicKey` decoding lazy inside WASM (#5048)
- reorganize crates (#4970)
- introduce `FindTriggers` query, remove `FindTriggerById` (#5040)
- dont depend on signatures for update (#5039)
- change parameters format in genesis.json (#5020)
- only send current and previous view change proof (#4929)
- disable sending message when not ready to prevent busy loop (#5032)
- move total asset quantity to asset definition (#5029)
- sign only block's header, not the whole payload (#5000)
- use `HashOf<BlockHeader>` as the type of the block hash (#4998)
- simplify `/health` and `/api_version` (#4960)
- unnest wasm samples from `client`, exclude it from workspace (#4863)
- rename `configs` to `defaults`, remove `swarm` (#4862)

### Fixed

- flatten inner role in json (#5198)
- fix `cargo audit` warnings (#5183)
- add range check to signature index (#5157)
- fix model macro example in docs (#5149)
- close ws properly in blocks/events stream (#5101)
- broken trusted peers check (#5121)
- check that next block has height +1 (#5111)
- fix timestamp of genesis block (#5098)
- fix `iroha_genesis` compilation without `transparent_api` feature (#5056)
- serialize WASM code for snapshots (#5009)
- correctly handle `replace_top_block` (#4870)
- fix cloning of executor (#4955)
- display more error details (#4973)
- use `GET` for blocks stream (#4990)
- improve queue transactions handling (#4947)
- prevent redundant blocksync block messages (#4909)
- prevent deadlock on simultaneous sending large message (#4948)
- remove expired transaction from cache (#4922)
- fix torii url with path (#4903)

### Removed

- remove module-based api from client (#5184)
- remove `riffle_iter` (#5181)
- remove unused dependencies (#5173)
- remove `max` prefix from `blocks_in_memory` (#5145)
- remove consensus estimation (#5116)
- remove `event_recommendations` from block (#4932)

### Security

## [2.0.0-pre-rc.22.1] - 2024-07-30

### Fixed
Expand Down
15 changes: 12 additions & 3 deletions crates/iroha/tests/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ fn find_rate_and_make_exchange_isi_should_succeed() {

let assert_balance = |asset_id: AssetId, expected: Numeric| {
let got = test_client
.query_single(FindAssetQuantityById::new(asset_id))
.query(FindAssets)
.filter_with(|asset| asset.id.eq(asset_id))
.select_with(|asset| asset.value.numeric)
.execute_single()
.expect("query should succeed");
assert_eq!(got, expected);
};
Expand All @@ -293,7 +296,10 @@ fn find_rate_and_make_exchange_isi_should_succeed() {
assert_balance(buyer_eth.clone(), numeric!(200));

let rate: u32 = test_client
.query_single(FindAssetQuantityById::new(rate))
.query(FindAssets)
.filter_with(|asset| asset.id.eq(rate))
.select_with(|asset| asset.value.numeric)
.execute_single()
.expect("query should succeed")
.try_into()
.expect("numeric should be u32 originally");
Expand All @@ -306,7 +312,10 @@ fn find_rate_and_make_exchange_isi_should_succeed() {

let assert_purged = |asset_id: AssetId| {
let _err = test_client
.query_single(FindAssetQuantityById::new(asset_id))
.query(FindAssets)
.filter_with(|asset| asset.id.eq(asset_id))
.select_with(|asset| asset.value.numeric)
.execute_single()
.expect_err("query should fail, as zero assets are purged from accounts");
};
let seller_eth: AssetId = format!("eth#crypto#{}", &seller_id)
Expand Down
70 changes: 46 additions & 24 deletions crates/iroha/tests/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ fn multisig_base(suite: TestSuite) -> Result<()> {

// Check that the multisig transaction has not yet executed
let _err = test_client
.query_single(FindAccountMetadata::new(
transaction_target.clone(),
key.clone(),
))
.query(FindAccounts)
.filter_with(|account| account.id.eq(transaction_target.clone()))
.select_with(|account| account.metadata.key(key.clone()))
.execute_single()
.expect_err("instructions shouldn't execute without enough approvals");

// The last approve to proceed to validate and execute the instructions
Expand All @@ -268,7 +268,11 @@ fn multisig_base(suite: TestSuite) -> Result<()> {
}

// Check if the multisig transaction has executed
let res = test_client.query_single(FindAccountMetadata::new(transaction_target, key.clone()));
let res = test_client
.query(FindAccounts)
.filter_with(|account| account.id.eq(transaction_target.clone()))
.select_with(|account| account.metadata.key(key.clone()))
.execute_single();
match (&transaction_ttl_ms_opt, &unauthorized_target_opt) {
(None, None) => {
res.unwrap();
Expand All @@ -279,12 +283,17 @@ fn multisig_base(suite: TestSuite) -> Result<()> {
}

// Check if the transaction entry is deleted
let res = test_client.query_single(FindAccountMetadata::new(
multisig_account_id,
format!("multisig/proposals/{instructions_hash}")
.parse()
.unwrap(),
));
let res = test_client
.query(FindAccounts)
.filter_with(|account| account.id.eq(multisig_account_id))
.select_with(|account| {
account.metadata.key(
format!("multisig/proposals/{instructions_hash}")
.parse()
.unwrap(),
)
})
.execute_single();
match (&transaction_ttl_ms_opt, &unauthorized_target_opt) {
(None, Some(_)) => {
// In case failing validation, the entry can exit only by expiring
Expand Down Expand Up @@ -407,10 +416,14 @@ fn multisig_recursion_base(suite: TestSuite) -> Result<()> {

let proposal_value_at = |msa: AccountId, mst_hash: HashOf<Vec<InstructionBox>>| {
test_client
.query_single(FindAccountMetadata::new(
msa.clone(),
format!("multisig/proposals/{mst_hash}").parse().unwrap(),
))
.query(FindAccounts)
.filter_with(|account| account.id.eq(msa.clone()))
.select_with(|account| {
account
.metadata
.key(format!("multisig/proposals/{mst_hash}").parse().unwrap())
})
.execute_single()
.expect("should be initialized by the root proposal")
.try_into_any::<MultisigProposalValue>()
.unwrap()
Expand Down Expand Up @@ -457,10 +470,10 @@ fn multisig_recursion_base(suite: TestSuite) -> Result<()> {

// Check that the multisig transaction has not yet executed
let _err = test_client
.query_single(FindAccountMetadata::new(
transaction_target.clone(),
key.clone(),
))
.query(FindAccounts)
.filter_with(|account| account.id.eq(transaction_target.clone()))
.select_with(|account| account.metadata.key(key.clone()))
.execute_single()
.expect_err("instructions shouldn't execute without enough approvals");

// The last approve to proceed to validate and execute the instructions
Expand All @@ -476,7 +489,11 @@ fn multisig_recursion_base(suite: TestSuite) -> Result<()> {
}

// Check if the multisig transaction has executed
let res = test_client.query_single(FindAccountMetadata::new(transaction_target, key.clone()));
let res = test_client
.query(FindAccounts)
.filter_with(|account| account.id.eq(transaction_target))
.select_with(|account| account.metadata.key(key.clone()))
.execute_single();
match (&transaction_ttl_ms_opt, &unauthorized_target_opt) {
(None, None) => {
res.unwrap();
Expand All @@ -493,10 +510,15 @@ fn multisig_recursion_base(suite: TestSuite) -> Result<()> {
(msa_12345, approval_hash_to_012345),
(msa_012345, instructions_hash),
] {
let res = test_client.query_single(FindAccountMetadata::new(
msa,
format!("multisig/proposals/{mst_hash}").parse().unwrap(),
));
let res = test_client
.query(FindAccounts)
.filter_with(|account| account.id.eq(msa))
.select_with(|account| {
account
.metadata
.key(format!("multisig/proposals/{mst_hash}").parse().unwrap())
})
.execute_single();
match (&transaction_ttl_ms_opt, &unauthorized_target_opt) {
(None, Some(_)) => {
// In case the root proposal is failing validation, the relevant entries can exit only by expiring
Expand Down
89 changes: 89 additions & 0 deletions crates/iroha/tests/queries/metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use std::{collections::BTreeMap, str::FromStr};

use iroha::{client::QueryError, data_model::prelude::*};
use iroha_data_model::query::{
builder::SingleQueryError,
error::{FindError, QueryExecutionFail},
};
use iroha_test_network::*;
use iroha_test_samples::{ALICE_ID, BOB_ID};
use serde_json::json;

#[test]
fn find_accounts_with_asset() {
let (network, _rt) = NetworkBuilder::new().start_blocking().unwrap();
let test_client = network.client();

let key = Name::from_str("key").unwrap();
let another_key = Name::from_str("another_key").unwrap();

test_client
.submit_blocking(SetKeyValue::account(
BOB_ID.clone(),
key.clone(),
json!({"funny": "value"}),
))
.unwrap();
test_client
.submit_blocking(SetKeyValue::account(
BOB_ID.clone(),
another_key.clone(),
"value",
))
.unwrap();

// we have the following configuration:
// key another_key
// ALICE "value" -
// BOB {"funny": "value"} "value"

// check that bulk retrieval works as expected
let key_values = test_client
.query(FindAccounts)
.filter_with(|account| account.id.eq(ALICE_ID.clone()) | account.id.eq(BOB_ID.clone()))
.select_with(|account| (account.id, account.metadata.key(key.clone())))
.execute_all()
.unwrap()
.into_iter()
.collect::<BTreeMap<_, _>>();

assert_eq!(key_values.len(), 2);
assert_eq!(key_values[&ALICE_ID], "value".into());
assert_eq!(key_values[&BOB_ID], json!({"funny": "value"}).into());

// check that missing metadata key produces an error
let alice_no_key_err = test_client
.query(FindAccounts)
.filter_with(|account| account.id.eq(ALICE_ID.clone()))
.select_with(|account| account.metadata.key(another_key.clone()))
.execute_single()
.unwrap_err();

let SingleQueryError::QueryError(QueryError::Validation(ValidationFail::QueryFailed(
QueryExecutionFail::Find(FindError::MetadataKey(returned_key)),
))) = alice_no_key_err
else {
panic!("Got unexpected query error on missing metadata key {alice_no_key_err:?}",);
};
assert_eq!(returned_key, another_key);

// check single key retrieval
let another_key_value = test_client
.query(FindAccounts)
.filter_with(|account| account.id.eq(BOB_ID.clone()))
.select_with(|account| account.metadata.key(another_key.clone()))
.execute_single()
.unwrap();
assert_eq!(another_key_value, "value".into());

// check predicates on non-existing metadata (they should just evaluate to false)
let accounts = test_client
.query(FindAccounts)
.filter_with(|account| account.metadata.key(another_key.clone()).eq("value".into()))
.select_with(|account| account.id)
.execute_all()
.unwrap();

assert_eq!(accounts.len(), 1);
assert_eq!(accounts[0], BOB_ID.clone());
}
1 change: 1 addition & 0 deletions crates/iroha/tests/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use iroha_test_network::*;

mod account;
mod asset;
mod metadata;
mod query_errors;
mod role;
mod smart_contract;
Expand Down
10 changes: 6 additions & 4 deletions crates/iroha/tests/queries/smart_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ fn live_query_is_dropped_after_smart_contract_end() -> Result<()> {
);
client.submit_transaction_blocking(&transaction)?;

let metadata_value: Json = client.query_single(FindAccountMetadata::new(
client.account.clone(),
"cursor".parse().unwrap(),
))?;
let metadata_value = client
.query(FindAccounts)
.filter_with(|account| account.id.eq(client.account.clone()))
.select_with(|account| account.metadata.key("cursor".parse().unwrap()))
.execute_single()?;

let asset_cursor = metadata_value.try_into_any()?;

// here we are breaking the abstraction preventing us from using a cursor we pulled from the metadata
Expand Down
Loading

0 comments on commit 07cb9fe

Please sign in to comment.