1
// This file is part of Substrate.
2

            
3
// Copyright (C) Parity Technologies (UK) Ltd.
4
// SPDX-License-Identifier: Apache-2.0
5

            
6
// Licensed under the Apache License, Version 2.0 (the "License");
7
// you may not use this file except in compliance with the License.
8
// You may obtain a copy of the License at
9
//
10
// http://www.apache.org/licenses/LICENSE-2.0
11
//
12
// Unless required by applicable law or agreed to in writing, software
13
// distributed under the License is distributed on an "AS IS" BASIS,
14
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
// See the License for the specific language governing permissions and
16
// limitations under the License.
17

            
18
pub mod constants {
19
    use frame_support::{
20
        parameter_types,
21
        weights::{constants, RuntimeDbWeight},
22
    };
23

            
24
    parameter_types! {
25
        /// By default, Substrate uses `RocksDB`, so this will be the weight used throughout
26
        /// the runtime.
27
        pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight {
28
            read: 25_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
29
            write: 100_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
30
        };
31
    }
32

            
33
    #[cfg(test)]
34
    mod test_db_weights {
35
        use {super::constants::RocksDbWeight as W, frame_support::weights::constants};
36

            
37
        /// Checks that all weights exist and have sane values.
38
        // NOTE: If this test fails but you are sure that the generated values are fine,
39
        // you can delete it.
40
        #[test]
41
1
        fn sane() {
42
1
            // At least 1 µs.
43
1
            assert!(
44
1
                W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
45
                "Read weight should be at least 1 µs."
46
            );
47
1
            assert!(
48
1
                W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
49
                "Write weight should be at least 1 µs."
50
            );
51
            // At most 1 ms.
52
1
            assert!(
53
1
                W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
54
                "Read weight should be at most 1 ms."
55
            );
56
1
            assert!(
57
1
                W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
58
                "Write weight should be at most 1 ms."
59
            );
60
1
        }
61
    }
62
}