diff --git a/crates/katana/primitives/src/genesis/json.rs b/crates/katana/primitives/src/genesis/json.rs index f6481d1eb2..dc417a2cdf 100644 --- a/crates/katana/primitives/src/genesis/json.rs +++ b/crates/katana/primitives/src/genesis/json.rs @@ -625,6 +625,9 @@ mod tests { use std::path::PathBuf; use std::str::FromStr; + use super::*; + use std::io::{Cursor, Write}; + use std::path::Path; use ethers::types::U256; use starknet::macros::felt; @@ -798,373 +801,319 @@ mod tests { ); } - // #[test] - // fn deserialize_from_json_with_class() { - // let file = File::open("./src/genesis/test-genesis-with-class.json").unwrap(); - // let genesis: GenesisJson = serde_json::from_reader(BufReader::new(file)).unwrap(); - - // assert_eq!( - // genesis.classes, - // vec![ - // GenesisClassJson { - // class_hash: Some(felt!("0x8")), - // class: PathBuf::from("../../contracts/compiled/erc20.json").into(), - // name: None, - // }, - // GenesisClassJson { - // class_hash: Some(felt!("0x80085")), - // class: - // PathBuf::from("../../contracts/compiled/universal_deployer.json").into(), - // name: "haha" }, - // GenesisClassJson { - // class_hash: Some(felt!("0xa55")), - // class: serde_json::to_value(DEFAULT_OZ_ACCOUNT_CONTRACT.clone()) - // .unwrap() - // .into(), - // name: "haha" - // }, - // ] - // ); - // } - - // #[test] - // fn genesis_load_from_json() { - // let path = PathBuf::from("./src/genesis/test-genesis.json"); - - // let json = GenesisJson::load(path).unwrap(); - // let actual_genesis = Genesis::try_from(json).unwrap(); - - // let expected_classes = HashMap::from([ - // ( - // felt!("0x07b3e05f48f0c69e4a65ce5e076a66271a527aff2c34ce1083ec6e1526997a69"), - // GenesisClass { - // sierra: None, - // casm: DEFAULT_LEGACY_UDC_CASM.clone().into(), - // compiled_class_hash: felt!( - // "0x07b3e05f48f0c69e4a65ce5e076a66271a527aff2c34ce1083ec6e1526997a69" - // ), - // }, - // ), - // ( - // felt!("0x80085"), - // GenesisClass { - // sierra: None, - // casm: DEFAULT_LEGACY_UDC_CASM.clone().into(), - // compiled_class_hash: felt!("0x80085"), - // }, - // ), - // ( - // felt!("0x8"), - // GenesisClass { - // sierra: None, - // compiled_class_hash: felt!("0x8"), - // casm: DEFAULT_LEGACY_ERC20_CONTRACT_CASM.clone().into(), - // }, - // ), - // ( - // DEFAULT_OZ_ACCOUNT_CONTRACT_CLASS_HASH, - // GenesisClass { - // compiled_class_hash: DEFAULT_OZ_ACCOUNT_CONTRACT_COMPILED_CLASS_HASH, - // casm: DEFAULT_OZ_ACCOUNT_CONTRACT_CASM.clone().into(), - // sierra: Some(DEFAULT_OZ_ACCOUNT_CONTRACT.clone().flatten().unwrap().into()), - // }, - // ), - // ( - // felt!("0xa55"), - // GenesisClass { - // compiled_class_hash: DEFAULT_OZ_ACCOUNT_CONTRACT_COMPILED_CLASS_HASH, - // casm: DEFAULT_OZ_ACCOUNT_CONTRACT_CASM.clone().into(), - // sierra: Some(DEFAULT_OZ_ACCOUNT_CONTRACT.clone().flatten().unwrap().into()), - // }, - // ), - // ]); - - // let expected_fee_token = FeeTokenConfig { - // address: ContractAddress::from(felt!("0x55")), - // name: String::from("ETHER"), - // symbol: String::from("ETH"), - // total_supply: U256::from_str("0xD3C21BCECCEDA1000000").unwrap() * 5, - // decimals: 18, - // class_hash: felt!("0x8"), - // storage: Some(HashMap::from([ - // (felt!("0x111"), felt!("0x1")), - // (felt!("0x222"), felt!("0x2")), - // ])), - // }; - - // let acc_1 = ContractAddress::from(felt!( - // "0x66efb28ac62686966ae85095ff3a772e014e7fbf56d4c5f6fac5606d4dde23a" - // )); - // let acc_2 = ContractAddress::from(felt!( - // "0x6b86e40118f29ebe393a75469b4d926c7a44c2e2681b6d319520b7c1156d114" - // )); - // let acc_3 = ContractAddress::from(felt!( - // "0x79156ecb3d8f084001bb498c95e37fa1c4b40dbb35a3ae47b77b1ad535edcb9" - // )); - // let acc_4 = ContractAddress::from(felt!( - // "0x053a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf" - // )); - // let contract_1 = ContractAddress::from(felt!( - // "0x29873c310fbefde666dc32a1554fea6bb45eecc84f680f8a2b0a8fbb8cb89af" - // )); - // let contract_2 = ContractAddress::from(felt!( - // "0xe29882a1fcba1e7e10cad46212257fea5c752a4f9b1b1ec683c503a2cf5c8a" - // )); - // let contract_3 = ContractAddress::from(felt!( - // "0x05400e90f7e0ae78bd02c77cd75527280470e2fe19c54970dd79dc37a9d3645c" - // )); - - // let expected_allocations = BTreeMap::from([ - // ( - // acc_1, - // GenesisAllocation::Account(GenesisAccountAlloc::Account(GenesisAccount { - // public_key: felt!("0x1"), - // balance: Some(U256::from_str("0xD3C21BCECCEDA1000000").unwrap()), - // nonce: Some(felt!("0x1")), - // class_hash: felt!("0x80085"), - // storage: Some(HashMap::from([ - // (felt!("0x1"), felt!("0x1")), - // (felt!("0x2"), felt!("0x2")), - // ])), - // })), - // ), - // ( - // acc_2, - // GenesisAllocation::Account(GenesisAccountAlloc::Account(GenesisAccount { - // public_key: felt!("0x2"), - // balance: Some(U256::from_str("0xD3C21BCECCEDA1000000").unwrap()), - // class_hash: DEFAULT_OZ_ACCOUNT_CONTRACT_CLASS_HASH, - // nonce: None, - // storage: None, - // })), - // ), - // ( - // acc_3, - // GenesisAllocation::Account(GenesisAccountAlloc::Account(GenesisAccount { - // public_key: felt!("0x3"), - // balance: None, - // class_hash: DEFAULT_OZ_ACCOUNT_CONTRACT_CLASS_HASH, - // nonce: None, - // storage: None, - // })), - // ), - // ( - // acc_4, - // GenesisAllocation::Account(GenesisAccountAlloc::DevAccount(DevGenesisAccount { - // private_key: felt!("0x115"), - // inner: GenesisAccount { - // public_key: felt!("0x4"), - // balance: Some(U256::from_str("0xD3C21BCECCEDA1000000").unwrap()), - // class_hash: DEFAULT_OZ_ACCOUNT_CONTRACT_CLASS_HASH, - // nonce: None, - // storage: None, - // }, - // })), - // ), - // ( - // contract_1, - // GenesisAllocation::Contract(GenesisContractAlloc { - // balance: Some(U256::from_str("0xD3C21BCECCEDA1000000").unwrap()), - // nonce: None, - // class_hash: Some(felt!("0x8")), - // storage: Some(HashMap::from([ - // (felt!("0x1"), felt!("0x1")), - // (felt!("0x2"), felt!("0x2")), - // ])), - // }), - // ), - // ( - // contract_2, - // GenesisAllocation::Contract(GenesisContractAlloc { - // balance: Some(U256::from_str("0xD3C21BCECCEDA1000000").unwrap()), - // nonce: None, - // class_hash: None, - // storage: None, - // }), - // ), - // ( - // contract_3, - // GenesisAllocation::Contract(GenesisContractAlloc { - // balance: None, - // nonce: None, - // class_hash: None, - // storage: Some(HashMap::from([(felt!("0x1"), felt!("0x1"))])), - // }), - // ), - // ]); - - // let expected_genesis = Genesis { - // classes: expected_classes, - // number: 0, - // fee_token: expected_fee_token, - // allocations: expected_allocations, - // timestamp: 5123512314u64, - // sequencer_address: ContractAddress::from(felt!("0x100")), - // state_root: felt!("0x99"), - // parent_hash: felt!("0x999"), - // gas_prices: GasPrices { eth: 1111, strk: 2222 }, - // universal_deployer: Some(UniversalDeployerConfig { - // class_hash: DEFAULT_LEGACY_UDC_CLASS_HASH, - // address: ContractAddress::from(felt!( - // "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf" - // )), - // storage: Some([(felt!("0x10"), felt!("0x100"))].into()), - // }), - // }; - - // assert_eq!(actual_genesis.number, expected_genesis.number); - // assert_eq!(actual_genesis.parent_hash, expected_genesis.parent_hash); - // assert_eq!(actual_genesis.timestamp, expected_genesis.timestamp); - // assert_eq!(actual_genesis.state_root, expected_genesis.state_root); - // assert_eq!(actual_genesis.gas_prices, expected_genesis.gas_prices); - - // assert_eq!(actual_genesis.fee_token.address, expected_genesis.fee_token.address); - // assert_eq!(actual_genesis.fee_token.name, expected_genesis.fee_token.name); - // assert_eq!(actual_genesis.fee_token.symbol, expected_genesis.fee_token.symbol); - // assert_eq!(actual_genesis.fee_token.decimals, expected_genesis.fee_token.decimals); - // assert_eq!(actual_genesis.fee_token.total_supply, - // expected_genesis.fee_token.total_supply); assert_eq!(actual_genesis.fee_token. - // class_hash, expected_genesis.fee_token.class_hash); - - // assert_eq!(actual_genesis.universal_deployer, expected_genesis.universal_deployer); - - // assert_eq!(actual_genesis.allocations.len(), expected_genesis.allocations.len()); - - // for alloc in actual_genesis.allocations { - // let expected_alloc = expected_genesis.allocations.get(&alloc.0).unwrap(); - // assert_eq!(alloc.1, *expected_alloc); - // } - - // assert_eq!(actual_genesis.classes.len(), expected_genesis.classes.len()); + #[test] + fn deserialize_from_json_with_class() { + let file = File::open("./src/genesis/test-genesis-with-class.json").unwrap(); + let genesis: GenesisJson = serde_json::from_reader(BufReader::new(file)).unwrap(); - // for class in actual_genesis.classes { - // let expected_class = expected_genesis.classes.get(&class.0).unwrap(); - // assert_eq!(class.1.compiled_class_hash, expected_class.compiled_class_hash); - // assert_eq!(class.1.casm, expected_class.casm); - // assert_eq!(class.1.sierra, expected_class.sierra.clone()); - // } - // } + assert_eq!( + genesis.classes, + vec![ + GenesisClassJson { + class_hash: None, + class: PathBuf::from("../../contracts/compiled/erc20.json").into(), + name: Some("MyErc20".to_string()), + }, + GenesisClassJson { + class_hash: Some(felt!("0x80085")), + class: + PathBuf::from("../../contracts/compiled/universal_deployer.json").into(), + name: None, + }, + GenesisClassJson { + class_hash: Some(felt!("0xa55")), + class: serde_json::to_value(DEFAULT_OZ_ACCOUNT_CONTRACT.clone()) + .unwrap() + .into(), + name: None, + }, + ] + ); + } // #[test] - // fn default_genesis_try_from_json() { - // let json = r#" + // fn test_load_genesis_json() { + // let file_path = Path::new("test-genesis.json"); + + // let data = r#" // { // "number": 0, - // "parentHash": "0x999", + // "parent_hash": "0x999", // "timestamp": 5123512314, - // "stateRoot": "0x99", - // "sequencerAddress": "0x100", - // "gasPrices": { + // "state_root": "0x99", + // "sequencer_address": "0x100", + // "gas_prices": { // "ETH": 1111, // "STRK": 2222 // }, - // "feeToken": { + // "fee_token": { + // "address": "0x55", // "name": "ETHER", // "symbol": "ETH", - // "decimals": 18 + // "decimals": 18, + // "class": "MyErc20", + // "storage": { + // "0x111": "0x1", + // "0x222": "0x2" + // } // }, - // "universalDeployer": {}, - // "accounts": { - // "0x66efb28ac62686966ae85095ff3a772e014e7fbf56d4c5f6fac5606d4dde23a": { - // "publicKey": "0x1", - // "balance": "0xD3C21BCECCEDA1000000" + // "universal_deployer": { + // "address": "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf", + // "storage": { + // "0x10": "0x100" // } // }, + // "accounts": {}, // "contracts": {}, // "classes": [] // } // "#; - // let genesis_json: GenesisJson = GenesisJson::from_str(json).unwrap(); - // let actual_genesis = Genesis::try_from(genesis_json).unwrap(); - - // let classes = HashMap::from([ - // ( - // DEFAULT_LEGACY_UDC_CLASS_HASH, - // GenesisClass { - // sierra: None, - // casm: DEFAULT_LEGACY_UDC_CASM.clone().into(), - // compiled_class_hash: DEFAULT_LEGACY_UDC_COMPILED_CLASS_HASH, - // }, - // ), - // ( - // DEFAULT_LEGACY_ERC20_CONTRACT_CLASS_HASH, - // GenesisClass { - // sierra: None, - // casm: DEFAULT_LEGACY_ERC20_CONTRACT_CASM.clone().into(), - // compiled_class_hash: DEFAULT_LEGACY_ERC20_CONTRACT_COMPILED_CLASS_HASH, - // }, - // ), - // ( - // DEFAULT_OZ_ACCOUNT_CONTRACT_CLASS_HASH, - // GenesisClass { - // compiled_class_hash: DEFAULT_OZ_ACCOUNT_CONTRACT_COMPILED_CLASS_HASH, - // casm: DEFAULT_OZ_ACCOUNT_CONTRACT_CASM.clone().into(), - // sierra: Some(DEFAULT_OZ_ACCOUNT_CONTRACT.clone().flatten().unwrap().into()), - // }, - // ), - // ]); - - // let fee_token = FeeTokenConfig { - // address: DEFAULT_FEE_TOKEN_ADDRESS, - // name: String::from("ETHER"), - // symbol: String::from("ETH"), - // total_supply: U256::from_str("0xD3C21BCECCEDA1000000").unwrap(), - // decimals: 18, - // class_hash: DEFAULT_LEGACY_ERC20_CONTRACT_CLASS_HASH, - // storage: None, - // }; - - // let allocations = BTreeMap::from([( - // ContractAddress::from(felt!( - // "0x66efb28ac62686966ae85095ff3a772e014e7fbf56d4c5f6fac5606d4dde23a" - // )), - // GenesisAllocation::Account(GenesisAccountAlloc::Account(GenesisAccount { - // public_key: felt!("0x1"), - // balance: Some(U256::from_str("0xD3C21BCECCEDA1000000").unwrap()), - // class_hash: DEFAULT_OZ_ACCOUNT_CONTRACT_CLASS_HASH, - // nonce: None, - // storage: None, - // })), - // )]); - - // let expected_genesis = Genesis { - // fee_token, - // classes, - // allocations, - // number: 0, - // timestamp: 5123512314u64, - // state_root: felt!("0x99"), - // parent_hash: felt!("0x999"), - // sequencer_address: ContractAddress(felt!("0x100")), - // gas_prices: GasPrices { eth: 1111, strk: 2222 }, - // universal_deployer: Some(UniversalDeployerConfig { - // class_hash: DEFAULT_LEGACY_UDC_CLASS_HASH, - // address: DEFAULT_UDC_ADDRESS, - // storage: None, - // }), - // }; - - // assert_eq!(actual_genesis.universal_deployer, expected_genesis.universal_deployer); - // assert_eq!(actual_genesis.allocations.len(), expected_genesis.allocations.len()); - - // for (address, alloc) in actual_genesis.allocations { - // let expected_alloc = expected_genesis.allocations.get(&address).unwrap(); - // assert_eq!(alloc, *expected_alloc); - // } - - // // assert that the list of classes is the same - // assert_eq!(actual_genesis.classes.len(), expected_genesis.classes.len()); - - // for (hash, class) in actual_genesis.classes { - // let expected_class = expected_genesis.classes.get(&hash).unwrap(); - - // assert_eq!(class.compiled_class_hash, expected_class.compiled_class_hash); - // assert_eq!(class.casm, expected_class.casm); - // assert_eq!(class.sierra, expected_class.sierra.clone()); - // } + // let mut file = File::create(&file_path).unwrap(); + // file.write_all(data.as_bytes()).unwrap(); + + // let genesis = GenesisJson::load(&file_path); + // assert!(genesis.is_ok()); + // let genesis = genesis.unwrap(); + + // assert_eq!(genesis.number, 0); + // assert_eq!(genesis.parent_hash, felt!("0x999")); + // assert_eq!(genesis.timestamp, 5123512314); + // assert_eq!(genesis.state_root, felt!("0x99")); + // assert_eq!(genesis.sequencer_address, felt!("0x100")); + // assert_eq!(genesis.gas_prices["ETH"], 1111); + // assert_eq!(genesis.gas_prices["STRK"], 2222); + // assert_eq!(genesis.fee_token.address, felt!("0x55")); + // assert_eq!(genesis.fee_token.name, "ETHER"); + // assert_eq!(genesis.fee_token.symbol, "ETH"); + // assert_eq!(genesis.fee_token.decimals, 18); + // assert_eq!(genesis.fee_token.class, "MyErc20"); + // assert_eq!(genesis.fee_token.storage[&felt!("0x111")], felt!("0x1")); + // assert_eq!(genesis.fee_token.storage[&felt!("0x222")], felt!("0x2")); + // assert_eq!(genesis.universal_deployer.unwrap().address, felt!("0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf")); + // assert_eq!(genesis.universal_deployer.unwrap().storage[&felt("0x10")], felt!("0x100")); // } +// #[test] +// fn genesis_load_from_json() { +// let path = PathBuf::from("./src/genesis/test-genesis.json"); + +// let json = GenesisJson::load(path).unwrap(); +// let actual_genesis = Genesis::try_from(json).unwrap(); + +// let expected_classes = HashMap::from([ +// ( +// felt!("0x07b3e05f48f0c69e4a65ce5e076a66271a527aff2c34ce1083ec6e1526997a69"), +// GenesisClass { +// sierra: None, +// casm: DEFAULT_LEGACY_UDC_CASM.clone().into(), +// compiled_class_hash: felt!( +// "0x07b3e05f48f0c69e4a65ce5e076a66271a527aff2c34ce1083ec6e1526997a69" +// ), +// }, +// ), +// ( +// felt!("0x80085"), +// GenesisClass { +// sierra: None, +// casm: DEFAULT_LEGACY_UDC_CASM.clone().into(), +// compiled_class_hash: felt!("0x80085"), +// }, +// ), +// ( +// felt!("0x07b3e05f48f0c69e4a65ce5e076a66271a527aff2c34ce1083ec6e1526997a69"), +// GenesisClass { +// sierra: None, +// compiled_class_hash: felt!("0x8"), +// casm: DEFAULT_LEGACY_ERC20_CONTRACT_CASM.clone().into(), +// }, +// ), +// ( +// DEFAULT_OZ_ACCOUNT_CONTRACT_CLASS_HASH, +// GenesisClass { +// compiled_class_hash: DEFAULT_OZ_ACCOUNT_CONTRACT_COMPILED_CLASS_HASH, +// casm: DEFAULT_OZ_ACCOUNT_CONTRACT_CASM.clone().into(), +// sierra: Some(DEFAULT_OZ_ACCOUNT_CONTRACT.clone().flatten().unwrap().into()), +// }, +// ), +// ( +// felt!("0xa55"), +// GenesisClass { +// compiled_class_hash: DEFAULT_OZ_ACCOUNT_CONTRACT_COMPILED_CLASS_HASH, +// casm: DEFAULT_OZ_ACCOUNT_CONTRACT_CASM.clone().into(), +// sierra: Some(DEFAULT_OZ_ACCOUNT_CONTRACT.clone().flatten().unwrap().into()), +// }, +// ), +// ]); + +// let expected_fee_token = FeeTokenConfig { +// address: ContractAddress::from(felt!("0x55")), +// name: String::from("ETHER"), +// symbol: String::from("ETH"), +// total_supply: U256::from_str("0xD3C21BCECCEDA1000000").unwrap() * 5, +// decimals: 18, +// class_hash: felt!("0x8"), +// storage: Some(HashMap::from([ +// (felt!("0x111"), felt!("0x1")), +// (felt!("0x222"), felt!("0x2")), +// ])), +// }; + +// let acc_1 = ContractAddress::from(felt!( +// "0x66efb28ac62686966ae85095ff3a772e014e7fbf56d4c5f6fac5606d4dde23a" +// )); +// let acc_2 = ContractAddress::from(felt!( +// "0x6b86e40118f29ebe393a75469b4d926c7a44c2e2681b6d319520b7c1156d114" +// )); +// let acc_3 = ContractAddress::from(felt!( +// "0x79156ecb3d8f084001bb498c95e37fa1c4b40dbb35a3ae47b77b1ad535edcb9" +// )); +// let acc_4 = ContractAddress::from(felt!( +// "0x053a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf" +// )); +// let contract_1 = ContractAddress::from(felt!( +// "0x29873c310fbefde666dc32a1554fea6bb45eecc84f680f8a2b0a8fbb8cb89af" +// )); +// let contract_2 = ContractAddress::from(felt!( +// "0xe29882a1fcba1e7e10cad46212257fea5c752a4f9b1b1ec683c503a2cf5c8a" +// )); +// let contract_3 = ContractAddress::from(felt!( +// "0x05400e90f7e0ae78bd02c77cd75527280470e2fe19c54970dd79dc37a9d3645c" +// )); + +// let expected_allocations = BTreeMap::from([ +// ( +// acc_1, +// GenesisAllocation::Account(GenesisAccountAlloc::Account(GenesisAccount { +// public_key: felt!("0x1"), +// balance: Some(U256::from_str("0xD3C21BCECCEDA1000000").unwrap()), +// nonce: Some(felt!("0x1")), +// class_hash: felt!("0x80085"), +// storage: Some(HashMap::from([ +// (felt!("0x1"), felt!("0x1")), +// (felt!("0x2"), felt!("0x2")), +// ])), +// })), +// ), +// ( +// acc_2, +// GenesisAllocation::Account(GenesisAccountAlloc::Account(GenesisAccount { +// public_key: felt!("0x2"), +// balance: Some(U256::from_str("0xD3C21BCECCEDA1000000").unwrap()), +// class_hash: DEFAULT_OZ_ACCOUNT_CONTRACT_CLASS_HASH, +// nonce: None, +// storage: None, +// })), +// ), +// ( +// acc_3, +// GenesisAllocation::Account(GenesisAccountAlloc::Account(GenesisAccount { +// public_key: felt!("0x3"), +// balance: None, +// class_hash: DEFAULT_OZ_ACCOUNT_CONTRACT_CLASS_HASH, +// nonce: None, +// storage: None, +// })), +// ), +// ( +// acc_4, +// GenesisAllocation::Account(GenesisAccountAlloc::DevAccount(DevGenesisAccount { +// private_key: felt!("0x115"), +// inner: GenesisAccount { +// public_key: felt!("0x4"), +// balance: Some(U256::from_str("0xD3C21BCECCEDA1000000").unwrap()), +// class_hash: DEFAULT_OZ_ACCOUNT_CONTRACT_CLASS_HASH, +// nonce: None, +// storage: None, +// }, +// })), +// ), +// ( +// contract_1, +// GenesisAllocation::Contract(GenesisContractAlloc { +// balance: Some(U256::from_str("0xD3C21BCECCEDA1000000").unwrap()), +// nonce: None, +// class_hash: Some(felt!("0x8")), +// storage: Some(HashMap::from([ +// (felt!("0x1"), felt!("0x1")), +// (felt!("0x2"), felt!("0x2")), +// ])), +// }), +// ), +// ( +// contract_2, +// GenesisAllocation::Contract(GenesisContractAlloc { +// balance: Some(U256::from_str("0xD3C21BCECCEDA1000000").unwrap()), +// nonce: None, +// class_hash: None, +// storage: None, +// }), +// ), +// ( +// contract_3, +// GenesisAllocation::Contract(GenesisContractAlloc { +// balance: None, +// nonce: None, +// class_hash: None, +// storage: Some(HashMap::from([(felt!("0x1"), felt!("0x1"))])), +// }), +// ), +// ]); + +// let expected_genesis = Genesis { +// classes: expected_classes, +// number: 0, +// fee_token: expected_fee_token, +// allocations: expected_allocations, +// timestamp: 5123512314u64, +// sequencer_address: ContractAddress::from(felt!("0x100")), +// state_root: felt!("0x99"), +// parent_hash: felt!("0x999"), +// gas_prices: GasPrices { eth: 1111, strk: 2222 }, +// universal_deployer: Some(UniversalDeployerConfig { +// class_hash: DEFAULT_LEGACY_UDC_CLASS_HASH, +// address: ContractAddress::from(felt!( +// "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf" +// )), +// storage: Some([(felt!("0x10"), felt!("0x100"))].into()), +// }), +// }; + +// assert_eq!(actual_genesis.number, expected_genesis.number); +// assert_eq!(actual_genesis.parent_hash, expected_genesis.parent_hash); +// assert_eq!(actual_genesis.timestamp, expected_genesis.timestamp); +// assert_eq!(actual_genesis.state_root, expected_genesis.state_root); +// assert_eq!(actual_genesis.gas_prices, expected_genesis.gas_prices); + +// assert_eq!(actual_genesis.fee_token.address, expected_genesis.fee_token.address); +// assert_eq!(actual_genesis.fee_token.name, expected_genesis.fee_token.name); +// assert_eq!(actual_genesis.fee_token.symbol, expected_genesis.fee_token.symbol); +// assert_eq!(actual_genesis.fee_token.decimals, expected_genesis.fee_token.decimals); +// assert_eq!(actual_genesis.fee_token.total_supply, +// expected_genesis.fee_token.total_supply); assert_eq!(actual_genesis.fee_token. +// class_hash, expected_genesis.fee_token.class_hash); + +// assert_eq!(actual_genesis.universal_deployer, expected_genesis.universal_deployer); + +// assert_eq!(actual_genesis.allocations.len(), expected_genesis.allocations.len()); + +// for alloc in actual_genesis.allocations { +// let expected_alloc = expected_genesis.allocations.get(&alloc.0).unwrap(); +// assert_eq!(alloc.1, *expected_alloc); +// } + +// assert_eq!(actual_genesis.classes.len(), expected_genesis.classes.len()); + +// for class in actual_genesis.classes { +// let expected_class = expected_genesis.classes.get(&class.0).unwrap(); +// assert_eq!(class.1.compiled_class_hash, expected_class.compiled_class_hash); +// assert_eq!(class.1.casm, expected_class.casm); +// assert_eq!(class.1.sierra, expected_class.sierra.clone()); +// } +// } + + + // #[test] // fn genesis_from_json_with_unresolved_paths() { // let file = File::open("./src/genesis/test-genesis.json").unwrap(); diff --git a/crates/katana/primitives/src/genesis/test-genesis-with-class.json b/crates/katana/primitives/src/genesis/test-genesis-with-class.json index 5a6f151d6e..dbc68a5e3d 100644 --- a/crates/katana/primitives/src/genesis/test-genesis-with-class.json +++ b/crates/katana/primitives/src/genesis/test-genesis-with-class.json @@ -58,7 +58,7 @@ "classes": [ { "class": "../../contracts/compiled/erc20.json", - "classHash": "0x8" + "name": "MyErc20" }, { "class": "../../contracts/compiled/universal_deployer.json",