Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions client/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ pub struct FullDeps<C, P, A: ChainApi, BE, SC> {
pub filter_pool: Option<FilterPool>,
/// Frontier Backend.
pub frontier_backend: Arc<dyn fc_db::BackendReader<Block> + Send + Sync>,
/// Backend.
pub backend: Arc<BE>,
/// Maximum number of logs in a query.
pub max_past_logs: u32,
/// Fee history cache.
Expand Down Expand Up @@ -224,7 +222,6 @@ where
network,
filter_pool,
frontier_backend,
backend: _,
max_past_logs,
fee_history_cache,
fee_history_cache_limit,
Expand Down
1 change: 0 additions & 1 deletion client/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ pub fn new_full(config: Configuration, cli: &Cli) -> Result<TaskManager, Service

move |deny_unsafe, subscription_task_executor: sc_rpc::SubscriptionTaskExecutor| {
let deps = crate::rpc::FullDeps {
backend: backend.clone(),
frontier_backend: match frontier_backend.clone() {
fc_db::Backend::KeyValue(b) => Arc::new(b),
fc_db::Backend::Sql(b) => Arc::new(b),
Expand Down
1 change: 0 additions & 1 deletion pallet/ethy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ pallet-assets-ext = { path = "../assets-ext" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
pallet-assets = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
seed-runtime = { path = "../../runtime" }

[features]
default = ["std"]
Expand Down
138 changes: 53 additions & 85 deletions pallet/ethy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ use crate::{
use codec::{Decode, Encode};
use ethereum_types::U64;
use frame_support::{
pallet_prelude::{OptionQuery, ValueQuery},
storage_alias,
traits::{UnixTime, ValidatorSet as ValidatorSetT},
StorageHasher, Twox64Concat,
Identity, Twox64Concat,
};
use scale_info::TypeInfo;
use seed_pallet_common::test_prelude::*;
use seed_primitives::{
ethy::{crypto::AuthorityId, EventProofId},
Signature,
};
use seed_runtime::migrations::{Map, Value};
use sp_application_crypto::RuntimeAppPublic;
use sp_core::{ByteArray, Get};
use sp_keystore::{testing::MemoryKeystore, Keystore, KeystoreExt};
Expand Down Expand Up @@ -258,9 +259,38 @@ impl MockReceiptBuilder {
}
}

#[storage_alias]
pub type BlockResponseAt<Test: Config> =
StorageMap<crate::Pallet<Test>, Identity, u64, MockBlockResponse>;

#[storage_alias]
pub type TransactionReceiptFor<Test: Config> =
StorageMap<crate::Pallet<Test>, Twox64Concat, EthHash, MockReceiptResponse>;

#[storage_alias]
pub type CallAt<Test: Config> =
StorageDoubleMap<crate::Pallet<Test>, Twox64Concat, u64, Twox64Concat, EthAddress, Vec<u8>>;

#[storage_alias]
pub type Forcing<Test: Config> = StorageValue<crate::Pallet<Test>, bool, ValueQuery>;

#[storage_alias]
pub type Validators<Test: Config> = StorageValue<crate::Pallet<Test>, Vec<AccountId>, ValueQuery>;

#[storage_alias]
pub type Timestamp<Test: Config> = StorageValue<crate::Pallet<Test>, u64, OptionQuery>;

#[storage_alias]
pub type LastCallResult<Test: Config> =
StorageValue<crate::Pallet<Test>, (EthCallId, CheckedEthCallResult), OptionQuery>;

#[storage_alias]
pub type LastCallFailure<Test: Config> =
StorageValue<crate::Pallet<Test>, (EthCallId, EthCallFailure), OptionQuery>;

/// set the block timestamp
pub fn mock_timestamp(now: u64) {
Value::unsafe_storage_put::<u64>(b"Test", b"Timestamp", now)
Timestamp::<Test>::put(now)
}

// get the system unix timestamp in seconds
Expand Down Expand Up @@ -321,12 +351,7 @@ impl MockEthereumRpcClient {
block_number: mock_block.number.unwrap().as_u64(),
timestamp: mock_block.timestamp,
};
Map::unsafe_storage_put::<MockBlockResponse>(
b"Test",
b"BlockResponseAt",
&Twox64Concat::hash(&block_number.encode()),
mock_block_response,
);
BlockResponseAt::<Test>::insert(block_number, mock_block_response)
}
/// Mock a tx receipt response for a hash
pub fn mock_transaction_receipt_for(tx_hash: EthHash, mock_tx_receipt: TransactionReceipt) {
Expand All @@ -338,20 +363,11 @@ impl MockEthereumRpcClient {
to: mock_tx_receipt.to,
logs: mock_tx_receipt.logs.into_iter().map(From::from).collect(),
};
Map::unsafe_storage_put::<MockReceiptResponse>(
b"Test",
b"TransactionReceiptFor",
&Twox64Concat::hash(&tx_hash.encode()),
mock_receipt_response,
);
TransactionReceiptFor::<Test>::insert(tx_hash, mock_receipt_response);
}
/// setup a mock returndata for an `eth_call` at `block` and `contract` address
pub fn mock_call_at(block_number: u64, contract: H160, return_data: &[u8]) {
let mut key = Twox64Concat::hash(&block_number.encode());
let key_2 = Twox64Concat::hash(&contract.encode());
key.extend_from_slice(&key_2);
println!("mock_call_at: {:?} : {:?}", block_number, key);
Map::unsafe_storage_put::<Vec<u8>>(b"Test", b"CallAt", &key, return_data.to_vec());
CallAt::<Test>::insert(block_number, contract, return_data.to_vec())
}
}

Expand All @@ -361,28 +377,8 @@ impl BridgeEthereumRpcApi for MockEthereumRpcClient {
block_number: LatestOrNumber,
) -> Result<Option<EthBlock>, BridgeRpcError> {
let mock_block_response = match block_number {
LatestOrNumber::Latest => {
let mut response: Vec<BlockNumber> = Map::unsafe_keys_get::<
BlockNumber,
MockBlockResponse,
Twox64Concat,
>(b"Test", b"BlockResponseAt");
if response.is_empty() {
return Ok(None)
}
response.sort();
let last_key = response.iter().last().unwrap();
Map::unsafe_storage_get::<MockBlockResponse>(
b"Test",
b"BlockResponseAt",
&Twox64Concat::hash(&last_key.encode()),
)
},
LatestOrNumber::Number(block) => Map::unsafe_storage_get::<MockBlockResponse>(
b"Test",
b"BlockResponseAt",
&Twox64Concat::hash(&block.encode()),
),
LatestOrNumber::Latest => BlockResponseAt::<Test>::iter().last().map(|x| x.1).or(None),
LatestOrNumber::Number(block) => BlockResponseAt::<Test>::get(block),
};
if mock_block_response.is_none() {
return Ok(None)
Expand All @@ -401,11 +397,7 @@ impl BridgeEthereumRpcApi for MockEthereumRpcClient {
fn get_transaction_receipt(
hash: EthHash,
) -> Result<Option<TransactionReceipt>, BridgeRpcError> {
let mock_receipt = Map::unsafe_storage_get::<MockReceiptResponse>(
b"Test",
b"TransactionReceiptFor",
&Twox64Concat::hash(&hash.encode()),
);
let mock_receipt = TransactionReceiptFor::<Test>::get(hash);
if mock_receipt.is_none() {
return Ok(None)
}
Expand All @@ -429,28 +421,10 @@ impl BridgeEthereumRpcApi for MockEthereumRpcClient {
) -> Result<Vec<u8>, BridgeRpcError> {
let block_number = match at_block {
LatestOrNumber::Number(n) => n,
LatestOrNumber::Latest => {
let mut response = Map::unsafe_keys_get::<
BlockNumber,
MockBlockResponse,
Twox64Concat,
>(b"Test", b"BlockResponseAt");
response.sort();
let last_key = response.iter().last().unwrap();
Map::unsafe_storage_get::<MockBlockResponse>(
b"Test",
b"BlockResponseAt",
&Twox64Concat::hash(&last_key.encode()),
)
.unwrap()
.block_number
},
LatestOrNumber::Latest =>
BlockResponseAt::<Test>::iter().last().unwrap().1.block_number,
};
let mut key = Twox64Concat::hash(&block_number.encode());
let key_2 = Twox64Concat::hash(&target.encode());
key.extend_from_slice(&key_2);
Map::unsafe_storage_get::<Vec<u8>>(b"Test", b"CallAt", &key)
.ok_or(BridgeRpcError::HttpFetch)
CallAt::<Test>::get(block_number, target).ok_or(BridgeRpcError::HttpFetch)
}
}

Expand All @@ -471,15 +445,15 @@ impl ValidatorSetT<AccountId> for MockValidatorSet {
}
/// Returns the active set of validators.
fn validators() -> Vec<Self::ValidatorId> {
Value::unsafe_storage_get::<Vec<AccountId>>(b"Test", b"Validators").unwrap_or_default()
Validators::<Test>::get()
}
}
impl MockValidatorSet {
/// Mock n validator stashes
pub fn mock_n_validators(n: u8) {
let validators: Vec<AccountId> =
(1..=n as u64).map(|i| H160::from_low_u64_be(i).into()).collect();
Value::unsafe_storage_put::<Vec<AccountId>>(b"Test", b"Validators", validators);
Validators::<Test>::put(validators);
}
}

Expand All @@ -501,31 +475,26 @@ impl EthCallOracleSubscriber for MockEthCallSubscriber {
block_number: u64,
block_timestamp: u64,
) {
Value::unsafe_storage_put::<(EthCallId, CheckedEthCallResult)>(
b"Test",
b"LastCallResult",
(call_id, CheckedEthCallResult::Ok(*return_data, block_number, block_timestamp)),
);
LastCallResult::<Test>::put((
call_id,
CheckedEthCallResult::Ok(*return_data, block_number, block_timestamp),
));
}
/// Stores the failed call info
/// Available via `Self::failed_call_for()`
fn on_eth_call_failed(call_id: Self::CallId, reason: EthCallFailure) {
Value::unsafe_storage_put::<(EthCallId, EthCallFailure)>(
b"Test",
b"LastCallFailure",
(call_id, reason),
);
LastCallFailure::<Test>::put((call_id, reason))
}
}

impl MockEthCallSubscriber {
/// Returns last known successful call, if any
pub fn success_result() -> Option<(EthCallId, CheckedEthCallResult)> {
Value::unsafe_storage_get::<(EthCallId, CheckedEthCallResult)>(b"Test", b"LastCallResult")
LastCallResult::<Test>::get()
}
/// Returns last known failed call, if any
pub fn failed_result() -> Option<(EthCallId, EthCallFailure)> {
Value::unsafe_storage_get::<(EthCallId, EthCallFailure)>(b"Test", b"LastCallFailure")
LastCallFailure::<Test>::get()
}
}

Expand All @@ -534,8 +503,7 @@ pub struct MockFinalSessionTracker;
impl FinalSessionTracker for MockFinalSessionTracker {
fn is_active_session_final() -> bool {
// at block 100, or if we are forcing, the active session is final
let forcing: bool =
Value::unsafe_storage_get::<bool>(b"Test", b"Forcing").unwrap_or_default();
let forcing: bool = Forcing::<Test>::get();
frame_system::Pallet::<Test>::block_number() == 100 || forcing
}
}
Expand All @@ -544,7 +512,7 @@ impl FinalSessionTracker for MockFinalSessionTracker {
pub struct MockUnixTime;
impl UnixTime for MockUnixTime {
fn now() -> core::time::Duration {
match Value::unsafe_storage_get::<u64>(b"Test", b"Timestamp") {
match Timestamp::<Test>::get() {
// Use configured value for tests requiring precise timestamps
Some(s) => core::time::Duration::new(s, 0),
// fallback, use block number to derive timestamp for tests that only care abut block
Expand Down
3 changes: 1 addition & 2 deletions pallet/ethy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ use seed_primitives::{
},
xrpl::XrplAccountId,
};
use seed_runtime::migrations::Value;
use sp_core::{bounded::WeakBoundedVec, ByteArray};
use sp_keystore::{testing::MemoryKeystore, Keystore};
use sp_runtime::{
Expand Down Expand Up @@ -1220,7 +1219,7 @@ fn force_new_era_with_scheduled_authority_change_works() {
assert!(NextAuthorityChange::<Test>::get().is_none());

// Simulate force new era
Value::unsafe_storage_put::<bool>(b"Test", b"Forcing", true);
Forcing::<Test>::put(true);

// Add a validator to the next_keys, simulating a change in validator during the last
// session
Expand Down
14 changes: 11 additions & 3 deletions pallet/futurepass/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use frame_support::traits::{Currency, ExistenceRequirement, InstanceFilter, Rese
use seed_pallet_common::test_prelude::*;
use seed_runtime::{
impls::{ProxyPalletProvider, ProxyType},
AnnouncementDepositBase, AnnouncementDepositFactor, ProxyDepositBase, ProxyDepositFactor,
AnnouncementDepositBase, AnnouncementDepositFactor, Inspect, ProxyDepositBase,
ProxyDepositFactor,
};
use sp_core::{ecdsa, Pair};

Expand Down Expand Up @@ -130,12 +131,19 @@ impl ProxyProvider<Test> for ProxyPalletProvider {
let (proxy_definitions, reserve_amount) = pallet_proxy::Proxies::<Test>::get(futurepass);
// get proxy_definitions length + 1 (cost of upcoming insertion); cost to reserve
let new_reserve = pallet_proxy::Pallet::<Test>::deposit(proxy_definitions.len() as u32 + 1);
let extra_reserve_required = new_reserve - reserve_amount + ExistentialDeposit::get();
let mut extra_reserve_required = new_reserve - reserve_amount;

let account_balance =
pallet_assets_ext::Pallet::<Test>::balance(MOCK_NATIVE_ASSET_ID, &futurepass);
let minimum_balance = ExistentialDeposit::get();
if account_balance < minimum_balance {
extra_reserve_required = extra_reserve_required.saturating_add(minimum_balance);
}
<pallet_balances::Pallet<Test> as Currency<_>>::transfer(
funder,
futurepass,
extra_reserve_required,
ExistenceRequirement::AllowDeath,
ExistenceRequirement::KeepAlive,
)?;
let proxy_type = ProxyType::try_from(*proxy_type)?;

Expand Down
Loading