Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: deploying a contract through the test_contract_cairo1 #254

Open
L0GYKAL opened this issue Jun 30, 2024 · 0 comments
Open

bug: deploying a contract through the test_contract_cairo1 #254

L0GYKAL opened this issue Jun 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@L0GYKAL
Copy link

L0GYKAL commented Jun 30, 2024

SNOS version:
8d6ae34

Current behavior:

called `Result::unwrap()` on an `Err` value: ExecutionError(VirtualMachineExecutionErrorWithTrace { trace: "Error in the called contract (0x00000000000000000000000000000000000000000000000000000000c0000200):\nError at pc=0:797:\nGot an exception while executing a hint: Hint Error: Execution failed. Failure reason: 0x4661696c656420746f20646573657269616c697a6520706172616d202334 ('Failed to deserialize param #4').\nCairo traceback (most recent call last):\nUnknown location (pc=0:505)\n", source: CairoRunError(VmException(VmException { pc: 797, inst_location: None, inner_exc: Hint((0, CustomHint("Execution failed. Failure reason: 0x4661696c656420746f20646573657269616c697a6520706172616d202334 ('Failed to deserialize param #4')."))), error_attr_value: None, traceback: Some("Cairo traceback (most recent call last):\nUnknown location (pc=0:505)\n") })) })
thread 'os::deploy_accounts_test' panicked at tests/integration/common/transaction_utils.rs:154:84:
called `Result::unwrap()` on an `Err` value: ExecutionError(VirtualMachineExecutionErrorWithTrace { trace: "Error in the called contract (0x00000000000000000000000000000000000000000000000000000000c0000200):\nError at pc=0:797:\nGot an exception while executing a hint: Hint Error: Execution failed. Failure reason: 0x4661696c656420746f20646573657269616c697a6520706172616d202334 ('Failed to deserialize param #4').\nCairo traceback (most recent call last):\nUnknown location (pc=0:505)\n", source: CairoRunError(VmException(VmException { pc: 797, inst_location: None, inner_exc: Hint((0, CustomHint("Execution failed. Failure reason: 0x4661696c656420746f20646573657269616c697a6520706172616d202334 ('Failed to deserialize param #4')."))), error_attr_value: None, traceback: Some("Cairo traceback (most recent call last):\nUnknown location (pc=0:505)\n") })) })
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/std/src/panicking.rs:647:5
   1: core::panicking::panic_fmt
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/core/src/result.rs:1649:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/core/src/result.rs:1073:23
   4: integration::common::transaction_utils::execute_txs::{{closure}}
             at ./tests/integration/common/transaction_utils.rs:154:34
   5: core::iter::adapters::map::map_fold::{{closure}}
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/core/src/iter/adapters/map.rs:85:28
   6: core::iter::traits::iterator::Iterator::fold
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/core/src/iter/traits/iterator.rs:2640:21
   7: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/core/src/iter/adapters/map.rs:125:9
   8: core::iter::traits::iterator::Iterator::for_each
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/core/src/iter/traits/iterator.rs:858:9
   9: alloc::vec::Vec<T,A>::extend_trusted
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/alloc/src/vec/mod.rs:2917:17
  10: <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/alloc/src/vec/spec_extend.rs:26:9
  11: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/alloc/src/vec/spec_from_iter_nested.rs:62:9
  12: alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/alloc/src/vec/in_place_collect.rs:233:20
  13: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/alloc/src/vec/mod.rs:2791:9
  14: core::iter::traits::iterator::Iterator::collect
             at /rustc/a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01/library/core/src/iter/traits/iterator.rs:2054:9
  15: integration::common::transaction_utils::execute_txs
             at ./tests/integration/common/transaction_utils.rs:154:9
  16: integration::common::transaction_utils::execute_txs_and_run_os
             at ./tests/integration/common/transaction_utils.rs:163:40
  17: integration::os::deploy_accounts_test::deploy_accounts_test
             at ./tests/integration/os.rs:283:12
  18: integration::os::deploy_accounts_test
             at ./tests/integration/os.rs:204:1
  19: integration::os::deploy_accounts_test::{{closure}}
             at ./tests/integration/os.rs:204:10

Expected behavior:
I suppose the test should pass and no error would be thrown.

Steps to reproduce:

Deposit the compiled ERC20 contracts modified with no constructor argument in tests/integration/contracts/.
erc20_cairo_erc_20.compiled_contract_class.json
Execute the test.

Related code:

#[rstest]
fn deploy_erc20_test(block_context: BlockContext, initial_state: InitialState, max_fee: Fee) {
   let tx_version = TransactionVersion::ZERO;
   let cairo_version = CairoVersion::Cairo1;
   let mut nonce_manager = NonceManager::default();

   // Create the initial state:
   let InitialState {
       mut state,
       //erc20_address: erc20,
       test_contract_cairo1_address: test_contract1,
       account_without_validations_cairo1_address: sender_address,
       ..
   } = initial_state;

    // fund the initial account
    // fund_account(&block_context, sender_address, 10**10, &mut state);

    let file_path = get_test_file_path("erc20_cairo_erc_20.compiled_contract_class.json");
    let erc20_class = blockifier::execution::contract_class::ContractClassV1::from_file(file_path.to_str().unwrap());
    let erc20_class_hash = class_hash!(420_u16);
    //
    declare_contract_in_state(&mut state, erc20_class_hash, blockifier::execution::contract_class::ContractClass::V1(erc20_class));

    // test_deploy
    let my_erc20_address = ContractAddress::from(420u16);
    deploy_contract_in_state(&mut state, erc20_class_hash, my_erc20_address);

    // invoke transaction

    let entrypoint_args = &[
        stark_felt!(255_u8),      // contract_address_salt
        stark_felt!(0_u8),        // calldata length
        //stark_felt!("01234"),       // calldata: name
        //stark_felt!("01234"),       // calldata: symbol
        //stark_felt!(1_u8),       // calldata: decimal
        //stark_felt!(100_u128), // calldata: initial supply
        //stark_felt!(vec_to_u128(sender_address.serialize().unwrap())), //calldata: recipient of the supply
    ];
    //
    let deploy_tx = deploy_contract(&sender_address, &mut nonce_manager, &test_contract1, &erc20_class_hash.0, entrypoint_args, max_fee);
    let txs = vec![
        deploy_tx,
    ];

   let r = execute_txs_and_run_os(state, block_context, txs);

   // temporarily expect test to break in the descent code
    assert!(r.is_ok(), "The result should not be None");
}

fn deploy_contract_in_state(state: &mut CachedState<DictStateReader>, class_hash: ClassHash, contract_address: ContractAddress) {
    state.set_class_hash_at(contract_address, class_hash).expect("Couldn't deploy contract");
}

fn deploy_contract(sender_address: &ContractAddress, nonce_manager: &mut NonceManager, deployer_contract_address: &ContractAddress, deployed_contract_classhash: &StarkHash, entrypoint_args: &[StarkFelt], max_fee: Fee) -> AccountTransaction{
    let tx_version = TransactionVersion::ZERO;
    let mut new_list = Vec::with_capacity(entrypoint_args.len() + 1);
    new_list.push(*deployed_contract_classhash);
    new_list.extend_from_slice(entrypoint_args);

    let test_deploy_tx = test_utils::account_invoke_tx(invoke_tx_args! {
        max_fee,
        sender_address: *sender_address,
        calldata: create_calldata(*deployer_contract_address, "test_deploy", &*new_list),
        version: tx_version,
        nonce: nonce_manager.next(*sender_address),
    });
    test_deploy_tx
}

fn get_test_file_path(file_name: &str) -> PathBuf {
    // Start from the project root, adjust as necessary
    let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    path.push("tests");
    path.push("integration");
    path.push("contracts");
    path.push(file_name);
    path
}
@L0GYKAL L0GYKAL added the bug Something isn't working label Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant