mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 12:49:23 +00:00
Replace "coin" with "network"
The Processor's coins folder referred to the networks it could process, as did its Coin trait. This, and other similar cases throughout the codebase, have now been corrected. Also corrects dated documentation for a key pair is confirmed under the validator-sets pallet.
This commit is contained in:
@@ -11,18 +11,18 @@ use serai_db::{DbTxn, MemDb};
|
||||
|
||||
use crate::{
|
||||
Plan, Db,
|
||||
coins::{OutputType, Output, Block, Coin},
|
||||
networks::{OutputType, Output, Block, Network},
|
||||
scanner::{ScannerEvent, Scanner, ScannerHandle},
|
||||
tests::sign,
|
||||
};
|
||||
|
||||
async fn spend<C: Coin, D: Db>(
|
||||
coin: &C,
|
||||
keys: &HashMap<Participant, ThresholdKeys<C::Curve>>,
|
||||
scanner: &mut ScannerHandle<C, D>,
|
||||
async fn spend<N: Network, D: Db>(
|
||||
network: &N,
|
||||
keys: &HashMap<Participant, ThresholdKeys<N::Curve>>,
|
||||
scanner: &mut ScannerHandle<N, D>,
|
||||
batch: u32,
|
||||
outputs: Vec<C::Output>,
|
||||
) -> Vec<C::Output> {
|
||||
outputs: Vec<N::Output>,
|
||||
) -> Vec<N::Output> {
|
||||
let key = keys[&Participant::new(1).unwrap()].group_key();
|
||||
|
||||
let mut keys_txs = HashMap::new();
|
||||
@@ -31,13 +31,13 @@ async fn spend<C: Coin, D: Db>(
|
||||
*i,
|
||||
(
|
||||
keys.clone(),
|
||||
coin
|
||||
network
|
||||
.prepare_send(
|
||||
keys.clone(),
|
||||
coin.get_latest_block_number().await.unwrap() - C::CONFIRMATIONS,
|
||||
network.get_latest_block_number().await.unwrap() - N::CONFIRMATIONS,
|
||||
// Send to a change output
|
||||
Plan { key, inputs: outputs.clone(), payments: vec![], change: Some(key) },
|
||||
coin.get_fee().await,
|
||||
network.get_fee().await,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
@@ -46,10 +46,10 @@ async fn spend<C: Coin, D: Db>(
|
||||
),
|
||||
);
|
||||
}
|
||||
sign(coin.clone(), keys_txs).await;
|
||||
sign(network.clone(), keys_txs).await;
|
||||
|
||||
for _ in 0 .. C::CONFIRMATIONS {
|
||||
coin.mine_block().await;
|
||||
for _ in 0 .. N::CONFIRMATIONS {
|
||||
network.mine_block().await;
|
||||
}
|
||||
match timeout(Duration::from_secs(30), scanner.events.recv()).await.unwrap().unwrap() {
|
||||
ScannerEvent::Block { key: this_key, block: _, batch: this_batch, outputs } => {
|
||||
@@ -66,27 +66,27 @@ async fn spend<C: Coin, D: Db>(
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn test_addresses<C: Coin>(coin: C) {
|
||||
let mut keys = frost::tests::key_gen::<_, C::Curve>(&mut OsRng);
|
||||
pub async fn test_addresses<N: Network>(network: N) {
|
||||
let mut keys = frost::tests::key_gen::<_, N::Curve>(&mut OsRng);
|
||||
for (_, keys) in keys.iter_mut() {
|
||||
C::tweak_keys(keys);
|
||||
N::tweak_keys(keys);
|
||||
}
|
||||
let key = keys[&Participant::new(1).unwrap()].group_key();
|
||||
|
||||
// Mine blocks so there's a confirmed block
|
||||
for _ in 0 .. C::CONFIRMATIONS {
|
||||
coin.mine_block().await;
|
||||
for _ in 0 .. N::CONFIRMATIONS {
|
||||
network.mine_block().await;
|
||||
}
|
||||
|
||||
let mut db = MemDb::new();
|
||||
let (mut scanner, active_keys) = Scanner::new(coin.clone(), db.clone());
|
||||
let (mut scanner, active_keys) = Scanner::new(network.clone(), db.clone());
|
||||
assert!(active_keys.is_empty());
|
||||
let mut txn = db.txn();
|
||||
scanner.rotate_key(&mut txn, coin.get_latest_block_number().await.unwrap(), key).await;
|
||||
scanner.rotate_key(&mut txn, network.get_latest_block_number().await.unwrap(), key).await;
|
||||
txn.commit();
|
||||
|
||||
// Receive funds to the branch address and make sure it's properly identified
|
||||
let block_id = coin.test_send(C::branch_address(key)).await.id();
|
||||
let block_id = network.test_send(N::branch_address(key)).await.id();
|
||||
|
||||
// Verify the Scanner picked them up
|
||||
let outputs =
|
||||
@@ -105,7 +105,7 @@ pub async fn test_addresses<C: Coin>(coin: C) {
|
||||
};
|
||||
|
||||
// Spend the branch output, creating a change output and ensuring we actually get change
|
||||
let outputs = spend(&coin, &keys, &mut scanner, 1, outputs).await;
|
||||
let outputs = spend(&network, &keys, &mut scanner, 1, outputs).await;
|
||||
// Also test spending the change output
|
||||
spend(&coin, &keys, &mut scanner, 2, outputs).await;
|
||||
spend(&network, &keys, &mut scanner, 2, outputs).await;
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@ use serai_client::{
|
||||
|
||||
use messages::key_gen::*;
|
||||
use crate::{
|
||||
coins::Coin,
|
||||
networks::Network,
|
||||
key_gen::{KeyConfirmed, KeyGen},
|
||||
};
|
||||
|
||||
const ID: KeyGenId =
|
||||
KeyGenId { set: ValidatorSet { session: Session(1), network: NetworkId::Monero }, attempt: 3 };
|
||||
|
||||
pub async fn test_key_gen<C: Coin>() {
|
||||
pub async fn test_key_gen<N: Network>() {
|
||||
let mut entropies = HashMap::new();
|
||||
let mut dbs = HashMap::new();
|
||||
let mut key_gens = HashMap::new();
|
||||
@@ -34,7 +34,7 @@ pub async fn test_key_gen<C: Coin>() {
|
||||
entropies.insert(i, entropy);
|
||||
let db = MemDb::new();
|
||||
dbs.insert(i, db.clone());
|
||||
key_gens.insert(i, KeyGen::<C, MemDb>::new(db, entropies[&i].clone()));
|
||||
key_gens.insert(i, KeyGen::<N, MemDb>::new(db, entropies[&i].clone()));
|
||||
}
|
||||
|
||||
let mut all_commitments = HashMap::new();
|
||||
@@ -65,7 +65,7 @@ pub async fn test_key_gen<C: Coin>() {
|
||||
// 3 ... are rebuilt once, one at each of the following steps
|
||||
let rebuild = |key_gens: &mut HashMap<_, _>, dbs: &HashMap<_, MemDb>, i| {
|
||||
key_gens.remove(&i);
|
||||
key_gens.insert(i, KeyGen::<C, _>::new(dbs[&i].clone(), entropies[&i].clone()));
|
||||
key_gens.insert(i, KeyGen::<N, _>::new(dbs[&i].clone(), entropies[&i].clone()));
|
||||
};
|
||||
rebuild(&mut key_gens, &dbs, 1);
|
||||
rebuild(&mut key_gens, &dbs, 2);
|
||||
@@ -102,7 +102,7 @@ pub async fn test_key_gen<C: Coin>() {
|
||||
let key_gen = key_gens.get_mut(&i).unwrap();
|
||||
let mut txn = dbs.get_mut(&i).unwrap().txn();
|
||||
let i = Participant::new(u16::try_from(i).unwrap()).unwrap();
|
||||
if let ProcessorMessage::GeneratedKeyPair { id, substrate_key, coin_key } = key_gen
|
||||
if let ProcessorMessage::GeneratedKeyPair { id, substrate_key, network_key } = key_gen
|
||||
.handle(
|
||||
&mut txn,
|
||||
CoordinatorMessage::Shares {
|
||||
@@ -117,9 +117,9 @@ pub async fn test_key_gen<C: Coin>() {
|
||||
{
|
||||
assert_eq!(id, ID);
|
||||
if res.is_none() {
|
||||
res = Some((substrate_key, coin_key.clone()));
|
||||
res = Some((substrate_key, network_key.clone()));
|
||||
}
|
||||
assert_eq!(res.as_ref().unwrap(), &(substrate_key, coin_key));
|
||||
assert_eq!(res.as_ref().unwrap(), &(substrate_key, network_key));
|
||||
} else {
|
||||
panic!("didn't get key back");
|
||||
}
|
||||
@@ -134,7 +134,7 @@ pub async fn test_key_gen<C: Coin>() {
|
||||
for i in 1 ..= 5 {
|
||||
let key_gen = key_gens.get_mut(&i).unwrap();
|
||||
let mut txn = dbs.get_mut(&i).unwrap().txn();
|
||||
let KeyConfirmed { substrate_keys, coin_keys } = key_gen
|
||||
let KeyConfirmed { substrate_keys, network_keys } = key_gen
|
||||
.confirm(&mut txn, ID.set, (sr25519::Public(res.0), res.1.clone().try_into().unwrap()))
|
||||
.await;
|
||||
txn.commit();
|
||||
@@ -142,9 +142,12 @@ pub async fn test_key_gen<C: Coin>() {
|
||||
let params =
|
||||
ThresholdParams::new(3, 5, Participant::new(u16::try_from(i).unwrap()).unwrap()).unwrap();
|
||||
assert_eq!(substrate_keys.params(), params);
|
||||
assert_eq!(coin_keys.params(), params);
|
||||
assert_eq!(network_keys.params(), params);
|
||||
assert_eq!(
|
||||
(substrate_keys.group_key().to_bytes(), coin_keys.group_key().to_bytes().as_ref().to_vec()),
|
||||
(
|
||||
substrate_keys.group_key().to_bytes(),
|
||||
network_keys.group_key().to_bytes().as_ref().to_vec()
|
||||
),
|
||||
res
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#[cfg(feature = "bitcoin")]
|
||||
mod bitcoin {
|
||||
use crate::coins::Bitcoin;
|
||||
use crate::networks::Bitcoin;
|
||||
|
||||
async fn bitcoin() -> Bitcoin {
|
||||
let bitcoin = Bitcoin::new("http://serai:seraidex@127.0.0.1:18443".to_string()).await;
|
||||
@@ -8,7 +8,7 @@ mod bitcoin {
|
||||
bitcoin
|
||||
}
|
||||
|
||||
test_coin!(
|
||||
test_network!(
|
||||
Bitcoin,
|
||||
bitcoin,
|
||||
bitcoin_key_gen,
|
||||
@@ -21,7 +21,7 @@ mod bitcoin {
|
||||
|
||||
#[cfg(feature = "monero")]
|
||||
mod monero {
|
||||
use crate::coins::{Coin, Monero};
|
||||
use crate::networks::{Network, Monero};
|
||||
|
||||
async fn monero() -> Monero {
|
||||
let monero = Monero::new("http://127.0.0.1:18081".to_string());
|
||||
@@ -31,7 +31,7 @@ mod monero {
|
||||
monero
|
||||
}
|
||||
|
||||
test_coin!(
|
||||
test_network!(
|
||||
Monero,
|
||||
monero,
|
||||
monero_key_gen,
|
||||
|
||||
@@ -50,10 +50,10 @@ macro_rules! async_sequential {
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! test_coin {
|
||||
macro_rules! test_network {
|
||||
(
|
||||
$C: ident,
|
||||
$coin: ident,
|
||||
$N: ident,
|
||||
$network: ident,
|
||||
$key_gen: ident,
|
||||
$scanner: ident,
|
||||
$signer: ident,
|
||||
@@ -65,32 +65,32 @@ macro_rules! test_coin {
|
||||
// This doesn't interact with a node and accordingly doesn't need to be run sequentially
|
||||
#[tokio::test]
|
||||
async fn $key_gen() {
|
||||
test_key_gen::<$C>().await;
|
||||
test_key_gen::<$N>().await;
|
||||
}
|
||||
|
||||
sequential!();
|
||||
|
||||
async_sequential! {
|
||||
async fn $scanner() {
|
||||
test_scanner($coin().await).await;
|
||||
test_scanner($network().await).await;
|
||||
}
|
||||
}
|
||||
|
||||
async_sequential! {
|
||||
async fn $signer() {
|
||||
test_signer($coin().await).await;
|
||||
test_signer($network().await).await;
|
||||
}
|
||||
}
|
||||
|
||||
async_sequential! {
|
||||
async fn $wallet() {
|
||||
test_wallet($coin().await).await;
|
||||
test_wallet($network().await).await;
|
||||
}
|
||||
}
|
||||
|
||||
async_sequential! {
|
||||
async fn $addresses() {
|
||||
test_addresses($coin().await).await;
|
||||
test_addresses($network().await).await;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -12,27 +12,27 @@ use serai_client::primitives::BlockHash;
|
||||
use serai_db::{DbTxn, Db, MemDb};
|
||||
|
||||
use crate::{
|
||||
coins::{OutputType, Output, Block, Coin},
|
||||
networks::{OutputType, Output, Block, Network},
|
||||
scanner::{ScannerEvent, Scanner, ScannerHandle},
|
||||
};
|
||||
|
||||
pub async fn test_scanner<C: Coin>(coin: C) {
|
||||
pub async fn test_scanner<N: Network>(network: N) {
|
||||
let mut keys =
|
||||
frost::tests::key_gen::<_, C::Curve>(&mut OsRng).remove(&Participant::new(1).unwrap()).unwrap();
|
||||
C::tweak_keys(&mut keys);
|
||||
frost::tests::key_gen::<_, N::Curve>(&mut OsRng).remove(&Participant::new(1).unwrap()).unwrap();
|
||||
N::tweak_keys(&mut keys);
|
||||
let group_key = keys.group_key();
|
||||
|
||||
// Mine blocks so there's a confirmed block
|
||||
for _ in 0 .. C::CONFIRMATIONS {
|
||||
coin.mine_block().await;
|
||||
for _ in 0 .. N::CONFIRMATIONS {
|
||||
network.mine_block().await;
|
||||
}
|
||||
|
||||
let first = Arc::new(Mutex::new(true));
|
||||
let activation_number = coin.get_latest_block_number().await.unwrap();
|
||||
let activation_number = network.get_latest_block_number().await.unwrap();
|
||||
let db = MemDb::new();
|
||||
let new_scanner = || async {
|
||||
let mut db = db.clone();
|
||||
let (mut scanner, active_keys) = Scanner::new(coin.clone(), db.clone());
|
||||
let (mut scanner, active_keys) = Scanner::new(network.clone(), db.clone());
|
||||
let mut first = first.lock().unwrap();
|
||||
if *first {
|
||||
assert!(active_keys.is_empty());
|
||||
@@ -48,11 +48,11 @@ pub async fn test_scanner<C: Coin>(coin: C) {
|
||||
let scanner = new_scanner().await;
|
||||
|
||||
// Receive funds
|
||||
let block = coin.test_send(C::address(keys.group_key())).await;
|
||||
let block = network.test_send(N::address(keys.group_key())).await;
|
||||
let block_id = block.id();
|
||||
|
||||
// Verify the Scanner picked them up
|
||||
let verify_event = |mut scanner: ScannerHandle<C, MemDb>| async {
|
||||
let verify_event = |mut scanner: ScannerHandle<N, MemDb>| async {
|
||||
let outputs =
|
||||
match timeout(Duration::from_secs(30), scanner.events.recv()).await.unwrap().unwrap() {
|
||||
ScannerEvent::Block { key, block, batch, outputs } => {
|
||||
@@ -80,7 +80,7 @@ pub async fn test_scanner<C: Coin>(coin: C) {
|
||||
let mut blocks = vec![];
|
||||
let mut curr_block = activation_number + 1;
|
||||
loop {
|
||||
let block = coin.get_block(curr_block).await.unwrap().id();
|
||||
let block = network.get_block(curr_block).await.unwrap().id();
|
||||
blocks.push(BlockHash(block.as_ref().try_into().unwrap()));
|
||||
if block == block_id {
|
||||
break;
|
||||
|
||||
@@ -13,18 +13,18 @@ use serai_db::{DbTxn, Db, MemDb};
|
||||
use messages::sign::*;
|
||||
use crate::{
|
||||
Payment, Plan,
|
||||
coins::{Output, Transaction, Coin},
|
||||
networks::{Output, Transaction, Network},
|
||||
signer::{SignerEvent, Signer},
|
||||
};
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub async fn sign<C: Coin>(
|
||||
coin: C,
|
||||
pub async fn sign<N: Network>(
|
||||
network: N,
|
||||
mut keys_txs: HashMap<
|
||||
Participant,
|
||||
(ThresholdKeys<C::Curve>, (C::SignableTransaction, C::Eventuality)),
|
||||
(ThresholdKeys<N::Curve>, (N::SignableTransaction, N::Eventuality)),
|
||||
>,
|
||||
) -> <C::Transaction as Transaction<C>>::Id {
|
||||
) -> <N::Transaction as Transaction<N>>::Id {
|
||||
let actual_id = SignId {
|
||||
key: keys_txs[&Participant::new(1).unwrap()].0.group_key().to_bytes().as_ref().to_vec(),
|
||||
id: [0xaa; 32],
|
||||
@@ -45,7 +45,7 @@ pub async fn sign<C: Coin>(
|
||||
let i = Participant::new(u16::try_from(i).unwrap()).unwrap();
|
||||
let keys = keys.remove(&i).unwrap();
|
||||
t = keys.params().t();
|
||||
signers.insert(i, Signer::<_, MemDb>::new(coin.clone(), keys));
|
||||
signers.insert(i, Signer::<_, MemDb>::new(network.clone(), keys));
|
||||
dbs.insert(i, MemDb::new());
|
||||
}
|
||||
drop(keys);
|
||||
@@ -146,29 +146,29 @@ pub async fn sign<C: Coin>(
|
||||
tx_id.unwrap()
|
||||
}
|
||||
|
||||
pub async fn test_signer<C: Coin>(coin: C) {
|
||||
pub async fn test_signer<N: Network>(network: N) {
|
||||
let mut keys = key_gen(&mut OsRng);
|
||||
for (_, keys) in keys.iter_mut() {
|
||||
C::tweak_keys(keys);
|
||||
N::tweak_keys(keys);
|
||||
}
|
||||
let key = keys[&Participant::new(1).unwrap()].group_key();
|
||||
|
||||
let outputs = coin.get_outputs(&coin.test_send(C::address(key)).await, key).await.unwrap();
|
||||
let sync_block = coin.get_latest_block_number().await.unwrap() - C::CONFIRMATIONS;
|
||||
let fee = coin.get_fee().await;
|
||||
let outputs = network.get_outputs(&network.test_send(N::address(key)).await, key).await.unwrap();
|
||||
let sync_block = network.get_latest_block_number().await.unwrap() - N::CONFIRMATIONS;
|
||||
let fee = network.get_fee().await;
|
||||
|
||||
let amount = 2 * C::DUST;
|
||||
let amount = 2 * N::DUST;
|
||||
let mut keys_txs = HashMap::new();
|
||||
let mut eventualities = vec![];
|
||||
for (i, keys) in keys.drain() {
|
||||
let (signable, eventuality) = coin
|
||||
let (signable, eventuality) = network
|
||||
.prepare_send(
|
||||
keys.clone(),
|
||||
sync_block,
|
||||
Plan {
|
||||
key,
|
||||
inputs: outputs.clone(),
|
||||
payments: vec![Payment { address: C::address(key), data: None, amount }],
|
||||
payments: vec![Payment { address: N::address(key), data: None, amount }],
|
||||
change: Some(key),
|
||||
},
|
||||
fee,
|
||||
@@ -184,23 +184,26 @@ pub async fn test_signer<C: Coin>(coin: C) {
|
||||
|
||||
// The signer may not publish the TX if it has a connection error
|
||||
// It doesn't fail in this case
|
||||
let txid = sign(coin.clone(), keys_txs).await;
|
||||
let tx = coin.get_transaction(&txid).await.unwrap();
|
||||
let txid = sign(network.clone(), keys_txs).await;
|
||||
let tx = network.get_transaction(&txid).await.unwrap();
|
||||
assert_eq!(tx.id(), txid);
|
||||
// Mine a block, and scan it, to ensure that the TX actually made it on chain
|
||||
coin.mine_block().await;
|
||||
let outputs = coin
|
||||
.get_outputs(&coin.get_block(coin.get_latest_block_number().await.unwrap()).await.unwrap(), key)
|
||||
network.mine_block().await;
|
||||
let outputs = network
|
||||
.get_outputs(
|
||||
&network.get_block(network.get_latest_block_number().await.unwrap()).await.unwrap(),
|
||||
key,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(outputs.len(), 2);
|
||||
// Adjust the amount for the fees
|
||||
let amount = amount - tx.fee(&coin).await;
|
||||
let amount = amount - tx.fee(&network).await;
|
||||
// Check either output since Monero will randomize its output order
|
||||
assert!((outputs[0].amount() == amount) || (outputs[1].amount() == amount));
|
||||
|
||||
// Check the eventualities pass
|
||||
for eventuality in eventualities {
|
||||
assert!(coin.confirm_completion(&eventuality, &tx));
|
||||
assert!(network.confirm_completion(&eventuality, &tx));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,29 +10,29 @@ use serai_db::{DbTxn, Db, MemDb};
|
||||
|
||||
use crate::{
|
||||
Payment, Plan,
|
||||
coins::{Output, Transaction, Block, Coin},
|
||||
networks::{Output, Transaction, Block, Network},
|
||||
scanner::{ScannerEvent, Scanner},
|
||||
scheduler::Scheduler,
|
||||
tests::sign,
|
||||
};
|
||||
|
||||
// Tests the Scanner, Scheduler, and Signer together
|
||||
pub async fn test_wallet<C: Coin>(coin: C) {
|
||||
pub async fn test_wallet<N: Network>(network: N) {
|
||||
let mut keys = key_gen(&mut OsRng);
|
||||
for (_, keys) in keys.iter_mut() {
|
||||
C::tweak_keys(keys);
|
||||
N::tweak_keys(keys);
|
||||
}
|
||||
let key = keys[&Participant::new(1).unwrap()].group_key();
|
||||
|
||||
let mut db = MemDb::new();
|
||||
let (mut scanner, active_keys) = Scanner::new(coin.clone(), db.clone());
|
||||
let (mut scanner, active_keys) = Scanner::new(network.clone(), db.clone());
|
||||
assert!(active_keys.is_empty());
|
||||
let (block_id, outputs) = {
|
||||
let mut txn = db.txn();
|
||||
scanner.rotate_key(&mut txn, coin.get_latest_block_number().await.unwrap(), key).await;
|
||||
scanner.rotate_key(&mut txn, network.get_latest_block_number().await.unwrap(), key).await;
|
||||
txn.commit();
|
||||
|
||||
let block = coin.test_send(C::address(key)).await;
|
||||
let block = network.test_send(N::address(key)).await;
|
||||
let block_id = block.id();
|
||||
|
||||
match timeout(Duration::from_secs(30), scanner.events.recv()).await.unwrap().unwrap() {
|
||||
@@ -51,11 +51,11 @@ pub async fn test_wallet<C: Coin>(coin: C) {
|
||||
|
||||
let mut txn = db.txn();
|
||||
let mut scheduler = Scheduler::new::<MemDb>(&mut txn, key);
|
||||
let amount = 2 * C::DUST;
|
||||
let amount = 2 * N::DUST;
|
||||
let plans = scheduler.schedule::<MemDb>(
|
||||
&mut txn,
|
||||
outputs.clone(),
|
||||
vec![Payment { address: C::address(key), data: None, amount }],
|
||||
vec![Payment { address: N::address(key), data: None, amount }],
|
||||
);
|
||||
txn.commit();
|
||||
assert_eq!(
|
||||
@@ -63,7 +63,7 @@ pub async fn test_wallet<C: Coin>(coin: C) {
|
||||
vec![Plan {
|
||||
key,
|
||||
inputs: outputs.clone(),
|
||||
payments: vec![Payment { address: C::address(key), data: None, amount }],
|
||||
payments: vec![Payment { address: N::address(key), data: None, amount }],
|
||||
change: Some(key),
|
||||
}]
|
||||
);
|
||||
@@ -71,16 +71,16 @@ pub async fn test_wallet<C: Coin>(coin: C) {
|
||||
{
|
||||
let mut buf = vec![];
|
||||
plans[0].write(&mut buf).unwrap();
|
||||
assert_eq!(plans[0], Plan::<C>::read::<&[u8]>(&mut buf.as_ref()).unwrap());
|
||||
assert_eq!(plans[0], Plan::<N>::read::<&[u8]>(&mut buf.as_ref()).unwrap());
|
||||
}
|
||||
|
||||
// Execute the plan
|
||||
let fee = coin.get_fee().await;
|
||||
let fee = network.get_fee().await;
|
||||
let mut keys_txs = HashMap::new();
|
||||
let mut eventualities = vec![];
|
||||
for (i, keys) in keys.drain() {
|
||||
let (signable, eventuality) = coin
|
||||
.prepare_send(keys.clone(), coin.get_block_number(&block_id).await, plans[0].clone(), fee)
|
||||
let (signable, eventuality) = network
|
||||
.prepare_send(keys.clone(), network.get_block_number(&block_id).await, plans[0].clone(), fee)
|
||||
.await
|
||||
.unwrap()
|
||||
.0
|
||||
@@ -90,23 +90,23 @@ pub async fn test_wallet<C: Coin>(coin: C) {
|
||||
keys_txs.insert(i, (keys, (signable, eventuality)));
|
||||
}
|
||||
|
||||
let txid = sign(coin.clone(), keys_txs).await;
|
||||
let tx = coin.get_transaction(&txid).await.unwrap();
|
||||
coin.mine_block().await;
|
||||
let block_number = coin.get_latest_block_number().await.unwrap();
|
||||
let block = coin.get_block(block_number).await.unwrap();
|
||||
let txid = sign(network.clone(), keys_txs).await;
|
||||
let tx = network.get_transaction(&txid).await.unwrap();
|
||||
network.mine_block().await;
|
||||
let block_number = network.get_latest_block_number().await.unwrap();
|
||||
let block = network.get_block(block_number).await.unwrap();
|
||||
let first_outputs = outputs;
|
||||
let outputs = coin.get_outputs(&block, key).await.unwrap();
|
||||
let outputs = network.get_outputs(&block, key).await.unwrap();
|
||||
assert_eq!(outputs.len(), 2);
|
||||
let amount = amount - tx.fee(&coin).await;
|
||||
let amount = amount - tx.fee(&network).await;
|
||||
assert!((outputs[0].amount() == amount) || (outputs[1].amount() == amount));
|
||||
|
||||
for eventuality in eventualities {
|
||||
assert!(coin.confirm_completion(&eventuality, &tx));
|
||||
assert!(network.confirm_completion(&eventuality, &tx));
|
||||
}
|
||||
|
||||
for _ in 1 .. C::CONFIRMATIONS {
|
||||
coin.mine_block().await;
|
||||
for _ in 1 .. N::CONFIRMATIONS {
|
||||
network.mine_block().await;
|
||||
}
|
||||
|
||||
match timeout(Duration::from_secs(30), scanner.events.recv()).await.unwrap().unwrap() {
|
||||
|
||||
Reference in New Issue
Block a user