Skip to content

Commit ea662d0

Browse files
authored
Update v0_1::ChainConfig::from(v0_3::ChainConfig) (#1886)
Update committable version in sequencer and use it to coerce a v3 Commitment into a v1 commitment. Co-authored-by: tbro <[email protected]>
1 parent 18b96df commit ea662d0

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/src/v0/v0_3/chain_config.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use committable::{Commitment, Committable};
33
use ethers::types::{Address, U256};
44
use itertools::Either;
55
use serde::{Deserialize, Serialize};
6-
use std::str::FromStr;
76

87
/// Global variables for an Espresso blockchain.
98
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
@@ -110,9 +109,8 @@ impl From<&v0_1::ResolvableChainConfig> for ResolvableChainConfig {
110109
Either::Left(chain_config) => ResolvableChainConfig {
111110
chain_config: Either::Left(ChainConfig::from(chain_config)),
112111
},
113-
// TODO does this work? is there a better way?
114112
Either::Right(c) => ResolvableChainConfig {
115-
chain_config: Either::Right(Commitment::from_str(&c.to_string()).unwrap()),
113+
chain_config: Either::Right(Commitment::from_raw(*c.as_ref())),
116114
},
117115
}
118116
}
@@ -173,3 +171,28 @@ impl Default for ChainConfig {
173171
}
174172
}
175173
}
174+
175+
#[cfg(test)]
176+
mod test {
177+
use super::*;
178+
179+
#[test]
180+
fn test_upgrade_chain_config_v3_resolvable_chain_config_from_v1() {
181+
let expectation: ResolvableChainConfig = ChainConfig::default().into();
182+
let v1_resolvable: v0_1::ResolvableChainConfig = v0_1::ChainConfig::default().into();
183+
let v3_resolvable: ResolvableChainConfig = ResolvableChainConfig::from(&v1_resolvable);
184+
assert_eq!(expectation, v3_resolvable);
185+
let expectation: ResolvableChainConfig = ChainConfig::default().commit().into();
186+
let v1_resolvable: v0_1::ResolvableChainConfig =
187+
v0_1::ChainConfig::default().commit().into();
188+
let v3_resolvable: ResolvableChainConfig = ResolvableChainConfig::from(&v1_resolvable);
189+
assert_eq!(expectation, v3_resolvable);
190+
}
191+
#[test]
192+
fn test_upgrade_chain_config_v1_chain_config_from_v3() {
193+
let expectation = v0_1::ChainConfig::default();
194+
let v3_chain_config = ChainConfig::default();
195+
let v1_chain_config = v0_1::ChainConfig::from(v3_chain_config);
196+
assert_eq!(expectation, v1_chain_config);
197+
}
198+
}

0 commit comments

Comments
 (0)