mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-11 13:39:25 +00:00
add specific network/coin/balance types (#619)
* add specific network/coin/balance types * misc fixes * fix clippy * misc fixes * fix pr comments * Make halting for external networks * fix encode/decode
This commit is contained in:
@@ -33,17 +33,17 @@ fn test_batch_signer() {
|
||||
let block = BlockHash([0xaa; 32]);
|
||||
|
||||
let batch = Batch {
|
||||
network: NetworkId::Monero,
|
||||
network: ExternalNetworkId::Monero,
|
||||
id,
|
||||
block,
|
||||
instructions: vec![
|
||||
InInstructionWithBalance {
|
||||
instruction: InInstruction::Transfer(SeraiAddress([0xbb; 32])),
|
||||
balance: Balance { coin: Coin::Bitcoin, amount: Amount(1000) },
|
||||
balance: ExternalBalance { coin: ExternalCoin::Bitcoin, amount: Amount(1000) },
|
||||
},
|
||||
InInstructionWithBalance {
|
||||
instruction: InInstruction::Dex(DexCall::SwapAndAddLiquidity(SeraiAddress([0xbb; 32]))),
|
||||
balance: Balance { coin: Coin::Monero, amount: Amount(9999999999999999) },
|
||||
balance: ExternalBalance { coin: ExternalCoin::Monero, amount: Amount(9999999999999999) },
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -70,7 +70,7 @@ fn test_batch_signer() {
|
||||
let i = Participant::new(u16::try_from(i).unwrap()).unwrap();
|
||||
let keys = keys.get(&i).unwrap().clone();
|
||||
|
||||
let mut signer = BatchSigner::<MemDb>::new(NetworkId::Monero, Session(0), vec![keys]);
|
||||
let mut signer = BatchSigner::<MemDb>::new(ExternalNetworkId::Monero, Session(0), vec![keys]);
|
||||
let mut db = MemDb::new();
|
||||
|
||||
let mut txn = db.txn();
|
||||
|
||||
@@ -12,7 +12,7 @@ use frost::{
|
||||
use serai_db::{DbTxn, Db, MemDb};
|
||||
|
||||
use serai_client::{
|
||||
primitives::{NetworkId, Coin, Amount, Balance},
|
||||
primitives::{ExternalNetworkId, ExternalCoin, Amount, ExternalBalance},
|
||||
validator_sets::primitives::Session,
|
||||
};
|
||||
|
||||
@@ -185,12 +185,11 @@ pub async fn test_signer<N: Network>(
|
||||
let payments = vec![Payment {
|
||||
address: N::external_address(&network, key).await,
|
||||
data: None,
|
||||
balance: Balance {
|
||||
balance: ExternalBalance {
|
||||
coin: match N::NETWORK {
|
||||
NetworkId::Serai => panic!("test_signer called with Serai"),
|
||||
NetworkId::Bitcoin => Coin::Bitcoin,
|
||||
NetworkId::Ethereum => Coin::Ether,
|
||||
NetworkId::Monero => Coin::Monero,
|
||||
ExternalNetworkId::Bitcoin => ExternalCoin::Bitcoin,
|
||||
ExternalNetworkId::Ethereum => ExternalCoin::Ether,
|
||||
ExternalNetworkId::Monero => ExternalCoin::Monero,
|
||||
},
|
||||
amount: Amount(amount),
|
||||
},
|
||||
@@ -224,7 +223,7 @@ pub async fn test_signer<N: Network>(
|
||||
.await;
|
||||
// Don't run if Ethereum as the received output will revert by the contract
|
||||
// (and therefore not actually exist)
|
||||
if N::NETWORK != NetworkId::Ethereum {
|
||||
if N::NETWORK != ExternalNetworkId::Ethereum {
|
||||
assert_eq!(outputs.len(), 1 + usize::from(u8::from(plan.change.is_some())));
|
||||
// Adjust the amount for the fees
|
||||
let amount = amount - tx.fee(&network).await;
|
||||
|
||||
@@ -11,7 +11,7 @@ use tokio::time::timeout;
|
||||
use serai_db::{DbTxn, Db, MemDb};
|
||||
|
||||
use serai_client::{
|
||||
primitives::{NetworkId, Coin, Amount, Balance},
|
||||
primitives::{ExternalNetworkId, ExternalCoin, Amount, ExternalBalance},
|
||||
validator_sets::primitives::Session,
|
||||
};
|
||||
|
||||
@@ -89,12 +89,11 @@ pub async fn test_wallet<N: Network>(
|
||||
vec![Payment {
|
||||
address: N::external_address(&network, key).await,
|
||||
data: None,
|
||||
balance: Balance {
|
||||
balance: ExternalBalance {
|
||||
coin: match N::NETWORK {
|
||||
NetworkId::Serai => panic!("test_wallet called with Serai"),
|
||||
NetworkId::Bitcoin => Coin::Bitcoin,
|
||||
NetworkId::Ethereum => Coin::Ether,
|
||||
NetworkId::Monero => Coin::Monero,
|
||||
ExternalNetworkId::Bitcoin => ExternalCoin::Bitcoin,
|
||||
ExternalNetworkId::Ethereum => ExternalCoin::Ether,
|
||||
ExternalNetworkId::Monero => ExternalCoin::Monero,
|
||||
},
|
||||
amount: Amount(amount),
|
||||
},
|
||||
@@ -117,12 +116,11 @@ pub async fn test_wallet<N: Network>(
|
||||
vec![Payment {
|
||||
address: N::external_address(&network, key).await,
|
||||
data: None,
|
||||
balance: Balance {
|
||||
balance: ExternalBalance {
|
||||
coin: match N::NETWORK {
|
||||
NetworkId::Serai => panic!("test_wallet called with Serai"),
|
||||
NetworkId::Bitcoin => Coin::Bitcoin,
|
||||
NetworkId::Ethereum => Coin::Ether,
|
||||
NetworkId::Monero => Coin::Monero,
|
||||
ExternalNetworkId::Bitcoin => ExternalCoin::Bitcoin,
|
||||
ExternalNetworkId::Ethereum => ExternalCoin::Ether,
|
||||
ExternalNetworkId::Monero => ExternalCoin::Monero,
|
||||
},
|
||||
amount: Amount(amount),
|
||||
}
|
||||
@@ -160,7 +158,7 @@ pub async fn test_wallet<N: Network>(
|
||||
|
||||
// Don't run if Ethereum as the received output will revert by the contract
|
||||
// (and therefore not actually exist)
|
||||
if N::NETWORK != NetworkId::Ethereum {
|
||||
if N::NETWORK != ExternalNetworkId::Ethereum {
|
||||
assert_eq!(outputs.len(), 1 + usize::from(u8::from(plans[0].change.is_some())));
|
||||
// Adjust the amount for the fees
|
||||
let amount = amount - tx.fee(&network).await;
|
||||
@@ -183,7 +181,7 @@ pub async fn test_wallet<N: Network>(
|
||||
network.mine_block().await;
|
||||
}
|
||||
|
||||
if N::NETWORK != NetworkId::Ethereum {
|
||||
if N::NETWORK != ExternalNetworkId::Ethereum {
|
||||
match timeout(Duration::from_secs(30), scanner.events.recv()).await.unwrap().unwrap() {
|
||||
ScannerEvent::Block { is_retirement_block, block: block_id, outputs: these_outputs } => {
|
||||
scanner.multisig_completed.send(false).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user