mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-23 12:09:37 +00:00
add test send to wallet-rpc with arb data (#246)
* add test send to wallet-rpc with arb data * convert literals to const
This commit is contained in:
parent
b0e0fc44cf
commit
9e01588b11
3 changed files with 48 additions and 10 deletions
|
@ -11,7 +11,7 @@ use curve25519_dalek::{
|
|||
|
||||
use crate::{hash, hash_to_scalar, serialize::write_varint, transaction::Input};
|
||||
|
||||
mod extra;
|
||||
pub mod extra;
|
||||
pub(crate) use extra::{PaymentId, ExtraField, Extra};
|
||||
|
||||
/// Address encoding and decoding functionality.
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
use monero_serai::{wallet::TransactionError, transaction::Transaction};
|
||||
use monero_serai::{
|
||||
wallet::{TransactionError, extra::MAX_TX_EXTRA_NONCE_SIZE},
|
||||
transaction::Transaction,
|
||||
};
|
||||
|
||||
mod runner;
|
||||
|
||||
test!(
|
||||
add_single_data_less_than_255,
|
||||
add_single_data_less_than_max,
|
||||
(
|
||||
|_, mut builder: Builder, addr| async move {
|
||||
let arbitrary_data = vec![b'\0', 254];
|
||||
let arbitrary_data = vec![b'\0', (MAX_TX_EXTRA_NONCE_SIZE as u8) - 1];
|
||||
|
||||
// make sure we can add to tx
|
||||
let result = builder.add_data(arbitrary_data.clone());
|
||||
|
@ -24,10 +27,10 @@ test!(
|
|||
);
|
||||
|
||||
test!(
|
||||
add_multiple_data_less_than_255,
|
||||
add_multiple_data_less_than_max,
|
||||
(
|
||||
|_, mut builder: Builder, addr| async move {
|
||||
let data = vec![b'\0', 254];
|
||||
let data = vec![b'\0', (MAX_TX_EXTRA_NONCE_SIZE as u8) - 1];
|
||||
|
||||
// Add tx multiple times
|
||||
for _ in 0 .. 5 {
|
||||
|
@ -47,11 +50,11 @@ test!(
|
|||
);
|
||||
|
||||
test!(
|
||||
add_single_data_more_than_255,
|
||||
add_single_data_more_than_max,
|
||||
(
|
||||
|_, mut builder: Builder, addr| async move {
|
||||
// Make a data that is bigger than 255 bytes
|
||||
let mut data = vec![b'a'; 256];
|
||||
let mut data = vec![b'a'; MAX_TX_EXTRA_NONCE_SIZE + 1];
|
||||
|
||||
// Make sure we get an error if we try to add it to the TX
|
||||
assert_eq!(builder.add_data(data.clone()), Err(TransactionError::TooMuchData));
|
||||
|
|
|
@ -18,8 +18,11 @@ use monero_rpc::{
|
|||
};
|
||||
|
||||
use monero_serai::{
|
||||
wallet::address::{Network, AddressSpec, SubaddressIndex},
|
||||
wallet::{Scanner, address::MoneroAddress},
|
||||
wallet::{
|
||||
address::{Network, AddressSpec, SubaddressIndex, MoneroAddress},
|
||||
extra::MAX_TX_EXTRA_NONCE_SIZE,
|
||||
Scanner,
|
||||
},
|
||||
rpc::Rpc,
|
||||
transaction::Transaction,
|
||||
};
|
||||
|
@ -200,3 +203,35 @@ test!(
|
|||
},
|
||||
),
|
||||
);
|
||||
|
||||
test!(
|
||||
test_send_to_wallet_rpc_with_arb_data,
|
||||
(
|
||||
|_, mut builder: Builder, _| async move {
|
||||
// initialize rpc
|
||||
let (wallet_rpc, _, wallet_rpc_addr) = initialize_rpcs().await;
|
||||
|
||||
// add destination
|
||||
builder.add_payment(
|
||||
MoneroAddress::from_str(Network::Mainnet, &wallet_rpc_addr.to_string()).unwrap(),
|
||||
1000000,
|
||||
);
|
||||
|
||||
// Make 2 data that is full 255 bytes
|
||||
for _ in 0 .. 2 {
|
||||
let data = vec![b'a'; MAX_TX_EXTRA_NONCE_SIZE];
|
||||
assert!(builder.add_data(data).is_ok());
|
||||
}
|
||||
|
||||
(builder.build().unwrap(), (wallet_rpc,))
|
||||
},
|
||||
|_, tx: Transaction, _, data: (WalletClient,)| async move {
|
||||
// confirm receipt
|
||||
data.0.refresh(None).await.unwrap();
|
||||
let transfer =
|
||||
data.0.get_transfer(Hash::from_slice(&tx.hash()), None).await.unwrap().unwrap();
|
||||
assert_eq!(transfer.amount.as_pico(), 1000000);
|
||||
assert_eq!(transfer.subaddr_index, Index { major: 0, minor: 0 });
|
||||
},
|
||||
),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue