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

chore(pallets): restructure pallet smart contract #755

Merged
merged 14 commits into from
Jun 29, 2023
Merged
23 changes: 13 additions & 10 deletions substrate-node/pallets/pallet-smart-contract/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_support::{
assert_ok,
traits::{OnFinalize, OnInitialize},
BoundedVec,
};
use frame_system::{EventRecord, Pallet as System, RawOrigin};
use pallet_balances::Pallet as Balances;
Expand All @@ -14,12 +15,15 @@ use pallet_tfgrid::{
CityNameInput, CountryNameInput, DocumentHashInput, DocumentLinkInput, Gw4Input, Ip4Input,
LatitudeInput, LongitudeInput, Pallet as TfgridModule, PkInput, RelayInput, ResourcesInput,
};
use pallet_timestamp::Pallet as Timestamp;
use sp_runtime::traits::{Bounded, One, StaticLookup};
use sp_runtime::{
traits::{Bounded, One, StaticLookup},
SaturatedConversion,
};
use sp_std::{
convert::{TryFrom, TryInto},
fmt::Debug,
vec,
vec::Vec,
};
use tfchain_support::{
resources::Resources,
Expand Down Expand Up @@ -154,7 +158,7 @@ benchmarks! {

let report = types::NruConsumption {
contract_id: contract_id,
timestamp: Timestamp::<T>::get().saturated_into::<u64>() / 1000,
timestamp: SmartContractModule::<T>::get_current_timestamp_in_secs(),
window: 1000,
nru: 10 * GIGABYTE,
};
Expand Down Expand Up @@ -258,9 +262,7 @@ benchmarks! {
let solution_provider_id = 1;
assert!(SmartContractModule::<T>::solution_providers(solution_provider_id).is_some());
let solution_provider = SmartContractModule::<T>::solution_providers(solution_provider_id).unwrap();
assert_eq!(
solution_provider.providers, providers
);
assert_eq!(solution_provider.providers, providers);
assert_last_event::<T>(Event::SolutionProviderCreated(solution_provider).into());
}

Expand All @@ -276,6 +278,7 @@ benchmarks! {
verify {
assert!(SmartContractModule::<T>::solution_providers(solution_provider_id).is_some());
let solution_provider = SmartContractModule::<T>::solution_providers(solution_provider_id).unwrap();
assert_eq!(solution_provider.approved, approve);
assert_last_event::<T>(Event::SolutionProviderApproved(solution_provider_id, approve).into());
}

Expand All @@ -292,10 +295,10 @@ benchmarks! {
_create_node_contract::<T>(user.clone());
let contract_id = 1;

let now = Timestamp::<T>::get().saturated_into::<u64>() / 1000;
let now = SmartContractModule::<T>::get_current_timestamp_in_secs();
let elapsed_seconds = 5; // need to be < 6 secs to bill at same block!
let then: u64 = now + elapsed_seconds;
Timestamp::<T>::set_timestamp((then * 1000).try_into().unwrap());
pallet_timestamp::Pallet::<T>::set_timestamp((then * 1000).try_into().unwrap());

_push_contract_used_resources_report::<T>(farmer.clone());
_push_contract_nru_consumption_report::<T>(farmer.clone(), then, elapsed_seconds);
Expand All @@ -309,7 +312,7 @@ benchmarks! {
assert_eq!(lock.amount_locked, cost);
let contract_bill = types::ContractBill {
contract_id,
timestamp: <Timestamp<T>>::get().saturated_into::<u64>() / 1000,
timestamp: SmartContractModule::<T>::get_current_timestamp_in_secs(),
discount_level: types::DiscountLevel::Gold,
amount_billed: cost.saturated_into::<u128>(),
};
Expand Down Expand Up @@ -810,7 +813,7 @@ pub(crate) fn get_public_ip_gw_input(public_ip_gw_input: &[u8]) -> Gw4Input {
BoundedVec::try_from(public_ip_gw_input.to_vec()).expect("Invalid public ip (gw) input.")
}

pub(crate) fn get_deployment_hash_input(deployment_hash_input: &[u8]) -> HexHash {
pub(crate) fn get_deployment_hash_input(deployment_hash_input: &[u8]) -> types::HexHash {
deployment_hash_input
.to_vec()
.try_into()
Expand Down
Loading