Skip to content

Commit

Permalink
remove getter
Browse files Browse the repository at this point in the history
  • Loading branch information
Aideepakchaudhary committed Oct 24, 2024
1 parent 9ff2c4e commit 1bcb8b8
Show file tree
Hide file tree
Showing 21 changed files with 213 additions and 241 deletions.
16 changes: 5 additions & 11 deletions pallets/chainbridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,19 @@ pub mod pallet {

/// All whitelisted chains and their respective transaction counts
#[pallet::storage]
#[pallet::getter(fn chains)]
pub type ChainNonces<T: Config> = StorageMap<_, Blake2_256, ChainId, DepositNonce>;

/// Tracks current relayer set
#[pallet::storage]
#[pallet::getter(fn relayers)]
pub type Relayers<T: Config> = StorageMap<_, Blake2_256, T::AccountId, bool>;

/// Utilized by the bridge software to map resource IDs to actual methods
#[pallet::storage]
#[pallet::getter(fn resources)]
pub type Resources<T: Config> = StorageMap<_, Blake2_256, ResourceId, Vec<u8>>;

/// All known proposals.
/// The key is the hash of the call and the deposit ID, to ensure it's unique
#[pallet::storage]
#[pallet::getter(fn votes)]
pub type Votes<T: Config> = StorageDoubleMap<
_,
Blake2_256,
Expand All @@ -190,7 +186,6 @@ pub mod pallet {

/// Number of votes required for a proposal to execute
#[pallet::storage]
#[pallet::getter(fn relayer_threshold)]
pub type RelayerThreshold<T: Config> =
StorageValue<Value = u32, QueryKind = ValueQuery, OnEmpty = DefaultRelayerThreshold<T>>;

Expand All @@ -201,7 +196,6 @@ pub mod pallet {

/// Number of relayers in set
#[pallet::storage]
#[pallet::getter(fn relayer_count)]
pub type RelayerCount<T: Config> =
StorageValue<Value = u32, QueryKind = ValueQuery, OnEmpty = DefaultRelayerCount<T>>;

Expand Down Expand Up @@ -435,7 +429,7 @@ pub mod pallet {

/// Checks if who is a relayer
pub fn is_relayer(who: &T::AccountId) -> bool {
Self::relayers(who).unwrap_or(false)
Relayers::<T>::get(who).unwrap_or(false)
}

/// Provides an AccountId for the pallet.
Expand All @@ -446,18 +440,18 @@ pub mod pallet {

/// Asserts if a resource is registered
pub fn resource_exists(id: ResourceId) -> bool {
Self::resources(id).is_some()
Resources::<T>::get(id).is_some()
}

/// Checks if a chain exists as a whitelisted destination
pub fn chain_whitelisted(id: ChainId) -> bool {
Self::chains(id).is_some()
ChainNonces::<T>::get(id).is_some()
}

/// Increments the deposit nonce for the specified chain ID
fn bump_nonce(id: ChainId) -> DepositNonce {
let nonce = Self::chains(id).unwrap_or_default() + 1;
<ChainNonces<T>>::insert(id, nonce);
let nonce = ChainNonces::<T>::get(id).unwrap_or_default() + 1;
ChainNonces::<T>::insert(id, nonce);
nonce
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/chainbridge/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn new_test_ext_initialized(
t.execute_with(|| {
// Set and check threshold
assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD));
assert_eq!(Bridge::relayer_threshold(), TEST_THRESHOLD);
assert_eq!(RelayerThreshold::<Test>::get(), TEST_THRESHOLD);
// Add relayers
assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_A));
assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_B));
Expand Down
36 changes: 18 additions & 18 deletions pallets/chainbridge/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ fn setup_resources() {
let method2 = "Pallet.do_somethingElse".as_bytes().to_vec();

assert_ok!(Bridge::set_resource(RuntimeOrigin::root(), id, method.clone()));
assert_eq!(Bridge::resources(id), Some(method));
assert_eq!(Resources::<Test>::get(id), Some(method));

assert_ok!(Bridge::set_resource(RuntimeOrigin::root(), id, method2.clone()));
assert_eq!(Bridge::resources(id), Some(method2));
assert_eq!(Resources::<Test>::get(id), Some(method2));

assert_ok!(Bridge::remove_resource(RuntimeOrigin::root(), id));
assert_eq!(Bridge::resources(id), None);
assert_eq!(Resources::<Test>::get(id), None);
})
}

Expand Down Expand Up @@ -233,12 +233,12 @@ fn asset_transfer_invalid_chain() {
fn add_remove_relayer() {
new_test_ext().execute_with(|| {
assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD,));
assert_eq!(Bridge::relayer_count(), 0);
assert_eq!(RelayerCount::<Test>::get(), 0);

assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_A));
assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_B));
assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_C));
assert_eq!(Bridge::relayer_count(), 3);
assert_eq!(RelayerCount::<Test>::get(), 3);

// Already exists
assert_noop!(
Expand All @@ -248,12 +248,12 @@ fn add_remove_relayer() {

// Confirm removal
assert_ok!(Bridge::remove_relayer(RuntimeOrigin::root(), RELAYER_B));
assert_eq!(Bridge::relayer_count(), 2);
assert_eq!(RelayerCount::<Test>::get(), 2);
assert_noop!(
Bridge::remove_relayer(RuntimeOrigin::root(), RELAYER_B),
Error::<Test>::RelayerInvalid
);
assert_eq!(Bridge::relayer_count(), 2);
assert_eq!(RelayerCount::<Test>::get(), 2);

assert_events(vec![
RuntimeEvent::Bridge(Event::RelayerAdded(RELAYER_A)),
Expand Down Expand Up @@ -285,7 +285,7 @@ fn create_sucessful_proposal() {
r_id,
Box::new(proposal.clone())
));
let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap();
let prop = Votes::<Test>::get(src_id, (prop_id, proposal.clone())).unwrap();
let expected = ProposalVotes {
votes_for: vec![RELAYER_A],
votes_against: vec![],
Expand All @@ -302,7 +302,7 @@ fn create_sucessful_proposal() {
r_id,
Box::new(proposal.clone())
));
let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap();
let prop = Votes::<Test>::get(src_id, (prop_id, proposal.clone())).unwrap();
let expected = ProposalVotes {
votes_for: vec![RELAYER_A],
votes_against: vec![RELAYER_B],
Expand All @@ -319,7 +319,7 @@ fn create_sucessful_proposal() {
r_id,
Box::new(proposal.clone())
));
let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap();
let prop = Votes::<Test>::get(src_id, (prop_id, proposal)).unwrap();
let expected = ProposalVotes {
votes_for: vec![RELAYER_A, RELAYER_C],
votes_against: vec![RELAYER_B],
Expand Down Expand Up @@ -355,7 +355,7 @@ fn create_unsucessful_proposal() {
r_id,
Box::new(proposal.clone())
));
let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap();
let prop = Votes::<Test>::get(src_id, (prop_id, proposal.clone())).unwrap();
let expected = ProposalVotes {
votes_for: vec![RELAYER_A],
votes_against: vec![],
Expand All @@ -372,7 +372,7 @@ fn create_unsucessful_proposal() {
r_id,
Box::new(proposal.clone())
));
let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap();
let prop = Votes::<Test>::get(src_id, (prop_id, proposal.clone())).unwrap();
let expected = ProposalVotes {
votes_for: vec![RELAYER_A],
votes_against: vec![RELAYER_B],
Expand All @@ -389,7 +389,7 @@ fn create_unsucessful_proposal() {
r_id,
Box::new(proposal.clone())
));
let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap();
let prop = Votes::<Test>::get(src_id, (prop_id, proposal)).unwrap();
let expected = ProposalVotes {
votes_for: vec![RELAYER_A],
votes_against: vec![RELAYER_B, RELAYER_C],
Expand Down Expand Up @@ -427,7 +427,7 @@ fn execute_after_threshold_change() {
r_id,
Box::new(proposal.clone())
));
let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap();
let prop = Votes::<Test>::get(src_id, (prop_id, proposal.clone())).unwrap();
let expected = ProposalVotes {
votes_for: vec![RELAYER_A],
votes_against: vec![],
Expand All @@ -447,7 +447,7 @@ fn execute_after_threshold_change() {
Box::new(proposal.clone())
));

let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap();
let prop = Votes::<Test>::get(src_id, (prop_id, proposal)).unwrap();
let expected = ProposalVotes {
votes_for: vec![RELAYER_A],
votes_against: vec![],
Expand Down Expand Up @@ -485,7 +485,7 @@ fn proposal_expires() {
r_id,
Box::new(proposal.clone())
));
let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap();
let prop = Votes::<Test>::get(src_id, (prop_id, proposal.clone())).unwrap();
let expected = ProposalVotes {
votes_for: vec![RELAYER_A],
votes_against: vec![],
Expand All @@ -510,7 +510,7 @@ fn proposal_expires() {
);

// Proposal state should remain unchanged
let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap();
let prop = Votes::<Test>::get(src_id, (prop_id, proposal.clone())).unwrap();
let expected = ProposalVotes {
votes_for: vec![RELAYER_A],
votes_against: vec![],
Expand All @@ -529,7 +529,7 @@ fn proposal_expires() {
),
Error::<Test>::ProposalExpired
);
let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap();
let prop = Votes::<Test>::get(src_id, (prop_id, proposal)).unwrap();
let expected = ProposalVotes {
votes_for: vec![RELAYER_A],
votes_against: vec![],
Expand Down
9 changes: 4 additions & 5 deletions pallets/ddc-clusters-gov/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ pub mod pallet {
}

#[pallet::storage]
#[pallet::getter(fn proposal_of)]
pub type ClusterProposal<T: Config> = StorageMap<
_,
Identity,
Expand All @@ -161,13 +160,11 @@ pub mod pallet {

/// Votes on a given cluster proposal, if it is ongoing.
#[pallet::storage]
#[pallet::getter(fn voting)]
pub type ClusterProposalVoting<T: Config> =
StorageMap<_, Identity, ClusterId, Votes<T::AccountId, BlockNumberFor<T>>, OptionQuery>;

/// Public referendums initiated by clusters
#[pallet::storage]
#[pallet::getter(fn submission_depositor)]
pub type SubmissionDeposits<T: Config> =
StorageMap<_, Identity, ReferendumIndex, SubmissionDeposit<T::AccountId>, OptionQuery>;

Expand Down Expand Up @@ -534,7 +531,8 @@ pub mod pallet {
cluster_id: ClusterId,
approve: bool,
) -> Result<bool, DispatchError> {
let mut voting = Self::voting(cluster_id).ok_or(Error::<T>::ProposalMissing)?;
let mut voting =
ClusterProposalVoting::<T>::get(cluster_id).ok_or(Error::<T>::ProposalMissing)?;

let position_yes = voting.ayes.iter().position(|a| a == &voter_id);
let position_no = voting.nays.iter().position(|a| a == &voter_id);
Expand Down Expand Up @@ -579,7 +577,8 @@ pub mod pallet {

/// Close a vote that is either approved, disapproved or whose voting period has ended.
fn do_close(cluster_id: ClusterId, caller_id: T::AccountId) -> DispatchResultWithPostInfo {
let voting = Self::voting(cluster_id).ok_or(Error::<T>::ProposalMissing)?;
let voting =
ClusterProposalVoting::<T>::get(cluster_id).ok_or(Error::<T>::ProposalMissing)?;

let mut no_votes = voting.nays.len() as MemberCount;
let mut yes_votes = voting.ayes.len() as MemberCount;
Expand Down
4 changes: 0 additions & 4 deletions pallets/ddc-clusters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,10 @@ pub mod pallet {
}

#[pallet::storage]
#[pallet::getter(fn clusters)]
pub type Clusters<T: Config> =
StorageMap<_, Blake2_128Concat, ClusterId, Cluster<T::AccountId>>;

#[pallet::storage]
#[pallet::getter(fn clusters_protocol_params)]
pub type ClustersGovParams<T: Config> = StorageMap<
_,
Twox64Concat,
Expand All @@ -152,7 +150,6 @@ pub mod pallet {
>;

#[pallet::storage]
#[pallet::getter(fn clusters_nodes)]
pub type ClustersNodes<T: Config> = StorageDoubleMap<
_,
Blake2_128Concat,
Expand All @@ -164,7 +161,6 @@ pub mod pallet {
>;

#[pallet::storage]
#[pallet::getter(fn clusters_nodes_stats)]
pub type ClustersNodesStats<T: Config> =
StorageMap<_, Twox64Concat, ClusterId, ClusterNodesStats>;

Expand Down
7 changes: 3 additions & 4 deletions pallets/ddc-clusters/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ fn create_cluster_works() {
cluster_protocol_params.clone()
));

let created_cluster = DdcClusters::clusters(cluster_id).unwrap();
let created_cluster = Clusters::<Test>::get(cluster_id).unwrap();
assert_eq!(created_cluster.cluster_id, cluster_id);
assert_eq!(created_cluster.manager_id, cluster_manager_id);
assert_eq!(created_cluster.reserve_id, cluster_reserve_id);
assert_eq!(created_cluster.props.node_provider_auth_contract, Some(auth_contract.clone()));

let created_cluster_protocol_params =
DdcClusters::clusters_protocol_params(cluster_id).unwrap();
let created_cluster_protocol_params = ClustersGovParams::<Test>::get(cluster_id).unwrap();
assert_eq!(
created_cluster_protocol_params.treasury_share,
cluster_protocol_params.treasury_share
Expand Down Expand Up @@ -482,7 +481,7 @@ fn set_cluster_params_works() {
},
));

let updated_cluster = DdcClusters::clusters(cluster_id).unwrap();
let updated_cluster = Clusters::<Test>::get(cluster_id).unwrap();
assert_eq!(updated_cluster.props.node_provider_auth_contract, Some(auth_contract_2));
assert_eq!(updated_cluster.props.erasure_coding_required, 4);
assert_eq!(updated_cluster.props.erasure_coding_total, 6);
Expand Down
2 changes: 1 addition & 1 deletion pallets/ddc-customers/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ benchmarks! {
whitelist_account!(user);
}: _(RawOrigin::Signed(user), cluster_id, bucket_params)
verify {
assert_eq!(Pallet::<T>::buckets_count(), 1);
assert_eq!(BucketsCount::<T>::get(), 1);
}

deposit {
Expand Down
Loading

0 comments on commit 1bcb8b8

Please sign in to comment.