Skip to content

Commit

Permalink
fix storage at type (#784)
Browse files Browse the repository at this point in the history
* fix storage at type

* fix b256

* Update tests/eth_provider.rs

Co-authored-by: greged93 <[email protected]>

* Update src/eth_provider/provider.rs

Co-authored-by: greged93 <[email protected]>

* fix type

---------

Co-authored-by: greged93 <[email protected]>
  • Loading branch information
Eikix and greged93 committed Feb 23, 2024
1 parent c3070fa commit c5e3b2e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/eth_provider/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub trait EthereumProvider {
/// Returns the balance of an address in native eth.
async fn balance(&self, address: Address, block_id: Option<BlockId>) -> EthProviderResult<U256>;
/// Returns the storage of an address at a certain index.
async fn storage_at(&self, address: Address, index: U256, block_id: Option<BlockId>) -> EthProviderResult<U256>;
async fn storage_at(&self, address: Address, index: U256, block_id: Option<BlockId>) -> EthProviderResult<B256>;
/// Returns the nonce for the address at the given block.
async fn transaction_count(&self, address: Address, block_id: Option<BlockId>) -> EthProviderResult<U256>;
/// Returns the code for the address at the given block.
Expand Down Expand Up @@ -272,7 +272,7 @@ where
Ok(low + (high << 128))
}

async fn storage_at(&self, address: Address, index: U256, block_id: Option<BlockId>) -> EthProviderResult<U256> {
async fn storage_at(&self, address: Address, index: U256, block_id: Option<BlockId>) -> EthProviderResult<B256> {
let eth_block_id = EthBlockId::new(block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest)));
let starknet_block_id: StarknetBlockId = eth_block_id.try_into()?;

Expand All @@ -286,7 +286,9 @@ where

let low: U256 = into_via_wrapper!(storage.low);
let high: U256 = into_via_wrapper!(storage.high);
Ok(low + (high << 128))
let storage: U256 = low + (high << 128);

Ok(storage.into())
}

async fn transaction_count(&self, address: Address, block_id: Option<BlockId>) -> EthProviderResult<U256> {
Expand Down
2 changes: 1 addition & 1 deletion src/eth_rpc/api/eth_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub trait EthApi {

/// Returns the value from a storage position at a given address
#[method(name = "getStorageAt")]
async fn storage_at(&self, address: Address, index: U256, block_id: Option<BlockId>) -> Result<U256>;
async fn storage_at(&self, address: Address, index: U256, block_id: Option<BlockId>) -> Result<B256>;

/// Returns the number of transactions sent from an address at given block number.
#[method(name = "getTransactionCount")]
Expand Down
2 changes: 1 addition & 1 deletion src/eth_rpc/servers/eth_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ where
}

#[tracing::instrument(skip_all, ret, err, fields(address = %address, index = ?index, block_id = ?block_id))]
async fn storage_at(&self, address: Address, index: U256, block_id: Option<BlockId>) -> Result<U256> {
async fn storage_at(&self, address: Address, index: U256, block_id: Option<BlockId>) -> Result<B256> {
Ok(self.eth_provider.storage_at(address, index, block_id).await?)
}

Expand Down
6 changes: 3 additions & 3 deletions tests/eth_provider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(feature = "testing")]
use std::cmp::min;
use std::str::FromStr as _;
use std::str::FromStr;

use kakarot_rpc::eth_provider::provider::EthereumProvider;
use kakarot_rpc::models::felt::Felt252Wrapper;
Expand All @@ -13,7 +13,7 @@ use reth_rpc_types::request::TransactionInput;
use reth_rpc_types::TransactionRequest;
use rstest::*;

use reth_primitives::{Address, BlockNumberOrTag, Bytes, U256, U64};
use reth_primitives::{Address, BlockNumberOrTag, Bytes, B256, U256, U64};

#[rstest]
#[awt]
Expand Down Expand Up @@ -134,7 +134,7 @@ async fn test_storage_at(#[future] counter: (Katana, KakarotEvmContract), _setup

// Then
let count = eth_provider.storage_at(counter_address, U256::from(0), None).await.unwrap();
assert_eq!(U256::from(1), count);
assert_eq!(B256::left_padding_from(&[0x1]), count);
}

#[rstest]
Expand Down

0 comments on commit c5e3b2e

Please sign in to comment.