compact param in calls (#1499)

* impl #[codec(compact)] for param

* update modules

* test all and build runtime

* Update srml/support/src/dispatch.rs

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>

* Update srml/support/src/dispatch.rs

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>

* delete wip comment

* update param to use #[compact] instead of Cmpact<>

* fmt

* impl metadata

* test metadata

* add compact attr test

* script buid

* update test
This commit is contained in:
thiolliere
2019-01-22 14:42:13 +01:00
committed by Bastian Köcher
parent 8f38593def
commit 2492931944
24 changed files with 576 additions and 541 deletions
+7 -7
View File
@@ -32,12 +32,12 @@ dependencies = [
[[package]]
name = "hash-db"
version = "0.9.0"
source = "git+https://github.com/paritytech/trie#e61df32342920f602a9d8d71caa5117c779d3ff1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "hash256-std-hasher"
version = "0.9.0"
source = "git+https://github.com/paritytech/trie#e61df32342920f602a9d8d71caa5117c779d3ff1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -144,7 +144,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "sr-io"
version = "0.1.0"
dependencies = [
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-std 0.1.0",
@@ -178,8 +178,8 @@ name = "substrate-primitives"
version = "0.1.0"
dependencies = [
"byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash256-std-hasher 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash256-std-hasher 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"primitive-types 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -219,8 +219,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda"
"checksum crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c240f247c278fa08a6d4820a6a222bfc6e0d999e51ba67be94f44c905b2161f2"
"checksum fixed-hash 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a557e80084b05c32b455963ff565a9de6f2866da023d6671705c6aff6f65e01c"
"checksum hash-db 0.9.0 (git+https://github.com/paritytech/trie)" = "<none>"
"checksum hash256-std-hasher 0.9.0 (git+https://github.com/paritytech/trie)" = "<none>"
"checksum hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dc5ec43724866bbc8337e09cab4d4b5f9fdbbe589f04bdc8bfda906a639ad338"
"checksum hash256-std-hasher 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "811bd8c26961527b7d5623b71162d865325639f8ca204d4ec90b5b87473a122d"
"checksum impl-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9c88568d828291c50eed30cd7fb9f8e688ad0013620186fa3e777b9f206c79f2"
"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
"checksum parity-codec 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e7b6a1290fe78aa6bbb5f3338ecede3062687a98b9e40cd1dbcaa47261d44097"
+24 -24
View File
@@ -212,12 +212,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "hash-db"
version = "0.9.0"
source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "hash256-std-hasher"
version = "0.9.0"
source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -392,9 +392,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "memory-db"
version = "0.9.0"
source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -897,7 +897,7 @@ name = "sr-io"
version = "0.1.0"
dependencies = [
"environmental 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-std 0.1.0",
@@ -1018,7 +1018,7 @@ dependencies = [
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)",
@@ -1106,8 +1106,8 @@ dependencies = [
"base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash256-std-hasher 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash256-std-hasher 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1135,7 +1135,7 @@ dependencies = [
name = "substrate-state-machine"
version = "0.1.0"
dependencies = [
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1143,8 +1143,8 @@ dependencies = [
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"substrate-primitives 0.1.0",
"substrate-trie 0.4.0",
"trie-db 0.9.0 (git+https://github.com/paritytech/trie)",
"trie-root 0.9.0 (git+https://github.com/paritytech/trie)",
"trie-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-root 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1193,11 +1193,11 @@ dependencies = [
name = "substrate-trie"
version = "0.4.0"
dependencies = [
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"memory-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memory-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.9.0 (git+https://github.com/paritytech/trie)",
"trie-root 0.9.0 (git+https://github.com/paritytech/trie)",
"trie-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-root 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1401,10 +1401,10 @@ dependencies = [
[[package]]
name = "trie-db"
version = "0.9.0"
source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1412,9 +1412,9 @@ dependencies = [
[[package]]
name = "trie-root"
version = "0.9.0"
source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1583,8 +1583,8 @@ dependencies = [
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b"
"checksum hash-db 0.9.0 (git+https://github.com/paritytech/trie)" = "<none>"
"checksum hash256-std-hasher 0.9.0 (git+https://github.com/paritytech/trie)" = "<none>"
"checksum hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dc5ec43724866bbc8337e09cab4d4b5f9fdbbe589f04bdc8bfda906a639ad338"
"checksum hash256-std-hasher 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "811bd8c26961527b7d5623b71162d865325639f8ca204d4ec90b5b87473a122d"
"checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461"
"checksum hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4da5f0e01bd8a71a224a4eedecaacfcabda388dbb7a80faf04d3514287572d95"
"checksum hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1d340b6514f232f6db1bd16db65302a5278a04fef9ce867cb932e7e5fa21130a"
@@ -1608,7 +1608,7 @@ dependencies = [
"checksum mashup-impl 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "aa607bfb674b4efb310512527d64266b065de3f894fc52f84efcbf7eaa5965fb"
"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum memory-db 0.9.0 (git+https://github.com/paritytech/trie)" = "<none>"
"checksum memory-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "812321f5fb5adb04c60a872d9e45c6f060f77ed4df7a28eee49d1565cb0af47f"
"checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882"
"checksum mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "71646331f2619b1026cc302f87a2b8b648d5c6dd6937846a16cc8ce0f347f432"
"checksum mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "46e73a04c2fa6250b8d802134d56d554a9ec2922bf977777c805ea5def61ce40"
@@ -1686,8 +1686,8 @@ dependencies = [
"checksum tokio-timer 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4f37f0111d76cc5da132fe9bc0590b9b9cfd079bc7e75ac3846278430a299ff8"
"checksum tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "66268575b80f4a4a710ef83d087fdfeeabdce9b74c797535fbac18a2cb906e92"
"checksum tokio-uds 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "99ce87382f6c1a24b513a72c048b2c8efe66cb5161c9061d00bee510f08dc168"
"checksum trie-db 0.9.0 (git+https://github.com/paritytech/trie)" = "<none>"
"checksum trie-root 0.9.0 (git+https://github.com/paritytech/trie)" = "<none>"
"checksum trie-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6fce41ab9c34e9a79f3f3c149c17dfedba15d10ee273ef1ae40dd48f7d91eb0e"
"checksum trie-root 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6c08a925fd6305f1b7ebbbb663352ddbfe3033648303a91ab127b8b5b12f04"
"checksum twox-hash 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "555cd4909480122bbbf21e34faac4cb08a171f324775670447ed116726c474af"
"checksum uint 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "082df6964410f6aa929a61ddfafc997e4f32c62c22490e439ac351cec827f436"
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
+11 -11
View File
@@ -110,7 +110,7 @@ mod tests {
fn xt() -> UncheckedExtrinsic {
sign(CheckedExtrinsic {
signed: Some((alice(), 0)),
function: Call::Balances(balances::Call::transfer::<Runtime>(bob().into(), 69.into())),
function: Call::Balances(balances::Call::transfer::<Runtime>(bob().into(), 69)),
})
}
@@ -378,11 +378,11 @@ mod tests {
vec![
CheckedExtrinsic {
signed: None,
function: Call::Timestamp(timestamp::Call::set(42.into())),
function: Call::Timestamp(timestamp::Call::set(42)),
},
CheckedExtrinsic {
signed: Some((alice(), 0)),
function: Call::Balances(balances::Call::transfer(bob().into(), 69.into())),
function: Call::Balances(balances::Call::transfer(bob().into(), 69)),
},
]
)
@@ -403,15 +403,15 @@ mod tests {
vec![
CheckedExtrinsic {
signed: None,
function: Call::Timestamp(timestamp::Call::set(52.into())),
function: Call::Timestamp(timestamp::Call::set(52)),
},
CheckedExtrinsic {
signed: Some((bob(), 0)),
function: Call::Balances(balances::Call::transfer(alice().into(), 5.into())),
function: Call::Balances(balances::Call::transfer(alice().into(), 5)),
},
CheckedExtrinsic {
signed: Some((alice(), 1)),
function: Call::Balances(balances::Call::transfer(bob().into(), 15.into())),
function: Call::Balances(balances::Call::transfer(bob().into(), 15)),
}
]
)
@@ -426,7 +426,7 @@ mod tests {
vec![
CheckedExtrinsic {
signed: None,
function: Call::Timestamp(timestamp::Call::set(42.into())),
function: Call::Timestamp(timestamp::Call::set(42)),
},
CheckedExtrinsic {
signed: Some((alice(), 0)),
@@ -697,24 +697,24 @@ mod tests {
vec![
CheckedExtrinsic {
signed: None,
function: Call::Timestamp(timestamp::Call::set(42.into())),
function: Call::Timestamp(timestamp::Call::set(42)),
},
CheckedExtrinsic {
signed: Some((charlie(), 0)),
function: Call::Contract(
contract::Call::put_code::<Runtime>(10_000.into(), transfer_code)
contract::Call::put_code::<Runtime>(10_000, transfer_code)
),
},
CheckedExtrinsic {
signed: Some((charlie(), 1)),
function: Call::Contract(
contract::Call::create::<Runtime>(10.into(), 10_000.into(), transfer_ch, Vec::new())
contract::Call::create::<Runtime>(10, 10_000, transfer_ch, Vec::new())
),
},
CheckedExtrinsic {
signed: Some((charlie(), 2)),
function: Call::Contract(
contract::Call::call::<Runtime>(indices::address::Address::Id(addr), 10.into(), 10_000.into(), vec![0x00, 0x01, 0x02, 0x03])
contract::Call::call::<Runtime>(indices::address::Address::Id(addr), 10, 10_000, vec![0x00, 0x01, 0x02, 0x03])
),
},
]
+24 -24
View File
@@ -212,12 +212,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "hash-db"
version = "0.9.0"
source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "hash256-std-hasher"
version = "0.9.0"
source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -392,9 +392,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "memory-db"
version = "0.9.0"
source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -978,7 +978,7 @@ name = "sr-io"
version = "0.1.0"
dependencies = [
"environmental 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-std 0.1.0",
@@ -1396,7 +1396,7 @@ dependencies = [
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)",
@@ -1496,8 +1496,8 @@ dependencies = [
"base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash256-std-hasher 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash256-std-hasher 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1525,7 +1525,7 @@ dependencies = [
name = "substrate-state-machine"
version = "0.1.0"
dependencies = [
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1533,8 +1533,8 @@ dependencies = [
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"substrate-primitives 0.1.0",
"substrate-trie 0.4.0",
"trie-db 0.9.0 (git+https://github.com/paritytech/trie)",
"trie-root 0.9.0 (git+https://github.com/paritytech/trie)",
"trie-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-root 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1555,11 +1555,11 @@ dependencies = [
name = "substrate-trie"
version = "0.4.0"
dependencies = [
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"memory-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memory-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.9.0 (git+https://github.com/paritytech/trie)",
"trie-root 0.9.0 (git+https://github.com/paritytech/trie)",
"trie-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-root 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1763,10 +1763,10 @@ dependencies = [
[[package]]
name = "trie-db"
version = "0.9.0"
source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1774,9 +1774,9 @@ dependencies = [
[[package]]
name = "trie-root"
version = "0.9.0"
source = "git+https://github.com/paritytech/trie#2616db2a2529098949e5d39aa06dd4e502a9e5f7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hash-db 0.9.0 (git+https://github.com/paritytech/trie)",
"hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1945,8 +1945,8 @@ dependencies = [
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b"
"checksum hash-db 0.9.0 (git+https://github.com/paritytech/trie)" = "<none>"
"checksum hash256-std-hasher 0.9.0 (git+https://github.com/paritytech/trie)" = "<none>"
"checksum hash-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dc5ec43724866bbc8337e09cab4d4b5f9fdbbe589f04bdc8bfda906a639ad338"
"checksum hash256-std-hasher 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "811bd8c26961527b7d5623b71162d865325639f8ca204d4ec90b5b87473a122d"
"checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461"
"checksum hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4da5f0e01bd8a71a224a4eedecaacfcabda388dbb7a80faf04d3514287572d95"
"checksum hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1d340b6514f232f6db1bd16db65302a5278a04fef9ce867cb932e7e5fa21130a"
@@ -1970,7 +1970,7 @@ dependencies = [
"checksum mashup-impl 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "aa607bfb674b4efb310512527d64266b065de3f894fc52f84efcbf7eaa5965fb"
"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum memory-db 0.9.0 (git+https://github.com/paritytech/trie)" = "<none>"
"checksum memory-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "812321f5fb5adb04c60a872d9e45c6f060f77ed4df7a28eee49d1565cb0af47f"
"checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882"
"checksum mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "71646331f2619b1026cc302f87a2b8b648d5c6dd6937846a16cc8ce0f347f432"
"checksum mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "46e73a04c2fa6250b8d802134d56d554a9ec2922bf977777c805ea5def61ce40"
@@ -2051,8 +2051,8 @@ dependencies = [
"checksum tokio-timer 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4f37f0111d76cc5da132fe9bc0590b9b9cfd079bc7e75ac3846278430a299ff8"
"checksum tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "66268575b80f4a4a710ef83d087fdfeeabdce9b74c797535fbac18a2cb906e92"
"checksum tokio-uds 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "99ce87382f6c1a24b513a72c048b2c8efe66cb5161c9061d00bee510f08dc168"
"checksum trie-db 0.9.0 (git+https://github.com/paritytech/trie)" = "<none>"
"checksum trie-root 0.9.0 (git+https://github.com/paritytech/trie)" = "<none>"
"checksum trie-db 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6fce41ab9c34e9a79f3f3c149c17dfedba15d10ee273ef1ae40dd48f7d91eb0e"
"checksum trie-root 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6c08a925fd6305f1b7ebbbb663352ddbfe3033648303a91ab127b8b5b12f04"
"checksum twox-hash 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "555cd4909480122bbbf21e34faac4cb08a171f324775670447ed116726c474af"
"checksum uint 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "082df6964410f6aa929a61ddfafc997e4f32c62c22490e439ac351cec827f436"
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
+23 -28
View File
@@ -46,7 +46,6 @@ extern crate sr_primitives as primitives;
extern crate srml_system as system;
use runtime_support::{StorageValue, StorageMap, Parameter};
use codec::{Compact, HasCompact};
use primitives::traits::{Member, SimpleArithmetic, Zero, StaticLookup};
use system::ensure_signed;
@@ -67,9 +66,8 @@ decl_module! {
/// Issue a new class of fungible assets. There are, and will only ever be, `total`
/// such assets and they'll all belong to the `origin` initially. It will have an
/// identifier `AssetId` instance: this will be specified in the `Issued` event.
fn issue(origin, total: <T::Balance as HasCompact>::Type) {
fn issue(origin, #[compact] total: T::Balance) {
let origin = ensure_signed(origin)?;
let total = total.into();
let id = Self::next_asset_id();
<NextAssetId<T>>::mutate(|id| *id += 1);
@@ -82,16 +80,14 @@ decl_module! {
/// Move some assets from one holder to another.
fn transfer(origin,
id: Compact<AssetId>,
#[compact] id: AssetId,
target: <T::Lookup as StaticLookup>::Source,
amount: <T::Balance as HasCompact>::Type
#[compact] amount: T::Balance
) {
let origin = ensure_signed(origin)?;
let id = id.into();
let origin_account = (id, origin.clone());
let origin_balance = <Balances<T>>::get(&origin_account);
let target = T::Lookup::lookup(target)?;
let amount = amount.into();
ensure!(!amount.is_zero(), "transfer amount should be non-zero");
ensure!(origin_balance >= amount, "origin account balance must be greater than or equal to the transfer amount");
@@ -101,9 +97,8 @@ decl_module! {
}
/// Destroy any assets of `id` owned by `origin`.
fn destroy(origin, id: Compact<AssetId>) {
fn destroy(origin, #[compact] id: AssetId) {
let origin = ensure_signed(origin)?;
let id = id.into();
let balance = <Balances<T>>::take((id, origin.clone()));
ensure!(!balance.is_zero(), "origin balance should be non-zero");
@@ -204,7 +199,7 @@ mod tests {
#[test]
fn issuing_asset_units_to_issuer_should_work() {
with_externalities(&mut new_test_ext(), || {
assert_ok!(Assets::issue(Origin::signed(1), 100.into()));
assert_ok!(Assets::issue(Origin::signed(1), 100));
assert_eq!(Assets::balance(0, 1), 100);
});
}
@@ -212,16 +207,16 @@ mod tests {
#[test]
fn querying_total_supply_should_work() {
with_externalities(&mut new_test_ext(), || {
assert_ok!(Assets::issue(Origin::signed(1), 100.into()));
assert_ok!(Assets::issue(Origin::signed(1), 100));
assert_eq!(Assets::balance(0, 1), 100);
assert_ok!(Assets::transfer(Origin::signed(1), 0.into(), 2, 50.into()));
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
assert_eq!(Assets::balance(0, 1), 50);
assert_eq!(Assets::balance(0, 2), 50);
assert_ok!(Assets::transfer(Origin::signed(2), 0.into(), 3, 31.into()));
assert_ok!(Assets::transfer(Origin::signed(2), 0, 3, 31));
assert_eq!(Assets::balance(0, 1), 50);
assert_eq!(Assets::balance(0, 2), 19);
assert_eq!(Assets::balance(0, 3), 31);
assert_ok!(Assets::destroy(Origin::signed(3), 0.into()));
assert_ok!(Assets::destroy(Origin::signed(3), 0));
assert_eq!(Assets::total_supply(0), 69);
});
}
@@ -229,9 +224,9 @@ mod tests {
#[test]
fn transferring_amount_above_available_balance_should_work() {
with_externalities(&mut new_test_ext(), || {
assert_ok!(Assets::issue(Origin::signed(1), 100.into()));
assert_ok!(Assets::issue(Origin::signed(1), 100));
assert_eq!(Assets::balance(0, 1), 100);
assert_ok!(Assets::transfer(Origin::signed(1), 0.into(), 2, 50.into()));
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
assert_eq!(Assets::balance(0, 1), 50);
assert_eq!(Assets::balance(0, 2), 50);
});
@@ -240,50 +235,50 @@ mod tests {
#[test]
fn transferring_amount_less_than_available_balance_should_not_work() {
with_externalities(&mut new_test_ext(), || {
assert_ok!(Assets::issue(Origin::signed(1), 100.into()));
assert_ok!(Assets::issue(Origin::signed(1), 100));
assert_eq!(Assets::balance(0, 1), 100);
assert_ok!(Assets::transfer(Origin::signed(1), 0.into(), 2, 50.into()));
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
assert_eq!(Assets::balance(0, 1), 50);
assert_eq!(Assets::balance(0, 2), 50);
assert_ok!(Assets::destroy(Origin::signed(1), 0.into()));
assert_ok!(Assets::destroy(Origin::signed(1), 0));
assert_eq!(Assets::balance(0, 1), 0);
assert_noop!(Assets::transfer(Origin::signed(1), 0.into(), 1, 50.into()), "origin account balance must be greater than or equal to the transfer amount");
assert_noop!(Assets::transfer(Origin::signed(1), 0, 1, 50), "origin account balance must be greater than or equal to the transfer amount");
});
}
#[test]
fn transferring_less_than_one_unit_should_not_work() {
with_externalities(&mut new_test_ext(), || {
assert_ok!(Assets::issue(Origin::signed(1), 100.into()));
assert_ok!(Assets::issue(Origin::signed(1), 100));
assert_eq!(Assets::balance(0, 1), 100);
assert_noop!(Assets::transfer(Origin::signed(1), 0.into(), 2, 0.into()), "transfer amount should be non-zero");
assert_noop!(Assets::transfer(Origin::signed(1), 0, 2, 0), "transfer amount should be non-zero");
});
}
#[test]
fn transferring_more_units_than_total_supply_should_not_work() {
with_externalities(&mut new_test_ext(), || {
assert_ok!(Assets::issue(Origin::signed(1), 100.into()));
assert_ok!(Assets::issue(Origin::signed(1), 100));
assert_eq!(Assets::balance(0, 1), 100);
assert_noop!(Assets::transfer(Origin::signed(1), 0.into(), 2, 101.into()), "origin account balance must be greater than or equal to the transfer amount");
assert_noop!(Assets::transfer(Origin::signed(1), 0, 2, 101), "origin account balance must be greater than or equal to the transfer amount");
});
}
#[test]
fn destroying_asset_balance_with_positive_balance_should_work() {
with_externalities(&mut new_test_ext(), || {
assert_ok!(Assets::issue(Origin::signed(1), 100.into()));
assert_ok!(Assets::issue(Origin::signed(1), 100));
assert_eq!(Assets::balance(0, 1), 100);
assert_ok!(Assets::destroy(Origin::signed(1), 0.into()));
assert_ok!(Assets::destroy(Origin::signed(1), 0));
});
}
#[test]
fn destroying_asset_balance_with_zero_balance_should_not_work() {
with_externalities(&mut new_test_ext(), || {
assert_ok!(Assets::issue(Origin::signed(1), 100.into()));
assert_ok!(Assets::issue(Origin::signed(1), 100));
assert_eq!(Assets::balance(0, 2), 0);
assert_noop!(Assets::destroy(Origin::signed(2), 0.into()), "origin balance should be non-zero");
assert_noop!(Assets::destroy(Origin::signed(2), 0), "origin balance should be non-zero");
});
}
}
+6 -7
View File
@@ -43,7 +43,7 @@ extern crate substrate_primitives;
use rstd::prelude::*;
use rstd::{cmp, result};
use codec::{Codec, HasCompact};
use codec::Codec;
use runtime_support::{StorageValue, StorageMap, Parameter};
use runtime_support::dispatch::Result;
use primitives::traits::{Zero, SimpleArithmetic, MakePayment,
@@ -132,12 +132,11 @@ decl_module! {
pub fn transfer(
origin,
dest: <T::Lookup as StaticLookup>::Source,
value: <T::Balance as HasCompact>::Type
#[compact] value: T::Balance
) {
let transactor = ensure_signed(origin)?;
let dest = T::Lookup::lookup(dest)?;
let value = value.into();
let from_balance = Self::free_balance(&transactor);
let to_balance = Self::free_balance(&dest);
let would_create = to_balance.is_zero();
@@ -174,12 +173,12 @@ decl_module! {
/// Set the balances of a given account.
fn set_balance(
who: <T::Lookup as StaticLookup>::Source,
free: <T::Balance as HasCompact>::Type,
reserved: <T::Balance as HasCompact>::Type
#[compact] free: T::Balance,
#[compact] reserved: T::Balance
) {
let who = T::Lookup::lookup(who)?;
Self::set_free_balance(&who, free.into());
Self::set_reserved_balance(&who, reserved.into());
Self::set_free_balance(&who, free);
Self::set_reserved_balance(&who, reserved);
}
}
}
+10 -10
View File
@@ -34,7 +34,7 @@ fn default_indexing_on_new_accounts_should_not_work2() {
assert_eq!(Balances::is_dead_account(&5), true); // account 5 should not exist
// account 1 has 256 * 10 = 2560, account 5 is not exist, ext_deposit is 10, value is 9, not satisfies for ext_deposit
assert_noop!(
Balances::transfer(Some(1).into(), 5, 9.into()),
Balances::transfer(Some(1).into(), 5, 9),
"value too low to create account"
);
assert_eq!(Balances::is_dead_account(&5), true); // account 5 should not exist
@@ -62,7 +62,7 @@ fn reserved_balance_should_prevent_reclaim_count() {
assert_eq!(Balances::is_dead_account(&2), false);
assert_eq!(System::account_nonce(&2), 1);
assert_ok!(Balances::transfer(Some(4).into(), 5, (256 * 1 + 0x69).into())); // account 4 tries to take index 1 for account 5.
assert_ok!(Balances::transfer(Some(4).into(), 5, 256 * 1 + 0x69)); // account 4 tries to take index 1 for account 5.
assert_eq!(Balances::total_balance(&5), 256 * 1 + 0x69);
assert_eq!(Balances::is_dead_account(&5), false);
@@ -71,7 +71,7 @@ fn reserved_balance_should_prevent_reclaim_count() {
assert_eq!(System::account_nonce(&2), 0); // nonce zero
assert_eq!(Balances::is_dead_account(&2), true);
assert_ok!(Balances::transfer(Some(4).into(), 6, (256 * 1 + 0x69).into())); // account 4 tries to take index 1 again for account 6.
assert_ok!(Balances::transfer(Some(4).into(), 6, 256 * 1 + 0x69)); // account 4 tries to take index 1 again for account 6.
assert_eq!(Balances::total_balance(&6), 256 * 1 + 0x69);
assert_eq!(Balances::is_dead_account(&6), false);
},
@@ -101,7 +101,7 @@ fn dust_account_removal_should_work() {
assert_eq!(System::account_nonce(&2), 1);
assert_eq!(Balances::total_balance(&2), 256 * 20);
assert_ok!(Balances::transfer(Some(2).into(), 5, (256 * 10 + 1).into())); // index 1 (account 2) becomes zombie
assert_ok!(Balances::transfer(Some(2).into(), 5, 256 * 10 + 1)); // index 1 (account 2) becomes zombie
assert_eq!(Balances::total_balance(&2), 0);
assert_eq!(Balances::total_balance(&5), 256 * 10 + 1);
assert_eq!(System::account_nonce(&2), 0);
@@ -121,7 +121,7 @@ fn dust_account_removal_should_work2() {
System::inc_account_nonce(&2);
assert_eq!(System::account_nonce(&2), 1);
assert_eq!(Balances::total_balance(&2), 256 * 20);
assert_ok!(Balances::transfer(Some(2).into(), 5, (256 * 10).into())); // index 1 (account 2) becomes zombie for 256*10 + 50(fee) < 256 * 10 (ext_deposit)
assert_ok!(Balances::transfer(Some(2).into(), 5, 256 * 10)); // index 1 (account 2) becomes zombie for 256*10 + 50(fee) < 256 * 10 (ext_deposit)
assert_eq!(Balances::total_balance(&2), 0);
assert_eq!(Balances::total_balance(&5), 256 * 10);
assert_eq!(System::account_nonce(&2), 0);
@@ -147,7 +147,7 @@ fn balance_transfer_works() {
with_externalities(&mut ExtBuilder::default().build(), || {
Balances::set_free_balance(&1, 111);
Balances::increase_total_stake_by(111);
assert_ok!(Balances::transfer(Some(1).into(), 2, 69.into()));
assert_ok!(Balances::transfer(Some(1).into(), 2, 69));
assert_eq!(Balances::total_balance(&1), 42);
assert_eq!(Balances::total_balance(&2), 69);
});
@@ -186,7 +186,7 @@ fn balance_transfer_when_reserved_should_not_work() {
with_externalities(&mut ExtBuilder::default().build(), || {
Balances::set_free_balance(&1, 111);
assert_ok!(Balances::reserve(&1, 69));
assert_noop!(Balances::transfer(Some(1).into(), 2, 69.into()), "balance too low to send value");
assert_noop!(Balances::transfer(Some(1).into(), 2, 69), "balance too low to send value");
});
}
@@ -317,7 +317,7 @@ fn transferring_too_high_value_should_not_panic() {
<FreeBalance<Runtime>>::insert(2, 1);
assert_err!(
Balances::transfer(Some(1).into(), 2, u64::max_value().into()),
Balances::transfer(Some(1).into(), 2, u64::max_value()),
"destination balance too high to receive value"
);
@@ -345,7 +345,7 @@ fn account_removal_on_free_too_low() {
// Transfer funds from account 1 of such amount that after this transfer
// the balance of account 1 will be below the exsistential threshold.
// This should lead to the removal of all balance of this account.
assert_ok!(Balances::transfer(Some(1).into(), 2, 20.into()));
assert_ok!(Balances::transfer(Some(1).into(), 2, 20));
// Verify free balance removal of account 1.
assert_eq!(Balances::free_balance(&1), 0);
@@ -365,7 +365,7 @@ fn transfer_overflow_isnt_exploitable() {
let evil_value = u64::max_value() - 49;
assert_err!(
Balances::transfer(Some(1).into(), 5, evil_value.into()),
Balances::transfer(Some(1).into(), 5, evil_value),
"got overflow after adding a fee to value"
);
}
+6 -11
View File
@@ -102,7 +102,7 @@ use account_db::AccountDb;
use rstd::prelude::*;
use rstd::marker::PhantomData;
use codec::{Codec, HasCompact};
use codec::Codec;
use runtime_primitives::traits::{Hash, As, SimpleArithmetic,Bounded, StaticLookup};
use runtime_support::dispatch::{Result, Dispatchable};
use runtime_support::{Parameter, StorageMap, StorageValue, StorageDoubleMap};
@@ -198,11 +198,10 @@ decl_module! {
/// Stores code in the storage. You can instantiate contracts only with stored code.
fn put_code(
origin,
gas_limit: <T::Gas as HasCompact>::Type,
#[compact] gas_limit: T::Gas,
code: Vec<u8>
) -> Result {
let origin = ensure_signed(origin)?;
let gas_limit = gas_limit.into();
let schedule = <Module<T>>::current_schedule();
let mut gas_meter = gas::buy_gas::<T>(&origin, gas_limit)?;
@@ -221,13 +220,11 @@ decl_module! {
fn call(
origin,
dest: <T::Lookup as StaticLookup>::Source,
value: <T::Balance as HasCompact>::Type,
gas_limit: <T::Gas as HasCompact>::Type,
#[compact] value: T::Balance,
#[compact] gas_limit: T::Gas,
data: Vec<u8>
) -> Result {
let origin = ensure_signed(origin)?;
let value = value.into();
let gas_limit = gas_limit.into();
let dest = T::Lookup::lookup(dest)?;
// Pay for the gas upfront.
@@ -277,14 +274,12 @@ decl_module! {
/// upon any message received by this account.
fn create(
origin,
endowment: <T::Balance as HasCompact>::Type,
gas_limit: <T::Gas as HasCompact>::Type,
#[compact] endowment: T::Balance,
#[compact] gas_limit: T::Gas,
code_hash: CodeHash<T>,
data: Vec<u8>
) -> Result {
let origin = ensure_signed(origin)?;
let endowment = endowment.into();
let gas_limit = gas_limit.into();
// Pay for the gas upfront.
//
+12 -12
View File
@@ -189,8 +189,8 @@ fn refunds_unused_gas() {
assert_ok!(Contract::call(
Origin::signed(0),
1,
0.into(),
100_000.into(),
0,
100_000,
Vec::new()
));
@@ -220,7 +220,7 @@ fn account_removal_removes_storage() {
// the balance of account 1 is will be below than exsistential threshold.
//
// This should lead to the removal of all storage associated with this account.
assert_ok!(Balances::transfer(Origin::signed(1), 2, 20.into()));
assert_ok!(Balances::transfer(Origin::signed(1), 2, 20));
// Verify that all entries from account 1 is removed, while
// entries from account 2 is in place.
@@ -277,14 +277,14 @@ fn instantiate_and_call() {
assert_ok!(Contract::put_code(
Origin::signed(ALICE),
100_000.into(),
100_000,
wasm,
));
assert_ok!(Contract::create(
Origin::signed(ALICE),
100.into(),
100_000.into(),
100,
100_000,
HASH_RETURN_FROM_START_FN.into(),
vec![],
));
@@ -335,7 +335,7 @@ const HASH_DISPATCH_CALL: [u8; 32] = hex!("49dfdcaf9c1553be10634467e95b8e71a3bc1
fn dispatch_call() {
// This test can fail due to the encoding changes. In case it becomes too annoying
// let's rewrite so as we use this module controlled call or we serialize it in runtime.
let encoded = codec::Encode::encode(&Call::Balances(balances::Call::transfer(CHARLIE, 50.into())));
let encoded = codec::Encode::encode(&Call::Balances(balances::Call::transfer(CHARLIE, 50)));
assert_eq!(&encoded[..], &hex!("00000300000000000000C8")[..]);
let wasm = wabt::wat2wasm(CODE_DISPATCH_CALL).unwrap();
@@ -348,7 +348,7 @@ fn dispatch_call() {
assert_ok!(Contract::put_code(
Origin::signed(ALICE),
100_000.into(),
100_000,
wasm,
));
@@ -363,8 +363,8 @@ fn dispatch_call() {
assert_ok!(Contract::create(
Origin::signed(ALICE),
100.into(),
100_000.into(),
100,
100_000,
HASH_DISPATCH_CALL.into(),
vec![],
));
@@ -372,8 +372,8 @@ fn dispatch_call() {
assert_ok!(Contract::call(
Origin::signed(ALICE),
BOB, // newly created account
0.into(),
100_000.into(),
0,
100_000,
vec![],
));
+1 -1
View File
@@ -984,7 +984,7 @@ mod tests {
assert_eq!(
&mock_ext.dispatches,
&[DispatchEntry(
Call::Balances(balances::Call::set_balance(42, 1337.into(), 0.into())),
Call::Balances(balances::Call::set_balance(42, 1337, 0)),
)]
);
}
+17 -20
View File
@@ -18,7 +18,6 @@
use rstd::prelude::*;
use rstd::result;
use codec::Compact;
use substrate_primitives::u32_trait::Value as U32;
use primitives::traits::{Hash, EnsureOrigin};
use srml_support::dispatch::{Dispatchable, Parameter};
@@ -68,9 +67,8 @@ decl_event!(
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin {
fn deposit_event<T>() = default;
fn propose(origin, threshold: Compact<u32>, proposal: Box<<T as Trait>::Proposal>) {
fn propose(origin, #[compact] threshold: u32, proposal: Box<<T as Trait>::Proposal>) {
let who = ensure_signed(origin)?;
let threshold = threshold.into();
ensure!(Self::is_councillor(&who), "proposer not on council");
@@ -92,9 +90,8 @@ decl_module! {
}
}
fn vote(origin, proposal: T::Hash, index: Compact<ProposalIndex>, approve: bool) {
fn vote(origin, proposal: T::Hash, #[compact] index: ProposalIndex, approve: bool) {
let who = ensure_signed(origin)?;
let index = index.into();
ensure!(Self::is_councillor(&who), "voter not on council");
@@ -220,7 +217,7 @@ mod tests {
}
fn set_balance_proposal(value: u64) -> Call {
Call::Balances(balances::Call::set_balance(42, value.into(), 0.into()))
Call::Balances(balances::Call::set_balance(42, value.into(), 0))
}
#[test]
@@ -229,7 +226,7 @@ mod tests {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
let hash = proposal.blake2_256().into();
assert_ok!(CouncilMotions::propose(Origin::signed(1), 3.into(), Box::new(proposal.clone())));
assert_ok!(CouncilMotions::propose(Origin::signed(1), 3, Box::new(proposal.clone())));
assert_eq!(CouncilMotions::proposals(), vec![hash]);
assert_eq!(CouncilMotions::proposal_of(&hash), Some(proposal));
assert_eq!(CouncilMotions::voting(&hash), Some((0, 3, vec![1], Vec::<u64>::new())));
@@ -248,7 +245,7 @@ mod tests {
with_externalities(&mut new_test_ext(true), || {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
assert_noop!(CouncilMotions::propose(Origin::signed(42), 3.into(), Box::new(proposal.clone())), "proposer not on council");
assert_noop!(CouncilMotions::propose(Origin::signed(42), 3, Box::new(proposal.clone())), "proposer not on council");
});
}
@@ -258,8 +255,8 @@ mod tests {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
let hash: H256 = proposal.blake2_256().into();
assert_ok!(CouncilMotions::propose(Origin::signed(1), 3.into(), Box::new(proposal.clone())));
assert_noop!(CouncilMotions::vote(Origin::signed(42), hash.clone(), 0.into(), true), "voter not on council");
assert_ok!(CouncilMotions::propose(Origin::signed(1), 3, Box::new(proposal.clone())));
assert_noop!(CouncilMotions::vote(Origin::signed(42), hash.clone(), 0, true), "voter not on council");
});
}
@@ -269,8 +266,8 @@ mod tests {
System::set_block_number(3);
let proposal = set_balance_proposal(42);
let hash: H256 = proposal.blake2_256().into();
assert_ok!(CouncilMotions::propose(Origin::signed(1), 3.into(), Box::new(proposal.clone())));
assert_noop!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 1.into(), true), "mismatched index");
assert_ok!(CouncilMotions::propose(Origin::signed(1), 3, Box::new(proposal.clone())));
assert_noop!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 1, true), "mismatched index");
});
}
@@ -280,12 +277,12 @@ mod tests {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
let hash: H256 = proposal.blake2_256().into();
assert_ok!(CouncilMotions::propose(Origin::signed(1), 2.into(), Box::new(proposal.clone())));
assert_ok!(CouncilMotions::propose(Origin::signed(1), 2, Box::new(proposal.clone())));
assert_eq!(CouncilMotions::voting(&hash), Some((0, 2, vec![1], Vec::<u64>::new())));
assert_noop!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0.into(), true), "duplicate vote ignored");
assert_ok!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0.into(), false));
assert_noop!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0, true), "duplicate vote ignored");
assert_ok!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0, false));
assert_eq!(CouncilMotions::voting(&hash), Some((0, 2, Vec::<u64>::new(), vec![1])));
assert_noop!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0.into(), false), "duplicate vote ignored");
assert_noop!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0, false), "duplicate vote ignored");
assert_eq!(System::events(), vec![
EventRecord {
@@ -306,8 +303,8 @@ mod tests {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
let hash: H256 = proposal.blake2_256().into();
assert_ok!(CouncilMotions::propose(Origin::signed(1), 3.into(), Box::new(proposal.clone())));
assert_ok!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 0.into(), false));
assert_ok!(CouncilMotions::propose(Origin::signed(1), 3, Box::new(proposal.clone())));
assert_ok!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 0, false));
assert_eq!(System::events(), vec![
EventRecord {
@@ -332,8 +329,8 @@ mod tests {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
let hash: H256 = proposal.blake2_256().into();
assert_ok!(CouncilMotions::propose(Origin::signed(1), 2.into(), Box::new(proposal.clone())));
assert_ok!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 0.into(), true));
assert_ok!(CouncilMotions::propose(Origin::signed(1), 2, Box::new(proposal.clone())));
assert_ok!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 0, true));
assert_eq!(System::events(), vec![
EventRecord {
+216 -226
View File
@@ -17,7 +17,6 @@
//! Council system: Handles the voting in and maintenance of council members.
use rstd::prelude::*;
use codec::{Compact, HasCompact};
use primitives::traits::{Zero, One, As, StaticLookup};
use runtime_io::print;
use srml_support::{StorageValue, StorageMap, dispatch::Result};
@@ -91,9 +90,8 @@ decl_module! {
/// Set candidate approvals. Approval slots stay valid as long as candidates in those slots
/// are registered.
fn set_approvals(origin, votes: Vec<bool>, index: Compact<VoteIndex>) {
fn set_approvals(origin, votes: Vec<bool>, #[compact] index: VoteIndex) {
let who = ensure_signed(origin)?;
let index: VoteIndex = index.into();
let candidates = Self::candidates();
ensure!(!Self::presentation_active(), "no approval changes during presentation period");
@@ -126,13 +124,12 @@ decl_module! {
/// May be called by anyone. Returns the voter deposit to `signed`.
fn reap_inactive_voter(
origin,
reporter_index: Compact<u32>,
#[compact] reporter_index: u32,
who: <T::Lookup as StaticLookup>::Source,
who_index: Compact<u32>,
assumed_vote_index: Compact<VoteIndex>
#[compact] who_index: u32,
#[compact] assumed_vote_index: VoteIndex
) {
let reporter = ensure_signed(origin)?;
let assumed_vote_index: VoteIndex = assumed_vote_index.into();
let who = T::Lookup::lookup(who)?;
ensure!(!Self::presentation_active(), "cannot reap during presentation period");
@@ -141,9 +138,7 @@ decl_module! {
ensure!(assumed_vote_index == Self::vote_index(), "vote index not current");
ensure!(assumed_vote_index > last_active + Self::inactivity_grace_period(), "cannot reap during grace period");
let voters = Self::voters();
let reporter_index: u32 = reporter_index.into();
let reporter_index = reporter_index as usize;
let who_index: u32 = who_index.into();
let who_index = who_index as usize;
ensure!(reporter_index < voters.len() && voters[reporter_index] == reporter, "bad reporter index");
ensure!(who_index < voters.len() && voters[who_index] == who, "bad target index");
@@ -175,13 +170,12 @@ decl_module! {
}
/// Remove a voter. All votes are cancelled and the voter deposit is returned.
fn retract_voter(origin, index: Compact<u32>) {
fn retract_voter(origin, #[compact] index: u32) {
let who = ensure_signed(origin)?;
ensure!(!Self::presentation_active(), "cannot retract when presenting");
ensure!(<LastActiveOf<T>>::exists(&who), "cannot retract non-voter");
let voters = Self::voters();
let index: u32 = index.into();
let index = index as usize;
ensure!(index < voters.len(), "retraction index invalid");
ensure!(voters[index] == who, "retraction index mismatch");
@@ -193,11 +187,10 @@ decl_module! {
/// Submit oneself for candidacy.
///
/// Account must have enough transferrable funds in it to pay the bond.
fn submit_candidacy(origin, slot: Compact<u32>) {
fn submit_candidacy(origin, #[compact] slot: u32) {
let who = ensure_signed(origin)?;
ensure!(!Self::is_a_candidate(&who), "duplicate candidate submission");
let slot: u32 = slot.into();
let slot = slot as usize;
let count = Self::candidate_count() as usize;
let candidates = Self::candidates();
@@ -227,13 +220,11 @@ decl_module! {
fn present_winner(
origin,
candidate: <T::Lookup as StaticLookup>::Source,
total: <T::Balance as HasCompact>::Type,
index: Compact<VoteIndex>
#[compact] total: T::Balance,
#[compact] index: VoteIndex
) -> Result {
let who = ensure_signed(origin)?;
let total = total.into();
ensure!(!total.is_zero(), "stake deposited to present winner and be added to leaderboard should be non-zero");
let index: VoteIndex = index.into();
let candidate = T::Lookup::lookup(candidate)?;
ensure!(index == Self::vote_index(), "index not current");
@@ -280,8 +271,7 @@ decl_module! {
/// Set the desired member count; if lower than the current count, then seats will not be up
/// election when they expire. If more, then a new vote will be started if one is not already
/// in progress.
fn set_desired_seats(count: Compact<u32>) {
let count: u32 = count.into();
fn set_desired_seats(#[compact] count: u32) {
<DesiredSeats<T>>::put(count);
}
@@ -299,14 +289,14 @@ decl_module! {
/// Set the presentation duration. If there is currently a vote being presented for, will
/// invoke `finalise_vote`.
fn set_presentation_duration(count: <T::BlockNumber as HasCompact>::Type) {
<PresentationDuration<T>>::put(count.into());
fn set_presentation_duration(#[compact] count: T::BlockNumber) {
<PresentationDuration<T>>::put(count);
}
/// Set the presentation duration. If there is current a vote being presented for, will
/// invoke `finalise_vote`.
fn set_term_duration(count: <T::BlockNumber as HasCompact>::Type) {
<TermDuration<T>>::put(count.into());
fn set_term_duration(#[compact] count: T::BlockNumber) {
<TermDuration<T>>::put(count);
}
fn on_finalise(n: T::BlockNumber) {
@@ -601,14 +591,14 @@ mod tests {
assert_eq!(Council::is_a_candidate(&1), false);
assert_eq!(Council::is_a_candidate(&2), false);
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0));
assert_eq!(Council::candidates(), vec![1]);
assert_eq!(Council::candidate_reg_info(1), Some((0, 0)));
assert_eq!(Council::candidate_reg_info(2), None);
assert_eq!(Council::is_a_candidate(&1), true);
assert_eq!(Council::is_a_candidate(&2), false);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1));
assert_eq!(Council::candidates(), vec![1, 2]);
assert_eq!(Council::candidate_reg_info(1), Some((0, 0)));
assert_eq!(Council::candidate_reg_info(2), Some((0, 1)));
@@ -635,10 +625,10 @@ mod tests {
System::set_block_number(1);
assert_eq!(Council::candidates(), vec![0, 0, 1]);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1));
assert_eq!(Council::candidates(), vec![0, 2, 1]);
assert_ok!(Council::submit_candidacy(Origin::signed(3), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 0));
assert_eq!(Council::candidates(), vec![3, 2, 1]);
});
}
@@ -651,10 +641,10 @@ mod tests {
System::set_block_number(1);
assert_eq!(Council::candidates(), vec![0, 0, 1]);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0));
assert_eq!(Council::candidates(), vec![2, 0, 1]);
assert_ok!(Council::submit_candidacy(Origin::signed(3), 1.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 1));
assert_eq!(Council::candidates(), vec![2, 3, 1]);
});
}
@@ -663,7 +653,7 @@ mod tests {
fn candidate_submission_not_using_free_slot_should_not_work() {
with_externalities(&mut new_test_ext_with_candidate_holes(), || {
System::set_block_number(1);
assert_noop!(Council::submit_candidacy(Origin::signed(4), 3.into()), "invalid candidate slot");
assert_noop!(Council::submit_candidacy(Origin::signed(4), 3), "invalid candidate slot");
});
}
@@ -672,7 +662,7 @@ mod tests {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(1);
assert_eq!(Council::candidates(), Vec::<u64>::new());
assert_noop!(Council::submit_candidacy(Origin::signed(1), 1.into()), "invalid candidate slot");
assert_noop!(Council::submit_candidacy(Origin::signed(1), 1), "invalid candidate slot");
});
}
@@ -681,9 +671,9 @@ mod tests {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(1);
assert_eq!(Council::candidates(), Vec::<u64>::new());
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0));
assert_eq!(Council::candidates(), vec![1]);
assert_noop!(Council::submit_candidacy(Origin::signed(2), 0.into()), "invalid candidate slot");
assert_noop!(Council::submit_candidacy(Origin::signed(2), 0), "invalid candidate slot");
});
}
@@ -692,9 +682,9 @@ mod tests {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(1);
assert_eq!(Council::candidates(), Vec::<u64>::new());
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0));
assert_eq!(Council::candidates(), vec![1]);
assert_noop!(Council::submit_candidacy(Origin::signed(1), 1.into()), "duplicate candidate submission");
assert_noop!(Council::submit_candidacy(Origin::signed(1), 1), "duplicate candidate submission");
});
}
@@ -703,7 +693,7 @@ mod tests {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(1);
assert_eq!(Council::candidates(), Vec::<u64>::new());
assert_noop!(Council::submit_candidacy(Origin::signed(7), 0.into()), "candidate has not enough funds");
assert_noop!(Council::submit_candidacy(Origin::signed(7), 0), "candidate has not enough funds");
});
}
@@ -712,20 +702,20 @@ mod tests {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(1);
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0));
assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0));
assert_eq!(Council::approvals_of(1), vec![true]);
assert_eq!(Council::approvals_of(4), vec![true]);
assert_eq!(Council::voters(), vec![1, 4]);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 2.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 2));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true, true], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, true], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true, true], 0));
assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, true], 0));
assert_eq!(Council::approvals_of(1), vec![true]);
assert_eq!(Council::approvals_of(4), vec![true]);
@@ -743,7 +733,7 @@ mod tests {
assert_eq!(Council::candidates().len(), 0);
assert_noop!(Council::set_approvals(Origin::signed(4), vec![], 0.into()), "amount of candidates to receive approval votes should be non-zero");
assert_noop!(Council::set_approvals(Origin::signed(4), vec![], 0), "amount of candidates to receive approval votes should be non-zero");
});
}
@@ -752,10 +742,10 @@ mod tests {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(1);
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0));
assert_eq!(Council::candidates().len(), 1);
assert_noop!(Council::set_approvals(Origin::signed(4), vec![true, true], 0.into()), "amount of candidate approval votes cannot exceed amount of candidates");
assert_noop!(Council::set_approvals(Origin::signed(4), vec![true, true], 0), "amount of candidate approval votes cannot exceed amount of candidates");
});
}
@@ -764,15 +754,15 @@ mod tests {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(1);
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0));
assert_eq!(Council::approvals_of(4), vec![true]);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 2.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 2));
assert_eq!(Council::candidates().len(), 3);
assert_ok!(Council::set_approvals(Origin::signed(4), vec![true, false, true], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![true, false, true], 0));
assert_eq!(Council::approvals_of(4), vec![true, false, true]);
});
@@ -783,15 +773,15 @@ mod tests {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(1);
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 2.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 2));
assert_eq!(Council::candidates().len(), 3);
assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true, true], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, true], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![true, false, true], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true, true], 0));
assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, true], 0));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![true, false, true], 0));
assert_eq!(Council::voters(), vec![1, 2, 3, 4]);
assert_eq!(Council::approvals_of(1), vec![true]);
@@ -799,7 +789,7 @@ mod tests {
assert_eq!(Council::approvals_of(3), vec![false, true, true]);
assert_eq!(Council::approvals_of(4), vec![true, false, true]);
assert_ok!(Council::retract_voter(Origin::signed(1), 0.into()));
assert_ok!(Council::retract_voter(Origin::signed(1), 0));
assert_eq!(Council::voters(), vec![4, 2, 3]);
assert_eq!(Council::approvals_of(1), Vec::<bool>::new());
@@ -807,7 +797,7 @@ mod tests {
assert_eq!(Council::approvals_of(3), vec![false, true, true]);
assert_eq!(Council::approvals_of(4), vec![true, false, true]);
assert_ok!(Council::retract_voter(Origin::signed(2), 1.into()));
assert_ok!(Council::retract_voter(Origin::signed(2), 1));
assert_eq!(Council::voters(), vec![4, 3]);
assert_eq!(Council::approvals_of(1), Vec::<bool>::new());
@@ -815,7 +805,7 @@ mod tests {
assert_eq!(Council::approvals_of(3), vec![false, true, true]);
assert_eq!(Council::approvals_of(4), vec![true, false, true]);
assert_ok!(Council::retract_voter(Origin::signed(3), 1.into()));
assert_ok!(Council::retract_voter(Origin::signed(3), 1));
assert_eq!(Council::voters(), vec![4]);
assert_eq!(Council::approvals_of(1), Vec::<bool>::new());
@@ -829,11 +819,11 @@ mod tests {
fn invalid_retraction_index_should_not_work() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(1);
assert_ok!(Council::submit_candidacy(Origin::signed(3), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 0));
assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0));
assert_eq!(Council::voters(), vec![1, 2]);
assert_noop!(Council::retract_voter(Origin::signed(1), 1.into()), "retraction index mismatch");
assert_noop!(Council::retract_voter(Origin::signed(1), 1), "retraction index mismatch");
});
}
@@ -841,9 +831,9 @@ mod tests {
fn overflow_retraction_index_should_not_work() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(1);
assert_ok!(Council::submit_candidacy(Origin::signed(3), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0.into()));
assert_noop!(Council::retract_voter(Origin::signed(1), 1.into()), "retraction index invalid");
assert_ok!(Council::submit_candidacy(Origin::signed(3), 0));
assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0));
assert_noop!(Council::retract_voter(Origin::signed(1), 1), "retraction index invalid");
});
}
@@ -851,9 +841,9 @@ mod tests {
fn non_voter_retraction_should_not_work() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(1);
assert_ok!(Council::submit_candidacy(Origin::signed(3), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0.into()));
assert_noop!(Council::retract_voter(Origin::signed(2), 0.into()), "cannot retract non-voter");
assert_ok!(Council::submit_candidacy(Origin::signed(3), 0));
assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0));
assert_noop!(Council::retract_voter(Origin::signed(2), 0), "cannot retract non-voter");
});
}
@@ -863,10 +853,10 @@ mod tests {
System::set_block_number(4);
assert!(!Council::presentation_active());
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 1.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 1));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0));
assert_eq!(Council::voters(), vec![2, 5]);
assert_eq!(Council::approvals_of(2), vec![true, false]);
assert_eq!(Council::approvals_of(5), vec![false, true]);
@@ -874,8 +864,8 @@ mod tests {
System::set_block_number(6);
assert!(Council::presentation_active());
assert_eq!(Council::present_winner(Origin::signed(4), 2, 20.into(), 0.into()), Ok(()));
assert_eq!(Council::present_winner(Origin::signed(4), 5, 50.into(), 0.into()), Ok(()));
assert_eq!(Council::present_winner(Origin::signed(4), 2, 20, 0), Ok(()));
assert_eq!(Council::present_winner(Origin::signed(4), 5, 50, 0), Ok(()));
assert_eq!(Council::leaderboard(), Some(vec![(0, 0), (0, 0), (20, 2), (50, 5)]));
assert_ok!(Council::end_block(System::block_number()));
@@ -895,12 +885,12 @@ mod tests {
fn presentations_with_zero_staked_deposit_should_not_work() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(4);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_noop!(Council::present_winner(Origin::signed(4), 2, 0.into(), 0.into()), "stake deposited to present winner and be added to leaderboard should be non-zero");
assert_noop!(Council::present_winner(Origin::signed(4), 2, 0, 0), "stake deposited to present winner and be added to leaderboard should be non-zero");
});
}
@@ -910,16 +900,16 @@ mod tests {
assert!(Balances::can_slash(&4, 10));
System::set_block_number(4);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 1.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 1));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50.into(), 0.into()));
assert_eq!(Council::present_winner(Origin::signed(4), 5, 50.into(), 0.into()), Err("duplicate presentation"));
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50, 0));
assert_eq!(Council::present_winner(Origin::signed(4), 5, 50, 0), Err("duplicate presentation"));
assert_ok!(Council::end_block(System::block_number()));
assert_eq!(Council::active_council(), vec![(5, 11), (2, 11)]);
@@ -931,27 +921,27 @@ mod tests {
fn retracting_inactive_voter_should_work() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(4);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20, 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(8);
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(10);
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50.into(), 1.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50, 1));
assert_ok!(Council::end_block(System::block_number()));
assert_ok!(Council::reap_inactive_voter(Origin::signed(5),
(Council::voters().iter().position(|&i| i == 5).unwrap() as u32).into(),
2, (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(),
2.into()
2
));
assert_eq!(Council::voters(), vec![5]);
@@ -965,21 +955,21 @@ mod tests {
fn presenting_for_double_election_should_not_work() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(4);
assert_eq!(Council::submit_candidacy(Origin::signed(2), 0.into()), Ok(()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into()));
assert_eq!(Council::submit_candidacy(Origin::signed(2), 0), Ok(()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20, 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(8);
assert_eq!(Council::submit_candidacy(Origin::signed(2), 0.into()), Ok(()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 1.into()));
assert_eq!(Council::submit_candidacy(Origin::signed(2), 0), Ok(()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 1));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(10);
assert_noop!(Council::present_winner(Origin::signed(4), 2, 20.into(), 1.into()), "candidate must not form a duplicated member if elected");
assert_noop!(Council::present_winner(Origin::signed(4), 2, 20, 1), "candidate must not form a duplicated member if elected");
});
}
@@ -987,30 +977,30 @@ mod tests {
fn retracting_inactive_voter_with_other_candidates_in_slots_should_work() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(4);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20, 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(8);
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(10);
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50.into(), 1.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50, 1));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(11);
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0));
assert_ok!(Council::reap_inactive_voter(Origin::signed(5),
(Council::voters().iter().position(|&i| i == 5).unwrap() as u32).into(),
2, (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(),
2.into()
2
));
assert_eq!(Council::voters(), vec![5]);
@@ -1024,27 +1014,27 @@ mod tests {
fn retracting_inactive_voter_with_bad_reporter_index_should_not_work() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(4);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20, 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(8);
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(10);
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50.into(), 1.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50, 1));
assert_ok!(Council::end_block(System::block_number()));
assert_noop!(Council::reap_inactive_voter(Origin::signed(2),
42.into(),
42,
2, (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(),
2.into()
2
), "bad reporter index");
});
}
@@ -1053,27 +1043,27 @@ mod tests {
fn retracting_inactive_voter_with_bad_target_index_should_not_work() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(4);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20, 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(8);
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(10);
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50.into(), 1.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50, 1));
assert_ok!(Council::end_block(System::block_number()));
assert_noop!(Council::reap_inactive_voter(Origin::signed(2),
(Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(),
2, 42.into(),
2.into()
2, 42,
2
), "bad target index");
});
}
@@ -1082,30 +1072,30 @@ mod tests {
fn attempting_to_retract_active_voter_should_slash_reporter() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(4);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 1.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(4), 2.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 3.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false, false, false], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, false, false], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, true, false], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 1));
assert_ok!(Council::submit_candidacy(Origin::signed(4), 2));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 3));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false, false, false], 0));
assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, false, false], 0));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, true, false], 0));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 3, 30.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 4, 40.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 3, 30, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 4, 40, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50, 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(8);
assert_ok!(Council::set_desired_seats(3.into()));
assert_ok!(Council::set_desired_seats(3));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(10);
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20.into(), 1.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 3, 30.into(), 1.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20, 1));
assert_ok!(Council::present_winner(Origin::signed(4), 3, 30, 1));
assert_ok!(Council::end_block(System::block_number()));
assert_eq!(Council::vote_index(), 2);
@@ -1117,7 +1107,7 @@ mod tests {
(Council::voters().iter().position(|&i| i == 4).unwrap() as u32).into(),
2,
(Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(),
2.into()
2
));
assert_eq!(Council::voters(), vec![2, 3, 5]);
@@ -1130,27 +1120,27 @@ mod tests {
fn attempting_to_retract_inactive_voter_by_nonvoter_should_not_work() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(4);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20, 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(8);
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 0));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(10);
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50.into(), 1.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50, 1));
assert_ok!(Council::end_block(System::block_number()));
assert_noop!(Council::reap_inactive_voter(Origin::signed(4),
0.into(),
0,
2, (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(),
2.into()
2
), "reporter must be a voter");
});
}
@@ -1159,23 +1149,23 @@ mod tests {
fn presenting_loser_should_not_work() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(4);
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 2.into()));
assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(4), 3.into()));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 4.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0));
assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 2));
assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(4), 3));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 4));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_ok!(Council::present_winner(Origin::signed(4), 1, 60.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 3, 30.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 4, 40.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 1, 60, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 3, 30, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 4, 40, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50, 0));
assert_eq!(Council::leaderboard(), Some(vec![
(30, 3),
@@ -1184,7 +1174,7 @@ mod tests {
(60, 1)
]));
assert_noop!(Council::present_winner(Origin::signed(4), 2, 20.into(), 0.into()), "candidate not worthy of leaderboard");
assert_noop!(Council::present_winner(Origin::signed(4), 2, 20, 0), "candidate not worthy of leaderboard");
});
}
@@ -1192,24 +1182,24 @@ mod tests {
fn presenting_loser_first_should_not_matter() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(4);
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 2.into()));
assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(4), 3.into()));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 4.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0));
assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 2));
assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(4), 3));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 4));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 1, 60.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 3, 30.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 4, 40.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 2, 20, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 1, 60, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 3, 30, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 4, 40, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50, 0));
assert_eq!(Council::leaderboard(), Some(vec![
(30, 3),
@@ -1225,7 +1215,7 @@ mod tests {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(4);
assert!(!Council::presentation_active());
assert_noop!(Council::present_winner(Origin::signed(5), 5, 1.into(), 0.into()), "cannot present outside of presentation period");
assert_noop!(Council::present_winner(Origin::signed(5), 5, 1, 0), "cannot present outside of presentation period");
});
}
@@ -1233,14 +1223,14 @@ mod tests {
fn present_with_invalid_vote_index_should_not_work() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(4);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 1.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 1));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_noop!(Council::present_winner(Origin::signed(4), 2, 20.into(), 1.into()), "index not current");
assert_noop!(Council::present_winner(Origin::signed(4), 2, 20, 1), "index not current");
});
}
@@ -1250,16 +1240,16 @@ mod tests {
System::set_block_number(4);
assert!(!Council::presentation_active());
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 1.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 1));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_eq!(Balances::free_balance(&1), 1);
assert_eq!(Balances::reserved_balance(&1), 9);
assert_noop!(Council::present_winner(Origin::signed(1), 1, 20.into(), 0.into()), "presenter must have sufficient slashable funds");
assert_noop!(Council::present_winner(Origin::signed(1), 1, 20, 0), "presenter must have sufficient slashable funds");
});
}
@@ -1270,14 +1260,14 @@ mod tests {
assert!(!Council::presentation_active());
assert_eq!(Balances::total_balance(&4), 40);
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 1.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 0));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 1));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_err!(Council::present_winner(Origin::signed(4), 2, 80.into(), 0.into()), "incorrect total");
assert_err!(Council::present_winner(Origin::signed(4), 2, 80, 0), "incorrect total");
assert_eq!(Balances::total_balance(&4), 38);
});
@@ -1289,22 +1279,22 @@ mod tests {
System::set_block_number(4);
assert!(!Council::presentation_active());
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 2.into()));
assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(4), 3.into()));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 4.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0));
assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 2));
assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(4), 3));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 4));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert!(Council::presentation_active());
assert_ok!(Council::present_winner(Origin::signed(4), 1, 60.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 1, 60, 0));
// leaderboard length is the empty seats plus the carry count (i.e. 5 + 2), where those
// to be carried are the lowest and stored in lowest indexes
assert_eq!(Council::leaderboard(), Some(vec![
@@ -1313,9 +1303,9 @@ mod tests {
(0, 0),
(60, 1)
]));
assert_ok!(Council::present_winner(Origin::signed(4), 3, 30.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 4, 40.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 3, 30, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 4, 40, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50, 0));
assert_eq!(Council::leaderboard(), Some(vec![
(30, 3),
(40, 4),
@@ -1348,33 +1338,33 @@ mod tests {
fn second_tally_should_use_runners_up() {
with_externalities(&mut new_test_ext(false), || {
System::set_block_number(4);
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0.into()));
assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1.into()));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 2.into()));
assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(4), 3.into()));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 4.into()));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0.into()));
assert_ok!(Council::submit_candidacy(Origin::signed(1), 0));
assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(2), 1));
assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(3), 2));
assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(4), 3));
assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0));
assert_ok!(Council::submit_candidacy(Origin::signed(5), 4));
assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(6);
assert_ok!(Council::present_winner(Origin::signed(4), 1, 60.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 3, 30.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 4, 40.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50.into(), 0.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 1, 60, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 3, 30, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 4, 40, 0));
assert_ok!(Council::present_winner(Origin::signed(4), 5, 50, 0));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(8);
assert_ok!(Council::set_approvals(Origin::signed(6), vec![false, false, true, false], 1.into()));
assert_ok!(Council::set_desired_seats(3.into()));
assert_ok!(Council::set_approvals(Origin::signed(6), vec![false, false, true, false], 1));
assert_ok!(Council::set_desired_seats(3));
assert_ok!(Council::end_block(System::block_number()));
System::set_block_number(10);
assert_ok!(Council::present_winner(Origin::signed(4), 3, 90.into(), 1.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 4, 40.into(), 1.into()));
assert_ok!(Council::present_winner(Origin::signed(4), 3, 90, 1));
assert_ok!(Council::present_winner(Origin::signed(4), 4, 40, 1));
assert_ok!(Council::end_block(System::block_number()));
assert!(!Council::presentation_active());
+5 -6
View File
@@ -18,7 +18,6 @@
use rstd::prelude::*;
use rstd::borrow::Borrow;
use codec::HasCompact;
use primitives::traits::{Hash, As, Zero};
use runtime_io::print;
use srml_support::dispatch::Result;
@@ -95,12 +94,12 @@ decl_module! {
}
}
fn set_cooloff_period(blocks: <T::BlockNumber as HasCompact>::Type) {
<CooloffPeriod<T>>::put(blocks.into());
fn set_cooloff_period(#[compact] blocks: T::BlockNumber) {
<CooloffPeriod<T>>::put(blocks);
}
fn set_voting_period(blocks: <T::BlockNumber as HasCompact>::Type) {
<VotingPeriod<T>>::put(blocks.into());
fn set_voting_period(#[compact] blocks: T::BlockNumber) {
<VotingPeriod<T>>::put(blocks);
}
fn on_finalise(n: T::BlockNumber) {
@@ -259,7 +258,7 @@ mod tests {
}
fn set_balance_proposal(value: u64) -> Call {
Call::Balances(balances::Call::set_balance(42, value.into(), 0.into()))
Call::Balances(balances::Call::set_balance(42, value.into(), 0))
}
fn cancel_referendum_proposal(id: u32) -> Call {
+50 -54
View File
@@ -36,7 +36,6 @@ extern crate srml_system as system;
use rstd::prelude::*;
use rstd::result;
use codec::{HasCompact, Compact};
use primitives::traits::{Zero, As};
use srml_support::{StorageValue, StorageMap, Parameter, Dispatchable, IsSubType};
use srml_support::dispatch::Result;
@@ -93,10 +92,9 @@ decl_module! {
fn propose(
origin,
proposal: Box<T::Proposal>,
value: <T::Balance as HasCompact>::Type
#[compact] value: T::Balance
) {
let who = ensure_signed(origin)?;
let value = value.into();
ensure!(value >= Self::minimum_deposit(), "value too low");
<balances::Module<T>>::reserve(&who, value)
@@ -112,9 +110,8 @@ decl_module! {
}
/// Propose a sensitive action to be taken.
fn second(origin, proposal: Compact<PropIndex>) {
fn second(origin, #[compact] proposal: PropIndex) {
let who = ensure_signed(origin)?;
let proposal: PropIndex = proposal.into();
let mut deposit = Self::deposit_of(proposal)
.ok_or("can only second an existing proposal")?;
<balances::Module<T>>::reserve(&who, deposit.0)
@@ -125,9 +122,8 @@ decl_module! {
/// Vote in a referendum. If `vote.is_aye()`, the vote is to enact the proposal;
/// otherwise it is a vote to keep the status quo.
fn vote(origin, ref_index: Compact<ReferendumIndex>, vote: Vote) {
fn vote(origin, #[compact] ref_index: ReferendumIndex, vote: Vote) {
let who = ensure_signed(origin)?;
let ref_index = ref_index.into();
ensure!(vote.multiplier() <= Self::max_lock_periods(), "vote has too great a strength");
ensure!(Self::is_active_referendum(ref_index), "vote given for invalid referendum.");
ensure!(!<balances::Module<T>>::total_balance(&who).is_zero(),
@@ -149,14 +145,14 @@ decl_module! {
}
/// Remove a referendum.
fn cancel_referendum(ref_index: Compact<ReferendumIndex>) {
Self::clear_referendum(ref_index.into());
fn cancel_referendum(#[compact] ref_index: ReferendumIndex) {
Self::clear_referendum(ref_index);
}
/// Cancel a proposal queued for enactment.
pub fn cancel_queued(when: <T::BlockNumber as HasCompact>::Type, which: Compact<u32>) -> Result {
let which = u32::from(which) as usize;
<DispatchQueue<T>>::mutate(when.into(), |items| if items.len() > which { items[which] = None });
pub fn cancel_queued(#[compact] when: T::BlockNumber, #[compact] which: u32) -> Result {
let which = which as usize;
<DispatchQueue<T>>::mutate(when, |items| if items.len() > which { items[which] = None });
Ok(())
}
@@ -549,13 +545,13 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap();
assert_noop!(Democracy::vote(Origin::signed(1), r.into(), Vote::new(true, 7)), "vote has too great a strength");
assert_noop!(Democracy::vote(Origin::signed(1), r.into(), Vote::new(false, 7)), "vote has too great a strength");
assert_noop!(Democracy::vote(Origin::signed(1), r, Vote::new(true, 7)), "vote has too great a strength");
assert_noop!(Democracy::vote(Origin::signed(1), r, Vote::new(false, 7)), "vote has too great a strength");
});
}
fn set_balance_proposal(value: u64) -> Call {
Call::Balances(balances::Call::set_balance(42, value.into(), 0.into()))
Call::Balances(balances::Call::set_balance(42, value.into(), 0))
}
fn propose_set_balance(who: u64, value: u64, locked: u64) -> super::Result {
@@ -584,7 +580,7 @@ mod tests {
System::set_block_number(2);
let r = 0;
assert_ok!(Democracy::vote(Origin::signed(1), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(1), r, AYE));
assert_eq!(Democracy::referendum_count(), 1);
assert_eq!(Democracy::voters_for(r), vec![1]);
@@ -602,10 +598,10 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
assert_ok!(propose_set_balance(1, 2, 5));
assert_ok!(Democracy::second(Origin::signed(2), 0.into()));
assert_ok!(Democracy::second(Origin::signed(5), 0.into()));
assert_ok!(Democracy::second(Origin::signed(5), 0.into()));
assert_ok!(Democracy::second(Origin::signed(5), 0.into()));
assert_ok!(Democracy::second(Origin::signed(2), 0));
assert_ok!(Democracy::second(Origin::signed(5), 0));
assert_ok!(Democracy::second(Origin::signed(5), 0));
assert_ok!(Democracy::second(Origin::signed(5), 0));
assert_eq!(Balances::free_balance(&1), 5);
assert_eq!(Balances::free_balance(&2), 15);
assert_eq!(Balances::free_balance(&5), 35);
@@ -617,10 +613,10 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
assert_ok!(propose_set_balance(1, 2, 5));
assert_ok!(Democracy::second(Origin::signed(2), 0.into()));
assert_ok!(Democracy::second(Origin::signed(5), 0.into()));
assert_ok!(Democracy::second(Origin::signed(5), 0.into()));
assert_ok!(Democracy::second(Origin::signed(5), 0.into()));
assert_ok!(Democracy::second(Origin::signed(2), 0));
assert_ok!(Democracy::second(Origin::signed(5), 0));
assert_ok!(Democracy::second(Origin::signed(5), 0));
assert_ok!(Democracy::second(Origin::signed(5), 0));
assert_eq!(Democracy::end_block(System::block_number()), Ok(()));
assert_eq!(Balances::free_balance(&1), 10);
assert_eq!(Balances::free_balance(&2), 20);
@@ -649,7 +645,7 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
assert_ok!(propose_set_balance(2, 2, 11));
assert_noop!(Democracy::second(Origin::signed(1), 0.into()), "seconder\'s balance too low");
assert_noop!(Democracy::second(Origin::signed(1), 0), "seconder\'s balance too low");
});
}
@@ -663,17 +659,17 @@ mod tests {
assert_eq!(Democracy::end_block(System::block_number()), Ok(()));
System::set_block_number(1);
assert_ok!(Democracy::vote(Origin::signed(1), 0.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(1), 0, AYE));
assert_eq!(Democracy::end_block(System::block_number()), Ok(()));
assert_eq!(Balances::free_balance(&42), 4);
System::set_block_number(2);
assert_ok!(Democracy::vote(Origin::signed(1), 1.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(1), 1, AYE));
assert_eq!(Democracy::end_block(System::block_number()), Ok(()));
assert_eq!(Balances::free_balance(&42), 3);
System::set_block_number(3);
assert_ok!(Democracy::vote(Origin::signed(1), 2.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(1), 2, AYE));
assert_eq!(Democracy::end_block(System::block_number()), Ok(()));
});
}
@@ -683,7 +679,7 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap();
assert_ok!(Democracy::vote(Origin::signed(1), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(1), r, AYE));
assert_eq!(Democracy::voters_for(r), vec![1]);
assert_eq!(Democracy::vote_of((r, 1)), AYE);
@@ -700,7 +696,7 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap();
assert_ok!(Democracy::vote(Origin::signed(1), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(1), r, AYE));
assert_ok!(Democracy::cancel_referendum(r.into()));
assert_eq!(Democracy::end_block(System::block_number()), Ok(()));
@@ -714,7 +710,7 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap();
assert_ok!(Democracy::vote(Origin::signed(1), r.into(), NAY));
assert_ok!(Democracy::vote(Origin::signed(1), r, NAY));
assert_eq!(Democracy::voters_for(r), vec![1]);
assert_eq!(Democracy::vote_of((r, 1)), NAY);
@@ -731,12 +727,12 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap();
assert_ok!(Democracy::vote(Origin::signed(1), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(2), r.into(), NAY));
assert_ok!(Democracy::vote(Origin::signed(3), r.into(), NAY));
assert_ok!(Democracy::vote(Origin::signed(4), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(5), r.into(), NAY));
assert_ok!(Democracy::vote(Origin::signed(6), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(1), r, AYE));
assert_ok!(Democracy::vote(Origin::signed(2), r, NAY));
assert_ok!(Democracy::vote(Origin::signed(3), r, NAY));
assert_ok!(Democracy::vote(Origin::signed(4), r, AYE));
assert_ok!(Democracy::vote(Origin::signed(5), r, NAY));
assert_ok!(Democracy::vote(Origin::signed(6), r, AYE));
assert_eq!(Democracy::tally(r), (110, 100, 210));
@@ -751,12 +747,12 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 1).unwrap();
assert_ok!(Democracy::vote(Origin::signed(1), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(2), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(3), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(4), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(5), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(6), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(1), r, AYE));
assert_ok!(Democracy::vote(Origin::signed(2), r, AYE));
assert_ok!(Democracy::vote(Origin::signed(3), r, AYE));
assert_ok!(Democracy::vote(Origin::signed(4), r, AYE));
assert_ok!(Democracy::vote(Origin::signed(5), r, AYE));
assert_ok!(Democracy::vote(Origin::signed(6), r, AYE));
assert_eq!(Democracy::tally(r), (210, 0, 210));
@@ -775,12 +771,12 @@ mod tests {
with_externalities(&mut new_test_ext_with_public_delay(1), || {
System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap();
assert_ok!(Democracy::vote(Origin::signed(1), r.into(), Vote::new(false, 6)));
assert_ok!(Democracy::vote(Origin::signed(2), r.into(), Vote::new(true, 5)));
assert_ok!(Democracy::vote(Origin::signed(3), r.into(), Vote::new(true, 4)));
assert_ok!(Democracy::vote(Origin::signed(4), r.into(), Vote::new(true, 3)));
assert_ok!(Democracy::vote(Origin::signed(5), r.into(), Vote::new(true, 2)));
assert_ok!(Democracy::vote(Origin::signed(6), r.into(), Vote::new(false, 1)));
assert_ok!(Democracy::vote(Origin::signed(1), r, Vote::new(false, 6)));
assert_ok!(Democracy::vote(Origin::signed(2), r, Vote::new(true, 5)));
assert_ok!(Democracy::vote(Origin::signed(3), r, Vote::new(true, 4)));
assert_ok!(Democracy::vote(Origin::signed(4), r, Vote::new(true, 3)));
assert_ok!(Democracy::vote(Origin::signed(5), r, Vote::new(true, 2)));
assert_ok!(Democracy::vote(Origin::signed(6), r, Vote::new(false, 1)));
assert_eq!(Democracy::tally(r), (440, 120, 210));
@@ -805,8 +801,8 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap();
assert_ok!(Democracy::vote(Origin::signed(5), r.into(), NAY));
assert_ok!(Democracy::vote(Origin::signed(6), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(5), r, NAY));
assert_ok!(Democracy::vote(Origin::signed(6), r, AYE));
assert_eq!(Democracy::tally(r), (60, 50, 110));
@@ -824,9 +820,9 @@ mod tests {
System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap();
assert_ok!(Democracy::vote(Origin::signed(4), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(5), r.into(), NAY));
assert_ok!(Democracy::vote(Origin::signed(6), r.into(), AYE));
assert_ok!(Democracy::vote(Origin::signed(4), r, AYE));
assert_ok!(Democracy::vote(Origin::signed(5), r, NAY));
assert_ok!(Democracy::vote(Origin::signed(6), r, AYE));
assert_eq!(Democracy::tally(r), (100, 50, 150));
+2 -3
View File
@@ -50,7 +50,6 @@ extern crate srml_system as system;
// might find it useful).
extern crate srml_balances as balances;
use codec::HasCompact;
use support::{StorageValue, dispatch::Result};
use system::ensure_signed;
@@ -178,9 +177,9 @@ decl_module! {
// without worrying about gameability or attack scenarios.
// If you not specify `Result` explicitly as return value, it will be added automatically
// for you and `Ok(())` will be returned.
fn set_dummy(new_value: <T::Balance as HasCompact>::Type) {
fn set_dummy(#[compact] new_value: T::Balance) {
// Put the new value into storage.
<Dummy<T>>::put(new_value.into());
<Dummy<T>>::put(new_value);
}
// The signature could also look like: `fn on_finalise()`
+2 -2
View File
@@ -328,7 +328,7 @@ mod tests {
transfer_fee: 0,
creation_fee: 0,
}.build_storage().unwrap().0);
let xt = primitives::testing::TestXt(Some(1), 0, Call::transfer(2, 69.into()));
let xt = primitives::testing::TestXt(Some(1), 0, Call::transfer(2, 69));
let mut t = runtime_io::TestExternalities::<Blake2Hasher>::new(t);
with_externalities(&mut t, || {
Executive::initialise_block(&Header::new(1, H256::default(), H256::default(),
@@ -398,7 +398,7 @@ mod tests {
#[test]
fn bad_extrinsic_not_inserted() {
let mut t = new_test_ext();
let xt = primitives::testing::TestXt(Some(1), 42, Call::transfer(33, 69.into()));
let xt = primitives::testing::TestXt(Some(1), 42, Call::transfer(33, 69));
with_externalities(&mut t, || {
Executive::initialise_block(&Header::new(1, H256::default(), H256::default(), [69u8; 32].into(), Digest::default()));
assert!(Executive::apply_extrinsic(xt).is_err());
+6 -7
View File
@@ -39,7 +39,6 @@ extern crate srml_timestamp as timestamp;
use rstd::prelude::*;
use primitives::traits::{As, Zero, One, Convert};
use codec::HasCompact;
use runtime_support::{StorageValue, StorageMap};
use runtime_support::dispatch::Result;
use runtime_support::for_each_tuple;
@@ -89,8 +88,8 @@ decl_module! {
}
/// Set a new session length. Won't kick in until the next session change (at current length).
fn set_length(new: <T::BlockNumber as HasCompact>::Type) {
<NextSessionLength<T>>::put(new.into());
fn set_length(#[compact] new: T::BlockNumber) {
<NextSessionLength<T>>::put(new);
}
/// Forces a new session.
@@ -309,7 +308,7 @@ mod tests {
fn should_work_with_early_exit() {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
assert_ok!(Session::set_length(10.into()));
assert_ok!(Session::set_length(10));
assert_eq!(Session::blocks_remaining(), 1);
Session::check_rotate_session(1);
@@ -344,14 +343,14 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
// Block 1: Change to length 3; no visible change.
System::set_block_number(1);
assert_ok!(Session::set_length(3.into()));
assert_ok!(Session::set_length(3));
Session::check_rotate_session(1);
assert_eq!(Session::length(), 2);
assert_eq!(Session::current_index(), 0);
// Block 2: Length now changed to 3. Index incremented.
System::set_block_number(2);
assert_ok!(Session::set_length(3.into()));
assert_ok!(Session::set_length(3));
Session::check_rotate_session(2);
assert_eq!(Session::length(), 3);
assert_eq!(Session::current_index(), 1);
@@ -364,7 +363,7 @@ mod tests {
// Block 4: Change to length 2; no visible change.
System::set_block_number(4);
assert_ok!(Session::set_length(2.into()));
assert_ok!(Session::set_length(2));
Session::check_rotate_session(4);
assert_eq!(Session::length(), 3);
assert_eq!(Session::current_index(), 1);
+9 -14
View File
@@ -118,9 +118,8 @@ decl_module! {
/// Retract the desire to stake for the transactor.
///
/// Effects will be felt at the beginning of the next era.
fn unstake(origin, intentions_index: Compact<u32>) -> Result {
fn unstake(origin, #[compact] intentions_index: u32) -> Result {
let who = ensure_signed(origin)?;
let intentions_index: u32 = intentions_index.into();
// unstake fails in degenerate case of having too few existing staked parties
if Self::intentions().len() <= Self::minimum_validator_count() as usize {
return Err("cannot unstake when there are too few staked participants")
@@ -149,9 +148,8 @@ decl_module! {
/// Will panic if called when source isn't currently nominating target.
/// Updates Nominating, NominatorsFor and NominationBalance.
fn unnominate(origin, target_index: Compact<u32>) {
fn unnominate(origin, #[compact] target_index: u32) {
let source = ensure_signed(origin)?;
let target_index: u32 = target_index.into();
let target_index = target_index as usize;
let target = <Nominating<T>>::get(&source).ok_or("Account must be nominating")?;
@@ -182,11 +180,10 @@ decl_module! {
/// An error (no-op) if `Self::intentions()[intentions_index] != origin`.
fn register_preferences(
origin,
intentions_index: Compact<u32>,
#[compact] intentions_index: u32,
prefs: ValidatorPrefs<T::Balance>
) {
let who = ensure_signed(origin)?;
let intentions_index: u32 = intentions_index.into();
if Self::intentions().get(intentions_index as usize) != Some(&who) {
return Err("Invalid index")
@@ -196,18 +193,17 @@ decl_module! {
}
/// Set the number of sessions in an era.
fn set_sessions_per_era(new: <T::BlockNumber as HasCompact>::Type) {
<NextSessionsPerEra<T>>::put(new.into());
fn set_sessions_per_era(#[compact] new: T::BlockNumber) {
<NextSessionsPerEra<T>>::put(new);
}
/// The length of the bonding duration in eras.
fn set_bonding_duration(new: <T::BlockNumber as HasCompact>::Type) {
<BondingDuration<T>>::put(new.into());
fn set_bonding_duration(#[compact] new: T::BlockNumber) {
<BondingDuration<T>>::put(new);
}
/// The ideal number of validators.
fn set_validator_count(new: Compact<u32>) {
let new: u32 = new.into();
fn set_validator_count(#[compact] new: u32) {
<ValidatorCount<T>>::put(new);
}
@@ -218,8 +214,7 @@ decl_module! {
}
/// Set the offline slash grace period.
fn set_offline_slash_grace(new: Compact<u32>) {
let new: u32 = new.into();
fn set_offline_slash_grace(#[compact] new: u32) {
<OfflineSlashGrace<T>>::put(new);
}
+7 -7
View File
@@ -90,7 +90,7 @@ fn note_offline_grace_should_work() {
with_externalities(&mut new_test_ext(0, 3, 3, 0, true, 10), || {
Balances::set_free_balance(&10, 70);
Balances::set_free_balance(&20, 70);
assert_ok!(Staking::set_offline_slash_grace(1.into()));
assert_ok!(Staking::set_offline_slash_grace(1));
assert_eq!(Staking::offline_slash_grace(), 1);
assert_eq!(Staking::slash_count(&10), 0);
@@ -145,7 +145,7 @@ fn note_offline_auto_unstake_session_change_should_work() {
with_externalities(&mut new_test_ext(0, 3, 3, 0, true, 10), || {
Balances::set_free_balance(&10, 7000);
Balances::set_free_balance(&20, 7000);
assert_ok!(Staking::register_preferences(Origin::signed(10), 0.into(), ValidatorPrefs { unstake_threshold: 1, validator_payment: 0 }));
assert_ok!(Staking::register_preferences(Origin::signed(10), 0, ValidatorPrefs { unstake_threshold: 1, validator_payment: 0 }));
assert_eq!(Staking::intentions(), vec![10, 20]);
@@ -251,7 +251,7 @@ fn staking_should_work() {
assert_eq!(Staking::validator_count(), 2);
assert_eq!(Session::validators(), vec![10, 20]);
assert_ok!(Staking::set_bonding_duration(2.into()));
assert_ok!(Staking::set_bonding_duration(2));
assert_eq!(Staking::bonding_duration(), 2);
// Block 1: Add three validators. No obvious change.
@@ -284,7 +284,7 @@ fn staking_should_work() {
// Block 5: Transfer stake from highest to lowest. No change yet.
System::set_block_number(5);
assert_ok!(Balances::transfer(Origin::signed(4), 1, 40.into()));
assert_ok!(Balances::transfer(Origin::signed(4), 1, 40));
Session::check_rotate_session(System::block_number());
// Block 6: Lowest now validator.
@@ -327,7 +327,7 @@ fn nominating_and_rewards_should_work() {
assert_eq!(Balances::total_balance(&4), 40);
System::set_block_number(2);
assert_ok!(Staking::unnominate(Origin::signed(4), 0.into()));
assert_ok!(Staking::unnominate(Origin::signed(4), 0));
Session::check_rotate_session(System::block_number());
assert_eq!(Staking::current_era(), 2);
assert_eq!(Session::validators(), vec![3, 2]);
@@ -460,7 +460,7 @@ fn staking_eras_work() {
// Block 3: Schedule an era length change; no visible changes.
System::set_block_number(3);
assert_ok!(Staking::set_sessions_per_era(3.into()));
assert_ok!(Staking::set_sessions_per_era(3));
Session::check_rotate_session(System::block_number());
assert_eq!(Session::current_index(), 3);
assert_eq!(Staking::sessions_per_era(), 2);
@@ -506,7 +506,7 @@ fn staking_balance_transfer_when_bonded_should_not_work() {
with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || {
Balances::set_free_balance(&1, 111);
assert_ok!(Staking::stake(Origin::signed(1)));
assert_noop!(Balances::transfer(Origin::signed(1), 2, 69.into()), "cannot transfer illiquid funds");
assert_noop!(Balances::transfer(Origin::signed(1), 2, 69), "cannot transfer illiquid funds");
});
}
+104 -25
View File
@@ -21,7 +21,7 @@ pub use rstd::prelude::{Vec, Clone, Eq, PartialEq};
#[cfg(feature = "std")]
pub use std::fmt;
pub use rstd::result;
pub use codec::{Codec, Decode, Encode, Input, Output};
pub use codec::{Codec, Decode, Encode, Input, Output, HasCompact, EncodeAsRef};
pub use srml_metadata::{
ModuleMetadata, FunctionMetadata, DecodeDifferent,
CallMetadata, FunctionArgumentMetadata, OuterDispatchMetadata, OuterDispatchCall
@@ -201,7 +201,7 @@ macro_rules! decl_module {
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
$fn_vis:vis fn $fn_name:ident(
$origin:ident $(, $param_name:ident : $param:ty)*
$origin:ident $(, $(#[$codec_attr:ident])* $param_name:ident : $param:ty)*
) $( -> $result:ty )* { $( $impl:tt )* }
$($rest:tt)*
) => {
@@ -215,7 +215,7 @@ macro_rules! decl_module {
$($t)*
$(#[doc = $doc_attr])*
$fn_vis fn $fn_name(
$origin $( , $param_name : $param )*
$origin $( , $(#[$codec_attr])* $param_name : $param )*
) $( -> $result )* { $( $impl )* }
]
$($rest)*
@@ -230,7 +230,7 @@ macro_rules! decl_module {
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
$fn_vis:vis fn $fn_name:ident(
$origin:ident : T::Origin $(, $param_name:ident : $param:ty)*
$origin:ident : T::Origin $(, $(#[$codec_attr:ident])* $param_name:ident : $param:ty)*
) $( -> $result:ty )* { $( $impl:tt )* }
$($rest:tt)*
) => {
@@ -249,7 +249,7 @@ macro_rules! decl_module {
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
$fn_vis:vis fn $fn_name:ident(
origin : $origin:ty $(, $param_name:ident : $param:ty)*
origin : $origin:ty $(, $(#[$codec_attr:ident])* $param_name:ident : $param:ty)*
) $( -> $result:ty )* { $( $impl:tt )* }
$($rest:tt)*
) => {
@@ -268,7 +268,7 @@ macro_rules! decl_module {
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
$fn_vis:vis fn $fn_name:ident(
$( $param_name:ident : $param:ty),*
$( $(#[$codec_attr:ident])* $param_name:ident : $param:ty),*
) $( -> $result:ty )* { $( $impl:tt )* }
$($rest:tt)*
) => {
@@ -282,7 +282,7 @@ macro_rules! decl_module {
$($t)*
$(#[doc = $doc_attr])*
$fn_vis fn $fn_name(
root $( , $param_name : $param )*
root $( , $(#[$codec_attr])* $param_name : $param )*
) $( -> $result )* { $( $impl )* }
]
$($rest)*
@@ -475,7 +475,7 @@ macro_rules! decl_module {
$(
$(#[doc = $doc_attr:tt])*
$fn_vis:vis fn $fn_name:ident(
$from:ident $( , $param_name:ident : $param:ty)*
$from:ident $( , $(#[$codec_attr:ident])* $param_name:ident : $param:ty)*
) $( -> $result:ty )* { $( $impl:tt )* }
)*
}
@@ -607,13 +607,13 @@ macro_rules! decl_module {
impl<$trait_instance: $trait_name> $crate::dispatch::Decode for $call_type<$trait_instance> {
fn decode<I: $crate::dispatch::Input>(input: &mut I) -> Option<Self> {
let _input_id = input.read_byte()?;
__impl_decode!(input; _input_id; 0; $call_type; $( fn $fn_name( $( $param_name ),* ); )*)
__impl_decode!(input; _input_id; 0; $call_type; $( fn $fn_name( $( $(#[$codec_attr on type $param])* $param_name ),* ); )*)
}
}
impl<$trait_instance: $trait_name> $crate::dispatch::Encode for $call_type<$trait_instance> {
fn encode_to<W: $crate::dispatch::Output>(&self, _dest: &mut W) {
__impl_encode!(_dest; *self; 0; $call_type; $( fn $fn_name( $( $param_name ),* ); )*);
__impl_encode!(_dest; *self; 0; $call_type; $( fn $fn_name( $( $(#[$codec_attr on type $param])* $param_name ),* ); )*);
if let $call_type::__PhantomItem(_) = *self { unreachable!() }
if let $call_type::__OtherPhantomItem(_) = *self { unreachable!() }
}
@@ -651,7 +651,7 @@ macro_rules! decl_module {
}
__dispatch_impl_metadata! {
$mod_type $trait_instance $trait_name $call_type $origin_type
{$( $(#[doc = $doc_attr])* fn $fn_name($from $(, $param_name : $param )*); )*}
{$( $(#[doc = $doc_attr])* fn $fn_name($from $(, $(#[$codec_attr])* $param_name : $param )*); )*}
}
}
}
@@ -665,14 +665,18 @@ macro_rules! __impl_decode {
$fn_id:expr;
$call_type:ident;
fn $fn_name:ident(
$( $param_name:ident ),*
$( $(#[$codec_attr:ident on type $param:ty])* $param_name:ident ),*
);
$($rest:tt)*
) => {
{
if $input_id == ($fn_id) {
$(
let $param_name = $crate::dispatch::Decode::decode($input)?;
__impl_decode!(@decode
$(#[$codec_attr on type $param])*
$param_name;
$input;
);
)*
return Some($call_type:: $fn_name( $( $param_name ),* ));
}
@@ -687,7 +691,31 @@ macro_rules! __impl_decode {
$call_type:ident;
) => {
None
}
};
(@decode
#[compact on type $param:ty]
$param_name:ident;
$input:expr;
) => {
let $param_name = <<$param as $crate::dispatch::HasCompact>::Type as $crate::dispatch::Decode>::decode($input)?.into();
};
(@decode
$param_name:ident;
$input:expr;
) => {
let $param_name = $crate::dispatch::Decode::decode($input)?;
};
(@decode
$(#[$codec_attr:ident on type])*
$param_name:ident;
$input:expr;
) => {
compile_error!(concat!(
"Invalid attribute for parameter `",
stringify!($param_name),
"`, the following attributes are supported: `#[compact]`"
))
};
}
#[macro_export]
@@ -699,7 +727,7 @@ macro_rules! __impl_encode {
$fn_id:expr;
$call_type:ident;
fn $fn_name:ident(
$( $param_name:ident ),*
$( $(#[$codec_attr:ident on type $param:ty])* $param_name:ident ),*
);
$($rest:tt)*
) => {
@@ -711,7 +739,11 @@ macro_rules! __impl_encode {
) = $self {
$dest.push_byte(($fn_id) as u8);
$(
$param_name.encode_to($dest);
__impl_encode!(@encode_as
$(#[$codec_attr on type $param])*
$param_name;
$dest;
);
)*
}
@@ -723,7 +755,30 @@ macro_rules! __impl_encode {
$self:expr;
$fn_id:expr;
$call_type:ident;
) => {{}}
) => {{}};
(@encode_as
#[compact on type $param:ty]
$param_name:ident;
$dest:expr;
) => {
<<$param as $crate::dispatch::HasCompact>::Type as $crate::dispatch::EncodeAsRef<$param>>::RefType::from($param_name).encode_to($dest);
};
(@encode_as
$param_name:ident;
$dest:expr;
) => {
$param_name.encode_to($dest);
};
(@encode_as
$(#[$codec_attr:ident on type $param:ty])*
$param_name:ident;
$dest:expr;
) => {
compile_error!(concat!(
"Invalid attribute for parameter `", stringify!($param_name),
"`, the following attributes are supported: `#[compact]`"
))
};
}
pub trait IsSubType<T: Callable> {
@@ -871,7 +926,7 @@ macro_rules! __call_to_metadata {
$(#[doc = $doc_attr:tt])*
fn $fn_name:ident($from:ident
$(
, $param_name:ident : $param:ty
, $(#[$codec_attr:ident])* $param_name:ident : $param:ty
)*
);
)*}
@@ -879,7 +934,7 @@ macro_rules! __call_to_metadata {
$crate::dispatch::CallMetadata {
name: $crate::dispatch::DecodeDifferent::Encode(stringify!($call_type)),
functions: __functions_to_metadata!(0; $origin_type;; $(
fn $fn_name( $( $param_name: $param ),* );
fn $fn_name( $($(#[$codec_attr])* $param_name: $param ),* );
$( $doc_attr ),*;
)*),
}
@@ -896,7 +951,7 @@ macro_rules! __functions_to_metadata{
$( $function_metadata:expr ),*;
fn $fn_name:ident(
$(
$param_name:ident : $param:ty
$(#[$codec_attr:ident])* $param_name:ident : $param:ty
),*
);
$( $fn_doc:expr ),*;
@@ -905,7 +960,7 @@ macro_rules! __functions_to_metadata{
__functions_to_metadata!(
$fn_id + 1; $origin_type;
$( $function_metadata, )* __function_to_metadata!(
fn $fn_name($( $param_name : $param ),*); $( $fn_doc ),*; $fn_id;
fn $fn_name($( $(#[$codec_attr])* $param_name : $param ),*); $( $fn_doc ),*; $fn_id;
);
$($rest)*
)
@@ -925,7 +980,7 @@ macro_rules! __functions_to_metadata{
macro_rules! __function_to_metadata {
(
fn $fn_name:ident(
$($param_name:ident : $param:ty),*
$( $(#[$codec_attr:ident])* $param_name:ident : $param:ty),*
);
$( $fn_doc:expr ),*;
$fn_id:expr;
@@ -937,13 +992,30 @@ macro_rules! __function_to_metadata {
$(
$crate::dispatch::FunctionArgumentMetadata {
name: $crate::dispatch::DecodeDifferent::Encode(stringify!($param_name)),
ty: $crate::dispatch::DecodeDifferent::Encode(stringify!($param)),
ty: $crate::dispatch::DecodeDifferent::Encode(
__function_to_metadata!(@stringify_expand_attr
$(#[$codec_attr])* $param_name: $param
)
),
}
),*
]),
documentation: $crate::dispatch::DecodeDifferent::Encode(&[ $( $fn_doc ),* ]),
}
};
(@stringify_expand_attr #[compact] $param_name:ident : $param:ty) => {
concat!("Compact<", stringify!($param), ">")
};
(@stringify_expand_attr $param_name:ident : $param:ty) => { stringify!($param) };
(@stringify_expand_attr $(#[codec_attr:ident])* $param_name:ident : $param:ty) => {
compile_error!(concat!(
"Invalid attribute for parameter `", stringify!($param_name),
"`, the following attributes are supported: `#[compact]`"
))
}
}
#[cfg(test)]
@@ -969,7 +1041,7 @@ mod tests {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
/// Hi, this is a comment.
fn aux_0(_origin) -> Result { unreachable!() }
fn aux_1(_origin, _data: i32) -> Result { unreachable!() }
fn aux_1(_origin, #[compact] _data: u32) -> Result { unreachable!() }
fn aux_2(_origin, _data: i32, _data2: String) -> Result { unreachable!() }
fn aux_3() -> Result { unreachable!() }
fn aux_4(_data: i32) -> Result { unreachable!() }
@@ -995,7 +1067,7 @@ mod tests {
arguments: DecodeDifferent::Encode(&[
FunctionArgumentMetadata {
name: DecodeDifferent::Encode("_data"),
ty: DecodeDifferent::Encode("i32"),
ty: DecodeDifferent::Encode("Compact<u32>")
}
]),
documentation: DecodeDifferent::Encode(&[]),
@@ -1048,4 +1120,11 @@ mod tests {
let metadata = Module::<TraitImpl>::metadata();
assert_eq!(EXPECTED_METADATA, metadata);
}
#[test]
fn compact_attr() {
let call: Call<TraitImpl> = Call::aux_1(0);
let encoded = call.encode();
assert_eq!(encoded.len(), 2);
}
}
+6 -9
View File
@@ -47,7 +47,6 @@ extern crate srml_system as system;
extern crate srml_consensus as consensus;
extern crate parity_codec as codec;
use codec::HasCompact;
use runtime_support::{StorageValue, Parameter};
use runtime_primitives::CheckInherentError;
use runtime_primitives::traits::{
@@ -100,10 +99,8 @@ decl_module! {
/// if this call hasn't been invoked by that time.
///
/// The timestamp should be greater than the previous one by the amount specified by `block_period`.
fn set(origin, now: <T::Moment as HasCompact>::Type) {
fn set(origin, #[compact] now: T::Moment) {
ensure_inherent(origin)?;
let now = now.into();
assert!(!<Self as Store>::DidUpdate::exists(), "Timestamp must be updated only once in the block");
assert!(
<system::Module<T>>::extrinsic_index() == Some(T::TIMESTAMP_SET_POSITION),
@@ -175,7 +172,7 @@ impl<T: Trait> ProvideInherent for Module<T> {
let t = match (xt.is_signed(), extract_function(&xt)) {
(Some(false), Some(Call::set(ref t))) => t.clone(),
_ => return Err(CheckInherentError::Other("No valid timestamp inherent in block".into())),
}.into().as_();
}.as_();
let minimum = (Self::now() + Self::block_period()).as_();
if t > data.as_() + MAX_TIMESTAMP_DRIFT {
@@ -239,7 +236,7 @@ mod tests {
with_externalities(&mut TestExternalities::new(t), || {
Timestamp::set_timestamp(42);
assert_ok!(Timestamp::dispatch(Call::set(69.into()), Origin::INHERENT));
assert_ok!(Timestamp::dispatch(Call::set(69), Origin::INHERENT));
assert_eq!(Timestamp::now(), 69);
});
}
@@ -254,8 +251,8 @@ mod tests {
with_externalities(&mut TestExternalities::new(t), || {
Timestamp::set_timestamp(42);
assert_ok!(Timestamp::dispatch(Call::set(69.into()), Origin::INHERENT));
let _ = Timestamp::dispatch(Call::set(70.into()), Origin::INHERENT);
assert_ok!(Timestamp::dispatch(Call::set(69), Origin::INHERENT));
let _ = Timestamp::dispatch(Call::set(70), Origin::INHERENT);
});
}
@@ -269,7 +266,7 @@ mod tests {
with_externalities(&mut TestExternalities::new(t), || {
Timestamp::set_timestamp(42);
let _ = Timestamp::dispatch(Call::set(46.into()), Origin::INHERENT);
let _ = Timestamp::dispatch(Call::set(46), Origin::INHERENT);
});
}
}
+28 -33
View File
@@ -41,7 +41,6 @@ extern crate srml_balances as balances;
use rstd::prelude::*;
use runtime_support::{StorageValue, StorageMap};
use runtime_primitives::{Permill, traits::{Zero, EnsureOrigin, StaticLookup}};
use codec::{HasCompact, Compact};
use balances::OnDilution;
use system::ensure_signed;
@@ -74,12 +73,11 @@ decl_module! {
/// proposal is awarded.
fn propose_spend(
origin,
value: <T::Balance as HasCompact>::Type,
#[compact] value: T::Balance,
beneficiary: <T::Lookup as StaticLookup>::Source
) {
let proposer = ensure_signed(origin)?;
let beneficiary = T::Lookup::lookup(beneficiary)?;
let value = value.into();
let bond = Self::calculate_bond(value);
<balances::Module<T>>::reserve(&proposer, bond)
@@ -93,29 +91,27 @@ decl_module! {
}
/// Set the balance of funds available to spend.
fn set_pot(new_pot: <T::Balance as HasCompact>::Type) {
fn set_pot(#[compact] new_pot: T::Balance) {
// Put the new value into storage.
<Pot<T>>::put(new_pot.into());
<Pot<T>>::put(new_pot);
}
/// (Re-)configure this module.
fn configure(
proposal_bond: Permill,
proposal_bond_minimum: <T::Balance as HasCompact>::Type,
spend_period: <T::BlockNumber as HasCompact>::Type,
#[compact] proposal_bond_minimum: T::Balance,
#[compact] spend_period: T::BlockNumber,
burn: Permill
) {
<ProposalBond<T>>::put(proposal_bond);
<ProposalBondMinimum<T>>::put(proposal_bond_minimum.into());
<SpendPeriod<T>>::put(spend_period.into());
<ProposalBondMinimum<T>>::put(proposal_bond_minimum);
<SpendPeriod<T>>::put(spend_period);
<Burn<T>>::put(burn);
}
/// Reject a proposed spend. The original deposit will be slashed.
fn reject_proposal(origin, proposal_id: Compact<ProposalIndex>) {
fn reject_proposal(origin, #[compact] proposal_id: ProposalIndex) {
T::RejectOrigin::ensure_origin(origin)?;
let proposal_id: ProposalIndex = proposal_id.into();
let proposal = <Proposals<T>>::take(proposal_id).ok_or("No proposal at that index")?;
let value = proposal.bond;
@@ -124,9 +120,8 @@ decl_module! {
/// Approve a proposal. At a later time, the proposal will be allocated to the beneficiary
/// and the original deposit will be returned.
fn approve_proposal(origin, proposal_id: Compact<ProposalIndex>) {
fn approve_proposal(origin, #[compact] proposal_id: ProposalIndex) {
T::ApproveOrigin::ensure_origin(origin)?;
let proposal_id = proposal_id.into();
ensure!(<Proposals<T>>::exists(proposal_id), "No proposal at that index");
@@ -353,7 +348,7 @@ mod tests {
#[test]
fn spend_proposal_takes_min_deposit() {
with_externalities(&mut new_test_ext(), || {
assert_ok!(Treasury::propose_spend(Origin::signed(0), 1.into(), 3));
assert_ok!(Treasury::propose_spend(Origin::signed(0), 1, 3));
assert_eq!(Balances::free_balance(&0), 99);
assert_eq!(Balances::reserved_balance(&0), 1);
});
@@ -362,7 +357,7 @@ mod tests {
#[test]
fn spend_proposal_takes_proportional_deposit() {
with_externalities(&mut new_test_ext(), || {
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100.into(), 3));
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
assert_eq!(Balances::free_balance(&0), 95);
assert_eq!(Balances::reserved_balance(&0), 5);
});
@@ -371,7 +366,7 @@ mod tests {
#[test]
fn spend_proposal_fails_when_proposer_poor() {
with_externalities(&mut new_test_ext(), || {
assert_noop!(Treasury::propose_spend(Origin::signed(2), 100.into(), 3), "Proposer's balance too low");
assert_noop!(Treasury::propose_spend(Origin::signed(2), 100, 3), "Proposer's balance too low");
});
}
@@ -380,8 +375,8 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
Treasury::on_dilution(100, 100);
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100.into(), 3));
assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0.into()));
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0));
<Treasury as OnFinalise<u64>>::on_finalise(1);
assert_eq!(Balances::free_balance(&3), 0);
@@ -404,8 +399,8 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
Treasury::on_dilution(100, 100);
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100.into(), 3));
assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0.into()));
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0));
<Treasury as OnFinalise<u64>>::on_finalise(2);
assert_eq!(Balances::free_balance(&3), 0);
@@ -418,23 +413,23 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
Treasury::on_dilution(100, 100);
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100.into(), 3));
assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0.into()));
assert_noop!(Treasury::reject_proposal(Origin::ROOT, 0.into()), "No proposal at that index");
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0));
assert_noop!(Treasury::reject_proposal(Origin::ROOT, 0), "No proposal at that index");
});
}
#[test]
fn reject_non_existant_spend_proposal_fails() {
with_externalities(&mut new_test_ext(), || {
assert_noop!(Treasury::reject_proposal(Origin::ROOT, 0.into()), "No proposal at that index");
assert_noop!(Treasury::reject_proposal(Origin::ROOT, 0), "No proposal at that index");
});
}
#[test]
fn accept_non_existant_spend_proposal_fails() {
with_externalities(&mut new_test_ext(), || {
assert_noop!(Treasury::approve_proposal(Origin::ROOT, 0.into()), "No proposal at that index");
assert_noop!(Treasury::approve_proposal(Origin::ROOT, 0), "No proposal at that index");
});
}
@@ -443,9 +438,9 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
Treasury::on_dilution(100, 100);
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100.into(), 3));
assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0.into()));
assert_noop!(Treasury::approve_proposal(Origin::ROOT, 0.into()), "No proposal at that index");
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0));
assert_noop!(Treasury::approve_proposal(Origin::ROOT, 0), "No proposal at that index");
});
}
@@ -454,8 +449,8 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
Treasury::on_dilution(100, 100);
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100.into(), 3));
assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0.into()));
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0));
<Treasury as OnFinalise<u64>>::on_finalise(2);
assert_eq!(Balances::free_balance(&3), 100);
@@ -468,8 +463,8 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
Treasury::on_dilution(100, 100);
assert_ok!(Treasury::propose_spend(Origin::signed(0), 150.into(), 3));
assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0.into()));
assert_ok!(Treasury::propose_spend(Origin::signed(0), 150, 3));
assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0));
<Treasury as OnFinalise<u64>>::on_finalise(2);
assert_eq!(Treasury::pot(), 100);