diff --git a/ethers-solc/src/artifacts/bytecode.rs b/ethers-solc/src/artifacts/bytecode.rs index 6673e089..0cdac2d8 100644 --- a/ethers-solc/src/artifacts/bytecode.rs +++ b/ethers-solc/src/artifacts/bytecode.rs @@ -352,10 +352,10 @@ impl BytecodeObject { } } -// Returns a not deployable bytecode by default as empty +// Returns an empty bytecode object impl Default for BytecodeObject { fn default() -> Self { - BytecodeObject::Unlinked("".to_string()) + BytecodeObject::Bytecode(Default::default()) } } @@ -457,3 +457,31 @@ impl From for DeployedBytecode { } } } + +#[cfg(test)] +mod tests { + use crate::{artifacts::ContractBytecode, ConfigurableContractArtifact}; + + #[test] + fn test_empty_bytecode() { + let empty = r#" + { + "abi": [], + "bytecode": { + "object": "0x", + "linkReferences": {} + }, + "deployedBytecode": { + "object": "0x", + "linkReferences": {} + } + } + "#; + + let artifact: ConfigurableContractArtifact = serde_json::from_str(empty).unwrap(); + let contract = artifact.into_contract_bytecode(); + let bytecode: ContractBytecode = contract.into(); + let bytecode = bytecode.unwrap(); + assert!(!bytecode.bytecode.object.is_unlinked()); + } +}