forked from ghostchain/ghost-node
		
	no need for finality delay to be an Option<u64>
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
		
							parent
							
								
									d8e934a98e
								
							
						
					
					
						commit
						7bb18939bd
					
				@ -1,6 +1,6 @@
 | 
			
		||||
[package]
 | 
			
		||||
name = "ghost-networks"
 | 
			
		||||
version = "0.1.7"
 | 
			
		||||
version = "0.1.8"
 | 
			
		||||
license.workspace = true
 | 
			
		||||
authors.workspace = true
 | 
			
		||||
edition.workspace = true
 | 
			
		||||
 | 
			
		||||
@ -30,9 +30,9 @@ fn prepare_network<T: Config>(
 | 
			
		||||
        default_endpoint: sp_std::vec![0x69; m as usize],
 | 
			
		||||
        gatekeeper,
 | 
			
		||||
        topic_name,
 | 
			
		||||
        finality_delay: Some(69),
 | 
			
		||||
        block_distance: 69,
 | 
			
		||||
        network_type: NetworkType::Evm,
 | 
			
		||||
        finality_delay: 69,
 | 
			
		||||
        block_distance: 69,
 | 
			
		||||
        incoming_fee: 0,
 | 
			
		||||
        outgoing_fee: 0,
 | 
			
		||||
    };
 | 
			
		||||
@ -107,7 +107,7 @@ benchmarks! {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    update_network_finality_delay {
 | 
			
		||||
        let delay = Some(1337);
 | 
			
		||||
        let delay = 1337;
 | 
			
		||||
        let (chain_id, network) = prepare_network::<T>(1, 1);
 | 
			
		||||
        let authority = T::UpdateOrigin::try_successful_origin()
 | 
			
		||||
            .map_err(|_| BenchmarkError::Weightless)?;
 | 
			
		||||
 | 
			
		||||
@ -54,8 +54,8 @@ pub struct NetworkData {
 | 
			
		||||
    pub default_endpoint: Vec<u8>,
 | 
			
		||||
    pub gatekeeper: Vec<u8>,
 | 
			
		||||
    pub topic_name: Vec<u8>,
 | 
			
		||||
    pub finality_delay: Option<u64>,
 | 
			
		||||
    pub network_type: NetworkType,
 | 
			
		||||
    pub finality_delay: u64,
 | 
			
		||||
    pub block_distance: u64,
 | 
			
		||||
    pub incoming_fee: u32,
 | 
			
		||||
    pub outgoing_fee: u32,
 | 
			
		||||
@ -157,7 +157,7 @@ pub mod module {
 | 
			
		||||
        NetworkRegistered { chain_id: T::NetworkId, network: NetworkData },
 | 
			
		||||
        NetworkNameUpdated { chain_id: T::NetworkId, chain_name: Vec<u8> },
 | 
			
		||||
        NetworkEndpointUpdated { chain_id: T::NetworkId, default_endpoint: Vec<u8> },
 | 
			
		||||
        NetworkFinalityDelayUpdated { chain_id: T::NetworkId, finality_delay: Option<u64> },
 | 
			
		||||
        NetworkFinalityDelayUpdated { chain_id: T::NetworkId, finality_delay: u64 },
 | 
			
		||||
        NetworkBlockDistanceUpdated { chain_id: T::NetworkId, block_distance: u64 },
 | 
			
		||||
        NetworkTypeUpdated { chain_id: T::NetworkId, network_type: NetworkType },
 | 
			
		||||
        NetworkGatekeeperUpdated { chain_id: T::NetworkId, gatekeeper: Vec<u8> },
 | 
			
		||||
@ -293,7 +293,7 @@ pub mod module {
 | 
			
		||||
        pub fn update_network_finality_delay(
 | 
			
		||||
            origin: OriginFor<T>,
 | 
			
		||||
            chain_id: T::NetworkId,
 | 
			
		||||
            finality_delay: Option<u64>,
 | 
			
		||||
            finality_delay: u64,
 | 
			
		||||
        ) -> DispatchResult {
 | 
			
		||||
            T::UpdateOrigin::ensure_origin_or_root(origin)?;
 | 
			
		||||
            Self::do_update_network_finality_delay(
 | 
			
		||||
@ -468,7 +468,7 @@ impl<T: Config> Pallet<T> {
 | 
			
		||||
    /// Update existent network default endpoint.
 | 
			
		||||
    pub fn do_update_network_finality_delay(
 | 
			
		||||
        chain_id: T::NetworkId,
 | 
			
		||||
        finality_delay: Option<u64>,
 | 
			
		||||
        finality_delay: u64,
 | 
			
		||||
    ) -> DispatchResult {
 | 
			
		||||
        Networks::<T>::try_mutate(&chain_id, |maybe_network| -> DispatchResult {
 | 
			
		||||
            ensure!(maybe_network.is_some(), Error::<T>::NetworkDoesNotExist);
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,7 @@ fn prepare_network_data() -> (u32, NetworkData) {
 | 
			
		||||
    (1u32, NetworkData {
 | 
			
		||||
        chain_name: "Ethereum".into(),
 | 
			
		||||
        default_endpoint: "https:://some-endpoint.my-server.com/v1/my-super-secret-key".into(),
 | 
			
		||||
        finality_delay: Some(69),
 | 
			
		||||
        finality_delay: 69,
 | 
			
		||||
        block_distance: 69,
 | 
			
		||||
        network_type: NetworkType::Evm,
 | 
			
		||||
        gatekeeper: b"0x1234567891234567891234567891234567891234".to_vec(),
 | 
			
		||||
@ -119,7 +119,7 @@ fn could_update_network_endpoint_from_authority_account() {
 | 
			
		||||
fn could_update_network_finality_delay_from_authority_account() {
 | 
			
		||||
    ExtBuilder::build()
 | 
			
		||||
        .execute_with(|| {
 | 
			
		||||
            let new_finality_delay = Some(1337);
 | 
			
		||||
            let new_finality_delay = 1337;
 | 
			
		||||
            let (chain_id, network) = prepare_network_data();
 | 
			
		||||
            register_and_check_network(chain_id, network.clone());
 | 
			
		||||
            assert_ok!(GhostNetworks::update_network_finality_delay(
 | 
			
		||||
@ -311,18 +311,19 @@ fn could_not_update_network_finality_delay_from_random_account() {
 | 
			
		||||
    ExtBuilder::build()
 | 
			
		||||
        .execute_with(|| {
 | 
			
		||||
            let (chain_id, network) = prepare_network_data();
 | 
			
		||||
            let finality_delay = 1337;
 | 
			
		||||
            register_and_check_network(chain_id, network.clone());
 | 
			
		||||
            assert_err!(GhostNetworks::update_network_finality_delay(
 | 
			
		||||
                    RuntimeOrigin::signed(RegistererAccount::get()),
 | 
			
		||||
                    chain_id, Some(1337)),
 | 
			
		||||
                    chain_id, finality_delay),
 | 
			
		||||
                    DispatchError::BadOrigin);
 | 
			
		||||
            assert_err!(GhostNetworks::update_network_finality_delay(
 | 
			
		||||
                    RuntimeOrigin::signed(RemoverAccount::get()),
 | 
			
		||||
                    chain_id, Some(1337)),
 | 
			
		||||
                    chain_id, finality_delay),
 | 
			
		||||
                    DispatchError::BadOrigin);
 | 
			
		||||
            assert_err!(GhostNetworks::update_network_finality_delay(
 | 
			
		||||
                    RuntimeOrigin::signed(RandomAccount::get()),
 | 
			
		||||
                    chain_id, Some(1337)),
 | 
			
		||||
                    chain_id, finality_delay),
 | 
			
		||||
                    DispatchError::BadOrigin);
 | 
			
		||||
            assert_eq!(Networks::<Test>::get(chain_id), Some(network));
 | 
			
		||||
        });
 | 
			
		||||
@ -497,7 +498,7 @@ fn could_not_update_finality_delay_for_non_existent_network() {
 | 
			
		||||
            assert_eq!(Networks::<Test>::get(chain_id), None);
 | 
			
		||||
            assert_err!(GhostNetworks::update_network_finality_delay(
 | 
			
		||||
                    RuntimeOrigin::signed(UpdaterAccount::get()),
 | 
			
		||||
                    chain_id, Some(1337)),
 | 
			
		||||
                    chain_id, 1337),
 | 
			
		||||
                    crate::Error::<Test>::NetworkDoesNotExist);
 | 
			
		||||
            assert_eq!(Networks::<Test>::get(chain_id), None);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user