-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbytecode.rs
More file actions
39 lines (32 loc) · 972 Bytes
/
bytecode.rs
File metadata and controls
39 lines (32 loc) · 972 Bytes
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
use alloy_primitives::Bytes;
use revm::{bytecode::BytecodeDecodeError, state::Bytecode};
use serde::{Deserialize, Serialize};
#[derive(Default, Debug, Serialize, Deserialize)]
pub struct StoredBytecode {
pub raw: Bytes,
}
impl From<Bytecode> for StoredBytecode {
fn from(code: Bytecode) -> Self {
Self {
raw: code.original_bytes(),
}
}
}
impl TryFrom<StoredBytecode> for Bytecode {
type Error = BytecodeDecodeError;
fn try_from(stored: StoredBytecode) -> Result<Self, Self::Error> {
Bytecode::new_raw_checked(stored.raw)
}
}
#[cfg(test)]
mod tests {
use crate::bytecode::StoredBytecode;
use alloy_primitives::Bytes;
use revm::state::Bytecode;
#[test]
fn test_bytecode() {
let raw_bytecode = Bytecode::new_raw(Bytes::from_static(&[1, 2, 3, 4]));
let stored = StoredBytecode::from(raw_bytecode);
assert_eq!(stored.raw, Bytes::from_static(&[1, 2, 3, 4]));
}
}