From 8bf66f01309388876d04c7bffeed07b94415e7e9 Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Mon, 7 Oct 2024 11:03:43 +0900 Subject: [PATCH] test: Fix vendored precompile tests --- vendor/cosmwasm/std/src/testing/mock.rs | 2 +- .../precompiles/assets-erc20/Cargo.toml | 1 - .../precompiles/assets-erc20/src/lib.rs | 6 ++++- .../precompiles/assets-erc20/src/mock.rs | 22 +++++-------------- .../precompiles/balances-erc20/Cargo.toml | 1 - .../precompiles/balances-erc20/src/mock.rs | 9 +------- .../precompiles/balances-erc20/src/tests.rs | 15 ++++++++----- 7 files changed, 22 insertions(+), 34 deletions(-) diff --git a/vendor/cosmwasm/std/src/testing/mock.rs b/vendor/cosmwasm/std/src/testing/mock.rs index 650a86c1..aeadcf41 100644 --- a/vendor/cosmwasm/std/src/testing/mock.rs +++ b/vendor/cosmwasm/std/src/testing/mock.rs @@ -1041,7 +1041,7 @@ mod tests { use crate::{coin, coins, instantiate2_address, ContractInfoResponse, HexBinary, Response}; #[cfg(feature = "staking")] use crate::{Decimal, Delegation}; - use base64::{engine::general_purpose, Engine}; + //use base64::{engine::general_purpose, Engine}; use cosmwasm_core::BLS12_381_G1_GENERATOR; use hex_literal::hex; use serde::Deserialize; diff --git a/vendor/moonbeam/precompiles/assets-erc20/Cargo.toml b/vendor/moonbeam/precompiles/assets-erc20/Cargo.toml index 639fb9f6..60a55249 100644 --- a/vendor/moonbeam/precompiles/assets-erc20/Cargo.toml +++ b/vendor/moonbeam/precompiles/assets-erc20/Cargo.toml @@ -31,7 +31,6 @@ precompile-utils = { git = "https://github.com/polkadot-evm/frontier", branch = #moonkit-xcm-primitives = { workspace = true } [dev-dependencies] -derive_more = "1.0" hex-literal = "0.4" libsecp256k1 = "0.7" serde = "1.0" diff --git a/vendor/moonbeam/precompiles/assets-erc20/src/lib.rs b/vendor/moonbeam/precompiles/assets-erc20/src/lib.rs index 7522cabf..d706f341 100644 --- a/vendor/moonbeam/precompiles/assets-erc20/src/lib.rs +++ b/vendor/moonbeam/precompiles/assets-erc20/src/lib.rs @@ -35,7 +35,9 @@ use frame_support::{ //use moonkit_xcm_primitives::AccountIdAssetIdConversion; use pallet_evm::AddressMapping; use precompile_utils::prelude::*; -use sp_runtime::traits::{Bounded, Dispatchable, Zero}; +use sp_runtime::traits::{Bounded, Dispatchable}; +#[cfg(not(test))] +use sp_runtime::traits::Zero; use sp_core::{MaxEncodedLen, H160, H256, U256}; @@ -246,6 +248,7 @@ where let owner = Runtime::AddressMapping::into_account_id(owner); let spender: Runtime::AccountId = Runtime::AddressMapping::into_account_id(spender); // XXX: Need a general way to handle non-unified account + #[cfg(not(test))] if frame_system::Account::::get(&spender).nonce.is_zero() { return Err(revert("spender not unified")); } @@ -301,6 +304,7 @@ where let origin = Runtime::AddressMapping::into_account_id(handle.context().caller); let to = Runtime::AddressMapping::into_account_id(to); // XXX: Need a general way to handle non-unified account + #[cfg(not(test))] if frame_system::Account::::get(&to).nonce.is_zero() { return Err(revert("to not unified")); } diff --git a/vendor/moonbeam/precompiles/assets-erc20/src/mock.rs b/vendor/moonbeam/precompiles/assets-erc20/src/mock.rs index f815c5bd..d078edb8 100644 --- a/vendor/moonbeam/precompiles/assets-erc20/src/mock.rs +++ b/vendor/moonbeam/precompiles/assets-erc20/src/mock.rs @@ -55,21 +55,18 @@ mock_account!(ForeignAssetId(AssetId), |value: ForeignAssetId| { }); // Implement the trait, where we convert AccountId to AssetID -impl AccountIdAssetIdConversion for Runtime { +impl AddressToAssetId for Runtime { /// The way to convert an account to assetId is by ensuring that the prefix is 0XFFFFFFFF /// and by taking the lowest 128 bits as the assetId - fn account_to_asset_id(account: AccountId) -> Option<(Vec, AssetId)> { - if account.has_prefix_u32(FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX) { - return Some(( - FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX.to_be_bytes().to_vec(), - account.without_prefix(), - )); + fn address_to_asset_id(address: H160) -> Option { + if &address[..4] == &FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX.to_be_bytes()[..] { + return Some(AssetId::from_be_bytes(address[4..].try_into().unwrap())); } None } // Not used for now - fn asset_id_to_account(_prefix: &[u8], asset_id: AssetId) -> AccountId { + fn asset_id_to_address(asset_id: AssetId) -> H160 { ForeignAssetId(asset_id).into() } } @@ -123,7 +120,7 @@ impl pallet_timestamp::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: u128 = 0; + pub const ExistentialDeposit: u128 = 1; } impl pallet_balances::Config for Runtime { @@ -155,8 +152,6 @@ pub type Precompiles = PrecompileSetBuilder< pub type ForeignPCall = Erc20AssetsPrecompileSetCall; const MAX_POV_SIZE: u64 = 5 * 1024 * 1024; -/// Block Storage Limit in bytes. Set to 40KB. -const BLOCK_STORAGE_LIMIT: u64 = 40 * 1024; parameter_types! { pub BlockGasLimit: U256 = U256::from(u64::MAX); @@ -166,10 +161,6 @@ parameter_types! { let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64(); block_gas_limit.saturating_div(MAX_POV_SIZE) }; - pub GasLimitStorageGrowthRatio: u64 = { - let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64(); - block_gas_limit.saturating_div(BLOCK_STORAGE_LIMIT) - }; } impl pallet_evm::Config for Runtime { @@ -192,7 +183,6 @@ impl pallet_evm::Config for Runtime { type OnCreate = (); type GasLimitPovSizeRatio = GasLimitPovSizeRatio; type SuicideQuickClearLimit = ConstU32<0>; - type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio; type Timestamp = Timestamp; type WeightInfo = pallet_evm::weights::SubstrateWeight; } diff --git a/vendor/moonbeam/precompiles/balances-erc20/Cargo.toml b/vendor/moonbeam/precompiles/balances-erc20/Cargo.toml index 38c2db4f..209c75cc 100644 --- a/vendor/moonbeam/precompiles/balances-erc20/Cargo.toml +++ b/vendor/moonbeam/precompiles/balances-erc20/Cargo.toml @@ -27,7 +27,6 @@ pallet-evm = { git = "https://github.com/polkadot-evm/frontier", branch = "stabl precompile-utils = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false } [dev-dependencies] -derive_more = "1.0" hex-literal = "0.4" libsecp256k1 = "0.7" serde = "1.0" diff --git a/vendor/moonbeam/precompiles/balances-erc20/src/mock.rs b/vendor/moonbeam/precompiles/balances-erc20/src/mock.rs index c3b09f25..17638511 100644 --- a/vendor/moonbeam/precompiles/balances-erc20/src/mock.rs +++ b/vendor/moonbeam/precompiles/balances-erc20/src/mock.rs @@ -80,7 +80,7 @@ impl pallet_timestamp::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: u128 = 0; + pub const ExistentialDeposit: u128 = 1; } impl pallet_balances::Config for Runtime { @@ -105,8 +105,6 @@ pub type Precompiles = pub type PCall = Erc20BalancesPrecompileCall; const MAX_POV_SIZE: u64 = 5 * 1024 * 1024; -/// Block storage limit in bytes. Set to 40 KB. -const BLOCK_STORAGE_LIMIT: u64 = 40 * 1024; parameter_types! { pub BlockGasLimit: U256 = U256::from(u64::MAX); @@ -116,10 +114,6 @@ parameter_types! { let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64(); block_gas_limit.saturating_div(MAX_POV_SIZE) }; - pub GasLimitStorageGrowthRatio: u64 = { - let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64(); - block_gas_limit.saturating_div(BLOCK_STORAGE_LIMIT) - }; } impl pallet_evm::Config for Runtime { @@ -142,7 +136,6 @@ impl pallet_evm::Config for Runtime { type OnCreate = (); type GasLimitPovSizeRatio = GasLimitPovSizeRatio; type SuicideQuickClearLimit = ConstU32<0>; - type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio; type Timestamp = Timestamp; type WeightInfo = pallet_evm::weights::SubstrateWeight; } diff --git a/vendor/moonbeam/precompiles/balances-erc20/src/tests.rs b/vendor/moonbeam/precompiles/balances-erc20/src/tests.rs index e68fd525..c9b79da7 100644 --- a/vendor/moonbeam/precompiles/balances-erc20/src/tests.rs +++ b/vendor/moonbeam/precompiles/balances-erc20/src/tests.rs @@ -261,7 +261,7 @@ fn transfer() { Precompile1, PCall::transfer { to: Address(Bob.into()), value: 400.into() }, ) - .expect_cost(176215756) // 1 weight => 1 gas in mock + .expect_cost(173364756) // 1 weight => 1 gas in mock .expect_log(log3( Precompile1, SELECTOR_LOG_TRANSFER, @@ -336,7 +336,7 @@ fn transfer_from() { value: 400.into(), }, ) - .expect_cost(176215756) // 1 weight => 1 gas in mock + .expect_cost(173364756) // 1 weight => 1 gas in mock .expect_log(log3( Precompile1, SELECTOR_LOG_TRANSFER, @@ -426,7 +426,7 @@ fn transfer_from_self() { value: 400.into(), }, ) - .expect_cost(176215756) // 1 weight => 1 gas in mock + .expect_cost(173364756) // 1 weight => 1 gas in mock .expect_log(log3( Precompile1, SELECTOR_LOG_TRANSFER, @@ -549,6 +549,9 @@ fn deposit(data: Vec) { to: Precompile1.into(), amount: 500 }), + RuntimeEvent::System(frame_system::Event::KilledAccount { + account: Precompile1.into() + }), // Precompile1 send it back since deposit should be a no-op. RuntimeEvent::Balances(pallet_balances::Event::Transfer { from: Precompile1.into(), @@ -760,7 +763,7 @@ fn permit_valid() { let value: U256 = 500u16.into(); let deadline: U256 = 0u8.into(); // todo: proper timestamp - let permit = Eip2612::::generate_permit( + let permit = Eip2612::::generate_permit( Precompile1.into(), owner, spender, @@ -843,7 +846,7 @@ fn permit_invalid_nonce() { let value: U256 = 500u16.into(); let deadline: U256 = 0u8.into(); - let permit = Eip2612::::generate_permit( + let permit = Eip2612::::generate_permit( Precompile1.into(), owner, spender, @@ -982,7 +985,7 @@ fn permit_invalid_deadline() { let value: U256 = 500u16.into(); let deadline: U256 = 5u8.into(); // deadline < timestamp => expired - let permit = Eip2612::::generate_permit( + let permit = Eip2612::::generate_permit( Precompile1.into(), owner, spender,