1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Tanssi is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>
16

            
17
use hex_literal::hex;
18
use snowbridge_beacon_primitives::{Fork, ForkVersions};
19

            
20
enum BuildEnv {
21
    Prod,
22
    Benchmark,
23
    TestLike,
24
}
25

            
26
18
const fn current_env() -> BuildEnv {
27
18
    if cfg!(feature = "runtime-benchmarks") {
28
        BuildEnv::Benchmark
29
18
    } else if cfg!(any(feature = "std", feature = "fast-runtime", test)) {
30
18
        BuildEnv::TestLike
31
    } else {
32
        BuildEnv::Prod
33
    }
34
18
}
35

            
36
// Very stupid, but benchmarks are written assuming a fork epoch,
37
// and test vectors assuming another one
38
// We need allow dead code here because for regular builds this variable is not used
39
// This variable is only used in test, fast-runtime or runtime-benchmarks
40
pub const ELECTRA_TEST_FORK_EPOCH: u64 = match current_env() {
41
    BuildEnv::Benchmark => 80000000000,
42
    _ => 0,
43
};
44

            
45
// TODO: change this when parity has new tests matching fulu
46
pub const FULU_TEST_FORK_EPOCH: u64 = match current_env() {
47
    BuildEnv::Benchmark => 80000000001,
48
    _ => 5000000000,
49
};
50

            
51
// For tests, benchmarks and fast-runtime configurations we use the mocked fork versions
52
18
pub const fn fork_versions() -> ForkVersions {
53
18
    match current_env() {
54
        BuildEnv::Prod => ForkVersions {
55
            genesis: Fork {
56
                version: hex!("90000069"),
57
                epoch: 0,
58
            },
59
            altair: Fork {
60
                version: hex!("90000070"),
61
                epoch: 50,
62
            },
63
            bellatrix: Fork {
64
                version: hex!("90000071"),
65
                epoch: 100,
66
            },
67
            capella: Fork {
68
                version: hex!("90000072"),
69
                epoch: 56832,
70
            },
71
            deneb: Fork {
72
                version: hex!("90000073"),
73
                epoch: 132608,
74
            },
75
            electra: Fork {
76
                version: hex!("90000074"),
77
                epoch: 222464,
78
            },
79
            fulu: Fork {
80
                version: hex!("90000075"),
81
                epoch: 272640, // https://notes.ethereum.org/@bbusa/fusaka-bpo-timeline
82
            },
83
        },
84
18
        _ => ForkVersions {
85
18
            genesis: Fork {
86
18
                version: [0, 0, 0, 0],
87
18
                epoch: 0,
88
18
            },
89
18
            altair: Fork {
90
18
                version: [1, 0, 0, 0],
91
18
                epoch: 0,
92
18
            },
93
18
            bellatrix: Fork {
94
18
                version: [2, 0, 0, 0],
95
18
                epoch: 0,
96
18
            },
97
18
            capella: Fork {
98
18
                version: [3, 0, 0, 0],
99
18
                epoch: 0,
100
18
            },
101
18
            deneb: Fork {
102
18
                version: [4, 0, 0, 0],
103
18
                epoch: 0,
104
18
            },
105
18
            electra: Fork {
106
18
                version: [5, 0, 0, 0],
107
18
                epoch: ELECTRA_TEST_FORK_EPOCH,
108
18
            },
109
18
            fulu: Fork {
110
18
                version: [6, 0, 0, 0],
111
18
                epoch: FULU_TEST_FORK_EPOCH,
112
18
            },
113
18
        },
114
    }
115
18
}