-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev: remove bytecode length from return (#546)
* dev: rename to er20 test * dev: return bytecode only and remove its length * dev: use evm_contract * chore: whitespace and naming * Update crates/core/src/contracts/account.rs Co-authored-by: Elias Tazartes <66871571+Eikix@users.noreply.github.com> --------- Co-authored-by: Elias Tazartes <66871571+Eikix@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
62 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use rstest::*; | ||
use starknet::core::types::{BlockId, BlockTag}; | ||
|
||
use crate::client::api::KakarotStarknetApi; | ||
use crate::contracts::account::{Account, KakarotAccount}; | ||
use crate::test_utils::deploy_helpers::{get_contract, get_contract_deployed_bytecode, KakarotTestEnvironmentContext}; | ||
use crate::test_utils::fixtures::kakarot_test_env_ctx; | ||
|
||
#[rstest] | ||
#[tokio::test(flavor = "multi_thread")] | ||
async fn test_bytecode(kakarot_test_env_ctx: KakarotTestEnvironmentContext) { | ||
// Given | ||
let contract_name = "Counter"; | ||
let counter_starknet_address = kakarot_test_env_ctx.evm_contract(contract_name).addresses.starknet_address; | ||
let counter_contract = get_contract(contract_name); | ||
let expected_bytecode = get_contract_deployed_bytecode(counter_contract); | ||
|
||
let starknet_block_id = BlockId::Tag(BlockTag::Latest); | ||
let starknet_provider = kakarot_test_env_ctx.client().starknet_provider(); | ||
let counter_contract_account = KakarotAccount::new(counter_starknet_address, starknet_provider.as_ref()); | ||
|
||
// When | ||
let actual_bytecode = counter_contract_account.bytecode(&starknet_block_id).await.unwrap(); | ||
|
||
// Then | ||
assert_eq!(expected_bytecode.to_vec(), actual_bytecode.to_vec()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use reth_primitives::U256; | ||
use starknet::core::types::BlockId; | ||
use starknet::providers::SequencerGatewayProvider; | ||
use starknet_crypto::FieldElement; | ||
|
||
use crate::client::api::KakarotStarknetApi; | ||
use crate::client::constants::{DUMMY_ARGENT_GAS_PRICE_ACCOUNT_ADDRESS, STARKNET_NATIVE_TOKEN}; | ||
use crate::contracts::erc20::starknet_erc20::StarknetErc20; | ||
use crate::mock::mock_starknet::init_testnet_client; | ||
|
||
#[tokio::test] | ||
async fn test_balance_of() { | ||
// Given | ||
let client = init_testnet_client(); | ||
let starknet_native_token_address = FieldElement::from_hex_be(STARKNET_NATIVE_TOKEN).unwrap(); | ||
let provider = client.starknet_provider(); | ||
let eth = StarknetErc20::<SequencerGatewayProvider>::new(&provider, starknet_native_token_address); | ||
|
||
let random_block = BlockId::Number(838054); | ||
|
||
// When | ||
let balance = eth.balance_of(&DUMMY_ARGENT_GAS_PRICE_ACCOUNT_ADDRESS, &random_block).await.unwrap(); | ||
|
||
// Then | ||
assert_eq!(U256::from(983627765290549u64), balance); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,2 @@ | ||
use reth_primitives::U256; | ||
use starknet::core::types::BlockId; | ||
use starknet::providers::SequencerGatewayProvider; | ||
use starknet_crypto::FieldElement; | ||
|
||
use crate::client::api::KakarotStarknetApi; | ||
use crate::client::constants::{DUMMY_ARGENT_GAS_PRICE_ACCOUNT_ADDRESS, STARKNET_NATIVE_TOKEN}; | ||
use crate::contracts::erc20::starknet_erc20::StarknetErc20; | ||
use crate::mock::mock_starknet::init_testnet_client; | ||
|
||
#[tokio::test] | ||
async fn test_balance_of() { | ||
// Given | ||
let client = init_testnet_client(); | ||
let starknet_native_token_address = FieldElement::from_hex_be(STARKNET_NATIVE_TOKEN).unwrap(); | ||
let provider = client.starknet_provider(); | ||
let eth = StarknetErc20::<SequencerGatewayProvider>::new(&provider, starknet_native_token_address); | ||
|
||
let random_block = BlockId::Number(838054); | ||
|
||
// When | ||
let balance = eth.balance_of(&DUMMY_ARGENT_GAS_PRICE_ACCOUNT_ADDRESS, &random_block).await.unwrap(); | ||
|
||
// Then | ||
assert_eq!(U256::from(983627765290549u64), balance); | ||
} | ||
mod account; | ||
mod erc20; |