Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Event not returned #1029

Closed
marioiordanov opened this issue Sep 14, 2023 · 7 comments · Fixed by #1034
Closed

Event not returned #1029

marioiordanov opened this issue Sep 14, 2023 · 7 comments · Fixed by #1034
Labels
bug Something isn't working

Comments

@marioiordanov
Copy link
Contributor

marioiordanov commented Sep 14, 2023

when sending transaction to UDC for deploying ERC20, event that is emitted in the ERC20 constructor is not returned in get_sorted_events.

Event that is missing is the event generated in ERC20._mint.

@juanbono juanbono added the bug Something isn't working label Sep 14, 2023
@juanbono juanbono moved this to In Progress in Starknet Sep 14, 2023
@juanbono
Copy link
Collaborator

Hi @marioiordanov ! Thanks for reporting!
I'm taking a look at this now.
Do you know of a testnet transaction that do the same or something similar to that? That can help debugging

@marioiordanov
Copy link
Contributor Author

events_declare.txt
events_invoke.txt
Account.txt

| Account address | 0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691
| Private key | 0x71d7bb07b9a64f6f78ac4c816aff4da9
| Public key | 0x39d9e6ce352ad4530a0ef5d5a18fd3303c3606a7fa6ac5b620020ad681cc33b

The account from Account.txt is deployed with the above mentioned properties - (address, public/private key).
Then events_declare.txt is executed - RPC declare transaction.
Then events_invoke.txt is executed - RPC invoke transaction, which is actually a deploy.

@marioiordanov
Copy link
Contributor Author

#[test]
    fn get_events_test() {
        let mut starknet = Starknet::new(&super::StarknetConfig {
            seed: 0,
            total_accounts: 1,
            predeployed_accounts_initial_balance: Felt::from(1000000000000000),
            chain_id: StarknetChainId::TestNet,
            gas_price: 100000000,
            ..Default::default()
        })
        .unwrap();
        let file =
            File::open(<path to events_declare.txt>)
                .unwrap();

        let txn: BroadcastedDeclareTransactionV1 = serde_json::from_reader(file).unwrap();
        let (txn_hash, class_hash) = starknet.add_declare_transaction_v1(txn).unwrap();

        let file =
            File::open(<path to events_invoke.txt>)
                .unwrap();
        let txn: BroadcastedInvokeTransaction = serde_json::from_reader(file).unwrap();
        let txn_hash = starknet.add_invoke_transaction(txn).unwrap();

        let receipt = starknet.get_transaction_receipt_by_hash(txn_hash).unwrap();
        println!("{}", serde_json::to_string_pretty(&receipt).unwrap());
    }

this is a snipped from starknet-devnet-rs. If you want to test it you can paste this code at the bottom of this file https://github.com/0xSpaceShard/starknet-devnet-rs/blob/9f8edf36ee8e74b52d87de601e8cc3283d2e5e54/crates/starknet/src/starknet/mod.rs

@juanbono
Copy link
Collaborator

juanbono commented Sep 15, 2023

Thanks @marioiordanov .

We reproduced the test and printed the receipt and got the following:

{
  "type": "DEPLOY",
  "transaction_hash": "0x70689022b038dda554c3ac3fa3eca8a1beb1472e1be7416016d85346b0be457",
  "actual_fee": "0x537dda63f0000",
  "messages_sent": [],
  "events": [
    {
      "from_address": "0x41a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
      "keys": [
        "0x26b160f10156dea0639bec90696772c640b9706a47f5b8c52ea1abe5858b34d"
      ],
      "data": [
        "0x2ca7ba2eba3687c026d5332ab6e34773b225e0f42a25035d9b052f974a9230d",
        "0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691",
        "0x1",
        "0x11ab8626b891bcb29f7cc36907af7670d6fb8a0528c7944330729d8f01e9ea3",
        "0x8",
        "0x546f6b656e",
        "0x4552433230",
        "0x12",
        "0x3b9aca00",
        "0x0",
        "0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691",
        "0x0",
        "0x1",
        "0x4d889c4017272a0d7d18c66acf7d51b606298111e396310f77c557dbd932248"
      ]
    },
    {
      "from_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
      "keys": [
        "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9"
      ],
      "data": [
        "0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691",
        "0x1000",
        "0xe58c382300",
        "0x0"
      ]
    }
  ],
  "execution_status": "SUCCEEDED",
  "finality_status": "ACCEPTED_ON_L2",
  "block_hash": "0x568fd678ad70c9d3d915ca8347bbe59c3a913f77a175313a947f84f2afa3e6f",
  "block_number": 1,
  "contract_address": "0x2ca7ba2eba3687c026d5332ab6e34773b225e0f42a25035d9b052f974a9230d"
}

There in the events we can see the event that you mentionted.
Since ERC20._emit emits a Transfer event, we calculated sn_keccak("Transfer") and got "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9" that matches with one of the events in the receipt.

Do you were expecting another one aside from those 2?

@marioiordanov
Copy link
Contributor Author

@juanbono the second event (key = 0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9) is the transfer of fee in the fee_contract. In the data array the first field is the sender address (account address provided above) and the second one is the receiver address in this case the TEST_SEQUENCER_ADDRESS from starknet_in_rust with decimal value 4096. As you can see in the _mint function, the sender address is 0. So this is the event that is missing

@edg-l edg-l mentioned this issue Sep 18, 2023
5 tasks
@github-project-automation github-project-automation bot moved this from In Progress to Done in Starknet Sep 18, 2023
@juanbono
Copy link
Collaborator

@marioiordanov a fix to this issue was merged. Can you check that everything is ok?

@marioiordanov
Copy link
Contributor Author

@juanbono indeed the missing event is returned, but its from_address property is UDC contract. I think the emit_event should have from_address -> the deployed address.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants