mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 14:41:11 +00:00
Fix subtle indices bug (#2128)
* Fix subtle indices bug * Also fix balances divide by zero.
This commit is contained in:
BIN
Binary file not shown.
@@ -58,8 +58,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("node"),
|
||||
impl_name: create_runtime_str!("substrate-node"),
|
||||
authoring_version: 10,
|
||||
spec_version: 45,
|
||||
impl_version: 45,
|
||||
spec_version: 46,
|
||||
impl_version: 46,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
|
||||
|
||||
BIN
Binary file not shown.
@@ -312,7 +312,7 @@ decl_storage! {
|
||||
// <= begin it should be >= balance
|
||||
// >= begin+length it should be <= 0
|
||||
|
||||
let per_block = balance / length;
|
||||
let per_block = balance / length.max(primitives::traits::One::one());
|
||||
let offset = begin * per_block + balance;
|
||||
|
||||
(who.clone(), VestingSchedule { offset, per_block })
|
||||
|
||||
@@ -54,7 +54,7 @@ impl<AccountId, AccountIndex> From<AccountId> for Address<AccountId, AccountInde
|
||||
}
|
||||
|
||||
fn need_more_than<T: PartialOrd>(a: T, b: T) -> Option<T> {
|
||||
if a < b { Some(a) } else { None }
|
||||
if a < b { Some(b) } else { None }
|
||||
}
|
||||
|
||||
impl<AccountId, AccountIndex> Decode for Address<AccountId, AccountIndex> where
|
||||
@@ -108,3 +108,31 @@ impl<AccountId, AccountIndex> Default for Address<AccountId, AccountIndex> where
|
||||
Address::Id(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{Encode, Decode};
|
||||
|
||||
type Address = super::Address<[u8; 8], u32>;
|
||||
fn index(i: u32) -> Address { super::Address::Index(i) }
|
||||
fn id(i: [u8; 8]) -> Address { super::Address::Id(i) }
|
||||
|
||||
fn compare(a: Option<Address>, d: &[u8]) {
|
||||
if let Some(ref a) = a {
|
||||
assert_eq!(d, &a.encode()[..]);
|
||||
}
|
||||
assert_eq!(Address::decode(&mut &d[..]), a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_should_work() {
|
||||
compare(Some(index(2)), &[2][..]);
|
||||
compare(None, &[240][..]);
|
||||
compare(None, &[252, 239, 0][..]);
|
||||
compare(Some(index(240)), &[252, 240, 0][..]);
|
||||
compare(Some(index(304)), &[252, 48, 1][..]);
|
||||
compare(None, &[253, 255, 255, 0, 0][..]);
|
||||
compare(Some(index(0x10000)), &[253, 0, 0, 1, 0][..]);
|
||||
compare(Some(id([42, 69, 42, 69, 42, 69, 42, 69])), &[255, 42, 69, 42, 69, 42, 69, 42, 69][..]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user