From ef91a5314c3be53fcf3ef27000a473bae6707990 Mon Sep 17 00:00:00 2001 From: Mostafa Date: Fri, 1 Nov 2024 18:56:15 +0800 Subject: [PATCH] use broadcasted transaction data for tests --- .../blockchains/pactus/TestPactusSigner.kt | 107 ++++++++++- .../tests/chains/pactus/pactus_compile.rs | 174 ++++++------------ .../tests/chains/pactus/pactus_sign.rs | 101 +++------- .../chains/pactus/pactus_transaction_util.rs | 34 +--- .../tests/chains/pactus/test_cases.rs | 59 ++++-- swift/Tests/Blockchains/PactusTests.swift | 70 ++++++- tests/chains/Pactus/CompilerTests.cpp | 65 ++++--- tests/chains/Pactus/SignerTests.cpp | 23 +-- tests/chains/Pactus/TestCases.h | 144 +++++++++++++-- 9 files changed, 456 insertions(+), 321 deletions(-) diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusSigner.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusSigner.kt index 2cbaaf9635e..c388a1c7d84 100644 --- a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusSigner.kt +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusSigner.kt @@ -24,18 +24,24 @@ class TestPactusSigner { } @Test - fun testPactusTransactionSigning() { + fun testPactusTransferSigning() { + // Successfully broadcasted transaction: + // https://pacviewer.com/transaction/1b6b7226f7935a15f05371d1a1fefead585a89704ce464b7cc1d453d299d235f + // val signingInput = Pactus.SigningInput.newBuilder() signingInput.apply { - privateKey = ByteString.copyFrom(PrivateKey("4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6".toHexByteArray()).data()) + privateKey = ByteString.copyFrom( + PrivateKey("4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6" + .toHexByteArray()).data() + ) transaction = Pactus.TransactionMessage.newBuilder().apply { - lockTime = 0x00030201 - fee = 1000 - memo = "test" + lockTime = 2335524 + fee = 10000000 + memo = "wallet-core" transfer = Pactus.TransferPayload.newBuilder().apply { sender = "pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr" receiver = "pc1r0g22ufzn8qtw0742dmfglnw73e260hep0k3yra" - amount = 20000 + amount = 200000000 }.build() }.build() } @@ -43,17 +49,100 @@ class TestPactusSigner { val output = AnySigner.sign(signingInput.build(), PACTUS, SigningOutput.parser()) assertEquals( - "0x34cd4656a98f7eb996e83efdc384cefbe3a9c52dca79a99245b4eacc0b0b4311", + "0x1b6b7226f7935a15f05371d1a1fefead585a89704ce464b7cc1d453d299d235f", Numeric.toHexString(output.transactionId.toByteArray()) ) assertEquals( - "0x50ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd09", + "0x8dea6d79ee7ec60f66433f189ed9b3c50b2ad6fa004e26790ee736693eda850695794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa", Numeric.toHexString(output.signature.toByteArray()) ) assertEquals( - "0x000101020300e807047465737401037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21a09c0150ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd0995794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa", + "0x000124a3230080ade2040b77616c6c65742d636f726501037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df218084af5f4ed8fee3d8992e82660dd05bbe8608fc56ceabffdeeee61e3213b9b49d33a0fc8dea6d79ee7ec60f66433f189ed9b3c50b2ad6fa004e26790ee736693eda850695794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa", + Numeric.toHexString(output.signedTransactionData.toByteArray()) + ) + } + + @Test + fun testPactusBondWithPublicKeySigning() { + // Successfully broadcasted transaction: + // https://pacviewer.com/transaction/d194b445642a04ec78ced4448696e50b733f2f0b517a23871882c0eefaf1c28f + // + val signingInput = Pactus.SigningInput.newBuilder() + signingInput.apply { + privateKey = ByteString.copyFrom( + PrivateKey("4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6" + .toHexByteArray()).data() + ) + transaction = Pactus.TransactionMessage.newBuilder().apply { + lockTime = 2339009 + fee = 10000000 + memo = "wallet-core" + bond = Pactus.BondPayload.newBuilder().apply { + sender = "pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr" + receiver = "pc1p9y5gmu9l002tt60wak9extgvwm69rq3a9ackrl" + stake = 1000000000 + publicKey = "public1pnz75msstqdrq5eguvcwanug0zauhqjw2cc4flmez3qethnp68y64ehc4k69amapj7x4na2uda0snqz4yxujgx3jsse4f64fgy7jkh0xauvhrc5ts09vfk48g85t0js66hvajm6xruemsvlxqv3xvkyur8v9v0mtn" + }.build() + }.build() + } + + val output = AnySigner.sign(signingInput.build(), PACTUS, SigningOutput.parser()) + + assertEquals( + "0xd194b445642a04ec78ced4448696e50b733f2f0b517a23871882c0eefaf1c28f", + Numeric.toHexString(output.transactionId.toByteArray()) + ) + + assertEquals( + "0x0d7bc6d94927534b89e2f53bcfc9fc849e0e2982438955eda55b4338328adac79d4ee3216d143f0e1629764ab650734f8ba188e716d71f9eff65e39ce7006300", + Numeric.toHexString(output.signature.toByteArray()) + ) + + assertEquals( + "0x0001c1b0230080ade2040b77616c6c65742d636f726502037098338e0b6808119dfd4457ab806b9c2059b89b0129288df0bf7bd4b5e9eeed8b932d0c76f451823d6098bd4dc20b03460a651c661dd9f10f17797049cac62a9fef228832bbcc3a39355cdf15b68bddf432f1ab3eab8debe1300aa43724834650866a9d552827a56bbcdde32e3c517079589b54e83d16f9435abb3b2de8c3e677067cc0644ccb13833b8094ebdc030d7bc6d94927534b89e2f53bcfc9fc849e0e2982438955eda55b4338328adac79d4ee3216d143f0e1629764ab650734f8ba188e716d71f9eff65e39ce700630095794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa", + Numeric.toHexString(output.signedTransactionData.toByteArray()) + ) + } + + @Test + fun testPactusBondWithoutPublicKeySigning() { + // Successfully broadcasted transaction: + // https://pacviewer.com/transaction/f83f583a5c40adf93a90ea536a7e4b467d30ca4f308d5da52624d80c42adec80 + // + val signingInput = Pactus.SigningInput.newBuilder() + signingInput.apply { + privateKey = ByteString.copyFrom( + PrivateKey("4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6" + .toHexByteArray()).data() + ) + transaction = Pactus.TransactionMessage.newBuilder().apply { + lockTime = 2335580 + fee = 10000000 + memo = "wallet-core" + bond = Pactus.BondPayload.newBuilder().apply { + sender = "pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr" + receiver = "pc1p6taz5l2kq5ppnxv4agnqj48svnvsy797xpe6wd" + stake = 1000000000 + }.build() + }.build() + } + + val output = AnySigner.sign(signingInput.build(), PACTUS, SigningOutput.parser()) + + assertEquals( + "0xf83f583a5c40adf93a90ea536a7e4b467d30ca4f308d5da52624d80c42adec80", + Numeric.toHexString(output.transactionId.toByteArray()) + ) + + assertEquals( + "0x9e6279fb64067c7d7316ac74630bbb8589df268aa4548f1c7d85c087a8748ff0715b9149afbd94c5d8ee6b37c787ec63e963cbb38be513ebc436aa58f9a8f00d", + Numeric.toHexString(output.signature.toByteArray()) + ) + + assertEquals( + "0x01015ca3230080ade2040b77616c6c65742d636f726502037098338e0b6808119dfd4457ab806b9c2059b89b01d2fa2a7d560502199995ea260954f064d90278be008094ebdc039e6279fb64067c7d7316ac74630bbb8589df268aa4548f1c7d85c087a8748ff0715b9149afbd94c5d8ee6b37c787ec63e963cbb38be513ebc436aa58f9a8f00d", Numeric.toHexString(output.signedTransactionData.toByteArray()) ) } diff --git a/rust/tw_tests/tests/chains/pactus/pactus_compile.rs b/rust/tw_tests/tests/chains/pactus/pactus_compile.rs index df0be68a0ce..27a0c274c76 100644 --- a/rust/tw_tests/tests/chains/pactus/pactus_compile.rs +++ b/rust/tw_tests/tests/chains/pactus/pactus_compile.rs @@ -3,7 +3,7 @@ // Copyright © 2017 Trust Wallet. use crate::chains::pactus::test_cases::PRIVATE_KEY; -use crate::chains::pactus::test_cases::{bond_test_case, transfer_test_case}; +use crate::chains::pactus::test_cases::TEST_CASES; use tw_any_coin::ffi::tw_transaction_compiler::{ tw_transaction_compiler_compile, tw_transaction_compiler_pre_image_hashes, }; @@ -20,121 +20,59 @@ use tw_proto::TxCompiler::Proto as CompilerProto; use tw_proto::{deserialize, serialize}; #[test] -fn test_pactus_transfer_compile() { - // Step 1: Create signing input. - let input = transfer_test_case::sign_input(); - - // Step 2: Obtain preimage hash - let input_data = TWDataHelper::create(serialize(&input).unwrap()); - let preimage_data = TWDataHelper::wrap(unsafe { - tw_transaction_compiler_pre_image_hashes(CoinType::Pactus as u32, input_data.ptr()) - }) - .to_vec() - .expect("!tw_transaction_compiler_pre_image_hashes returned nullptr"); - - let preimage: CompilerProto::PreSigningOutput = - deserialize(&preimage_data).expect("Coin entry returned an invalid output"); - - assert_eq!(preimage.error, SigningErrorType::OK); - assert!(preimage.error_message.is_empty()); - assert_eq!(preimage.data.to_hex(), transfer_test_case::SIGN_BYTES); - - // Step 3: Sign the data "externally" - let private_key = ed25519::sha512::KeyPair::try_from(PRIVATE_KEY).unwrap(); - let public_key = private_key.public().to_vec(); - - let signature = private_key - .sign(preimage.data.to_vec()) - .expect("Error signing data") - .to_vec(); - assert_eq!(signature.to_hex(), transfer_test_case::SIGNATURE); - - // Step 4: Compile transaction info - - let signatures = TWDataVectorHelper::create([signature]); - let public_keys = TWDataVectorHelper::create([public_key]); - - let input_data = TWDataHelper::create(serialize(&input).unwrap()); - let output_data = TWDataHelper::wrap(unsafe { - tw_transaction_compiler_compile( - CoinType::Pactus as u32, - input_data.ptr(), - signatures.ptr(), - public_keys.ptr(), - ) - }) - .to_vec() - .expect("!tw_transaction_compiler_compile returned nullptr"); - - let output: Proto::SigningOutput = - deserialize(&output_data).expect("Coin entry returned an invalid output"); - - assert_eq!(output.error, SigningErrorType::OK); - assert!(output.error_message.is_empty()); - assert_eq!(output.transaction_id.to_hex(), transfer_test_case::TX_ID); - assert_eq!(output.signature.to_hex(), transfer_test_case::SIGNATURE); - assert_eq!( - output.signed_transaction_data.to_hex(), - transfer_test_case::SIGNED_DATA - ); -} - -#[test] -fn test_pactus_bond_compile() { - // Step 1: Create signing input. - let input = bond_test_case::sign_input(); - - // Step 2: Obtain preimage hash - let input_data = TWDataHelper::create(serialize(&input).unwrap()); - let preimage_data = TWDataHelper::wrap(unsafe { - tw_transaction_compiler_pre_image_hashes(CoinType::Pactus as u32, input_data.ptr()) - }) - .to_vec() - .expect("!tw_transaction_compiler_pre_image_hashes returned nullptr"); - - let preimage: CompilerProto::PreSigningOutput = - deserialize(&preimage_data).expect("Coin entry returned an invalid output"); - - assert_eq!(preimage.error, SigningErrorType::OK); - assert!(preimage.error_message.is_empty()); - assert_eq!(preimage.data.to_hex(), bond_test_case::SIGN_BYTES); - - // Step 3: Sign the data "externally" - let private_key = ed25519::sha512::KeyPair::try_from(PRIVATE_KEY).unwrap(); - let public_key = private_key.public().to_vec(); - - let signature = private_key - .sign(preimage.data.to_vec()) - .expect("Error signing data") - .to_vec(); - assert_eq!(signature.to_hex(), bond_test_case::SIGNATURE); - - // Step 4: Compile transaction info - - let signatures = TWDataVectorHelper::create([signature]); - let public_keys = TWDataVectorHelper::create([public_key]); - - let input_data = TWDataHelper::create(serialize(&input).unwrap()); - let output_data = TWDataHelper::wrap(unsafe { - tw_transaction_compiler_compile( - CoinType::Pactus as u32, - input_data.ptr(), - signatures.ptr(), - public_keys.ptr(), - ) - }) - .to_vec() - .expect("!tw_transaction_compiler_compile returned nullptr"); - - let output: Proto::SigningOutput = - deserialize(&output_data).expect("Coin entry returned an invalid output"); - - assert_eq!(output.error, SigningErrorType::OK); - assert!(output.error_message.is_empty()); - assert_eq!(output.transaction_id.to_hex(), bond_test_case::TX_ID); - assert_eq!(output.signature.to_hex(), bond_test_case::SIGNATURE); - assert_eq!( - output.signed_transaction_data.to_hex(), - bond_test_case::SIGNED_DATA - ); +fn test_pactus_transaction_compile() { + for case in TEST_CASES.iter() { + // Step 1: Create signing input. + let input = (case.sign_input_fn)(); + + // Step 2: Obtain preimage hash + let input_data = TWDataHelper::create(serialize(&input).unwrap()); + let preimage_data = TWDataHelper::wrap(unsafe { + tw_transaction_compiler_pre_image_hashes(CoinType::Pactus as u32, input_data.ptr()) + }) + .to_vec() + .expect("!tw_transaction_compiler_pre_image_hashes returned nullptr"); + + let preimage: CompilerProto::PreSigningOutput = + deserialize(&preimage_data).expect("Coin entry returned an invalid output"); + + assert_eq!(preimage.error, SigningErrorType::OK); + assert!(preimage.error_message.is_empty()); + assert_eq!(preimage.data.to_hex(), case.data_to_sign); + + // Step 3: Sign the data "externally" + let private_key = ed25519::sha512::KeyPair::try_from(PRIVATE_KEY).unwrap(); + let public_key = private_key.public().to_vec(); + + let signature = private_key + .sign(preimage.data.to_vec()) + .expect("Error signing data") + .to_vec(); + assert_eq!(signature.to_hex(), case.signature); + + // Step 4: Compile transaction info + let signatures = TWDataVectorHelper::create([signature]); + let public_keys = TWDataVectorHelper::create([public_key]); + + let input_data = TWDataHelper::create(serialize(&input).unwrap()); + let output_data = TWDataHelper::wrap(unsafe { + tw_transaction_compiler_compile( + CoinType::Pactus as u32, + input_data.ptr(), + signatures.ptr(), + public_keys.ptr(), + ) + }) + .to_vec() + .expect("!tw_transaction_compiler_compile returned nullptr"); + + let output: Proto::SigningOutput = + deserialize(&output_data).expect("Coin entry returned an invalid output"); + + assert_eq!(output.error, SigningErrorType::OK); + assert!(output.error_message.is_empty()); + assert_eq!(output.transaction_id.to_hex(), case.transaction_id); + assert_eq!(output.signature.to_hex(), case.signature); + assert_eq!(output.signed_transaction_data.to_hex(), case.signed_data); + } } diff --git a/rust/tw_tests/tests/chains/pactus/pactus_sign.rs b/rust/tw_tests/tests/chains/pactus/pactus_sign.rs index d7bb20f7836..f6547b1918d 100644 --- a/rust/tw_tests/tests/chains/pactus/pactus_sign.rs +++ b/rust/tw_tests/tests/chains/pactus/pactus_sign.rs @@ -3,11 +3,7 @@ // Copyright © 2017 Trust Wallet. use crate::chains::pactus::test_cases::PRIVATE_KEY; -use crate::chains::pactus::test_cases::{ - bond_test_case, - transfer_test_case, - bond_without_public_key_test_case, -}; +use crate::chains::pactus::test_cases::TEST_CASES; use tw_any_coin::ffi::tw_any_signer::tw_any_signer_sign; use tw_coin_entry::error::prelude::*; use tw_coin_registry::coin_type::CoinType; @@ -17,82 +13,27 @@ use tw_proto::Pactus::Proto; use tw_proto::{deserialize, serialize}; #[test] -fn test_pactus_sign_transfer() { - let input = Proto::SigningInput { - private_key: PRIVATE_KEY.decode_hex().unwrap().into(), - ..transfer_test_case::sign_input() - }; - - let input_data = TWDataHelper::create(serialize(&input).unwrap()); - - let output = TWDataHelper::wrap(unsafe { - tw_any_signer_sign(input_data.ptr(), CoinType::Pactus as u32) - }) - .to_vec() - .expect("!tw_any_signer_sign returned nullptr"); - - let output: Proto::SigningOutput = deserialize(&output).unwrap(); - - assert_eq!(output.error, SigningErrorType::OK); - assert!(output.error_message.is_empty()); - assert_eq!(output.transaction_id.to_hex(), transfer_test_case::TX_ID); - assert_eq!(output.signature.to_hex(), transfer_test_case::SIGNATURE); - assert_eq!( - output.signed_transaction_data.to_hex(), - transfer_test_case::SIGNED_DATA - ); -} - -#[test] -fn test_pactus_sign_bond() { - let input = Proto::SigningInput { - private_key: PRIVATE_KEY.decode_hex().unwrap().into(), - ..bond_test_case::sign_input() - }; - - let input_data = TWDataHelper::create(serialize(&input).unwrap()); - - let output = TWDataHelper::wrap(unsafe { - tw_any_signer_sign(input_data.ptr(), CoinType::Pactus as u32) - }) - .to_vec() - .expect("!tw_any_signer_sign returned nullptr"); - - let output: Proto::SigningOutput = deserialize(&output).unwrap(); - - assert_eq!(output.error, SigningErrorType::OK); - assert!(output.error_message.is_empty()); - assert_eq!(output.transaction_id.to_hex(), bond_test_case::TX_ID); - assert_eq!(output.signature.to_hex(), bond_test_case::SIGNATURE); - assert_eq!( - output.signed_transaction_data.to_hex(), - bond_test_case::SIGNED_DATA - ); -} - -#[test] -fn test_pactus_sign_bond_without_public_key() { - let input = Proto::SigningInput { - private_key: PRIVATE_KEY.decode_hex().unwrap().into(), - ..bond_without_public_key_test_case::sign_input() - }; - - let input_data = TWDataHelper::create(serialize(&input).unwrap()); - - let output = TWDataHelper::wrap(unsafe { - tw_any_signer_sign(input_data.ptr(), CoinType::Pactus as u32) - }) +fn test_pactus_sign_transactions() { + for case in TEST_CASES.iter() { + let input = Proto::SigningInput { + private_key: PRIVATE_KEY.decode_hex().unwrap().into(), + ..(case.sign_input_fn)() + }; + + let input_data = TWDataHelper::create(serialize(&input).unwrap()); + + let output = TWDataHelper::wrap(unsafe { + tw_any_signer_sign(input_data.ptr(), CoinType::Pactus as u32) + }) .to_vec() .expect("!tw_any_signer_sign returned nullptr"); - let output: Proto::SigningOutput = deserialize(&output).unwrap(); + let output: Proto::SigningOutput = deserialize(&output).unwrap(); - assert_eq!(output.error, SigningErrorType::OK); - assert!(output.error_message.is_empty()); - assert_eq!(output.transaction_id.to_hex(), bond_without_public_key_test_case::TX_ID); - assert_eq!(output.signature.to_hex(), bond_without_public_key_test_case::SIGNATURE); - assert_eq!( - output.signed_transaction_data.to_hex(), - bond_without_public_key_test_case::SIGNED_DATA - ); -} \ No newline at end of file + assert_eq!(output.error, SigningErrorType::OK); + assert!(output.error_message.is_empty()); + assert_eq!(output.transaction_id.to_hex(), case.transaction_id); + assert_eq!(output.signature.to_hex(), case.signature); + assert_eq!(output.signed_transaction_data.to_hex(), case.signed_data); + } +} diff --git a/rust/tw_tests/tests/chains/pactus/pactus_transaction_util.rs b/rust/tw_tests/tests/chains/pactus/pactus_transaction_util.rs index 43cd8c676f0..989448e3210 100644 --- a/rust/tw_tests/tests/chains/pactus/pactus_transaction_util.rs +++ b/rust/tw_tests/tests/chains/pactus/pactus_transaction_util.rs @@ -1,36 +1,14 @@ +use super::test_cases::TEST_CASES; use tw_any_coin::test_utils::transaction_calc_tx_hash_utils::TransactionUtilHelper; use tw_coin_registry::coin_type::CoinType; -use crate::chains::pactus::test_cases::{bond_test_case, transfer_test_case}; - #[test] fn test_pactus_transaction_util_calc_tx_hash() { - struct TestCase<'a> { - tx_hex: &'a str, - tx_id: &'a str, - } - - let test_cases = vec![ - TestCase { - tx_hex: transfer_test_case::NOT_SIGNED_DATA, - tx_id: transfer_test_case::TX_ID, - }, - TestCase { - tx_hex: transfer_test_case::SIGNED_DATA, - tx_id: transfer_test_case::TX_ID, - }, - TestCase { - tx_hex: bond_test_case::NOT_SIGNED_DATA, - tx_id: bond_test_case::TX_ID, - }, - TestCase { - tx_hex: bond_test_case::NOT_SIGNED_DATA, - tx_id: bond_test_case::TX_ID, - }, - ]; + for case in TEST_CASES { + let tx_hash = TransactionUtilHelper::calc_tx_hash(CoinType::Pactus, case.signed_data); + assert_eq!(tx_hash, case.transaction_id); - for case in test_cases { - let tx_hash = TransactionUtilHelper::calc_tx_hash(CoinType::Pactus, case.tx_hex); - assert_eq!(tx_hash, case.tx_id); + let tx_hash = TransactionUtilHelper::calc_tx_hash(CoinType::Pactus, case.signed_data); + assert_eq!(tx_hash, case.transaction_id); } } diff --git a/rust/tw_tests/tests/chains/pactus/test_cases.rs b/rust/tw_tests/tests/chains/pactus/test_cases.rs index 4a934c41236..0a79e33bb2f 100644 --- a/rust/tw_tests/tests/chains/pactus/test_cases.rs +++ b/rust/tw_tests/tests/chains/pactus/test_cases.rs @@ -4,23 +4,18 @@ use tw_proto::Pactus::Proto; -/// A macro to define three constants: `SIGN_BYTES`, `NOT_SIGNED_DATA`, and `SIGNED_DATA`. +/// A macro to define test data. /// Transaction format explained here: https://docs.pactus.org/protocol/transaction/format/ -macro_rules! define_expected_data { +macro_rules! define_test_data { ( $tx_id:expr, $signature:expr, $public_key:expr $(, $param:expr)*, ) => { - pub const SIGN_BYTES: &str = concat!( + pub const DATA_TO_SIGN: &str = concat!( $( $param, )* ); - pub const NOT_SIGNED_DATA: &str = concat!( - "02", // Not Sign Flag - $($param, )* - ); - pub const SIGNED_DATA: &str = concat!( "00", // Signed Flag $($param, )* @@ -36,13 +31,13 @@ macro_rules! define_expected_data { // Private key for all the test cases pub const PRIVATE_KEY: &str = "4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6"; -// Successfully broadcasted transfer transaction: +// Successfully broadcasted transaction: // https://pacviewer.com/transaction/1b6b7226f7935a15f05371d1a1fefead585a89704ce464b7cc1d453d299d235f pub mod transfer_test_case { use super::*; use tw_encoding::hex::DecodeHex; - define_expected_data!( + define_test_data!( "1b6b7226f7935a15f05371d1a1fefead585a89704ce464b7cc1d453d299d235f", // transaction ID "4ed8fee3d8992e82660dd05bbe8608fc56ceabffdeeee61e3213b9b49d33a0fc\ 8dea6d79ee7ec60f66433f189ed9b3c50b2ad6fa004e26790ee736693eda8506", // Signature @@ -80,13 +75,13 @@ pub mod transfer_test_case { } } -// Successfully broadcasted bond transaction: +// Successfully broadcasted transaction: // https://pacviewer.com/transaction/d194b445642a04ec78ced4448696e50b733f2f0b517a23871882c0eefaf1c28f -pub mod bond_test_case { +pub mod bond_with_public_key_test_case { use super::*; use tw_encoding::hex::DecodeHex; - define_expected_data!( + define_test_data!( "d194b445642a04ec78ced4448696e50b733f2f0b517a23871882c0eefaf1c28f", // transaction ID "0d7bc6d94927534b89e2f53bcfc9fc849e0e2982438955eda55b4338328adac7\ 9d4ee3216d143f0e1629764ab650734f8ba188e716d71f9eff65e39ce7006300", // Signature @@ -129,7 +124,7 @@ pub mod bond_test_case { } } -// Successfully broadcasted bond without public key transaction: +// Successfully broadcasted transaction: // https://pacviewer.com/transaction/f83f583a5c40adf93a90ea536a7e4b467d30ca4f308d5da52624d80c42adec80 // // If the validator exists and has already been staked, there’s no need to send the public key. @@ -138,7 +133,7 @@ pub mod bond_without_public_key_test_case { use super::*; use tw_encoding::hex::DecodeHex; - define_expected_data!( + define_test_data!( "f83f583a5c40adf93a90ea536a7e4b467d30ca4f308d5da52624d80c42adec80", // transaction ID "9e6279fb64067c7d7316ac74630bbb8589df268aa4548f1c7d85c087a8748ff0\ 715b9149afbd94c5d8ee6b37c787ec63e963cbb38be513ebc436aa58f9a8f00d", // Signature @@ -176,4 +171,36 @@ pub mod bond_without_public_key_test_case { private_key: private_key_bytes.into(), } } -} \ No newline at end of file +} + +pub(crate) struct TestCase { + pub sign_input_fn: fn() -> Proto::SigningInput<'static>, + pub transaction_id: &'static str, + pub signature: &'static str, + pub data_to_sign: &'static str, + pub signed_data: &'static str, +} + +pub(crate) const TEST_CASES: &[TestCase; 3] = &[ + TestCase { + sign_input_fn: transfer_test_case::sign_input, + transaction_id: transfer_test_case::TX_ID, + signature: transfer_test_case::SIGNATURE, + data_to_sign: transfer_test_case::DATA_TO_SIGN, + signed_data: transfer_test_case::SIGNED_DATA, + }, + TestCase { + sign_input_fn: bond_with_public_key_test_case::sign_input, + transaction_id: bond_with_public_key_test_case::TX_ID, + signature: bond_with_public_key_test_case::SIGNATURE, + data_to_sign: bond_with_public_key_test_case::DATA_TO_SIGN, + signed_data: bond_with_public_key_test_case::SIGNED_DATA, + }, + TestCase { + sign_input_fn: bond_without_public_key_test_case::sign_input, + transaction_id: bond_without_public_key_test_case::TX_ID, + signature: bond_without_public_key_test_case::SIGNATURE, + data_to_sign: bond_without_public_key_test_case::DATA_TO_SIGN, + signed_data: bond_without_public_key_test_case::SIGNED_DATA, + }, +]; diff --git a/swift/Tests/Blockchains/PactusTests.swift b/swift/Tests/Blockchains/PactusTests.swift index 41fbb3d13e6..933bdeaebea 100644 --- a/swift/Tests/Blockchains/PactusTests.swift +++ b/swift/Tests/Blockchains/PactusTests.swift @@ -23,10 +23,12 @@ class PactusTests: XCTestCase { } func testTransferSign() { + // Successfully broadcasted transaction: + // https://pacviewer.com/transaction/1b6b7226f7935a15f05371d1a1fefead585a89704ce464b7cc1d453d299d235f let input = PactusSigningInput.with { $0.privateKey = privateKey.data $0.transaction = PactusTransactionMessage.with { - $0.lockTime = 0x24a32300 + $0.lockTime = 2335524 $0.fee = 10000000 $0.memo = "wallet-core" $0.transfer = PactusTransferPayload.with { @@ -40,25 +42,33 @@ class PactusTests: XCTestCase { let output: PactusSigningOutput = AnySigner.sign(input: input, coin: .pactus) let expectedTransactionID = "1b6b7226f7935a15f05371d1a1fefead585a89704ce464b7cc1d453d299d235f" - let expectedSignature = "4ed8fee3d8992e82660dd05bbe8608fc56ceabffdeeee61e3213b9b49d33a0fc8dea6d79ee7ec60f66433f189ed9b3c50b2ad6fa004e26790ee736693eda8506" - let expectedSignedData = "000124a3230080ade2040b77616c6c65742d636f726501037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df218084af5f4ed8fee3d8992e82660dd05bbe8608fc56ceabffdeeee61e3213b9b49d33a0fc8dea6d79ee7ec60f66433f189ed9b3c50b2ad6fa004e26790ee736693eda850695794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa" + let expectedSignature = "4ed8fee3d8992e82660dd05bbe8608fc56ceabffdeeee61e3213b9b49d33a0fc" + + "8dea6d79ee7ec60f66433f189ed9b3c50b2ad6fa004e26790ee736693eda8506" + let expectedSignedData = "000124a3230080ade2040b77616c6c65742d636f726501037098338e0b680811" + + "9dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df" + + "218084af5f4ed8fee3d8992e82660dd05bbe8608fc56ceabffdeeee61e3213b9" + + "b49d33a0fc8dea6d79ee7ec60f66433f189ed9b3c50b2ad6fa004e26790ee736" + + "693eda850695794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560b" + + "b72145f4fa"; XCTAssertEqual(output.transactionID.hexString, expectedTransactionID) XCTAssertEqual(output.signature.hexString, expectedSignature) XCTAssertEqual(output.signedTransactionData.hexString, expectedSignedData) } - func testBondSign() { + func testBondWithPublicKeySign() { + // Successfully broadcasted transaction: + // https://pacviewer.com/transaction/d194b445642a04ec78ced4448696e50b733f2f0b517a23871882c0eefaf1c28f let input = PactusSigningInput.with { $0.privateKey = privateKey.data $0.transaction = PactusTransactionMessage.with { - $0.lockTime = 0xc1b02300 + $0.lockTime = 2339009 $0.fee = 10000000 $0.memo = "wallet-core" $0.bond = PactusBondPayload.with { $0.sender = "pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr" $0.receiver = "pc1p9y5gmu9l002tt60wak9extgvwm69rq3a9ackrl" $0.stake = 1000000000 - $0.public_key = "public1pnz75msstqdrq5eguvcwanug0zauhqjw2cc4flmez3qethnp68y64ehc4k69amapj7x4na2uda0snqz4yxujgx3jsse4f64fgy7jkh0xauvhrc5ts09vfk48g85t0js66hvajm6xruemsvlxqv3xvkyur8v9v0mtn" + $0.publicKey = "public1pnz75msstqdrq5eguvcwanug0zauhqjw2cc4flmez3qethnp68y64ehc4k69amapj7x4na2uda0snqz4yxujgx3jsse4f64fgy7jkh0xauvhrc5ts09vfk48g85t0js66hvajm6xruemsvlxqv3xvkyur8v9v0mtn" } } } @@ -66,8 +76,52 @@ class PactusTests: XCTestCase { let output: PactusSigningOutput = AnySigner.sign(input: input, coin: .pactus) let expectedTransactionID = "d194b445642a04ec78ced4448696e50b733f2f0b517a23871882c0eefaf1c28f" - let expectedSignature = "0d7bc6d94927534b89e2f53bcfc9fc849e0e2982438955eda55b4338328adac79d4ee3216d143f0e1629764ab650734f8ba188e716d71f9eff65e39ce7006300" - let expectedSignedData = "0001c1b0230080ade2040b77616c6c65742d636f726502037098338e0b6808119dfd4457ab806b9c2059b89b0129288df0bf7bd4b5e9eeed8b932d0c76f451823d6098bd4dc20b03460a651c661dd9f10f17797049cac62a9fef228832bbcc3a39355cdf15b68bddf432f1ab3eab8debe1300aa43724834650866a9d552827a56bbcdde32e3c517079589b54e83d16f9435abb3b2de8c3e677067cc0644ccb13833b8094ebdc030d7bc6d94927534b89e2f53bcfc9fc849e0e2982438955eda55b4338328adac79d4ee3216d143f0e1629764ab650734f8ba188e716d71f9eff65e39ce700630095794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa" + let expectedSignature = "0d7bc6d94927534b89e2f53bcfc9fc849e0e2982438955eda55b4338328adac7" + + "9d4ee3216d143f0e1629764ab650734f8ba188e716d71f9eff65e39ce7006300" + let expectedSignedData = "0001c1b0230080ade2040b77616c6c65742d636f726502037098338e0b680811" + + "9dfd4457ab806b9c2059b89b0129288df0bf7bd4b5e9eeed8b932d0c76f45182" + + "3d6098bd4dc20b03460a651c661dd9f10f17797049cac62a9fef228832bbcc3a" + + "39355cdf15b68bddf432f1ab3eab8debe1300aa43724834650866a9d552827a5" + + "6bbcdde32e3c517079589b54e83d16f9435abb3b2de8c3e677067cc0644ccb13" + + "833b8094ebdc030d7bc6d94927534b89e2f53bcfc9fc849e0e2982438955eda5" + + "5b4338328adac79d4ee3216d143f0e1629764ab650734f8ba188e716d71f9eff" + + "65e39ce700630095794161374b22c696dabb98e93f6ca9300b22f3b904921fbf" + + "560bb72145f4fa" + + XCTAssertEqual(output.transactionID.hexString, expectedTransactionID) + XCTAssertEqual(output.signature.hexString, expectedSignature) + XCTAssertEqual(output.signedTransactionData.hexString, expectedSignedData) + } + + func testBondWithoutPublicKeySign() { + // Successfully broadcasted transaction: + // https://pacviewer.com/transaction/f83f583a5c40adf93a90ea536a7e4b467d30ca4f308d5da52624d80c42adec80 + let input = PactusSigningInput.with { + $0.privateKey = privateKey.data + $0.transaction = PactusTransactionMessage.with { + $0.lockTime = 2335580 + $0.fee = 10000000 + $0.memo = "wallet-core" + $0.bond = PactusBondPayload.with { + $0.sender = "pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr" + $0.receiver = "pc1p6taz5l2kq5ppnxv4agnqj48svnvsy797xpe6wd" + $0.stake = 1000000000 + } + } + } + + let output: PactusSigningOutput = AnySigner.sign(input: input, coin: .pactus) + + let expectedTransactionID = "f83f583a5c40adf93a90ea536a7e4b467d30ca4f308d5da52624d80c42adec80" + let expectedSignature = "9e6279fb64067c7d7316ac74630bbb8589df268aa4548f1c7d85c087a8748ff0" + + "715b9149afbd94c5d8ee6b37c787ec63e963cbb38be513ebc436aa58f9a8f00d" + let expectedSignedData = "00015ca3230080ade2040b77616c6c65742d636f726502037098338e0b680811" + + "9dfd4457ab806b9c2059b89b01d2fa2a7d560502199995ea260954f064d90278" + + "be008094ebdc039e6279fb64067c7d7316ac74630bbb8589df268aa4548f1c7d" + + "85c087a8748ff0715b9149afbd94c5d8ee6b37c787ec63e963cbb38be513ebc4" + + "36aa58f9a8f00d95794161374b22c696dabb98e93f6ca9300b22f3b904921fbf" + + "560bb72145f4fa"; + XCTAssertEqual(output.transactionID.hexString, expectedTransactionID) XCTAssertEqual(output.signature.hexString, expectedSignature) XCTAssertEqual(output.signedTransactionData.hexString, expectedSignedData) diff --git a/tests/chains/Pactus/CompilerTests.cpp b/tests/chains/Pactus/CompilerTests.cpp index 160bcf54acc..0d4a902e2d9 100644 --- a/tests/chains/Pactus/CompilerTests.cpp +++ b/tests/chains/Pactus/CompilerTests.cpp @@ -5,48 +5,45 @@ #include "HexCoding.h" #include "PrivateKey.h" #include "PublicKey.h" +#include "TestCases.h" #include "TestUtilities.h" #include "TransactionCompiler.h" #include "proto/Pactus.pb.h" #include "proto/TransactionCompiler.pb.h" -#include "TestCases.h" #include using namespace TW; TEST(PactusCompiler, CompileAndSign) { - // Set up a signing input. - - auto input = TransferTransaction1::createSigningInput(); - - auto inputString = input.SerializeAsString(); - auto inputStrData = TW::Data(inputString.begin(), inputString.end()); - - // Pre-hash the transaction. - auto preImageHashesData = TransactionCompiler::preImageHashes(TWCoinTypePactus, inputStrData); - TxCompiler::Proto::PreSigningOutput preSigningOutput; - preSigningOutput.ParseFromArray(preImageHashesData.data(), static_cast(preImageHashesData.size())); - auto actualDataToSign = data(preSigningOutput.data()); - - EXPECT_EQ(preSigningOutput.error(), Common::Proto::OK); - EXPECT_EQ(hex(actualDataToSign), TransferTransaction1::DATA_TO_SIGN); - - // // Sign the pre-hash data. - - auto privateKey = PrivateKey(parse_hex(TransferTransaction1::PRIVATE_KEY_HEX)); - auto publicKey = privateKey.getPublicKey(TWPublicKeyTypeED25519).bytes; - auto signature = privateKey.sign(actualDataToSign, TWCurveED25519); - EXPECT_EQ(hex(signature), "50ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd09"); - - // Compile the transaction. - - auto outputData = TransactionCompiler::compileWithSignatures(TWCoinTypePactus, inputStrData, {signature}, {publicKey}); - TW::Pactus::Proto::SigningOutput output; - output.ParseFromArray(outputData.data(), static_cast(outputData.size())); - - EXPECT_EQ(output.error(), Common::Proto::OK); - ASSERT_EQ(hex(output.signed_transaction_data()), "000101020300e807047465737401037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21a09c0150ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd0995794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa"); - ASSERT_EQ(hex(output.signature()), "50ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd09"); - ASSERT_EQ(hex(output.transaction_id()), "34cd4656a98f7eb996e83efdc384cefbe3a9c52dca79a99245b4eacc0b0b4311"); + for (const auto& testCase : TEST_CASES) { + auto input = testCase.createSigningInput(); + auto inputString = input.SerializeAsString(); + auto inputStrData = TW::Data(inputString.begin(), inputString.end()); + + // Pre-hash the transaction. + auto preImageHashesData = TransactionCompiler::preImageHashes(TWCoinTypePactus, inputStrData); + TxCompiler::Proto::PreSigningOutput preSigningOutput; + preSigningOutput.ParseFromArray(preImageHashesData.data(), static_cast(preImageHashesData.size())); + auto actualDataToSign = data(preSigningOutput.data()); + + EXPECT_EQ(preSigningOutput.error(), Common::Proto::OK); + EXPECT_EQ(hex(actualDataToSign), testCase.dataToSign); + + // Sign the pre-hash data. + auto privateKey = PrivateKey(parse_hex(PRIVATE_KEY_HEX)); + auto publicKey = privateKey.getPublicKey(TWPublicKeyTypeED25519).bytes; + auto signature = privateKey.sign(actualDataToSign, TWCurveED25519); + EXPECT_EQ(hex(signature), testCase.signature); + + // Compile the transaction. + auto outputData = TransactionCompiler::compileWithSignatures(TWCoinTypePactus, inputStrData, {signature}, {publicKey}); + TW::Pactus::Proto::SigningOutput output; + output.ParseFromArray(outputData.data(), static_cast(outputData.size())); + + EXPECT_EQ(output.error(), Common::Proto::OK); + ASSERT_EQ(hex(output.signed_transaction_data()), testCase.signedData); + ASSERT_EQ(hex(output.signature()), testCase.signature); + ASSERT_EQ(hex(output.transaction_id()), testCase.transactionID); + } } diff --git a/tests/chains/Pactus/SignerTests.cpp b/tests/chains/Pactus/SignerTests.cpp index 17b46fbce0c..cbb469310c0 100644 --- a/tests/chains/Pactus/SignerTests.cpp +++ b/tests/chains/Pactus/SignerTests.cpp @@ -5,28 +5,29 @@ #include "HexCoding.h" #include "PrivateKey.h" #include "PublicKey.h" +#include "TestCases.h" #include "TestUtilities.h" #include "TransactionCompiler.h" #include "proto/Pactus.pb.h" #include "proto/TransactionCompiler.pb.h" -#include "TestCases.h" #include using namespace TW; TEST(PactusSigner, Sign) { - // Set up a signing input. - auto input = TransferTransaction1::createSigningInput(); + for (const auto& testCase : TEST_CASES) { + auto input = testCase.createSigningInput(); - auto privateKey = PrivateKey(parse_hex(TransferTransaction1::PRIVATE_KEY_HEX)); - input.set_private_key(privateKey.bytes.data(), privateKey.bytes.size()); + auto privateKey = PrivateKey(parse_hex(PRIVATE_KEY_HEX)); + input.set_private_key(privateKey.bytes.data(), privateKey.bytes.size()); - TW::Pactus::Proto::SigningOutput output; - ANY_SIGN(input, TWCoinTypePactus); + TW::Pactus::Proto::SigningOutput output; + ANY_SIGN(input, TWCoinTypePactus); - EXPECT_EQ(output.error(), Common::Proto::OK); - ASSERT_EQ(hex(output.signed_transaction_data()), TransferTransaction1::SIGNED_TRANSACTION_DATA); - ASSERT_EQ(hex(output.signature()), TransferTransaction1::SIGNATURE); - ASSERT_EQ(hex(output.transaction_id()), TransferTransaction1::TRANSACTION_ID); + EXPECT_EQ(output.error(), Common::Proto::OK); + ASSERT_EQ(hex(output.signed_transaction_data()), testCase.signedData); + ASSERT_EQ(hex(output.signature()), testCase.signature); + ASSERT_EQ(hex(output.transaction_id()), testCase.transactionID); + } } diff --git a/tests/chains/Pactus/TestCases.h b/tests/chains/Pactus/TestCases.h index 4418eb3d588..1fc953b54e4 100644 --- a/tests/chains/Pactus/TestCases.h +++ b/tests/chains/Pactus/TestCases.h @@ -9,32 +9,142 @@ #include -namespace TransferTransaction1 { +const std::string PRIVATE_KEY_HEX = "4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6"; +namespace TransferTransaction { +// Successfully broadcasted transaction: +// https://pacviewer.com/transaction/1b6b7226f7935a15f05371d1a1fefead585a89704ce464b7cc1d453d299d235f static TW::Pactus::Proto::SigningInput createSigningInput() { TW::Pactus::Proto::SigningInput input; - - // Set up the transaction message TW::Pactus::Proto::TransactionMessage* trx = input.mutable_transaction(); - trx->set_lock_time(0x00030201); - trx->set_fee(1000); - trx->set_memo("test"); + trx->set_lock_time(2335524); + trx->set_fee(10000000); + trx->set_memo("wallet-core"); - // Set up the transfer payload TW::Pactus::Proto::TransferPayload* pld = trx->mutable_transfer(); pld->set_sender("pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr"); pld->set_receiver("pc1r0g22ufzn8qtw0742dmfglnw73e260hep0k3yra"); - pld->set_amount(20000); + pld->set_amount(200000000); return input; } -const std::string PRIVATE_KEY_HEX = "4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6"; -const std::string SIGNATURE = - "50ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd09"; -const std::string DATA_TO_SIGN = - "0101020300e807047465737401037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21a09c01"; -const std::string SIGNED_TRANSACTION_DATA = - "000101020300e807047465737401037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21a09c0150ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd0995794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa"; -const std::string TRANSACTION_ID = "34cd4656a98f7eb996e83efdc384cefbe3a9c52dca79a99245b4eacc0b0b4311"; -} // namespace TransferTransaction1 +const std::string transactionID = "1b6b7226f7935a15f05371d1a1fefead585a89704ce464b7cc1d453d299d235f"; +const std::string signature = "4ed8fee3d8992e82660dd05bbe8608fc56ceabffdeeee61e3213b9b49d33a0fc" + "8dea6d79ee7ec60f66433f189ed9b3c50b2ad6fa004e26790ee736693eda8506"; +const std::string dataToSign = "0124a3230080ade2040b77616c6c65742d636f726501037098338e0b6808119d" + "fd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21" + "8084af5f"; +const std::string signedData = "000124a3230080ade2040b77616c6c65742d636f726501037098338e0b680811" + "9dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df" + "218084af5f4ed8fee3d8992e82660dd05bbe8608fc56ceabffdeeee61e3213b9" + "b49d33a0fc8dea6d79ee7ec60f66433f189ed9b3c50b2ad6fa004e26790ee736" + "693eda850695794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560b" + "b72145f4fa"; +} // namespace TransferTransaction + +namespace BondWithPublicKeyTransaction { +// Successfully broadcasted transaction: +// https://pacviewer.com/transaction/d194b445642a04ec78ced4448696e50b733f2f0b517a23871882c0eefaf1c28f + +static TW::Pactus::Proto::SigningInput createSigningInput() { + TW::Pactus::Proto::SigningInput input; + TW::Pactus::Proto::TransactionMessage* trx = input.mutable_transaction(); + trx->set_lock_time(2339009); + trx->set_fee(10000000); + trx->set_memo("wallet-core"); + + TW::Pactus::Proto::BondPayload* pld = trx->mutable_bond(); + pld->set_sender("pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr"); + pld->set_receiver("pc1p9y5gmu9l002tt60wak9extgvwm69rq3a9ackrl"); + pld->set_stake(1000000000); + pld->set_public_key("public1pnz75msstqdrq5eguvcwanug0zauhqjw2cc4flmez3qethnp68y64ehc4k69amapj7x4na2uda0snqz4yxujgx3jsse4f64fgy7jkh0xauvhrc5ts09vfk48g85t0js66hvajm6xruemsvlxqv3xvkyur8v9v0mtn"); + + return input; +} + +const std::string transactionID = "d194b445642a04ec78ced4448696e50b733f2f0b517a23871882c0eefaf1c28f"; +const std::string signature = "0d7bc6d94927534b89e2f53bcfc9fc849e0e2982438955eda55b4338328adac7" + "9d4ee3216d143f0e1629764ab650734f8ba188e716d71f9eff65e39ce7006300"; +const std::string dataToSign = "01c1b0230080ade2040b77616c6c65742d636f726502037098338e0b6808119d" + "fd4457ab806b9c2059b89b0129288df0bf7bd4b5e9eeed8b932d0c76f451823d" + "6098bd4dc20b03460a651c661dd9f10f17797049cac62a9fef228832bbcc3a39" + "355cdf15b68bddf432f1ab3eab8debe1300aa43724834650866a9d552827a56b" + "bcdde32e3c517079589b54e83d16f9435abb3b2de8c3e677067cc0644ccb1383" + "3b8094ebdc03"; +const std::string signedData = "0001c1b0230080ade2040b77616c6c65742d636f726502037098338e0b680811" + "9dfd4457ab806b9c2059b89b0129288df0bf7bd4b5e9eeed8b932d0c76f45182" + "3d6098bd4dc20b03460a651c661dd9f10f17797049cac62a9fef228832bbcc3a" + "39355cdf15b68bddf432f1ab3eab8debe1300aa43724834650866a9d552827a5" + "6bbcdde32e3c517079589b54e83d16f9435abb3b2de8c3e677067cc0644ccb13" + "833b8094ebdc030d7bc6d94927534b89e2f53bcfc9fc849e0e2982438955eda5" + "5b4338328adac79d4ee3216d143f0e1629764ab650734f8ba188e716d71f9eff" + "65e39ce700630095794161374b22c696dabb98e93f6ca9300b22f3b904921fbf" + "560bb72145f4fa"; +} // namespace BondWithPublicKeyTransaction + +namespace BondWithoutPublicKeyTransaction { +// Successfully broadcasted transaction: +// https://pacviewer.com/transaction/f83f583a5c40adf93a90ea536a7e4b467d30ca4f308d5da52624d80c42adec80 + +static TW::Pactus::Proto::SigningInput createSigningInput() { + TW::Pactus::Proto::SigningInput input; + TW::Pactus::Proto::TransactionMessage* trx = input.mutable_transaction(); + trx->set_lock_time(2335580); + trx->set_fee(10000000); + trx->set_memo("wallet-core"); + + TW::Pactus::Proto::BondPayload* pld = trx->mutable_bond(); + pld->set_sender("pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr"); + pld->set_receiver("pc1p6taz5l2kq5ppnxv4agnqj48svnvsy797xpe6wd"); + pld->set_stake(1000000000); + + return input; +} + +const std::string transactionID = "f83f583a5c40adf93a90ea536a7e4b467d30ca4f308d5da52624d80c42adec80"; +const std::string signature = "9e6279fb64067c7d7316ac74630bbb8589df268aa4548f1c7d85c087a8748ff0" + "715b9149afbd94c5d8ee6b37c787ec63e963cbb38be513ebc436aa58f9a8f00d"; +const std::string dataToSign = "015ca3230080ade2040b77616c6c65742d636f726502037098338e0b6808119d" + "fd4457ab806b9c2059b89b01d2fa2a7d560502199995ea260954f064d90278be" + "008094ebdc03"; +const std::string signedData = "00015ca3230080ade2040b77616c6c65742d636f726502037098338e0b680811" + "9dfd4457ab806b9c2059b89b01d2fa2a7d560502199995ea260954f064d90278" + "be008094ebdc039e6279fb64067c7d7316ac74630bbb8589df268aa4548f1c7d" + "85c087a8748ff0715b9149afbd94c5d8ee6b37c787ec63e963cbb38be513ebc4" + "36aa58f9a8f00d95794161374b22c696dabb98e93f6ca9300b22f3b904921fbf" + "560bb72145f4fa"; + +} // namespace BondWithoutPublicKeyTransaction + +struct TestCase { + std::function createSigningInput; + std::string transactionID; + std::string signature; + std::string dataToSign; + std::string signedData; +}; + +const TestCase TEST_CASES[] = { + { + TransferTransaction::createSigningInput, + TransferTransaction::transactionID, + TransferTransaction::signature, + TransferTransaction::dataToSign, + TransferTransaction::signedData, + }, + { + BondWithPublicKeyTransaction::createSigningInput, + BondWithPublicKeyTransaction::transactionID, + BondWithPublicKeyTransaction::signature, + BondWithPublicKeyTransaction::dataToSign, + BondWithPublicKeyTransaction::signedData, + }, + { + BondWithoutPublicKeyTransaction::createSigningInput, + BondWithoutPublicKeyTransaction::transactionID, + BondWithoutPublicKeyTransaction::signature, + BondWithoutPublicKeyTransaction::dataToSign, + BondWithoutPublicKeyTransaction::signedData, + }, +}; \ No newline at end of file