Skip to content

Commit

Permalink
gas fix and test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ManojJiSharma committed Aug 13, 2024
1 parent 18fae6c commit 33438a8
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 95 deletions.
6 changes: 3 additions & 3 deletions chains/arbitrum/testing/rosetta-testing-arbitrum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ mod tests {
.await
.unwrap();
let value = 10 * u128::pow(10, client.config().currency_decimals);
let _ = wallet.faucet(value).await;
let _ = wallet.faucet(value, None).await;
let amount = wallet.balance().await.unwrap();
assert_eq!(amount, value);
})
Expand Down Expand Up @@ -349,7 +349,7 @@ mod tests {
)
.await
.unwrap();
wallet.faucet(faucet).await.unwrap();
wallet.faucet(faucet, None).await.unwrap();

let bytes = compile_snippet(
r"
Expand Down Expand Up @@ -402,7 +402,7 @@ mod tests {
)
.await
.unwrap();
wallet.faucet(faucet).await.unwrap();
wallet.faucet(faucet, None).await.unwrap();
let bytes = compile_snippet(
r"
function identity(bool a) public view returns (bool) {
Expand Down
19 changes: 12 additions & 7 deletions chains/astar/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ impl AstarClient {

// Verify if the ethereum block hash matches the provided ethereum block hash.
// TODO: compute the block hash
if U256(actual_eth_block.header.number.0) !=
U256::from(ethereum_block.header().number())
if U256(actual_eth_block.header.number.0)
!= U256::from(ethereum_block.header().number())
{
anyhow::bail!("ethereum block hash mismatch");
}
if actual_eth_block.header.parent_hash.as_fixed_bytes() !=
&ethereum_block.header().header().parent_hash.0
if actual_eth_block.header.parent_hash.as_fixed_bytes()
!= &ethereum_block.header().header().parent_hash.0
{
anyhow::bail!("ethereum block hash mismatch");
}
Expand Down Expand Up @@ -267,7 +267,12 @@ impl BlockchainClient for AstarClient {
Ok(balance)
}

async fn faucet(&self, address: &Address, value: u128) -> Result<Vec<u8>> {
async fn faucet(
&self,
address: &Address,
value: u128,
_high_gas_price: Option<u128>,
) -> Result<Vec<u8>> {
// convert address
let dest = {
let address: H160 = address.address().parse()?;
Expand Down Expand Up @@ -396,7 +401,7 @@ mod tests {
run_test(env, |env| async move {
let faucet = 100 * u128::pow(10, config.currency_decimals);
let wallet = env.ephemeral_wallet().await.unwrap();
wallet.faucet(faucet).await.unwrap();
wallet.faucet(faucet, None).await.unwrap();

let bytes = compile_snippet(
r"
Expand Down Expand Up @@ -465,7 +470,7 @@ mod tests {
run_test(env, |env| async move {
let faucet = 100 * u128::pow(10, config.currency_decimals);
let wallet = env.ephemeral_wallet().await.unwrap();
wallet.faucet(faucet).await.unwrap();
wallet.faucet(faucet, None).await.unwrap();

let bytes = compile_snippet(
r"
Expand Down
23 changes: 9 additions & 14 deletions chains/avalanche/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ mod tests {
use rosetta_config_ethereum::{AtBlock, CallResult};
use rosetta_core::BlockchainClient;
use rosetta_server_ethereum::MaybeWsEthereumClient;
use serial_test::serial;
use sha3::Digest;
use std::{collections::BTreeMap, future::Future, path::Path};
use serial_test::serial;

/// Account used to fund other testing accounts.
const FUNDING_ACCOUNT_PRIVATE_KEY: [u8; 32] =
hex!("56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027");

/// Avalanche rpc url
const AVALANCHE_RPC_WS_URL: &str = "ws://127.0.0.1:9650/ext/bc/local/ws";
const AVALANCHE_RPC_WS_URL: &str = "ws://127.0.0.1:9650/ext/bc/test/ws";

sol! {
interface TestContract {
Expand All @@ -68,7 +68,7 @@ mod tests {
}
}

/// Run the test in another thread while sending txs to force binance to mine new blocks
/// Run the test in another thread while sending txs to force binance to mine new blocks
/// # Panic
/// Panics if the future panics
async fn run_test<Fut: Future<Output = ()> + Send + 'static>(future: Fut) {
Expand Down Expand Up @@ -104,14 +104,9 @@ mod tests {
#[serial]
async fn network_status() {
run_test(async move {
let client = MaybeWsEthereumClient::new(
"avalanche",
"dev",
AVALANCHE_RPC_WS_URL,
None,
)
.await
.expect("Error creating client");
let client = MaybeWsEthereumClient::new("avalanche", "dev", AVALANCHE_RPC_WS_URL, None)
.await
.expect("Error creating client");
// Check if the genesis is consistent
let genesis_block = client.genesis_block();
assert_eq!(genesis_block.index, 0);
Expand Down Expand Up @@ -152,7 +147,7 @@ mod tests {
.await
.unwrap();
let value = 10 * u128::pow(10, client.config().currency_decimals);
let _ = wallet.faucet(value).await;
let _ = wallet.faucet(value, Some(25_000_000_000)).await;
let amount = wallet.balance().await.unwrap();
assert_eq!(amount, value);
})
Expand Down Expand Up @@ -205,7 +200,7 @@ mod tests {
)
.await
.unwrap();
wallet.faucet(faucet).await.unwrap();
wallet.faucet(faucet, Some(25_000_000_000)).await.unwrap();

let bytes = compile_snippet(
r"
Expand Down Expand Up @@ -258,7 +253,7 @@ mod tests {
)
.await
.unwrap();
wallet.faucet(faucet).await.unwrap();
wallet.faucet(faucet, Some(25_000_000_000)).await.unwrap();
let bytes = compile_snippet(
r"
function identity(bool a) public view returns (bool) {
Expand Down
8 changes: 4 additions & 4 deletions chains/binance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ mod tests {
.await
.unwrap();
let value = 10 * u128::pow(10, client.config().currency_decimals);
let _ = wallet.faucet(value).await;
let _ = wallet.faucet(value, None).await;
let amount = wallet.balance().await.unwrap();
assert_eq!(amount, value);
})
Expand Down Expand Up @@ -161,7 +161,7 @@ mod tests {
assert_eq!(balance, 0);

// Transfer faucets to alice
alice.faucet(faucet).await.unwrap();
alice.faucet(faucet, None).await.unwrap();
let balance = alice.balance().await.unwrap();
assert_eq!(balance, faucet);

Expand Down Expand Up @@ -209,7 +209,7 @@ mod tests {
Wallet::from_config(client.config().clone(), BINANCE_RPC_WS_URL, None, None)
.await
.unwrap();
wallet.faucet(faucet).await.unwrap();
wallet.faucet(faucet, None).await.unwrap();

let bytes = compile_snippet(
r"
Expand Down Expand Up @@ -252,7 +252,7 @@ mod tests {
Wallet::from_config(client.config().clone(), BINANCE_RPC_WS_URL, None, None)
.await
.unwrap();
wallet.faucet(faucet).await.unwrap();
wallet.faucet(faucet, None).await.unwrap();
let bytes = compile_snippet(
r"
function identity(bool a) public view returns (bool) {
Expand Down
4 changes: 2 additions & 2 deletions chains/ethereum/backend/src/jsonrpsee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ where
return Ok(revert);
}
}
} else if msg.message().contains("overflow") ||
msg.message().contains("underflow")
} else if msg.message().contains("overflow")
|| msg.message().contains("underflow")
{
// we assume it's an stack overflow or underflow error.
return Ok(ExitReason::Error(msg.message().to_string().into()));
Expand Down
7 changes: 6 additions & 1 deletion chains/ethereum/server/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ where
}

#[allow(clippy::single_match_else, clippy::missing_errors_doc)]
pub async fn faucet(&self, address: &Address, param: u128, high_gas_price: Option<u128>) -> Result<Vec<u8>> {
pub async fn faucet(
&self,
address: &Address,
param: u128,
high_gas_price: Option<u128>,
) -> Result<Vec<u8>> {
match self.private_key {
Some(private_key) => {
let chain_id = self.chain_id;
Expand Down
15 changes: 10 additions & 5 deletions chains/ethereum/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,15 @@ impl BlockchainClient for MaybeWsEthereumClient {
}
}

async fn faucet(&self, address: &Address, param: u128) -> Result<Vec<u8>> {
async fn faucet(
&self,
address: &Address,
param: u128,
high_gas_price: Option<u128>,
) -> Result<Vec<u8>> {
match self {
Self::Http(http_client) => http_client.faucet(address, param, None).await,
Self::Ws(ws_client) => ws_client.faucet(address, param, None).await,
Self::Http(http_client) => http_client.faucet(address, param, high_gas_price).await,
Self::Ws(ws_client) => ws_client.faucet(address, param, high_gas_price).await,
}
}

Expand Down Expand Up @@ -311,7 +316,7 @@ mod tests {
let wallet = env.ephemeral_wallet().await.unwrap();

let faucet = 100 * u128::pow(10, config.currency_decimals);
wallet.faucet(faucet).await.unwrap();
wallet.faucet(faucet, None).await.unwrap();

let bytes = compile_snippet(
r"
Expand Down Expand Up @@ -381,7 +386,7 @@ mod tests {
run_test(env, |env| async move {
let wallet = env.ephemeral_wallet().await.unwrap();
let faucet = 100 * u128::pow(10, config.currency_decimals);
wallet.faucet(faucet).await.unwrap();
wallet.faucet(faucet, None).await.unwrap();

let bytes = compile_snippet(
r"
Expand Down
4 changes: 2 additions & 2 deletions chains/ethereum/server/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub fn verify_proof(proof: &[Bytes], root: &[u8], path: &[u8], value: &[u8]) ->
} else if node_list.len() == 2 {
if i == proof.len() - 1 {
// exclusion proof
if !paths_match(&node_list[0], skip_length(&node_list[0]), path, path_offset) &&
is_empty_value(value)
if !paths_match(&node_list[0], skip_length(&node_list[0]), path, path_offset)
&& is_empty_value(value)
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions chains/ethereum/server/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ impl StateInner {
// Block is younger than the latest finalized block, so it can't be imported
return Ok(());
}
if block.number() == (best_block.number() + 1) &&
block.parent_hash() != best_block.hash()
if block.number() == (best_block.number() + 1)
&& block.parent_hash() != best_block.hash()
{
// the block is not descendent of the best finalized block
return Ok(());
Expand Down
4 changes: 2 additions & 2 deletions chains/ethereum/server/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ fn estimate_priority_fee<F: FeeEstimatorConfig>(rewards: &[Vec<U256>]) -> U256 {

// If we encountered a big change in fees at a certain position, then consider only
// the values >= it.
let values = if max_change >= F::EIP1559_FEE_ESTIMATION_THRESHOLD_MAX_CHANGE.into() &&
(max_change_index >= (rewards.len() / 2))
let values = if max_change >= F::EIP1559_FEE_ESTIMATION_THRESHOLD_MAX_CHANGE.into()
&& (max_change_index >= (rewards.len() / 2))
{
rewards[max_change_index..].to_vec()
} else {
Expand Down
4 changes: 2 additions & 2 deletions chains/ethereum/types/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ impl Signer for Keypair {
};
let v = u8::try_from(v)
.map_err(|_| secp256k1::Error::InvalidRecoveryId)
.map(u64::from)? &
1;
.map(u64::from)?
& 1;

// All transaction signatures whose s-value is greater than secp256k1n/2 are invalid.
// - https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2.md
Expand Down
38 changes: 19 additions & 19 deletions chains/ethereum/types/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,24 +273,24 @@ impl rlp::Decodable for Header {
impl rlp::Encodable for Header {
fn rlp_append(&self, s: &mut rlp::RlpStream) {
let mut size = 15;
if self.base_fee_per_gas.is_some() ||
self.withdrawals_root.is_some() ||
self.blob_gas_used.is_some() ||
self.excess_blob_gas.is_some() ||
self.parent_beacon_block_root.is_some()
if self.base_fee_per_gas.is_some()
|| self.withdrawals_root.is_some()
|| self.blob_gas_used.is_some()
|| self.excess_blob_gas.is_some()
|| self.parent_beacon_block_root.is_some()
{
size += 1;
}
if self.withdrawals_root.is_some() ||
self.blob_gas_used.is_some() ||
self.excess_blob_gas.is_some() ||
self.parent_beacon_block_root.is_some()
if self.withdrawals_root.is_some()
|| self.blob_gas_used.is_some()
|| self.excess_blob_gas.is_some()
|| self.parent_beacon_block_root.is_some()
{
size += 1;
}
if self.blob_gas_used.is_some() ||
self.excess_blob_gas.is_some() ||
self.parent_beacon_block_root.is_some()
if self.blob_gas_used.is_some()
|| self.excess_blob_gas.is_some()
|| self.parent_beacon_block_root.is_some()
{
size += 1;
}
Expand Down Expand Up @@ -322,10 +322,10 @@ impl rlp::Encodable for Header {
// but withdrawals root is present.
if let Some(ref base_fee) = self.base_fee_per_gas {
s.append(&U256::from(*base_fee));
} else if self.withdrawals_root.is_some() ||
self.blob_gas_used.is_some() ||
self.excess_blob_gas.is_some() ||
self.parent_beacon_block_root.is_some()
} else if self.withdrawals_root.is_some()
|| self.blob_gas_used.is_some()
|| self.excess_blob_gas.is_some()
|| self.parent_beacon_block_root.is_some()
{
s.begin_list(0);
}
Expand All @@ -334,9 +334,9 @@ impl rlp::Encodable for Header {
// but blob gas used is present.
if let Some(ref root) = self.withdrawals_root {
s.append(root);
} else if self.blob_gas_used.is_some() ||
self.excess_blob_gas.is_some() ||
self.parent_beacon_block_root.is_some()
} else if self.blob_gas_used.is_some()
|| self.excess_blob_gas.is_some()
|| self.parent_beacon_block_root.is_some()
{
s.append_empty_data();
}
Expand Down
8 changes: 4 additions & 4 deletions chains/ethereum/types/src/i256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ impl I256 {
// the result.
let overflow = matches!(
(self.sign(), rhs.sign(), result.sign()),
(Sign::Positive, Sign::Positive, Sign::Negative) |
(Sign::Negative, Sign::Negative, Sign::Positive)
(Sign::Positive, Sign::Positive, Sign::Negative)
| (Sign::Negative, Sign::Negative, Sign::Positive)
);

(result, overflow)
Expand Down Expand Up @@ -597,8 +597,8 @@ impl I256 {
// the result.
let overflow = matches!(
(self.sign(), rhs.sign(), result.sign()),
(Sign::Positive, Sign::Negative, Sign::Negative) |
(Sign::Negative, Sign::Positive, Sign::Positive)
(Sign::Positive, Sign::Negative, Sign::Negative)
| (Sign::Negative, Sign::Positive, Sign::Positive)
);

(result, overflow)
Expand Down
7 changes: 6 additions & 1 deletion chains/polkadot/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ impl BlockchainClient for PolkadotClient {
Ok(account_info.data.free)
}

async fn faucet(&self, address: &Address, value: u128) -> Result<Vec<u8>> {
async fn faucet(
&self,
address: &Address,
value: u128,
_high_gas_price: Option<u128>,
) -> Result<Vec<u8>> {
let address: AccountId32 = address
.address()
.parse()
Expand Down
Loading

0 comments on commit 33438a8

Please sign in to comment.