mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-12 05:59:23 +00:00
Update monero-wallet tests to compile
Some are _consistently_ failing due to the inputs we attempt to spend being too young. I'm unsure what's up with that. Most seem to pass _consistently_, implying it's not a random issue yet some configuration/env aspect.
This commit is contained in:
85
coins/monero/wallet/tests/runner/builder.rs
Normal file
85
coins/monero/wallet/tests/runner/builder.rs
Normal file
@@ -0,0 +1,85 @@
|
||||
use zeroize::{Zeroize, Zeroizing};
|
||||
|
||||
use curve25519_dalek::Scalar;
|
||||
|
||||
use monero_wallet::{
|
||||
primitives::Decoys,
|
||||
ringct::RctType,
|
||||
rpc::FeeRate,
|
||||
address::MoneroAddress,
|
||||
scan::SpendableOutput,
|
||||
send::{Change, SendError, SignableTransaction},
|
||||
extra::MAX_ARBITRARY_DATA_SIZE,
|
||||
};
|
||||
|
||||
/// A builder for Monero transactions.
|
||||
#[derive(Clone, PartialEq, Eq, Zeroize, Debug)]
|
||||
pub struct SignableTransactionBuilder {
|
||||
rct_type: RctType,
|
||||
sender_view_key: Zeroizing<Scalar>,
|
||||
inputs: Vec<(SpendableOutput, Decoys)>,
|
||||
payments: Vec<(MoneroAddress, u64)>,
|
||||
change: Change,
|
||||
data: Vec<Vec<u8>>,
|
||||
fee_rate: FeeRate,
|
||||
}
|
||||
|
||||
impl SignableTransactionBuilder {
|
||||
pub fn new(
|
||||
rct_type: RctType,
|
||||
sender_view_key: Zeroizing<Scalar>,
|
||||
change: Change,
|
||||
fee_rate: FeeRate,
|
||||
) -> Self {
|
||||
Self {
|
||||
rct_type,
|
||||
sender_view_key,
|
||||
inputs: vec![],
|
||||
payments: vec![],
|
||||
change,
|
||||
data: vec![],
|
||||
fee_rate,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_input(&mut self, input: (SpendableOutput, Decoys)) -> &mut Self {
|
||||
self.inputs.push(input);
|
||||
self
|
||||
}
|
||||
#[allow(unused)]
|
||||
pub fn add_inputs(&mut self, inputs: &[(SpendableOutput, Decoys)]) -> &mut Self {
|
||||
self.inputs.extend(inputs.iter().cloned());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_payment(&mut self, dest: MoneroAddress, amount: u64) -> &mut Self {
|
||||
self.payments.push((dest, amount));
|
||||
self
|
||||
}
|
||||
#[allow(unused)]
|
||||
pub fn add_payments(&mut self, payments: &[(MoneroAddress, u64)]) -> &mut Self {
|
||||
self.payments.extend(payments);
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn add_data(&mut self, data: Vec<u8>) -> Result<&mut Self, SendError> {
|
||||
if data.len() > MAX_ARBITRARY_DATA_SIZE {
|
||||
Err(SendError::TooMuchData)?;
|
||||
}
|
||||
self.data.push(data);
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn build(self) -> Result<SignableTransaction, SendError> {
|
||||
SignableTransaction::new(
|
||||
self.rct_type,
|
||||
self.sender_view_key,
|
||||
self.inputs,
|
||||
self.payments,
|
||||
self.change,
|
||||
self.data,
|
||||
self.fee_rate,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,25 @@ use tokio::sync::Mutex;
|
||||
|
||||
use monero_simple_request_rpc::SimpleRequestRpc;
|
||||
use monero_wallet::{
|
||||
ringct::RctType,
|
||||
transaction::Transaction,
|
||||
rpc::Rpc,
|
||||
ViewPair, Scanner,
|
||||
rpc::{Rpc, FeeRate},
|
||||
ViewPair,
|
||||
address::{Network, AddressType, AddressSpec, AddressMeta, MoneroAddress},
|
||||
SpendableOutput, FeeRate,
|
||||
scan::{SpendableOutput, Scanner},
|
||||
};
|
||||
|
||||
mod builder;
|
||||
pub use builder::SignableTransactionBuilder;
|
||||
|
||||
pub fn ring_len(rct_type: RctType) -> usize {
|
||||
match rct_type {
|
||||
RctType::ClsagBulletproof => 11,
|
||||
RctType::ClsagBulletproofPlus => 16,
|
||||
_ => panic!("ring size unknown for RctType"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn random_address() -> (Scalar, ViewPair, MoneroAddress) {
|
||||
let spend = Scalar::random(&mut OsRng);
|
||||
let spend_pub = &spend * ED25519_BASEPOINT_TABLE;
|
||||
@@ -56,7 +68,7 @@ pub async fn mine_until_unlocked(rpc: &SimpleRequestRpc, addr: &str, tx_hash: [u
|
||||
.await
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.all(|output| output.is_some())
|
||||
.any(|output| output.is_none())
|
||||
{
|
||||
height = rpc.generate_blocks(addr, 1).await.unwrap().1 + 1;
|
||||
}
|
||||
@@ -159,8 +171,6 @@ macro_rules! test {
|
||||
|
||||
use curve25519_dalek::{constants::ED25519_BASEPOINT_TABLE, scalar::Scalar};
|
||||
|
||||
#[cfg(feature = "multisig")]
|
||||
use transcript::{Transcript, RecommendedTranscript};
|
||||
#[cfg(feature = "multisig")]
|
||||
use frost::{
|
||||
curve::Ed25519,
|
||||
@@ -169,15 +179,19 @@ macro_rules! test {
|
||||
};
|
||||
|
||||
use monero_wallet::{
|
||||
Protocol,
|
||||
primitives::Decoys,
|
||||
ringct::RctType,
|
||||
rpc::FeePriority,
|
||||
address::{Network, AddressSpec},
|
||||
ViewPair, Scanner, Change, DecoySelection, Decoys, FeePriority,
|
||||
SignableTransaction, SignableTransactionBuilder,
|
||||
ViewPair,
|
||||
DecoySelection,
|
||||
scan::Scanner,
|
||||
send::{Change, SignableTransaction},
|
||||
};
|
||||
|
||||
use runner::{
|
||||
random_address, rpc, mine_until_unlocked, get_miner_tx_output,
|
||||
check_weight_and_fee,
|
||||
SignableTransactionBuilder, ring_len, random_address, rpc, mine_until_unlocked,
|
||||
get_miner_tx_output, check_weight_and_fee,
|
||||
};
|
||||
|
||||
type Builder = SignableTransactionBuilder;
|
||||
@@ -206,16 +220,21 @@ macro_rules! test {
|
||||
|
||||
let rpc = rpc().await;
|
||||
|
||||
let view = ViewPair::new(spend_pub, Zeroizing::new(Scalar::random(&mut OsRng)));
|
||||
let view_priv = Zeroizing::new(Scalar::random(&mut OsRng));
|
||||
let view = ViewPair::new(spend_pub, view_priv.clone());
|
||||
let addr = view.address(Network::Mainnet, AddressSpec::Standard);
|
||||
|
||||
let miner_tx = get_miner_tx_output(&rpc, &view).await;
|
||||
|
||||
let protocol = Protocol::try_from(rpc.get_protocol().await.unwrap()).unwrap();
|
||||
let rct_type = match rpc.get_hardfork_version().await.unwrap() {
|
||||
14 => RctType::ClsagBulletproof,
|
||||
15 | 16 => RctType::ClsagBulletproofPlus,
|
||||
_ => panic!("unrecognized hardfork version"),
|
||||
};
|
||||
|
||||
let builder = SignableTransactionBuilder::new(
|
||||
protocol,
|
||||
rpc.get_fee_rate(FeePriority::Unimportant).await.unwrap(),
|
||||
rct_type,
|
||||
view_priv,
|
||||
Change::new(
|
||||
&ViewPair::new(
|
||||
&Scalar::random(&mut OsRng) * ED25519_BASEPOINT_TABLE,
|
||||
@@ -223,6 +242,7 @@ macro_rules! test {
|
||||
),
|
||||
false
|
||||
),
|
||||
rpc.get_fee_rate(FeePriority::Unimportant).await.unwrap(),
|
||||
);
|
||||
|
||||
let sign = |tx: SignableTransaction| {
|
||||
@@ -239,16 +259,7 @@ macro_rules! test {
|
||||
{
|
||||
let mut machines = HashMap::new();
|
||||
for i in (1 ..= THRESHOLD).map(|i| Participant::new(i).unwrap()) {
|
||||
machines.insert(
|
||||
i,
|
||||
tx
|
||||
.clone()
|
||||
.multisig(
|
||||
&keys[&i],
|
||||
RecommendedTranscript::new(b"Monero Serai Test Transaction"),
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
machines.insert(i, tx.clone().multisig(&keys[&i]).unwrap());
|
||||
}
|
||||
|
||||
frost::tests::sign_without_caching(&mut OsRng, machines, &[])
|
||||
@@ -266,7 +277,7 @@ macro_rules! test {
|
||||
let decoys = Decoys::fingerprintable_canonical_select(
|
||||
&mut OsRng,
|
||||
&rpc,
|
||||
protocol.ring_len(),
|
||||
ring_len(rct_type),
|
||||
rpc.get_height().await.unwrap(),
|
||||
&[miner_tx.clone()],
|
||||
)
|
||||
@@ -290,7 +301,7 @@ macro_rules! test {
|
||||
|
||||
$(
|
||||
let (tx, state) = ($tx)(
|
||||
protocol,
|
||||
rct_type,
|
||||
rpc.clone(),
|
||||
builder.clone(),
|
||||
next_addr,
|
||||
|
||||
Reference in New Issue
Block a user