From d4cab90b8bcffabc47f4b4621ce071124bc0f7e9 Mon Sep 17 00:00:00 2001 From: Eugene Kovalev Date: Sun, 26 May 2024 23:26:40 +0300 Subject: [PATCH] Fix insufficient value issue in benchmarks --- pallets/gear/src/benchmarking/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pallets/gear/src/benchmarking/mod.rs b/pallets/gear/src/benchmarking/mod.rs index d328720ced3..0eaf508056e 100644 --- a/pallets/gear/src/benchmarking/mod.rs +++ b/pallets/gear/src/benchmarking/mod.rs @@ -107,7 +107,7 @@ use sp_consensus_babe::{ use sp_core::H256; use sp_runtime::{ traits::{Bounded, CheckedAdd, One, UniqueSaturatedInto, Zero}, - Digest, DigestItem, Perbill, + Digest, DigestItem, Perbill, Saturating, }; use sp_std::prelude::*; @@ -251,7 +251,12 @@ where module: WasmModule, data: Vec, ) -> Result, &'static str> { - let value = CurrencyOf::::minimum_balance(); + // In case of the `gr_create_program` syscall testing, we can have as many as + // `API_BENCHMARK_BATCHES * API_BENCHMARK_BATCH_SIZE` repetitions of it in a module, + // which requires a transfer of the ED each time the syscall is called. + // For the above to always succeed, we need to ensure the contract has enough funds. + let value = CurrencyOf::::minimum_balance() + .saturating_mul((API_BENCHMARK_BATCHES * API_BENCHMARK_BATCH_SIZE).into()); CurrencyOf::::make_free_balance_be(&caller, caller_funding::()); let salt = vec![0xff]; let addr = ProgramId::generate_from_user(module.hash, &salt).into_origin();