mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Restore workspace-wide clippy
Fixes accumulated errors in the Substrate code. Modifies the runtime build to work with a modern clippy. Removes e2e tests from the workspace.
This commit is contained in:
@@ -8,12 +8,13 @@ use blake2::{
|
||||
use scale::Encode;
|
||||
|
||||
use serai_client::{
|
||||
primitives::{Amount, NetworkId, Coin, Balance, BlockHash, SeraiAddress},
|
||||
primitives::{BlockHash, NetworkId, Coin, Amount, Balance, SeraiAddress},
|
||||
coins::CoinsEvent,
|
||||
validator_sets::primitives::Session,
|
||||
in_instructions::{
|
||||
primitives::{InInstruction, InInstructionWithBalance, Batch},
|
||||
InInstructionsEvent,
|
||||
},
|
||||
coins::CoinsEvent,
|
||||
Serai,
|
||||
};
|
||||
|
||||
@@ -32,9 +33,13 @@ serai_test!(
|
||||
let amount = Amount(OsRng.next_u64().saturating_add(1));
|
||||
let balance = Balance { coin, amount };
|
||||
|
||||
let mut external_network_block_hash = BlockHash([0; 32]);
|
||||
OsRng.fill_bytes(&mut external_network_block_hash.0);
|
||||
|
||||
let batch = Batch {
|
||||
network,
|
||||
id,
|
||||
external_network_block_hash,
|
||||
instructions: vec![InInstructionWithBalance {
|
||||
instruction: InInstruction::Transfer(address),
|
||||
balance,
|
||||
@@ -51,8 +56,11 @@ serai_test!(
|
||||
batches,
|
||||
vec![InInstructionsEvent::Batch {
|
||||
network,
|
||||
publishing_session: Session(0),
|
||||
id,
|
||||
instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
|
||||
external_network_block_hash,
|
||||
in_instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
|
||||
in_instruction_results: bitvec::bitvec![u8, bitvec::order::Lsb0; 1; 1],
|
||||
}]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,19 +7,22 @@ use blake2::{
|
||||
|
||||
use scale::Encode;
|
||||
|
||||
use serai_abi::coins::primitives::OutInstructionWithBalance;
|
||||
use sp_core::Pair;
|
||||
|
||||
use serai_client::{
|
||||
primitives::{
|
||||
Amount, NetworkId, Coin, Balance, BlockHash, SeraiAddress, ExternalAddress,
|
||||
BlockHash, NetworkId, Coin, Amount, Balance, SeraiAddress, ExternalAddress,
|
||||
insecure_pair_from_name,
|
||||
},
|
||||
coins::{
|
||||
primitives::{OutInstruction, OutInstructionWithBalance},
|
||||
CoinsEvent,
|
||||
},
|
||||
validator_sets::primitives::Session,
|
||||
in_instructions::{
|
||||
InInstructionsEvent,
|
||||
primitives::{InInstruction, InInstructionWithBalance, Batch},
|
||||
},
|
||||
coins::{primitives::OutInstruction, CoinsEvent},
|
||||
Serai, SeraiCoins,
|
||||
};
|
||||
|
||||
@@ -45,7 +48,7 @@ serai_test!(
|
||||
let batch = Batch {
|
||||
network,
|
||||
id,
|
||||
block: block_hash,
|
||||
external_network_block_hash: block_hash,
|
||||
instructions: vec![InInstructionWithBalance {
|
||||
instruction: InInstruction::Transfer(address),
|
||||
balance,
|
||||
@@ -61,9 +64,11 @@ serai_test!(
|
||||
batches,
|
||||
vec![InInstructionsEvent::Batch {
|
||||
network,
|
||||
publishing_session: Session(0),
|
||||
id,
|
||||
block: block_hash,
|
||||
instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
|
||||
external_network_block_hash: block_hash,
|
||||
in_instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
|
||||
in_instruction_results: bitvec::bitvec![u8, bitvec::order::Lsb0; 1; 1],
|
||||
}]
|
||||
);
|
||||
|
||||
|
||||
@@ -10,12 +10,12 @@ use schnorrkel::Schnorrkel;
|
||||
use sp_core::{sr25519::Signature, Pair as PairTrait};
|
||||
|
||||
use serai_abi::{
|
||||
genesis_liquidity::primitives::{oraclize_values_message, Values},
|
||||
validator_sets::primitives::{musig_context, Session, ValidatorSet},
|
||||
in_instructions::primitives::{InInstruction, InInstructionWithBalance, Batch},
|
||||
primitives::{
|
||||
Amount, NetworkId, Coin, Balance, BlockHash, SeraiAddress, insecure_pair_from_name,
|
||||
BlockHash, NetworkId, Coin, Amount, Balance, SeraiAddress, insecure_pair_from_name,
|
||||
},
|
||||
validator_sets::primitives::{musig_context, Session, ValidatorSet},
|
||||
genesis_liquidity::primitives::{oraclize_values_message, Values},
|
||||
in_instructions::primitives::{InInstruction, InInstructionWithBalance, Batch},
|
||||
};
|
||||
|
||||
use serai_client::{Serai, SeraiGenesisLiquidity};
|
||||
@@ -53,7 +53,7 @@ pub async fn set_up_genesis(
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// set up bloch hash
|
||||
// set up block hash
|
||||
let mut block = BlockHash([0; 32]);
|
||||
OsRng.fill_bytes(&mut block.0);
|
||||
|
||||
@@ -65,7 +65,12 @@ pub async fn set_up_genesis(
|
||||
})
|
||||
.or_insert(0);
|
||||
|
||||
let batch = Batch { network: coin.network(), id: batch_ids[&coin.network()], instructions };
|
||||
let batch = Batch {
|
||||
network: coin.network(),
|
||||
external_network_block_hash: block,
|
||||
id: batch_ids[&coin.network()],
|
||||
instructions,
|
||||
};
|
||||
provide_batch(serai, batch).await;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use scale::Encode;
|
||||
use sp_core::Pair;
|
||||
|
||||
use serai_client::{
|
||||
primitives::{insecure_pair_from_name, BlockHash, NetworkId, Balance, SeraiAddress},
|
||||
primitives::{BlockHash, NetworkId, Balance, SeraiAddress, insecure_pair_from_name},
|
||||
validator_sets::primitives::{ValidatorSet, KeyPair},
|
||||
in_instructions::{
|
||||
primitives::{Batch, SignedBatch, batch_message, InInstruction, InInstructionWithBalance},
|
||||
@@ -45,16 +45,29 @@ pub async fn provide_batch(serai: &Serai, batch: Batch) -> [u8; 32] {
|
||||
)
|
||||
.await;
|
||||
|
||||
let batches = serai.as_of(block).in_instructions().batch_events().await.unwrap();
|
||||
// TODO: impl From<Batch> for BatchEvent?
|
||||
assert_eq!(
|
||||
batches,
|
||||
vec![InInstructionsEvent::Batch {
|
||||
network: batch.network,
|
||||
id: batch.id,
|
||||
instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
|
||||
}],
|
||||
);
|
||||
{
|
||||
let mut batches = serai.as_of(block).in_instructions().batch_events().await.unwrap();
|
||||
assert_eq!(batches.len(), 1);
|
||||
let InInstructionsEvent::Batch {
|
||||
network,
|
||||
publishing_session,
|
||||
id,
|
||||
external_network_block_hash,
|
||||
in_instructions_hash,
|
||||
in_instruction_results: _,
|
||||
} = batches.swap_remove(0)
|
||||
else {
|
||||
panic!("Batch event wasn't Batch event")
|
||||
};
|
||||
assert_eq!(network, batch.network);
|
||||
assert_eq!(publishing_session, session);
|
||||
assert_eq!(id, batch.id);
|
||||
assert_eq!(external_network_block_hash, batch.external_network_block_hash);
|
||||
assert_eq!(
|
||||
in_instructions_hash,
|
||||
<[u8; 32]>::from(Blake2b::<U32>::digest(batch.instructions.encode()))
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Check the tokens events
|
||||
|
||||
@@ -75,7 +88,7 @@ pub async fn mint_coin(
|
||||
let batch = Batch {
|
||||
network,
|
||||
id: batch_id,
|
||||
block: block_hash,
|
||||
external_network_block_hash: block_hash,
|
||||
instructions: vec![InInstructionWithBalance {
|
||||
instruction: InInstruction::Transfer(address),
|
||||
balance,
|
||||
|
||||
@@ -6,8 +6,8 @@ use serai_abi::in_instructions::primitives::DexCall;
|
||||
|
||||
use serai_client::{
|
||||
primitives::{
|
||||
Amount, NetworkId, Coin, Balance, BlockHash, insecure_pair_from_name, ExternalAddress,
|
||||
SeraiAddress,
|
||||
BlockHash, NetworkId, Coin, Amount, Balance, SeraiAddress, ExternalAddress,
|
||||
insecure_pair_from_name,
|
||||
},
|
||||
in_instructions::primitives::{
|
||||
InInstruction, InInstructionWithBalance, Batch, IN_INSTRUCTION_EXECUTOR, OutAddress,
|
||||
@@ -229,7 +229,7 @@ serai_test!(
|
||||
let batch = Batch {
|
||||
network: NetworkId::Bitcoin,
|
||||
id: batch_id,
|
||||
block: block_hash,
|
||||
external_network_block_hash: block_hash,
|
||||
instructions: vec![InInstructionWithBalance {
|
||||
instruction: InInstruction::Dex(DexCall::SwapAndAddLiquidity(pair.public().into())),
|
||||
balance: Balance { coin: Coin::Bitcoin, amount: Amount(20_000_000_000_000) },
|
||||
@@ -313,7 +313,7 @@ serai_test!(
|
||||
let batch = Batch {
|
||||
network: NetworkId::Monero,
|
||||
id: coin1_batch_id,
|
||||
block: block_hash,
|
||||
external_network_block_hash: block_hash,
|
||||
instructions: vec![InInstructionWithBalance {
|
||||
instruction: InInstruction::Dex(DexCall::Swap(out_balance, out_address)),
|
||||
balance: Balance { coin: coin1, amount: Amount(200_000_000_000_000) },
|
||||
@@ -353,7 +353,7 @@ serai_test!(
|
||||
let batch = Batch {
|
||||
network: NetworkId::Ethereum,
|
||||
id: coin2_batch_id,
|
||||
block: block_hash,
|
||||
external_network_block_hash: block_hash,
|
||||
instructions: vec![InInstructionWithBalance {
|
||||
instruction: InInstruction::Dex(DexCall::Swap(out_balance, out_address.clone())),
|
||||
balance: Balance { coin: coin2, amount: Amount(200_000_000_000) },
|
||||
@@ -391,7 +391,7 @@ serai_test!(
|
||||
let batch = Batch {
|
||||
network: NetworkId::Monero,
|
||||
id: coin1_batch_id,
|
||||
block: block_hash,
|
||||
external_network_block_hash: block_hash,
|
||||
instructions: vec![InInstructionWithBalance {
|
||||
instruction: InInstruction::Dex(DexCall::Swap(out_balance, out_address.clone())),
|
||||
balance: Balance { coin: coin1, amount: Amount(100_000_000_000_000) },
|
||||
|
||||
@@ -4,13 +4,13 @@ use rand_core::{RngCore, OsRng};
|
||||
use serai_client::TemporalSerai;
|
||||
|
||||
use serai_abi::{
|
||||
emissions::primitives::{INITIAL_REWARD_PER_BLOCK, SECURE_BY},
|
||||
in_instructions::primitives::Batch,
|
||||
primitives::{
|
||||
BlockHash, Coin, COINS, FAST_EPOCH_DURATION, FAST_EPOCH_INITIAL_PERIOD, NETWORKS,
|
||||
TARGET_BLOCK_TIME,
|
||||
NETWORKS, COINS, TARGET_BLOCK_TIME, FAST_EPOCH_DURATION, FAST_EPOCH_INITIAL_PERIOD, BlockHash,
|
||||
Coin,
|
||||
},
|
||||
validator_sets::primitives::Session,
|
||||
emissions::primitives::{INITIAL_REWARD_PER_BLOCK, SECURE_BY},
|
||||
in_instructions::primitives::Batch,
|
||||
};
|
||||
|
||||
use serai_client::{
|
||||
@@ -42,7 +42,16 @@ async fn send_batches(serai: &Serai, ids: &mut HashMap<NetworkId, u32>) {
|
||||
let mut block = BlockHash([0; 32]);
|
||||
OsRng.fill_bytes(&mut block.0);
|
||||
|
||||
provide_batch(serai, Batch { network, id: ids[&network], block, instructions: vec![] }).await;
|
||||
provide_batch(
|
||||
serai,
|
||||
Batch {
|
||||
network,
|
||||
id: ids[&network],
|
||||
external_network_block_hash: block,
|
||||
instructions: vec![],
|
||||
},
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use sp_core::{
|
||||
|
||||
use serai_client::{
|
||||
primitives::{
|
||||
FAST_EPOCH_DURATION, TARGET_BLOCK_TIME, NETWORKS, EmbeddedEllipticCurve, NetworkId, BlockHash,
|
||||
FAST_EPOCH_DURATION, TARGET_BLOCK_TIME, NETWORKS, BlockHash, NetworkId, EmbeddedEllipticCurve,
|
||||
insecure_pair_from_name,
|
||||
},
|
||||
validator_sets::{
|
||||
@@ -311,7 +311,8 @@ async fn validator_set_rotation() {
|
||||
// provide a batch to complete the handover and retire the previous set
|
||||
let mut block_hash = BlockHash([0; 32]);
|
||||
OsRng.fill_bytes(&mut block_hash.0);
|
||||
let batch = Batch { network, id: 0, block: block_hash, instructions: vec![] };
|
||||
let batch =
|
||||
Batch { network, id: 0, external_network_block_hash: block_hash, instructions: vec![] };
|
||||
publish_tx(
|
||||
&serai,
|
||||
&SeraiInInstructions::execute_batch(SignedBatch {
|
||||
|
||||
Reference in New Issue
Block a user