mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-16 15:25:41 +00:00
ca8f0d6625
* bugfix: balances::transfer for new_account
issue:#722
would_create flag should depend on dest, not origin.
change
```rust
let would_create = from_balance.is_zero();
```
to
```rust
let to_balance = Self::free_balance(&dest);
let would_create = to_balance.is_zero();
```
in the other hand, provide `fn new_test_ext2()` and let `transfer_fee=10`, `creation_fee=50` for test case
* Update lib.rs
* Update tests.rs
* Make `impl_outer_origin!` support generic `Origin`s (#732)
* Make `impl_outer_origin!` support generic `Origin`s
* Support empty outer origin
* Contracts: fix transfer function. (#733)
* Remove dependency on the parity repo (#734)
* Fix test
* Anothe fix
101 lines
3.0 KiB
Rust
101 lines
3.0 KiB
Rust
// Copyright 2018 Parity Technologies (UK) Ltd.
|
|
// This file is part of Substrate.
|
|
|
|
// Substrate is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Substrate is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Test utilities
|
|
|
|
#![cfg(test)]
|
|
|
|
use primitives::BuildStorage;
|
|
use primitives::testing::{Digest, Header};
|
|
use substrate_primitives::{H256, Blake2Hasher};
|
|
use runtime_io;
|
|
use {GenesisConfig, Module, Trait, system};
|
|
|
|
impl_outer_origin!{
|
|
pub enum Origin for Runtime {}
|
|
}
|
|
|
|
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
|
|
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
|
pub struct Runtime;
|
|
impl system::Trait for Runtime {
|
|
type Origin = Origin;
|
|
type Index = u64;
|
|
type BlockNumber = u64;
|
|
type Hash = H256;
|
|
type Hashing = ::primitives::traits::BlakeTwo256;
|
|
type Digest = Digest;
|
|
type AccountId = u64;
|
|
type Header = Header;
|
|
type Event = ();
|
|
}
|
|
impl Trait for Runtime {
|
|
type Balance = u64;
|
|
type AccountIndex = u64;
|
|
type OnFreeBalanceZero = ();
|
|
type EnsureAccountLiquid = ();
|
|
type Event = ();
|
|
}
|
|
|
|
pub fn new_test_ext(ext_deposit: u64, monied: bool) -> runtime_io::TestExternalities<Blake2Hasher> {
|
|
let mut t = system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
|
|
let balance_factor = if ext_deposit > 0 {
|
|
256
|
|
} else {
|
|
1
|
|
};
|
|
t.extend(GenesisConfig::<Runtime>{
|
|
balances: if monied {
|
|
vec![(1, 10 * balance_factor), (2, 20 * balance_factor), (3, 30 * balance_factor), (4, 40 * balance_factor)]
|
|
} else {
|
|
vec![(10, balance_factor), (20, balance_factor)]
|
|
},
|
|
transaction_base_fee: 0,
|
|
transaction_byte_fee: 0,
|
|
existential_deposit: ext_deposit,
|
|
transfer_fee: 0,
|
|
creation_fee: 0,
|
|
reclaim_rebate: 0,
|
|
}.build_storage().unwrap());
|
|
t.into()
|
|
}
|
|
|
|
pub fn new_test_ext2(ext_deposit: u64, monied: bool) -> runtime_io::TestExternalities<Blake2Hasher> {
|
|
let mut t = system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
|
|
let balance_factor = if ext_deposit > 0 {
|
|
256
|
|
} else {
|
|
1
|
|
};
|
|
t.extend(GenesisConfig::<Runtime>{
|
|
balances: if monied {
|
|
vec![(1, 10 * balance_factor), (2, 20 * balance_factor), (3, 30 * balance_factor), (4, 40 * balance_factor)]
|
|
} else {
|
|
vec![(10, balance_factor), (20, balance_factor)]
|
|
},
|
|
transaction_base_fee: 0,
|
|
transaction_byte_fee: 0,
|
|
existential_deposit: ext_deposit,
|
|
transfer_fee: 10, // transfer_fee not zero
|
|
creation_fee: 50, // creation_fee not zero
|
|
reclaim_rebate: 0,
|
|
}.build_storage().unwrap());
|
|
t.into()
|
|
}
|
|
|
|
pub type System = system::Module<Runtime>;
|
|
pub type Balances = Module<Runtime>;
|