What changed, and why it matters
This commit only updates unit tests for the Avalanche transaction parser. It swaps test blockchain IDs from mainnet to testnet values, removes debug print statements, fixes an import order warning, and replaces placeholder assertions with real ones. There is no change to production code that handles user funds or device security.
No security action required. Treat as routine test maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is confined to #[cfg(test)] modules and one cosmetic import reordering in address.rs. Changes include: removing extern crate std and std::println from test modules; updating expected blockchain IDs to *_TEST_BLOCKCHAIN_ID constants; correcting expected bech32 addresses; uncommenting and fixing a mainnet base_tx test case; replacing assert!(false) and empty match arms with concrete assertions on parsed transaction fields. No runtime parsing logic, validation rules, or cryptographic code paths are modified.
Changed components
rust/apps/avalanche/src/address.rsrust/apps/avalanche/src/transactions/C_chain/evm_export.rsrust/apps/avalanche/src/transactions/C_chain/evm_import.rsrust/apps/avalanche/src/transactions/P_chain/add_permissionless_delegator.rsrust/apps/avalanche/src/transactions/P_chain/add_permissionless_validator.rsrust/apps/avalanche/src/transactions/P_chain/validator.rsrust/apps/avalanche/src/transactions/base_tx.rsrust/apps/avalanche/src/transactions/export.rsrust/apps/avalanche/src/transactions/import.rsrust/apps/avalanche/src/transactions/inputs/secp256k1_transfer_input.rsrust/apps/avalanche/src/transactions/outputs/secp256k1_transfer_output.rsrust/apps/avalanche/src/transactions/transferable.rsInspect captured patch +58 / −84
diff --git a/rust/apps/avalanche/src/address.rs b/rust/apps/avalanche/src/address.rs
index 7dfffa2..d923499 100644
--- a/rust/apps/avalanche/src/address.rs
+++ b/rust/apps/avalanche/src/address.rs
@@ -1,8 +1,8 @@
use crate::constants::*;
use crate::errors::{AvaxError, Result};
+use crate::network::Network;
#[cfg(feature = "testnet")]
use crate::network::TESTNET_ID;
-use crate::network::Network;
use crate::ripple_keypair::hash160;
use crate::transactions::structs::ParsedSizeAble;
use alloc::string::{String, ToString};
diff --git a/rust/apps/avalanche/src/transactions/C_chain/evm_export.rs b/rust/apps/avalanche/src/transactions/C_chain/evm_export.rs
index c307488..f472afb 100644
--- a/rust/apps/avalanche/src/transactions/C_chain/evm_export.rs
+++ b/rust/apps/avalanche/src/transactions/C_chain/evm_export.rs
@@ -142,8 +142,6 @@ impl TryFrom<Bytes> for ExportTx {
#[cfg(test)]
mod tests {
use super::*;
- extern crate std;
- use std::println;
#[test]
fn test_avax_c_export() {
diff --git a/rust/apps/avalanche/src/transactions/C_chain/evm_import.rs b/rust/apps/avalanche/src/transactions/C_chain/evm_import.rs
index 2cf90e1..1f3e98e 100644
--- a/rust/apps/avalanche/src/transactions/C_chain/evm_import.rs
+++ b/rust/apps/avalanche/src/transactions/C_chain/evm_import.rs
@@ -132,8 +132,6 @@ impl TryFrom<Bytes> for ImportTx {
#[cfg(test)]
mod tests {
use super::*;
- extern crate std;
- use std::println;
#[test]
fn test_avax_c_import() {
@@ -146,7 +144,7 @@ mod tests {
assert_eq!(result.inputs.get_len(), 1);
assert_eq!(result.outputs.get_len(), 1);
- assert_eq!(result.source_chain, X_BLOCKCHAIN_ID);
+ assert_eq!(result.source_chain, X_TEST_BLOCKCHAIN_ID);
assert_eq!(result.get_total_output_amount(), 99988770);
assert_eq!(result.get_total_input_amount(), 100000000);
}
diff --git a/rust/apps/avalanche/src/transactions/P_chain/add_permissionless_delegator.rs b/rust/apps/avalanche/src/transactions/P_chain/add_permissionless_delegator.rs
index f267d3c..12885fd 100644
--- a/rust/apps/avalanche/src/transactions/P_chain/add_permissionless_delegator.rs
+++ b/rust/apps/avalanche/src/transactions/P_chain/add_permissionless_delegator.rs
@@ -109,15 +109,12 @@ impl TryFrom<Bytes> for AddPermissLessionDelegatorTx {
#[cfg(test)]
mod tests {
use super::*;
- extern crate std;
- use std::println;
#[test]
fn test_add_permissionless_delegator() {
let input_bytes = "00000000001a000000050000000000000000000000000000000000000000000000000000000000000000000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000007000000003b9a9e0400000000000000000000000100000001e0beb088f94b8224eb5d6f1115561d7173cd6e7f00000002295a7b15e26c6cafda8883afd0f724e0e0b1dad4517148711434cb96fb3c8a61000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000005000000003b9aca0000000001000000006109bc613691602ca0811312357676416252412a87ded6c56c240baba1afe042000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000005000000003b9aca000000000100000000000000007072a3df0cd056d9b9ef00c09630bad3027dc312000000006760c3b100000000676215a9000000003b9aca000000000000000000000000000000000000000000000000000000000000000000000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000007000000003b9aca0000000000000000000000000100000001e0beb088f94b8224eb5d6f1115561d7173cd6e7f0000000b00000000000000000000000100000001a0f4d4d9a0ea219da5ed5499ad083e1942a0846a000000020000000900000001438c3a393f49bb27791ca830effec456c2642a487ee4ce89300dd2e591fc22ab6b2aa8e08515ca229f2a2f14168700e05a1f96bd61d1fc3ab31e9e71ef9f16bb000000000900000001438c3a393f49bb27791ca830effec456c2642a487ee4ce89300dd2e591fc22ab6b2aa8e08515ca229f2a2f14168700e05a1f96bd61d1fc3ab31e9e71ef9f16bb005c3d047c";
let mut bytes = Bytes::from(hex::decode(input_bytes).expect("Failed to decode hex string"));
let result = AddPermissLessionDelegatorTx::try_from(bytes.clone()).unwrap();
- println!("result: {:?}", result);
assert_eq!(result.base_tx.get_blockchain_id(), P_BLOCKCHAIN_ID);
}
}
diff --git a/rust/apps/avalanche/src/transactions/P_chain/add_permissionless_validator.rs b/rust/apps/avalanche/src/transactions/P_chain/add_permissionless_validator.rs
index dbdc65f..d9e6aac 100644
--- a/rust/apps/avalanche/src/transactions/P_chain/add_permissionless_validator.rs
+++ b/rust/apps/avalanche/src/transactions/P_chain/add_permissionless_validator.rs
@@ -133,7 +133,7 @@ mod tests {
let mut bytes = Bytes::from(hex::decode(input_bytes).expect("Failed to decode hex string"));
let result = AddPermissLessionValidatorTx::try_from(bytes.clone()).unwrap();
assert_eq!(
- "fuji1v8xh6fk89mwxx82pzntwaukyup57eysxj5xrzz".to_string(),
+ "avax1v8xh6fk89mwxx82pzntwaukyup57eysx7xzuwa".to_string(),
result.get_reward_address().unwrap()
);
}
diff --git a/rust/apps/avalanche/src/transactions/P_chain/validator.rs b/rust/apps/avalanche/src/transactions/P_chain/validator.rs
index ce0313b..fa6b4d9 100644
--- a/rust/apps/avalanche/src/transactions/P_chain/validator.rs
+++ b/rust/apps/avalanche/src/transactions/P_chain/validator.rs
@@ -36,7 +36,7 @@ impl TryFrom<Bytes> for Validator {
#[cfg(test)]
mod tests {
use super::*;
- extern crate std;
+ use crate::encode::cb58::Cb58Encodable;
#[test]
fn test_validator_parse() {
diff --git a/rust/apps/avalanche/src/transactions/base_tx.rs b/rust/apps/avalanche/src/transactions/base_tx.rs
index 153bb03..004fd42 100644
--- a/rust/apps/avalanche/src/transactions/base_tx.rs
+++ b/rust/apps/avalanche/src/transactions/base_tx.rs
@@ -138,8 +138,6 @@ impl TryFrom<Bytes> for BaseTx {
#[cfg(test)]
mod tests {
use super::*;
- extern crate std;
- use std::println;
#[test]
fn test_avax_base_transaction() {
@@ -149,30 +147,29 @@ mod tests {
let input_bytes = "00000000000000000005ab68eb1ee142a05cfe768c36e11f0b596db5a3c6c77aabe665dad9e638ca94f7000000023d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000007000000000bbdfb400000000000000000000000010000000169bc9b5b6cbbbd490abbd79a37ad6cd643be87ab3d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000007000000002faf0800000000000000000000000001000000016498cb45e255f5937b816a59c34a7559a2d437b10000000163c5b29498bf6a9f1e2a5d20f8eeddaf92096c0ce1c9c2cf6b93fd9a0d12f725000000003d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000005000000003b7c4580000000010000000000000000";
// x-chain mainnet test case
- // let input_bytes = "00000000000000000001ed5f38341e436e5d46e2bb00b45d62ae97d1b050c64bc634ae10626739e35c4b0000000221e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff000000070000000218711a00000000000000000000000001000000017c949a8013befa47e992078764ff735b18a26b5b21e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff0000000700000003cf87a80c00000000000000000000000100000001d5ae9a7d5b31660f08c0aefc1547fb195fbfc85d000000021ddbc2d7d67f14df1e36111bbeef2adae97067c4ceb9db94b73e8883a5a6dd640000000121e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff000000050000000395e95a000000000100000000885eea33e82eff5130de90152c0ebb98f5cfdc7c7529596fe2473a35654aac830000000021e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff0000000500000002522030ec00000001000000000000000400000000000000020000000900000001a6810c96af6f4e4281031b795f78c37f3395b6d35806179d37b40603d547e2f262969f5363e168c064712607679b01ed13a76daab84addc94a3745b0549a53e5000000000900000001cefe480034588db7b5e0993410b6dbdd2e37e3ec94e75b450dd4c56c32f3b4c61cd9dab507232eb1211a846165336a7d7d975b39612df8d88174e1a92c27535f004a454d1e";
- // let mut bytes =
- // Bytes::from(hex::decode(input_bytes).expect("Failed to decode hex string"));
- // let result = BaseTx::try_from(bytes).unwrap();
-
- // assert_eq!(result.get_blockchain_id(), X_BLOCKCHAIN_ID);
- // assert_eq!(
- // "fuji1dx7fkkmvhw75jz4m67dr0ttv6epmapat8vwcu4",
- // result
- // .get_outputs_addresses()
- // .get(0)
- // .unwrap()
- // .address
- // .get(0)
- // .unwrap()
- // );
- // assert_eq!(result.get_inputs_len(), 1);
- // assert_eq!(result.get_outputs_len(), 2);
+ let input_bytes = "00000000000000000001ed5f38341e436e5d46e2bb00b45d62ae97d1b050c64bc634ae10626739e35c4b0000000221e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff000000070000000218711a00000000000000000000000001000000017c949a8013befa47e992078764ff735b18a26b5b21e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff0000000700000003cf87a80c00000000000000000000000100000001d5ae9a7d5b31660f08c0aefc1547fb195fbfc85d000000021ddbc2d7d67f14df1e36111bbeef2adae97067c4ceb9db94b73e8883a5a6dd640000000121e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff000000050000000395e95a000000000100000000885eea33e82eff5130de90152c0ebb98f5cfdc7c7529596fe2473a35654aac830000000021e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff0000000500000002522030ec00000001000000000000000400000000000000020000000900000001a6810c96af6f4e4281031b795f78c37f3395b6d35806179d37b40603d547e2f262969f5363e168c064712607679b01ed13a76daab84addc94a3745b0549a53e5000000000900000001cefe480034588db7b5e0993410b6dbdd2e37e3ec94e75b450dd4c56c32f3b4c61cd9dab507232eb1211a846165336a7d7d975b39612df8d88174e1a92c27535f004a454d1e";
+ let mut bytes =
+ Bytes::from(hex::decode(input_bytes).expect("Failed to decode hex string"));
+ let result = BaseTx::try_from(bytes).unwrap();
+
+ assert_eq!(result.get_blockchain_id(), X_BLOCKCHAIN_ID);
+ assert_eq!(
+ "avax10j2f4qqnhmay06vjq7rkflmntvv2y66mzhk6s9",
+ result
+ .get_outputs_addresses()
+ .get(0)
+ .unwrap()
+ .address
+ .get(0)
+ .unwrap()
+ );
+ assert_eq!(result.get_inputs_len(), 2);
+ assert_eq!(result.get_outputs_len(), 2);
}
// x chain base tx
{
let input_bytes = "00000000000000000005ab68eb1ee142a05cfe768c36e11f0b596db5a3c6c77aabe665dad9e638ca94f7000000023d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000070000000001312d00000000000000000000000001000000018771921301d5bffff592dae86695a615bdb4a4413d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000070000000004b571c0000000000000000000000001000000010969ea62e2bb30e66d82e82fe267edf6871ea5f7000000019eae34633c2103aaee5253bb3ca3046c2ab4718a109ffcdb77b51d0427be6bb7000000003d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000050000000005f5e100000000010000000000000000";
- let input_bytes = "00000000000000000001ed5f38341e436e5d46e2bb00b45d62ae97d1b050c64bc634ae10626739e35c4b0000000121e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff00000007000000000089544000000000000000000000000100000001512e7191685398f00663e12197a3d8f6012d9ea300000001db720ad6707915cc4751fb7e5491a3af74e127a1d81817abe9438590c0833fe10000000021e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff000000050000000000989680000000010000000000000000";
let mut bytes =
Bytes::from(hex::decode(input_bytes).expect("Failed to decode hex string"));
match BaseTx::try_from(bytes) {
diff --git a/rust/apps/avalanche/src/transactions/export.rs b/rust/apps/avalanche/src/transactions/export.rs
index b466efa..bac0b52 100644
--- a/rust/apps/avalanche/src/transactions/export.rs
+++ b/rust/apps/avalanche/src/transactions/export.rs
@@ -105,9 +105,6 @@ impl TryFrom<Bytes> for ExportTx {
#[cfg(test)]
mod tests {
use super::*;
- use crate::transactions::type_id::TypeId;
- extern crate std;
- use std::println;
#[test]
fn test_avax_base_export_tx() {
@@ -123,7 +120,7 @@ mod tests {
let mut bytes =
Bytes::from(hex::decode(input_bytes).expect("Failed to decode hex string"));
let result = ExportTx::try_from(bytes).unwrap();
- assert_eq!(result.get_dest_chain(), X_BLOCKCHAIN_ID);
+ assert_eq!(result.get_dest_chain(), C_TEST_BLOCKCHAIN_ID);
}
}
}
diff --git a/rust/apps/avalanche/src/transactions/import.rs b/rust/apps/avalanche/src/transactions/import.rs
index 70f172f..6c41b86 100644
--- a/rust/apps/avalanche/src/transactions/import.rs
+++ b/rust/apps/avalanche/src/transactions/import.rs
@@ -81,9 +81,7 @@ impl TryFrom<Bytes> for ImportTx {
mod tests {
use super::*;
use crate::transactions::type_id::TypeId;
- extern crate std;
use core::result;
- use std::println;
#[test]
fn test_avax_base_import_tx() {
@@ -93,8 +91,7 @@ mod tests {
let mut bytes =
Bytes::from(hex::decode(input_bytes).expect("Failed to decode hex string"));
let result = ImportTx::try_from(bytes).unwrap();
- println!("result = {:?}", result);
- assert_eq!(result.base_tx.get_blockchain_id(), X_BLOCKCHAIN_ID);
+ assert_eq!(result.base_tx.get_blockchain_id(), X_TEST_BLOCKCHAIN_ID);
}
// x-chain import from c-chain
@@ -103,7 +100,7 @@ mod tests {
let mut bytes =
Bytes::from(hex::decode(input_bytes).expect("Failed to decode hex string"));
let result = ImportTx::try_from(bytes).unwrap();
- assert_eq!(result.source_chain, C_BLOCKCHAIN_ID);
+ assert_eq!(result.source_chain, C_TEST_BLOCKCHAIN_ID);
}
// p-chain import form c-chain xZAN6Dr6snqq3LzAhQsCJWpXntGaMVrQRDqDE1ZdCsCgBkwWS
diff --git a/rust/apps/avalanche/src/transactions/inputs/secp256k1_transfer_input.rs b/rust/apps/avalanche/src/transactions/inputs/secp256k1_transfer_input.rs
index e86d960..a6b3e26 100644
--- a/rust/apps/avalanche/src/transactions/inputs/secp256k1_transfer_input.rs
+++ b/rust/apps/avalanche/src/transactions/inputs/secp256k1_transfer_input.rs
@@ -51,8 +51,6 @@ impl TryFrom<Bytes> for SECP256K1TransferInput {
#[cfg(test)]
mod tests {
use super::*;
- extern crate std;
- use std::println;
#[test]
fn test_secp256k1_transfer_input_try_from() {
diff --git a/rust/apps/avalanche/src/transactions/outputs/secp256k1_transfer_output.rs b/rust/apps/avalanche/src/transactions/outputs/secp256k1_transfer_output.rs
index 1d410a7..29111f5 100644
--- a/rust/apps/avalanche/src/transactions/outputs/secp256k1_transfer_output.rs
+++ b/rust/apps/avalanche/src/transactions/outputs/secp256k1_transfer_output.rs
@@ -63,8 +63,6 @@ impl TryFrom<Bytes> for SECP256K1TransferOutput {
#[cfg(test)]
mod tests {
use super::*;
- extern crate std;
- use std::println;
#[test]
fn test_secp256k1_transfer_output() {
diff --git a/rust/apps/avalanche/src/transactions/transferable.rs b/rust/apps/avalanche/src/transactions/transferable.rs
index 02ef0f4..c82d0f6 100644
--- a/rust/apps/avalanche/src/transactions/transferable.rs
+++ b/rust/apps/avalanche/src/transactions/transferable.rs
@@ -202,8 +202,6 @@ impl InputTrait for InputType {
#[cfg(test)]
mod tests {
use super::*;
- extern crate std;
- use std::println;
#[test]
fn test_transferable_output() {
@@ -211,10 +209,15 @@ mod tests {
let binary_data = hex::decode(input_bytes).expect("Failed to decode hex string");
let mut bytes = Bytes::from(binary_data);
let output_len = bytes.get_u32();
- for _ in 0..output_len {
- let result = TransferableOutput::try_from(bytes.clone()).unwrap();
- }
- assert!(false);
+ assert_eq!(output_len, 2);
+ let result = TransferableOutput::try_from(bytes.clone()).unwrap();
+ assert_eq!(result.output.get_amount(), 100000000);
+ assert_eq!(result.output.get_addresses_len(), 1);
+ assert_eq!(
+ result.output.get_addresses(),
+ vec!["avax1saceyycp6klllavjmt5xd9dxzk7mffzp6fzwtu".to_string()]
+ );
+ assert_eq!(result.output.get_transfer_output_len(), 48);
}
#[test]
@@ -225,21 +228,18 @@ mod tests {
let mut bytes =
Bytes::from(hex::decode(input_bytes).expect("Failed to decode hex string"));
let input_len = bytes.get_u32();
- for _ in 0..input_len {
- let result = TransferableInput::try_from(bytes.clone());
- match result {
- Ok(_) => {}
- Err(e) => match e {
- AvaxError::InvalidHex(msg) => {
- assert_eq!(
- msg, "Unsupported input type found in input bytes.",
- "Unexpected error message"
- );
- }
- _ => {}
- },
- }
- }
+ assert_eq!(input_len, 1);
+ let result = TransferableInput::try_from(bytes.clone()).unwrap();
+ assert_eq!(
+ result.tx_id,
+ [
+ 87, 213, 226, 62, 46, 31, 70, 11, 97, 139, 186, 27, 85, 145, 63, 243, 206, 179,
+ 21, 240, 209, 172, 196, 31, 230, 64, 142, 220, 77, 233, 250, 205
+ ]
+ );
+ assert_eq!(result.utxo_index, 0);
+ assert_eq!(result.input.get_amount(), 498951949);
+ assert_eq!(result.input.get_transfer_input_len(), 20);
}
// x-chain import transferin
@@ -248,24 +248,18 @@ mod tests {
let mut bytes =
Bytes::from(hex::decode(input_bytes).expect("Failed to decode hex string"));
let input_len = bytes.get_u32();
- for _ in 0..input_len {
- let result = TransferableInput::try_from(bytes.clone());
- match result {
- Ok(_) => {
- println!("{:?}", result);
- }
- Err(e) => match e {
- AvaxError::InvalidHex(msg) => {
- assert_eq!(
- msg, "Unsupported output type found in input bytes.",
- "Unexpected error message"
- );
- }
- _ => {}
- },
- }
- }
- assert!(false);
+ assert_eq!(input_len, 1);
+ let result = TransferableInput::try_from(bytes.clone()).unwrap();
+ assert_eq!(
+ result.tx_id,
+ [
+ 220, 244, 202, 133, 71, 78, 135, 167, 67, 236, 143, 235, 84, 131, 109, 43, 64,
+ 59, 54, 199, 199, 56, 195, 226, 73, 143, 221, 52, 109, 172, 71, 116
+ ]
+ );
+ assert_eq!(result.utxo_index, 1);
+ assert_eq!(result.input.get_amount(), 200000000);
+ assert_eq!(result.input.get_transfer_input_len(), 20);
}
}
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.