-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheip_1559.rs
58 lines (51 loc) · 1.83 KB
/
eip_1559.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use common::types::Result;
use common_chain_ids::EthChainId;
use derive_more::Constructor;
use ethereum_types::U256;
#[derive(Clone, Constructor)]
pub struct Eip1559 {}
impl Eip1559 {
pub fn get_activation_block_number(&self, eth_chain_id: &EthChainId) -> Result<U256> {
match eth_chain_id {
EthChainId::Mainnet => Ok(U256::from(12_965_000)),
EthChainId::Ropsten => Ok(U256::from(10_499_401)),
_ => Err(format!("{} does not have an `EIP1559` activation block number! ", eth_chain_id).into()),
}
}
pub fn is_active(&self, eth_chain_id: &EthChainId, block_number: U256) -> Result<bool> {
match eth_chain_id {
EthChainId::Mainnet | EthChainId::Ropsten => {
Ok(block_number >= self.get_activation_block_number(eth_chain_id)?)
},
EthChainId::Goerli | EthChainId::Sepolia => Ok(true),
_ => Ok(false),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn should_eip_1559_get_activation_block_number() {
let eip_1559 = Eip1559::new();
let chain_id = EthChainId::Mainnet;
let result = eip_1559.get_activation_block_number(&chain_id).unwrap();
let expected_result = U256::from(12_965_000);
assert_eq!(result, expected_result);
}
#[test]
fn eip_1559_should_be_active() {
let block_number = U256::from(13_000_000);
let eip_1559 = Eip1559::new();
let chain_id = EthChainId::Mainnet;
let result = eip_1559.is_active(&chain_id, block_number).unwrap();
assert!(result);
}
#[test]
fn eip_1559_should_not_be_active() {
let block_number = U256::from(12_000_000);
let eip_1559 = Eip1559::new();
let chain_id = EthChainId::Mainnet;
eip_1559.is_active(&chain_id, block_number).unwrap();
}
}