mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Update processor tests to refund logic
This commit is contained in:
@@ -337,6 +337,8 @@ impl<D: Db, N: Network> MultisigManager<D, N> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn refund_plan(output: &N::Output, refund_to: N::Address) -> Plan<N> {
|
fn refund_plan(output: &N::Output, refund_to: N::Address) -> Plan<N> {
|
||||||
|
log::info!("creating refund plan for {}", hex::encode(output.id()));
|
||||||
|
assert_eq!(output.kind(), OutputType::External);
|
||||||
Plan {
|
Plan {
|
||||||
key: output.key(),
|
key: output.key(),
|
||||||
inputs: vec![output.clone()],
|
inputs: vec![output.clone()],
|
||||||
@@ -639,6 +641,10 @@ impl<D: Db, N: Network> MultisigManager<D, N> {
|
|||||||
if let Some(refund_to) = MultisigsDb::<N, D>::take_refund(txn, output.id().as_ref()) {
|
if let Some(refund_to) = MultisigsDb::<N, D>::take_refund(txn, output.id().as_ref()) {
|
||||||
// If this isn't a valid refund address, accumulate this output
|
// If this isn't a valid refund address, accumulate this output
|
||||||
let Ok(refund_to) = refund_to.consume().try_into() else {
|
let Ok(refund_to) = refund_to.consume().try_into() else {
|
||||||
|
log::info!(
|
||||||
|
"set refund for {} didn't have a valid address to refund to",
|
||||||
|
hex::encode(output.id())
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
plans.push(Self::refund_plan(output, refund_to));
|
plans.push(Self::refund_plan(output, refund_to));
|
||||||
@@ -830,6 +836,7 @@ impl<D: Db, N: Network> MultisigManager<D, N> {
|
|||||||
let (refund_to, instruction) = instruction_from_output::<N>(&output);
|
let (refund_to, instruction) = instruction_from_output::<N>(&output);
|
||||||
let refund = |txn| {
|
let refund = |txn| {
|
||||||
if let Some(refund_to) = refund_to {
|
if let Some(refund_to) = refund_to {
|
||||||
|
log::info!("setting refund for output {}", hex::encode(output.id()));
|
||||||
MultisigsDb::<N, D>::set_refund(txn, output.id().as_ref(), refund_to);
|
MultisigsDb::<N, D>::set_refund(txn, output.id().as_ref(), refund_to);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ fn batch_test() {
|
|||||||
let mut serai_address = [0; 32];
|
let mut serai_address = [0; 32];
|
||||||
OsRng.fill_bytes(&mut serai_address);
|
OsRng.fill_bytes(&mut serai_address);
|
||||||
let instruction =
|
let instruction =
|
||||||
if i == 1 { Some(InInstruction::Transfer(SeraiAddress(serai_address))) } else { None };
|
if i == 0 { Some(InInstruction::Transfer(SeraiAddress(serai_address))) } else { None };
|
||||||
|
|
||||||
// Send into the processor's wallet
|
// Send into the processor's wallet
|
||||||
let (tx, balance_sent) =
|
let (tx, balance_sent) =
|
||||||
@@ -258,9 +258,9 @@ fn batch_test() {
|
|||||||
network,
|
network,
|
||||||
id: i,
|
id: i,
|
||||||
block: BlockHash(block_with_tx.unwrap()),
|
block: BlockHash(block_with_tx.unwrap()),
|
||||||
instructions: if let Some(instruction) = instruction {
|
instructions: if let Some(instruction) = &instruction {
|
||||||
vec![InInstructionWithBalance {
|
vec![InInstructionWithBalance {
|
||||||
instruction,
|
instruction: instruction.clone(),
|
||||||
balance: Balance {
|
balance: Balance {
|
||||||
coin: balance_sent.coin,
|
coin: balance_sent.coin,
|
||||||
amount: Amount(
|
amount: Amount(
|
||||||
@@ -311,7 +311,7 @@ fn batch_test() {
|
|||||||
let serai_time =
|
let serai_time =
|
||||||
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
|
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
|
||||||
for coordinator in &mut coordinators {
|
for coordinator in &mut coordinators {
|
||||||
assert!(substrate_block(
|
let plans = substrate_block(
|
||||||
coordinator,
|
coordinator,
|
||||||
messages::substrate::CoordinatorMessage::SubstrateBlock {
|
messages::substrate::CoordinatorMessage::SubstrateBlock {
|
||||||
context: SubstrateContext {
|
context: SubstrateContext {
|
||||||
@@ -324,8 +324,35 @@ fn batch_test() {
|
|||||||
batches: vec![batch.batch.id],
|
batches: vec![batch.batch.id],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await;
|
||||||
.is_empty());
|
if instruction.is_some() || (instruction.is_none() && (network == NetworkId::Monero)) {
|
||||||
|
assert!(plans.is_empty());
|
||||||
|
} else {
|
||||||
|
// If no instruction was used, and the processor csn presume the origin, it'd have
|
||||||
|
// created a refund Plan
|
||||||
|
assert_eq!(plans.len(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// With the latter InInstruction not existing, we should've triggered a refund if the origin
|
||||||
|
// was detectable
|
||||||
|
// Check this is trying to sign a Plan
|
||||||
|
if network != NetworkId::Monero {
|
||||||
|
let mut refund_id = None;
|
||||||
|
for coordinator in &mut coordinators {
|
||||||
|
match coordinator.recv_message().await {
|
||||||
|
messages::ProcessorMessage::Sign(messages::sign::ProcessorMessage::Preprocess {
|
||||||
|
id,
|
||||||
|
..
|
||||||
|
}) => {
|
||||||
|
if refund_id.is_none() {
|
||||||
|
refund_id = Some(id.clone());
|
||||||
|
}
|
||||||
|
assert_eq!(refund_id.as_ref().unwrap(), &id);
|
||||||
|
}
|
||||||
|
_ => panic!("processor didn't send preprocess for expected refund transaction"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user