diff --git a/client/tests/integration/asset.rs b/client/tests/integration/asset.rs index e1f7723a806..81857bb0b8c 100644 --- a/client/tests/integration/asset.rs +++ b/client/tests/integration/asset.rs @@ -431,7 +431,11 @@ fn account_id_new(account_name: &str, account_domain: &str) -> AccountId { ) } -fn asset_id_new(definition_name: &str, definition_domain: &str, account_id: AccountId) -> AssetId { +pub fn asset_id_new( + definition_name: &str, + definition_domain: &str, + account_id: AccountId, +) -> AssetId { AssetId::new( AssetDefinitionId::new( definition_domain.parse().expect("Valid"), diff --git a/client/tests/integration/mod.rs b/client/tests/integration/mod.rs index 8c8008ce649..87f72688b6f 100644 --- a/client/tests/integration/mod.rs +++ b/client/tests/integration/mod.rs @@ -22,6 +22,7 @@ mod set_parameter; mod sorting; mod transfer_asset; mod triggers; +mod tx_chain_id; mod tx_history; mod tx_rollback; mod unregister_peer; diff --git a/client/tests/integration/tx_chain_id.rs b/client/tests/integration/tx_chain_id.rs new file mode 100644 index 00000000000..37ab24da9cb --- /dev/null +++ b/client/tests/integration/tx_chain_id.rs @@ -0,0 +1,66 @@ +use std::str::FromStr; + +use iroha_crypto::KeyPair; +use iroha_data_model::prelude::*; +use test_network::*; + +use super::asset::asset_id_new; + +#[test] +fn send_tx_with_different_chain_id() { + let (_rt, _peer, test_client) = ::new().with_port(11_240).start_with_runtime(); + wait_for_genesis_committed(&[test_client.clone()], 0); + // Given + let sender_account_id = AccountId::from_str("sender@wonderland").expect("Valid"); + let sender_keypair = KeyPair::generate().expect("Failed to generate sender KeyPair."); + let receiver_account_id = AccountId::from_str("receiver@wonderland").expect("Valid"); + let asset_definition_id = AssetDefinitionId::from_str("test_asset#wonderland").expect("Valid"); + let to_transfer = 1; + let create_sender_accout = Register::account(Account::new( + sender_account_id.clone(), + [sender_keypair.public_key().clone()], + )); + let create_receiver_account = Register::account(Account::new(receiver_account_id.clone(), [])); + let create_asset = + Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone())); + let register_asset: InstructionBox = Register::asset(Asset::new( + AssetId::new(asset_definition_id.clone(), sender_account_id.clone()), + AssetValue::Quantity(10), + )) + .into(); + + test_client + .submit_blocking(create_sender_accout) + .expect("Failed to create sender account."); + test_client + .submit_blocking(create_receiver_account) + .expect("Failed to create receiver account."); + test_client + .submit_blocking(create_asset) + .expect("Failed to create asset"); + test_client + .submit_blocking(register_asset.clone()) + .expect("Failed to register asset"); + let chain_id_0 = ChainId::new("0"); + let chain_id_1 = ChainId::new("1"); + + let transfer_instruction = Transfer::asset_quantity( + asset_id_new("test_asset", "wonderland", sender_account_id.clone()), + to_transfer, + receiver_account_id.clone(), + ); + let asset_transfer_tx_0 = TransactionBuilder::new(chain_id_0, sender_account_id.clone()) + .with_instructions([transfer_instruction.clone()]) + .sign(sender_keypair.clone()) + .expect("Failed to sign sender transaction, chainId = 0"); + let asset_transfer_tx_1 = TransactionBuilder::new(chain_id_1, sender_account_id.clone()) + .with_instructions([transfer_instruction]) + .sign(sender_keypair) + .expect("Failed to sign sender transaction, chainId = 1"); + test_client + .submit_transaction_blocking(&asset_transfer_tx_0) + .unwrap(); + let _err = test_client + .submit_transaction_blocking(&asset_transfer_tx_1) + .unwrap_err(); +}