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

Aligning client code with recent node changes #218

Merged
merged 1 commit into from
Dec 11, 2024
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
47 changes: 22 additions & 25 deletions lib/cli/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@
use crate::{cli::TransactionV1BuilderError, Error::TransactionBuild};
use casper_types::{
bytesrepr::Bytes, system::auction::Reservation, PackageAddr, TransactionArgs,
TransactionEntryPoint, TransactionInvocationTarget, TransactionRuntime, TransactionTarget,
TransferTarget,
TransactionEntryPoint, TransactionInvocationTarget, TransactionRuntimeParams,
TransactionTarget, TransferTarget,
};
use once_cell::sync::Lazy;
use rand::{thread_rng, Rng};
Expand Down Expand Up @@ -1156,10 +1156,10 @@
let entity_addr: EntityAddr = EntityAddr::new_account([0u8; 32]);
let entity_hash = entity_addr.value();
let entry_point = String::from("test-entry-point");
let params = TransactionRuntimeParams::VmCasperV1;
let target = &TransactionTarget::Stored {
id: TransactionInvocationTarget::ByHash(entity_hash),
runtime: TransactionRuntime::VmCasperV1,
transferred_value: 0,
runtime: params,
};

let entry_point_ref = &TransactionEntryPoint::Custom(entry_point);
Expand All @@ -1184,11 +1184,11 @@
chunked_args: None,
};

let params = TransactionRuntimeParams::VmCasperV1;
let transaction_builder_params = TransactionBuilderParams::InvocableEntity {
entity_hash: entity_hash.into(),
entry_point: "test-entry-point",
runtime: TransactionRuntime::VmCasperV1,
transferred_value: 0,
runtime: params,
};
let transaction =
create_transaction(transaction_builder_params, transaction_string_params, true);
Expand All @@ -1212,10 +1212,10 @@
#[test]
fn should_create_invocable_entity_alias_transaction() {
let alias = String::from("alias");
let params = TransactionRuntimeParams::VmCasperV1;
let target = &TransactionTarget::Stored {
id: TransactionInvocationTarget::ByName(alias),
runtime: TransactionRuntime::VmCasperV1,
transferred_value: 0,
runtime: params,
};
let transaction_string_params = TransactionStrParams {
secret_key: "",
Expand All @@ -1237,11 +1237,11 @@
chunked_args: None,
};

let params = TransactionRuntimeParams::VmCasperV1;
let transaction_builder_params = TransactionBuilderParams::InvocableEntityAlias {
entity_alias: "alias",
entry_point: "entry-point-alias",
runtime: TransactionRuntime::VmCasperV1,
transferred_value: 0,
runtime: params,
};
let transaction =
create_transaction(transaction_builder_params, transaction_string_params, true);
Expand All @@ -1267,13 +1267,13 @@
let package_addr: PackageAddr = vec![0u8; 32].as_slice().try_into().unwrap();
let entry_point = "test-entry-point-package";
let maybe_entity_version = Some(23);
let params = TransactionRuntimeParams::VmCasperV1;
let target = &TransactionTarget::Stored {
id: TransactionInvocationTarget::ByPackageHash {
addr: package_addr,
version: maybe_entity_version,
},
runtime: TransactionRuntime::VmCasperV1,
transferred_value: 0,
runtime: params,
};
let transaction_string_params = TransactionStrParams {
secret_key: "",
Expand All @@ -1294,13 +1294,12 @@
session_entry_point: None,
chunked_args: None,
};

let params = TransactionRuntimeParams::VmCasperV1;
let transaction_builder_params = TransactionBuilderParams::Package {
package_hash: package_addr.into(),
entry_point,
maybe_entity_version,
runtime: TransactionRuntime::VmCasperV1,
transferred_value: 0,
runtime: params,
};
let transaction =
create_transaction(transaction_builder_params, transaction_string_params, true);
Expand All @@ -1326,13 +1325,13 @@
let package_name = String::from("package-name");
let entry_point = "test-entry-point-package";
let maybe_entity_version = Some(23);
let params = TransactionRuntimeParams::VmCasperV1;
let target = &TransactionTarget::Stored {
id: TransactionInvocationTarget::ByPackageName {
name: package_name.clone(),
version: maybe_entity_version,
},
runtime: TransactionRuntime::VmCasperV1,
transferred_value: 0,
runtime: params,
};
let transaction_string_params = TransactionStrParams {
secret_key: "",
Expand All @@ -1354,12 +1353,12 @@
chunked_args: None,
};

let params = TransactionRuntimeParams::VmCasperV1;
let transaction_builder_params = TransactionBuilderParams::PackageAlias {
package_alias: &package_name,
entry_point,
maybe_entity_version,
runtime: TransactionRuntime::VmCasperV1,
transferred_value: 0,
runtime: params,
};
let transaction =
create_transaction(transaction_builder_params, transaction_string_params, true);
Expand All @@ -1383,12 +1382,11 @@
fn should_create_session_transaction() {
let transaction_bytes = Bytes::from(vec![1u8; 32]);
let is_install_upgrade = true;
let params = TransactionRuntimeParams::VmCasperV1;
let target = &TransactionTarget::Session {
is_install_upgrade,
runtime: TransactionRuntime::VmCasperV1,
runtime: params,
module_bytes: transaction_bytes.clone(),
transferred_value: 0,
seed: None,
};
let transaction_string_params = TransactionStrParams {
secret_key: "",
Expand All @@ -1410,12 +1408,11 @@
chunked_args: None,
};

let params = TransactionRuntimeParams::VmCasperV1;
let transaction_builder_params = TransactionBuilderParams::Session {
is_install_upgrade,
transaction_bytes,
runtime: TransactionRuntime::VmCasperV1,
transferred_value: 0,
seed: None,
runtime: params,
};
let transaction =
create_transaction(transaction_builder_params, transaction_string_params, true);
Expand Down Expand Up @@ -1451,7 +1448,7 @@

let maybe_source = Some(source_uref);

let source_uref_cl = &CLValue::from_t(Some(&source_uref)).unwrap();

Check warning on line 1451 in lib/cli/tests.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-20.04)

the borrowed expression implements the required traits

Check warning on line 1451 in lib/cli/tests.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-20.04)

the borrowed expression implements the required traits
let target_uref_cl = &CLValue::from_t(target_uref).unwrap();

let transaction_string_params = TransactionStrParams {
Expand Down
23 changes: 4 additions & 19 deletions lib/cli/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
};
use casper_types::{
Digest, InitiatorAddr, SecretKey, Transaction, TransactionArgs, TransactionEntryPoint,
TransactionRuntime,
TransactionRuntimeParams,
};

pub fn create_transaction(
Expand All @@ -32,7 +32,7 @@
let ttl = parse::ttl(transaction_params.ttl)?;
let maybe_session_account = parse::session_account(&transaction_params.initiator_addr)?;

let is_v2_wasm = matches!(&builder_params, TransactionBuilderParams::Session { runtime, .. } if runtime == &TransactionRuntime::VmCasperV2);
let is_v2_wasm = matches!(&builder_params, TransactionBuilderParams::Session { runtime, .. } if matches!(runtime, &TransactionRuntimeParams::VmCasperV2 { .. }));

let mut transaction_builder = make_transaction_builder(builder_params)?;

Expand Down Expand Up @@ -158,7 +158,7 @@
.map_err(CliError::from)
}
///
/// Reads a previously-saved [`TransactionV1`] from a file and sends it to the network for execution.

Check warning on line 161 in lib/cli/transaction.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-20.04)

unresolved link to `TransactionV1`
///
/// `rpc_id_str` is the RPC ID to use for this request. node_address is the address of the node to send the request to.
/// verbosity_level is the level of verbosity to use when outputting the response.
Expand All @@ -179,7 +179,7 @@
}

///
/// Reads a previously-saved [`TransactionV1`] from a file and sends it to the network for execution.

Check warning on line 182 in lib/cli/transaction.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-20.04)

unresolved link to `TransactionV1`
///
/// `rpc_id_str` is the RPC ID to use for this request. node_address is the address of the node to send the request to.
/// verbosity_level is the level of verbosity to use when outputting the response.
Expand All @@ -199,7 +199,7 @@
.map_err(CliError::from)
}

/// Reads a previously-saved [`TransactionV1`] from a file, cryptographically signs it, and outputs it to a

Check warning on line 202 in lib/cli/transaction.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-20.04)

unresolved link to `TransactionV1`
/// file or stdout.
///
/// `maybe_output_path` specifies the output file path, or if empty, will print it to `stdout`. If
Expand Down Expand Up @@ -272,28 +272,24 @@
entity_hash,
entry_point,
runtime,
transferred_value,
} => {
let transaction_builder = TransactionV1Builder::new_targeting_invocable_entity(
entity_hash,
entry_point,
runtime,
transferred_value,
);
Ok(transaction_builder)
}
TransactionBuilderParams::InvocableEntityAlias {
entity_alias,
entry_point,
runtime,
transferred_value,
} => {
let transaction_builder =
TransactionV1Builder::new_targeting_invocable_entity_via_alias(
entity_alias,
entry_point,
runtime,
transferred_value,
);
Ok(transaction_builder)
}
Expand All @@ -302,14 +298,12 @@
maybe_entity_version,
entry_point,
runtime,
transferred_value,
} => {
let transaction_builder = TransactionV1Builder::new_targeting_package(
package_hash,
maybe_entity_version,
entry_point,
runtime,
transferred_value,
);
Ok(transaction_builder)
}
Expand All @@ -318,15 +312,13 @@
maybe_entity_version,
entry_point,
runtime,
transferred_value,
} => {
let new_targeting_package_via_alias =
TransactionV1Builder::new_targeting_package_via_alias(
package_alias,
maybe_entity_version,
entry_point,
runtime,
transferred_value,
);
let transaction_builder = new_targeting_package_via_alias;
Ok(transaction_builder)
Expand All @@ -335,16 +327,9 @@
is_install_upgrade,
transaction_bytes,
runtime,
transferred_value,
seed,
} => {
let transaction_builder = TransactionV1Builder::new_session(
is_install_upgrade,
transaction_bytes,
runtime,
transferred_value,
seed,
);
let transaction_builder =
TransactionV1Builder::new_session(is_install_upgrade, transaction_bytes, runtime);
Ok(transaction_builder)
}
TransactionBuilderParams::Transfer {
Expand Down
30 changes: 9 additions & 21 deletions lib/cli/transaction_builder_params.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use casper_types::{
bytesrepr::Bytes, system::auction::Reservation, AddressableEntityHash, PackageHash, PublicKey,
TransactionRuntime, TransferTarget, URef, U512,
TransactionRuntimeParams, TransferTarget, URef, U512,
};

/// An enum representing the parameters needed to construct a transaction builder
Expand Down Expand Up @@ -77,21 +77,17 @@ pub enum TransactionBuilderParams<'a> {
entity_hash: AddressableEntityHash,
/// The entry point for the invocable entity transaction
entry_point: &'a str,
/// Transaction Runtime.
runtime: TransactionRuntime,
/// The amount to be transferred in the invocable entity transaction.
transferred_value: u64,
/// Transaction Runtime params.
runtime: TransactionRuntimeParams,
},
/// Parameters for the invocable entity alias variant of the transaction builder
InvocableEntityAlias {
/// The entity alias for the invocable entity alias transaction
entity_alias: &'a str,
/// The entry_point for the invocable entity alias transaction
entry_point: &'a str,
/// Transaction Runtime.
runtime: TransactionRuntime,
/// Transferred value.
transferred_value: u64,
/// Transaction Runtime params.
runtime: TransactionRuntimeParams,
},
/// Parameters for the package variant of the transaction builder
Package {
Expand All @@ -102,9 +98,7 @@ pub enum TransactionBuilderParams<'a> {
/// The entry_point for the package transaction
entry_point: &'a str,
/// Transaction Runtime.
runtime: TransactionRuntime,
/// Transferred value.
transferred_value: u64,
runtime: TransactionRuntimeParams,
},
/// Parameters for the package alias variant of the transaction builder
PackageAlias {
Expand All @@ -114,10 +108,8 @@ pub enum TransactionBuilderParams<'a> {
maybe_entity_version: Option<u32>,
/// The entry point for the package alias transaction
entry_point: &'a str,
/// Transaction Runtime.
runtime: TransactionRuntime,
/// Transferred value.
transferred_value: u64,
/// Transaction Runtime params.
runtime: TransactionRuntimeParams,
},
/// Parameters for the session variant of the transaction builder
Session {
Expand All @@ -126,11 +118,7 @@ pub enum TransactionBuilderParams<'a> {
/// The Bytes to be run by the execution engine for the session transaction
transaction_bytes: Bytes,
/// Transaction Runtime.
runtime: TransactionRuntime,
/// Transferred value.
transferred_value: u64,
/// The optional seed for the session transaction
seed: Option<[u8; 32]>,
runtime: TransactionRuntimeParams,
},
/// Parameters for the transfer variant of the transaction builder
Transfer {
Expand Down
Loading
Loading