Skip to content

Commit 4a76d94

Browse files
committed
Hide MockApi enum
1 parent ae75505 commit 4a76d94

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

packages/vm/src/testing/mock.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ pub fn mock_backend_with_balances(
4242
/// trims off zeros for the reverse operation.
4343
/// This is not really smart, but allows us to see a difference (and consistent length for canonical adddresses).
4444
#[derive(Copy, Clone)]
45-
pub enum MockApi {
45+
pub struct MockApi(MockApiImpl);
46+
47+
#[derive(Copy, Clone)]
48+
enum MockApiImpl {
4649
/// With this variant, all calls to the API fail with BackendError::Unknown
4750
/// containing the given message
4851
Error(&'static str),
@@ -55,7 +58,7 @@ pub enum MockApi {
5558

5659
impl MockApi {
5760
pub fn new_failing(backend_error: &'static str) -> Self {
58-
MockApi::Error(backend_error)
61+
Self(MockApiImpl::Error(backend_error))
5962
}
6063

6164
/// Returns [MockApi] with Bech32 prefix set to provided value.
@@ -74,9 +77,9 @@ impl MockApi {
7477
/// assert_eq!(addr.as_str(), "juno1h34lmpywh4upnjdg90cjf4j70aee6z8qqfspugamjp42e4q28kqsksmtyp");
7578
/// ```
7679
pub fn with_prefix(self, prefix: &'static str) -> Self {
77-
Self::Bech32 {
80+
Self(MockApiImpl::Bech32 {
7881
bech32_prefix: prefix,
79-
}
82+
})
8083
}
8184

8285
/// Returns an address built from provided input string.
@@ -100,9 +103,9 @@ impl MockApi {
100103
///
101104
pub fn addr_make(&self, input: &str) -> String {
102105
// handle error case
103-
let bech32_prefix = match self {
104-
MockApi::Error(e) => panic!("Generating address failed: {e}"),
105-
MockApi::Bech32 { bech32_prefix } => *bech32_prefix,
106+
let bech32_prefix = match self.0 {
107+
MockApiImpl::Error(e) => panic!("Generating address failed: {e}"),
108+
MockApiImpl::Bech32 { bech32_prefix } => bech32_prefix,
106109
};
107110

108111
let digest = Sha256::digest(input).to_vec();
@@ -115,9 +118,9 @@ impl MockApi {
115118

116119
impl Default for MockApi {
117120
fn default() -> Self {
118-
MockApi::Bech32 {
121+
Self(MockApiImpl::Bech32 {
119122
bech32_prefix: BECH32_PREFIX,
120-
}
123+
})
121124
}
122125
}
123126

@@ -126,9 +129,9 @@ impl BackendApi for MockApi {
126129
let gas_info = GasInfo::with_cost(GAS_COST_CANONICALIZE);
127130

128131
// handle error case
129-
let bech32_prefix = match self {
130-
MockApi::Error(e) => return (Err(BackendError::unknown(*e)), gas_info),
131-
MockApi::Bech32 { bech32_prefix } => *bech32_prefix,
132+
let bech32_prefix = match self.0 {
133+
MockApiImpl::Error(e) => return (Err(BackendError::unknown(e)), gas_info),
134+
MockApiImpl::Bech32 { bech32_prefix } => bech32_prefix,
132135
};
133136

134137
match decode(input) {
@@ -157,9 +160,9 @@ impl BackendApi for MockApi {
157160
let gas_info = GasInfo::with_cost(GAS_COST_HUMANIZE);
158161

159162
// handle error case
160-
let bech32_prefix = match self {
161-
MockApi::Error(e) => return (Err(BackendError::unknown(*e)), gas_info),
162-
MockApi::Bech32 { bech32_prefix } => *bech32_prefix,
163+
let bech32_prefix = match self.0 {
164+
MockApiImpl::Error(e) => return (Err(BackendError::unknown(e)), gas_info),
165+
MockApiImpl::Bech32 { bech32_prefix } => bech32_prefix,
163166
};
164167

165168
try_br!((validate_length(canonical), gas_info));

0 commit comments

Comments
 (0)