Skip to content

Commit

Permalink
feat: remove deprecated feeder gateway methods
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Dec 9, 2023
1 parent fec81d1 commit d38d1ec
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 1,338 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

**Complete Starknet library in Rust[](https://www.reddit.com/r/rust/comments/12e7tdb/rust_trademark_policy_feedback_form/)**

![starknet-version-v0.12.1](https://img.shields.io/badge/Starknet_Version-v0.12.1-2ea44f?logo=ethereum)
![starknet-version-v0.12.3](https://img.shields.io/badge/Starknet_Version-v0.12.3-2ea44f?logo=ethereum)
[![jsonrpc-spec-v0.5.1](https://img.shields.io/badge/JSON--RPC-v0.5.1-2ea44f?logo=ethereum)](https://github.com/starkware-libs/starknet-specs/tree/v0.5.1)
[![linting-badge](https://github.com/xJonathanLEI/starknet-rs/actions/workflows/lint.yaml/badge.svg?branch=master)](https://github.com/xJonathanLEI/starknet-rs/actions/workflows/lint.yaml)
[![crates-badge](https://img.shields.io/crates/v/starknet.svg)](https://crates.io/crates/starknet)
Expand Down
81 changes: 0 additions & 81 deletions starknet-core/src/types/contract/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,6 @@ pub struct LegacyParentLocation {
pub remark: String,
}

#[serde_as]
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))]
pub struct LegacyContractCode {
#[serde_as(as = "Vec<UfeHex>")]
pub bytecode: Vec<FieldElement>,
pub abi: Option<Vec<RawLegacyAbiEntry>>,
}

#[derive(Debug, Clone)]
pub enum RawLegacyAbiEntry {
Constructor(RawLegacyConstructor),
Expand Down Expand Up @@ -985,76 +976,4 @@ mod tests {

assert_eq!(original_text, serialized);
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_contract_code_deser() {
let raw = include_str!("../../../test-data/raw_gateway_responses/get_code/1_code.txt");

let cc: LegacyContractCode = serde_json::from_str(raw).unwrap();
let abi = cc.abi.unwrap();

assert_eq!(cc.bytecode.len(), 1347);
if let RawLegacyAbiEntry::Constructor(c) = &abi[0] {
assert_eq!(c.name, "constructor");
assert_eq!(c.inputs.len(), 2);
} else {
panic!("Did not deserialize AbiEntry::Constructor properly")
}

if let RawLegacyAbiEntry::Function(f) = &abi[1] {
assert_eq!(f.name, "execute");
assert_eq!(f.inputs.len(), 5);
assert_eq!(f.state_mutability, None);
} else {
panic!("Did not deserialize AbiEntry::Function properly");
}

if let RawLegacyAbiEntry::Function(f) = &abi[9] {
assert_eq!(f.name, "is_valid_signature");
assert_eq!(f.inputs.len(), 3);
assert_eq!(f.state_mutability, Some(FunctionStateMutability::View));
} else {
panic!("Did not deserialize AbiEntry::Function properly");
}
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_contract_code_deser_all_abi_types() {
// $ curl "https://alpha4.starknet.io/feeder_gateway/get_code?contractAddress=0x06ef97a90be1c0458f6e7bd1faf05021f2d81211f658155df0c5c97a39eb2d12"
// Contract built from: https://github.com/starkware-libs/cairo-lang/blob/3d33c4e829a87bc3d88cf04ed6a489e788918b8b/src/starkware/starknet/compiler/starknet_preprocessor_test.py#L143
let raw =
include_str!("../../../test-data/raw_gateway_responses/get_code/2_all_abi_types.txt");
let cc: LegacyContractCode = serde_json::from_str(raw).unwrap();
let abi = cc.abi.unwrap();

if let RawLegacyAbiEntry::Struct(s) = &abi[0] {
assert_eq!(s.name, "ExternalStruct3");
assert_eq!(s.size, 1);
} else {
panic!("Did not deserialize AbiEntry::Struct properly");
}

if let RawLegacyAbiEntry::Constructor(c) = &abi[3] {
assert_eq!(c.name, "constructor");
} else {
panic!("Did not deserialize AbiEntry::Constructor properly");
}

if let RawLegacyAbiEntry::Function(f) = &abi[5] {
assert_eq!(f.name, "g");
assert_eq!(f.outputs.len(), 1);
assert_eq!(f.state_mutability, Some(FunctionStateMutability::View));
} else {
panic!("Did not deserialize AbiEntry::Function properly");
}

if let RawLegacyAbiEntry::L1Handler(h) = &abi[6] {
assert_eq!(h.name, "handler");
assert_eq!(h.inputs.len(), 2);
} else {
panic!("Did not deserialize AbiEntry::L1Handler properly");
}
}
}
Loading

0 comments on commit d38d1ec

Please sign in to comment.