mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-27 22:19:39 +00:00
bdcc061bb4
Some checks failed
Coordinator Tests / build (push) Has been cancelled
Full Stack Tests / build (push) Has been cancelled
Lint / clippy (macos-13) (push) Has been cancelled
Lint / clippy (macos-14) (push) Has been cancelled
Processor Tests / build (push) Has been cancelled
Reproducible Runtime / build (push) Has been cancelled
Lint / clippy (ubuntu-latest) (push) Has been cancelled
Lint / clippy (windows-latest) (push) Has been cancelled
Lint / deny (push) Has been cancelled
Lint / fmt (push) Has been cancelled
Lint / machete (push) Has been cancelled
Monero Tests / unit-tests (push) Has been cancelled
Monero Tests / integration-tests (v0.17.3.2) (push) Has been cancelled
Monero Tests / integration-tests (v0.18.3.4) (push) Has been cancelled
networks/ Tests / test-networks (push) Has been cancelled
no-std build / build (push) Has been cancelled
Tests / test-infra (push) Has been cancelled
Tests / test-substrate (push) Has been cancelled
Tests / test-serai-client (push) Has been cancelled
Makes scanning synchronous and only error upon a malicious node/unplanned for hard fork.
160 lines
5.7 KiB
Rust
160 lines
5.7 KiB
Rust
use monero_simple_request_rpc::SimpleRequestRpc;
|
|
use monero_wallet::{
|
|
transaction::Transaction, rpc::Rpc, address::SubaddressIndex, extra::PaymentId, GuaranteedScanner,
|
|
};
|
|
|
|
mod runner;
|
|
|
|
#[allow(clippy::upper_case_acronyms)]
|
|
type SRR = SimpleRequestRpc;
|
|
type Tx = Transaction;
|
|
|
|
test!(
|
|
scan_standard_address,
|
|
(
|
|
|_, mut builder: Builder, _| async move {
|
|
let view = runner::random_address().1;
|
|
let scanner = Scanner::new(view.clone());
|
|
builder.add_payment(view.legacy_address(Network::Mainnet), 5);
|
|
(builder.build().unwrap(), scanner)
|
|
},
|
|
|_rpc: SRR, block, tx: Transaction, _, mut state: Scanner| async move {
|
|
let output = state.scan(block).unwrap().not_additionally_locked().swap_remove(0);
|
|
assert_eq!(output.transaction(), tx.hash());
|
|
assert_eq!(output.commitment().amount, 5);
|
|
let dummy_payment_id = PaymentId::Encrypted([0u8; 8]);
|
|
assert_eq!(output.payment_id(), Some(dummy_payment_id));
|
|
},
|
|
),
|
|
);
|
|
|
|
test!(
|
|
scan_subaddress,
|
|
(
|
|
|_, mut builder: Builder, _| async move {
|
|
let subaddress = SubaddressIndex::new(0, 1).unwrap();
|
|
|
|
let view = runner::random_address().1;
|
|
let mut scanner = Scanner::new(view.clone());
|
|
scanner.register_subaddress(subaddress);
|
|
|
|
builder.add_payment(view.subaddress(Network::Mainnet, subaddress), 5);
|
|
(builder.build().unwrap(), (scanner, subaddress))
|
|
},
|
|
|_rpc: SRR, block, tx: Transaction, _, mut state: (Scanner, SubaddressIndex)| async move {
|
|
let output = state.0.scan(block).unwrap().not_additionally_locked().swap_remove(0);
|
|
assert_eq!(output.transaction(), tx.hash());
|
|
assert_eq!(output.commitment().amount, 5);
|
|
assert_eq!(output.subaddress(), Some(state.1));
|
|
},
|
|
),
|
|
);
|
|
|
|
test!(
|
|
scan_integrated_address,
|
|
(
|
|
|_, mut builder: Builder, _| async move {
|
|
let view = runner::random_address().1;
|
|
let scanner = Scanner::new(view.clone());
|
|
|
|
let mut payment_id = [0u8; 8];
|
|
OsRng.fill_bytes(&mut payment_id);
|
|
|
|
builder.add_payment(view.legacy_integrated_address(Network::Mainnet, payment_id), 5);
|
|
(builder.build().unwrap(), (scanner, payment_id))
|
|
},
|
|
|_rpc: SRR, block, tx: Transaction, _, mut state: (Scanner, [u8; 8])| async move {
|
|
let output = state.0.scan(block).unwrap().not_additionally_locked().swap_remove(0);
|
|
assert_eq!(output.transaction(), tx.hash());
|
|
assert_eq!(output.commitment().amount, 5);
|
|
assert_eq!(output.payment_id(), Some(PaymentId::Encrypted(state.1)));
|
|
},
|
|
),
|
|
);
|
|
|
|
test!(
|
|
scan_guaranteed,
|
|
(
|
|
|_, mut builder: Builder, _| async move {
|
|
let view = runner::random_guaranteed_address().1;
|
|
let scanner = GuaranteedScanner::new(view.clone());
|
|
builder.add_payment(view.address(Network::Mainnet, None, None), 5);
|
|
(builder.build().unwrap(), scanner)
|
|
},
|
|
|_rpc: SRR, block, tx: Transaction, _, mut scanner: GuaranteedScanner| async move {
|
|
let output = scanner.scan(block).unwrap().not_additionally_locked().swap_remove(0);
|
|
assert_eq!(output.transaction(), tx.hash());
|
|
assert_eq!(output.commitment().amount, 5);
|
|
assert_eq!(output.subaddress(), None);
|
|
},
|
|
),
|
|
);
|
|
|
|
test!(
|
|
scan_guaranteed_subaddress,
|
|
(
|
|
|_, mut builder: Builder, _| async move {
|
|
let subaddress = SubaddressIndex::new(0, 2).unwrap();
|
|
|
|
let view = runner::random_guaranteed_address().1;
|
|
let mut scanner = GuaranteedScanner::new(view.clone());
|
|
scanner.register_subaddress(subaddress);
|
|
|
|
builder.add_payment(view.address(Network::Mainnet, Some(subaddress), None), 5);
|
|
(builder.build().unwrap(), (scanner, subaddress))
|
|
},
|
|
|_rpc: SRR, block, tx: Tx, _, mut state: (GuaranteedScanner, SubaddressIndex)| async move {
|
|
let output = state.0.scan(block).unwrap().not_additionally_locked().swap_remove(0);
|
|
assert_eq!(output.transaction(), tx.hash());
|
|
assert_eq!(output.commitment().amount, 5);
|
|
assert_eq!(output.subaddress(), Some(state.1));
|
|
},
|
|
),
|
|
);
|
|
|
|
test!(
|
|
scan_guaranteed_integrated,
|
|
(
|
|
|_, mut builder: Builder, _| async move {
|
|
let view = runner::random_guaranteed_address().1;
|
|
let scanner = GuaranteedScanner::new(view.clone());
|
|
let mut payment_id = [0u8; 8];
|
|
OsRng.fill_bytes(&mut payment_id);
|
|
|
|
builder.add_payment(view.address(Network::Mainnet, None, Some(payment_id)), 5);
|
|
(builder.build().unwrap(), (scanner, payment_id))
|
|
},
|
|
|_rpc: SRR, block, tx: Transaction, _, mut state: (GuaranteedScanner, [u8; 8])| async move {
|
|
let output = state.0.scan(block).unwrap().not_additionally_locked().swap_remove(0);
|
|
assert_eq!(output.transaction(), tx.hash());
|
|
assert_eq!(output.commitment().amount, 5);
|
|
assert_eq!(output.payment_id(), Some(PaymentId::Encrypted(state.1)));
|
|
},
|
|
),
|
|
);
|
|
|
|
test!(
|
|
scan_guaranteed_integrated_subaddress,
|
|
(
|
|
|_, mut builder: Builder, _| async move {
|
|
let subaddress = SubaddressIndex::new(0, 3).unwrap();
|
|
|
|
let view = runner::random_guaranteed_address().1;
|
|
let mut scanner = GuaranteedScanner::new(view.clone());
|
|
scanner.register_subaddress(subaddress);
|
|
|
|
let mut payment_id = [0u8; 8];
|
|
OsRng.fill_bytes(&mut payment_id);
|
|
|
|
builder.add_payment(view.address(Network::Mainnet, Some(subaddress), Some(payment_id)), 5);
|
|
(builder.build().unwrap(), (scanner, payment_id, subaddress))
|
|
},
|
|
|_rpc, block, tx: Tx, _, mut state: (GuaranteedScanner, [u8; 8], SubaddressIndex)| async move {
|
|
let output = state.0.scan(block).unwrap().not_additionally_locked().swap_remove(0);
|
|
assert_eq!(output.transaction(), tx.hash());
|
|
assert_eq!(output.commitment().amount, 5);
|
|
assert_eq!(output.payment_id(), Some(PaymentId::Encrypted(state.1)));
|
|
assert_eq!(output.subaddress(), Some(state.2));
|
|
},
|
|
),
|
|
);
|