Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moree fixes #643

Merged
merged 1 commit into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ pub enum ReserveIdentifier {
Setmint,
Nft,
TransactionPayment,

// always the last, indicate number of variants
Count,
}
3 changes: 0 additions & 3 deletions runtime/src/benchmarking/cdp_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ runtime_benchmarks! {
Change::NewValue(100_000 * dollar(STABLECOIN))
)

set_global_params {
}: _(RawOrigin::Root, Rate::saturating_from_rational(1, 1000000))

// `liquidate` by_auction
liquidate_by_auction {
let owner: AccountId = account("owner", 0, SEED);
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/benchmarking/cdp_treasury.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ runtime_benchmarks! {
set_expected_collateral_auction_size {
}: _(RawOrigin::Root, STAKING, 200 * dollar(STAKING))

extract_surplus_to_treasury {
extract_surplus_to_serp {
CdpTreasury::on_system_surplus(1_000 * dollar(STABLECOIN))?;
}: _(RawOrigin::Root, 200 * dollar(STABLECOIN))
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/benchmarking/currencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ runtime_benchmarks! {

let to: AccountId = account("to", 0, SEED);
let to_lookup = lookup_of_account(to.clone());
}: transfer(RawOrigin::Signed(from), to_lookup, NATIVE, amount)
}: transfer(RawOrigin::Signed(from), to_lookup, NATIVE, amount, false)
verify {
assert_eq!(<Currencies as MultiCurrency<_>>::total_balance(NATIVE, &to), amount);
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/benchmarking/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ runtime_benchmarks! {

let maker: AccountId = account("maker", 0, SEED);
let taker: AccountId = whitelisted_caller();
inject_liquidity(maker, trading_pair.first(), trading_pair.second(), 10_000 * dollar(trading_pair.first()), 10_000 * dollar(trading_pair.second()), false)?;
inject_liquidity(maker, trading_pair.first(), trading_pair.second(), 10_000 * dollar(trading_pair.first()), 10_000 * dollar(trading_pair.second()))?;

<Currencies as MultiCurrencyExtended<_>>::update_balance(path[0], &taker, (10_000 * dollar(path[0])).unique_saturated_into())?;
}: swap_with_exact_supply(RawOrigin::Signed(taker), path.clone(), 100 * dollar(path[0]), 0)
Expand Down
138 changes: 55 additions & 83 deletions runtime/src/benchmarking/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{AccountId, Balance, Event, EvmAccounts, Origin, Runtime, System, DOLLARS, EVM};
use crate::{dollar, AccountId, CurrencyId, Event, EvmAccounts, GetNativeCurrencyId, Origin, Runtime, System, EVM};

use super::utils::set_setheum_balance;
use super::utils::set_balance;
use frame_support::dispatch::DispatchError;
use frame_system::RawOrigin;
use orml_benchmarking::runtime_benchmarks;
use module_support::AddressMapping;
use orml_benchmarking::{runtime_benchmarks, whitelist_account};
use sp_core::H160;
use sp_io::hashing::keccak_256;
use sp_std::{prelude::*, vec};
use sp_std::{str::FromStr, vec};

fn dollar(d: u32) -> Balance {
let d: Balance = d.into();
DOLLARS.saturating_mul(d)
const NATIVE: CurrencyId = GetNativeCurrencyId::get();

fn contract_addr() -> H160 {
H160::from_str("0x5e0b4bfa0b55932a3587e648c3552a6515ba56b1").unwrap()
}

fn alice() -> secp256k1::SecretKey {
Expand All @@ -58,14 +60,15 @@ fn deploy_contract(caller: AccountId) -> Result<H160, DispatchError> {
let contract = hex_literal::hex!("608060405234801561001057600080fd5b5061016f806100206000396000f3fe608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063412a5a6d14610046575b600080fd5b61004e610050565b005b600061005a6100e2565b604051809103906000f080158015610076573d6000803e3d6000fd5b50905060008190806001815401808255809150509060018203906000526020600020016000909192909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050565b6040516052806100f28339019056fe6080604052348015600f57600080fd5b50603580601d6000396000f3fe6080604052600080fdfea165627a7a7230582092dc1966a8880ddf11e067f9dd56a632c11a78a4afd4a9f05924d427367958cc0029a165627a7a723058202b2cc7384e11c452cdbf39b68dada2d5e10a632cc0174a354b8b8c83237e28a40029").to_vec();

System::set_block_number(1);
EVM::create(Origin::signed(caller), contract, 0, 1000000000, 1000000000)
EVM::create(Origin::signed(caller.clone()), contract, 0, 1000000000, 1000000000)
.map_or_else(|e| Err(e.error), |_| Ok(()))?;

if let Event::EVM(module_evm::Event::Created(address)) = System::events().iter().last().unwrap().event {
Ok(address)
} else {
Err("deploy_contract failed".into())
}
System::assert_last_event(Event::EVM(module_evm::Event::Created(
module_evm_accounts::EvmAddressMapping::<Runtime>::get_evm_address(&caller).unwrap(),
contract_addr(),
vec![],
)));
Ok(contract_addr())
}

pub fn alice_account_id() -> AccountId {
Expand All @@ -88,108 +91,77 @@ runtime_benchmarks! {
{ Runtime, module_evm }

transfer_maintainer {
set_setheum_balance(&alice_account_id(), dollar(1000));
set_setheum_balance(&bob_account_id(), dollar(1000));
let alice_account = alice_account_id();

set_balance(NATIVE, &alice_account, 1_000_000 * dollar(NATIVE));
set_balance(NATIVE, &bob_account_id(), 1_000 * dollar(NATIVE));
let contract = deploy_contract(alice_account_id())?;
let bob_address = EvmAccounts::eth_address(&bob());

whitelist_account!(alice_account);
}: _(RawOrigin::Signed(alice_account_id()), contract, bob_address)

deploy {
set_setheum_balance(&alice_account_id(), dollar(1000));
set_setheum_balance(&bob_account_id(), dollar(1000));
let alice_account = alice_account_id();

set_balance(NATIVE, &alice_account, 1_000_000 * dollar(NATIVE));
set_balance(NATIVE, &bob_account_id(), 1_000 * dollar(NATIVE));
let contract = deploy_contract(alice_account_id())?;

whitelist_account!(alice_account);
}: _(RawOrigin::Signed(alice_account_id()), contract)

deploy_free {
set_setheum_balance(&alice_account_id(), dollar(1000));
set_setheum_balance(&bob_account_id(), dollar(1000));
let alice_account = alice_account_id();

set_balance(NATIVE, &alice_account, 1_000_000 * dollar(NATIVE));
set_balance(NATIVE, &bob_account_id(), 1_000 * dollar(NATIVE));
let contract = deploy_contract(alice_account_id())?;
}: _(RawOrigin::Root, contract)

enable_contract_development {
set_setheum_balance(&alice_account_id(), dollar(1000));
let alice_account = alice_account_id();

set_balance(NATIVE, &alice_account, 1_000 * dollar(NATIVE));

whitelist_account!(alice_account);
}: _(RawOrigin::Signed(alice_account_id()))

disable_contract_development {
set_setheum_balance(&alice_account_id(), dollar(1000));
let alice_account = alice_account_id();

set_balance(NATIVE, &alice_account, 1_000 * dollar(NATIVE));
EVM::enable_contract_development(Origin::signed(alice_account_id()))?;

whitelist_account!(alice_account);
}: _(RawOrigin::Signed(alice_account_id()))

set_code {
set_setheum_balance(&alice_account_id(), dollar(1000));
let alice_account = alice_account_id();

set_balance(NATIVE, &alice_account, 1_000_000 * dollar(NATIVE));
let contract = deploy_contract(alice_account_id())?;

let new_contract = hex_literal::hex!("608060405234801561001057600080fd5b5061016f806100206000396000f3fe608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063412a5a6d14610046575b600080fd5b61004e610050565b005b600061005a6100e2565b604051809103906000f080158015610076573d6000803e3d6000fd5b50905060008190806001815401808255809150509060018203906000526020600020016000909192909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050565b6040516052806100f28339019056fe6080604052348015600f57600080fd5b50603580601d6000396000f3fe6080604052600080fdfea165627a7a7230582092dc1966a8880ddf11e067f9dd56a632c11a78a4afd4a9f05924d427367958cc0029a165627a7a723058202b2cc7384e11c452cdbf39b68dada2d5e10a632cc0174a354b8b8c83237e28a400291234").to_vec();

whitelist_account!(alice_account);
}: _(RawOrigin::Signed(alice_account_id()), contract, new_contract)

selfdestruct {
set_setheum_balance(&alice_account_id(), dollar(1000));
let alice_account = alice_account_id();

set_balance(NATIVE, &alice_account, 1_000_000 * dollar(NATIVE));
let contract = deploy_contract(alice_account_id())?;

whitelist_account!(alice_account);
}: _(RawOrigin::Signed(alice_account_id()), contract)
}

#[cfg(test)]
mod tests {
use super::*;
use frame_support::assert_ok;

fn new_test_ext() -> sp_io::TestExternalities {
let t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}

#[test]
fn test_transfer_maintainer() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_transfer_maintainer());
});
}

#[test]
fn test_deploy() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_deploy());
});
}

#[test]
fn test_deploy_free() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_deploy_free());
});
}

#[test]
fn test_enable_contract_development() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_enable_contract_development());
});
}

#[test]
fn test_disable_contract_development() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_disable_contract_development());
});
}

#[test]
fn test_set_code() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_set_code());
});
}

#[test]
fn test_selfdestruct() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_selfdestruct());
});
}
use crate::benchmarking::utils::tests::new_test_ext;
use orml_benchmarking::impl_benchmark_test_suite;

impl_benchmark_test_suite!(new_test_ext(),);
}
44 changes: 11 additions & 33 deletions runtime/src/benchmarking/evm_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,18 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{AccountId, Balance, EvmAccounts, Runtime, DOLLARS};
use crate::{dollar, AccountId, CurrencyId, EvmAccounts, GetNativeCurrencyId, Runtime};

use super::utils::set_setheum_balance;
use super::utils::set_balance;
use codec::Encode;
use frame_benchmarking::{account, whitelisted_caller};
use frame_system::RawOrigin;
use orml_benchmarking::runtime_benchmarks;
use sp_io::hashing::keccak_256;
use sp_std::prelude::*;

const SEED: u32 = 0;

fn dollar(d: u32) -> Balance {
let d: Balance = d.into();
DOLLARS.saturating_mul(d)
}
const NATIVE: CurrencyId = GetNativeCurrencyId::get();

fn alice() -> secp256k1::SecretKey {
secp256k1::SecretKey::parse(&keccak_256(b"Alice")).unwrap()
Expand All @@ -56,39 +52,21 @@ runtime_benchmarks! {
{ Runtime, module_evm_accounts }

claim_account {
let caller: AccountId = account("caller", 0, SEED);
let caller: AccountId = whitelisted_caller();
let eth: AccountId = account("eth", 0, SEED);
set_setheum_balance(&bob_account_id(), dollar(1000));
}: _(RawOrigin::Signed(caller), EvmAccounts::eth_address(&alice()), EvmAccounts::eth_sign(&alice(), &caller.encode(), &[][..]).unwrap())
set_balance(NATIVE, &bob_account_id(), 1_000 * dollar(NATIVE));
}: _(RawOrigin::Signed(caller), EvmAccounts::eth_address(&alice()), EvmAccounts::eth_sign(&alice(), &caller.encode(), &[][..]))

claim_default_account {
let caller = whitelisted_caller();
}: _(RawOrigin::Signed(caller))
}: _(RawOrigin::Signed(caller))
}

#[cfg(test)]
mod tests {
use super::*;
use frame_support::assert_ok;

fn new_test_ext() -> sp_io::TestExternalities {
frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
.unwrap()
.into()
}

#[test]
fn test_claim_account() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_claim_account());
});
}

#[test]
fn test_claim_default_account() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_claim_account());
});
}
use crate::benchmarking::utils::tests::new_test_ext;
use orml_benchmarking::impl_benchmark_test_suite;

impl_benchmark_test_suite!(new_test_ext(),);
}
6 changes: 0 additions & 6 deletions runtime/src/benchmarking/serp_setmint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ runtime_benchmarks! {
CdpEngine::set_collateral_params(
RawOrigin::Root.into(),
currency_id,
Change::NoChange,
Change::NewValue(Some(Ratio::saturating_from_rational(150, 100))),
Change::NewValue(Some(Rate::saturating_from_rational(10, 100))),
Change::NewValue(Some(Ratio::saturating_from_rational(150, 100))),
Expand Down Expand Up @@ -146,7 +145,6 @@ runtime_benchmarks! {
CdpEngine::set_collateral_params(
RawOrigin::Root.into(),
currency_id,
Change::NoChange,
Change::NewValue(Some(Ratio::saturating_from_rational(150, 100))),
Change::NewValue(Some(Rate::saturating_from_rational(10, 100))),
Change::NewValue(Some(Ratio::saturating_from_rational(150, 100))),
Expand Down Expand Up @@ -208,7 +206,6 @@ runtime_benchmarks! {
collateral_amount,
debit_value * 100,
Default::default(),
false,
)?;
Dex::add_liquidity(
RawOrigin::Signed(maker.clone()).into(),
Expand All @@ -217,7 +214,6 @@ runtime_benchmarks! {
collateral_amount,
collateral_amount,
Default::default(),
false,
)?;
Dex::add_liquidity(
RawOrigin::Signed(maker.clone()).into(),
Expand All @@ -226,7 +222,6 @@ runtime_benchmarks! {
collateral_amount,
debit_value * 100,
Default::default(),
false,
)?;

let mut path = vec![currency_id];
Expand All @@ -246,7 +241,6 @@ runtime_benchmarks! {
CdpEngine::set_collateral_params(
RawOrigin::Root.into(),
currency_id,
Change::NoChange,
Change::NewValue(Some(Ratio::saturating_from_rational(150, 100))),
Change::NewValue(Some(Rate::saturating_from_rational(10, 100))),
Change::NewValue(Some(Ratio::saturating_from_rational(150, 100))),
Expand Down
Loading