Skip to content

Commit

Permalink
Stefan/fix test (#343)
Browse files Browse the repository at this point in the history
* to polkadot-v1.0.0

* gafi node

* benchmarks

* remove old module

* unittest

* fix warnings
  • Loading branch information
mutobui authored Oct 3, 2023
1 parent e04eff7 commit 34b77a3
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 172 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 22 additions & 22 deletions gafi-node/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,53 @@ name = "gafi-node"
clap = { version = "4.2.5", features = ["derive"] }
futures = { version = "0.3.21", features = ["thread-pool"] }

sc-cli = { workspace = true, default-features = false }
sc-cli = { workspace = true }
sp-core = { workspace = true, default-features = false }
sc-executor = { workspace = true, default-features = false }
sc-network = { workspace = true, default-features = false }
sc-service = { workspace = true, default-features = false }
sc-telemetry = { workspace = true, default-features = false }
sc-transaction-pool = { workspace = true, default-features = false }
sc-transaction-pool-api = { workspace = true, default-features = false }
sc-offchain = { workspace = true, default-features = false }
sc-statement-store = { workspace = true, default-features = false }
sc-consensus-aura = { workspace = true, default-features = false }
sc-executor = { workspace = true }
sc-network = { workspace = true }
sc-service = { workspace = true }
sc-telemetry = { workspace = true }
sc-transaction-pool = { workspace = true }
sc-transaction-pool-api = { workspace = true }
sc-offchain = { workspace = true }
sc-statement-store = { workspace = true }
sc-consensus-aura = { workspace = true }
sp-consensus-aura = { workspace = true, default-features = false }
sc-consensus = { workspace = true, default-features = false }
sc-consensus-grandpa = { workspace = true, default-features = false }
sc-consensus = { workspace = true }
sc-consensus-grandpa = { workspace = true }
sp-consensus-grandpa = { workspace = true, default-features = false }
sc-client-api = { workspace = true, default-features = false }
sc-client-api = { workspace = true }
sp-runtime = { workspace = true, default-features = false }
sp-io = { workspace = true, default-features = false }
sp-timestamp = { workspace = true, default-features = false }
sp-inherents = { workspace = true, default-features = false }
sp-keyring = { workspace = true, default-features = false }
sp-keyring = { workspace = true }
frame-system = { workspace = true, default-features = false }
pallet-transaction-payment = { workspace = true, default-features = false }

# These dependencies are used for the node template's RPCs
jsonrpsee = { version = "0.16.2", features = ["server"] }
sp-api = { workspace = true, default-features = false }
sc-rpc-api = { workspace = true, default-features = false }
sp-blockchain = { workspace = true, default-features = false }
sc-rpc-api = { workspace = true }
sp-blockchain = { workspace = true }
sp-block-builder = { workspace = true, default-features = false }
sc-basic-authorship = { workspace = true, default-features = false }
substrate-frame-rpc-system = { workspace = true, default-features = false }
pallet-transaction-payment-rpc = { workspace = true, default-features = false }
sc-basic-authorship = { workspace = true }
substrate-frame-rpc-system = { workspace = true }
pallet-transaction-payment-rpc = { workspace = true }

# These dependencies are used for runtime benchmarking
frame-benchmarking = { workspace = true, default-features = false }
frame-benchmarking-cli = { workspace = true, default-features = false }
frame-benchmarking-cli = { workspace = true }

# Local Dependencies
gafi-runtime = { version = "4.0.0-dev", path = "../runtime" }
gafi-support = { version = "4.0.0-dev", default-features = false, path = "../../support" }

# CLI-specific dependencies
try-runtime-cli = { workspace = true, default-features = false, optional = true }
try-runtime-cli = { workspace = true, optional = true }

[build-dependencies]
substrate-build-script-utils = { workspace = true, default-features = false }
substrate-build-script-utils = { workspace = true }

[features]
default = []
Expand Down
4 changes: 3 additions & 1 deletion gafi-node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ codec = { package = "parity-scale-codec", version = "3.6.1", default-features =
scale-info = { version = "2.5.0", default-features = false, features = [
"derive",
] }
log = { version = "0.4.19", default-features = false }

pallet-aura = { workspace = true, default-features = false }
pallet-balances = { workspace = true, default-features = false }
Expand Down Expand Up @@ -64,7 +65,7 @@ game-randomness = { version = "4.0.0-dev", default-features = false, path = "../
pallet-game = { version = "4.0.0-dev", default-features = false, path = "../../game/pallet-game" }

[build-dependencies]
substrate-wasm-builder = { workspace = true, default-features = false, optional = true }
substrate-wasm-builder = { workspace = true, optional = true }

[features]
default = ["std"]
Expand Down Expand Up @@ -99,6 +100,7 @@ std = [
"sp-transaction-pool/std",
"sp-version/std",
"substrate-wasm-builder",
"log/std",

"pallet-insecure-randomness-collective-flip/std",
"pallet-nfts/std",
Expand Down
2 changes: 1 addition & 1 deletion gafi-node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ where
);
let raw_payload = SignedPayload::new(call, extra)
.map_err(|e| {
// log::warn!("Unable to create signed payload: {:?}", e);
log::warn!("Unable to create signed payload: {:?}", e);
})
.ok()?;
let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?;
Expand Down
10 changes: 10 additions & 0 deletions game/pallet-game/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ benchmarks_instance_pallet! {
item: <T as pallet_nfts::Config>::Helper::item(0),
amount: 10,
unit_price: <T as pallet::Config<I>>::Currency::minimum_balance(),
start_block: None,
end_block: None,
}.into() );
}

Expand Down Expand Up @@ -502,6 +504,8 @@ benchmarks_instance_pallet! {
who,
bundle,
price: <T as pallet::Config<I>>::Currency::minimum_balance(),
start_block: None,
end_block: None,
}.into() );
}

Expand Down Expand Up @@ -545,6 +549,8 @@ benchmarks_instance_pallet! {
who,
wishlist: bundle,
price: <T as pallet::Config<I>>::Currency::minimum_balance(),
start_block: None,
end_block: None,
}.into() );
}

Expand Down Expand Up @@ -617,6 +623,8 @@ benchmarks_instance_pallet! {
source: bundle,
required: required.clone(),
maybe_price: Some(<T as pallet::Config<I>>::Currency::minimum_balance()),
start_block: None,
end_block: None,
}.into() );
}

Expand Down Expand Up @@ -765,6 +773,8 @@ benchmarks_instance_pallet! {
item: package.item,
amount: package.amount,
unit_price: <T as pallet::Config<I>>::Currency::minimum_balance(),
start_block: None,
end_block: None,
}.into() );
}

Expand Down
2 changes: 1 addition & 1 deletion game/pallet-game/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod types;
mod benchmarking;

mod weights;
use crate::weights::WeightInfo;
// use crate::weights::WeightInfo;
pub use weights::*;

use frame_support::{
Expand Down
52 changes: 23 additions & 29 deletions game/pallet-game/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,33 @@
use crate::{self as pallet_game};
use frame_support::{
dispatch::Vec,
parameter_types,
traits::{AsEnsureOriginWithArg, ConstU16, ConstU64, OnFinalize, OnInitialize},
traits::{AsEnsureOriginWithArg, ConstU64, OnFinalize, OnInitialize},
PalletId,
};
use frame_system as system;
use pallet_balances::AccountData;
use pallet_nfts::PalletFeatures;
use sp_core::{
sr25519::{self, Signature},
ConstU128, ConstU32, H256,
};
use sp_core::{sr25519::Signature, ConstU128, ConstU32, H256};
use sp_runtime::{
testing::{Header, TestXt},
testing::TestXt,
traits::{BlakeTwo256, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, Verify},
};
use system::{mocking};
use system::mocking;

pub type Extrinsic = TestXt<RuntimeCall, ()>;
type UncheckedExtrinsic = mocking::MockUncheckedExtrinsic<Test>;
type Block = mocking::MockBlock<Test>;
type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
type AccountPublic = <Signature as Verify>::Signer;
use sp_runtime::BuildStorage;

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
PalletGame: pallet_game,
Balances: pallet_balances,
Nfts: pallet_nfts,

}
);

Expand All @@ -45,43 +38,44 @@ impl system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type AccountId = sp_core::sr25519::Public;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u128>;
type AccountData = AccountData<u128>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ConstU16<42>;
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type MaxConsumers = ConstU32<16>;
}

pub const EXISTENTIAL_DEPOSIT: u128 = 1000;

parameter_types! {
pub ExistentialDeposit: u128 = EXISTENTIAL_DEPOSIT;
}

impl pallet_balances::Config for Test {
type MaxLocks = ConstU32<50>;
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
/// The type for recording an account's balance.
type Balance = u128;
/// The ubiquitous event type.
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
type ExistentialDeposit = ConstU128<EXISTENTIAL_DEPOSIT>;
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Test>;
type WeightInfo = ();
type FreezeIdentifier = ();
type MaxFreezes = ();
type HoldIdentifier = ();
type RuntimeHoldReason = ();
type MaxHolds = ();
}

Expand Down Expand Up @@ -229,5 +223,5 @@ pub fn run_to_block(n: u64) {

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
frame_system::GenesisConfig::<Test>::default().build_storage().unwrap().into()
}
10 changes: 5 additions & 5 deletions game/pallet-game/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ fn create_game_should_works() {
fn create_game_collection_should_works() {
new_test_ext().execute_with(|| {
run_to_block(1);
let (owner, admin) = do_create_game();
let (_, admin) = do_create_game();

assert_ok!(PalletGame::create_game_collection(
RuntimeOrigin::signed(admin.clone()),
Expand All @@ -305,7 +305,7 @@ fn create_game_collection_should_fails() {
// no permission
{
run_to_block(1);
let (owner, admin) = do_create_game();
let (owner, _) = do_create_game();

let acc = new_account(3, 3 * unit(GAKI));
// random acc should has no permission
Expand Down Expand Up @@ -413,7 +413,7 @@ fn set_accept_adding_should_works() {
fn add_game_collection_should_works() {
new_test_ext().execute_with(|| {
run_to_block(1);
let (owner, admin) = do_create_game();
let (_, admin) = do_create_game();

let who = new_account(1, 1000 * unit(GAKI));

Expand Down Expand Up @@ -1001,7 +1001,7 @@ pub fn buy_bundle_should_fails() {
run_to_block(1);

let price = 100 * unit(GAKI);
let seller = do_all_set_bundle(TEST_BUNDLE.clone().to_vec(), price);
let _ = do_all_set_bundle(TEST_BUNDLE.clone().to_vec(), price);

let buyer = new_account(1, 1 * unit(GAKI));

Expand Down Expand Up @@ -1801,7 +1801,7 @@ fn create_dynamic_pool_should_works() {
fn request_mint_should_works() {
new_test_ext().execute_with(|| {
run_to_block(1);
let (owner, _) = do_all_create_stable_pool(default_mint_config());
let (_, _) = do_all_create_stable_pool(default_mint_config());
let player = new_account(2, 1000_000 * unit(GAKI));

let amount = 10;
Expand Down
Loading

0 comments on commit 34b77a3

Please sign in to comment.