feat: implement Artifact for serde_json (#885)

This commit is contained in:
Matthias Seitz 2022-02-08 23:48:53 +01:00 committed by GitHub
parent 6453b1e833
commit 67271eba68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -565,3 +565,16 @@ impl ArtifactOutput for MinimalCombinedArtifactsHardhatFallback {
MinimalCombinedArtifacts::contract_to_artifact(file, name, contract)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_artifact() {
fn assert_artifact<T: Artifact>() {}
assert_artifact::<CompactContractBytecode>();
assert_artifact::<serde_json::Value>();
}
}

View File

@ -801,7 +801,7 @@ impl From<Contract> for ContractBytecode {
///
/// Unlike `CompactContractSome` which contains the `BytecodeObject`, this holds the whole
/// `Bytecode` object.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
pub struct CompactContractBytecode {
/// The Ethereum Contract ABI. If empty, it is represented as an empty
/// array. See https://docs.soliditylang.org/en/develop/abi-spec.html
@ -1002,6 +1002,12 @@ impl From<serde_json::Value> for CompactContract {
}
}
impl From<serde_json::Value> for CompactContractBytecode {
fn from(val: serde_json::Value) -> Self {
serde_json::from_value(val).unwrap_or_default()
}
}
impl From<ContractBytecode> for CompactContract {
fn from(c: ContractBytecode) -> Self {
let ContractBytecode { abi, bytecode, deployed_bytecode } = c;