claims.rs 46.5 KB
Newer Older
Shawn Tabrizi's avatar
Shawn Tabrizi committed
1
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
2
// This file is part of Polkadot.
Gav Wood's avatar
Gav Wood committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Substrate.  If not, see <http://www.gnu.org/licenses/>.

//! Module to process claims from Ethereum addresses.

19
use sp_std::{prelude::*, fmt::Debug};
20
use sp_io::{hashing::keccak_256, crypto::secp256k1_ecdsa_recover};
21
use frame_support::{
22
	decl_event, decl_storage, decl_module, decl_error, ensure,
23
24
25
	traits::{Currency, Get, VestingSchedule, EnsureOrigin, IsSubType},
	weights::{Weight, Pays, DispatchClass},
	pallet_prelude::DispatchResultWithPostInfo,
26
};
27
use frame_system::{ensure_signed, ensure_root, ensure_none};
28
use parity_scale_codec::{Encode, Decode};
Gav Wood's avatar
Gav Wood committed
29
#[cfg(feature = "std")]
30
use serde::{self, Serialize, Deserialize, Serializer, Deserializer};
31
32
#[cfg(feature = "std")]
use sp_runtime::traits::Zero;
33
use sp_runtime::{
34
	traits::{CheckedSub, SignedExtension, DispatchInfoOf}, RuntimeDebug, DispatchResult,
35
	transaction_validity::{
36
37
		TransactionLongevity, TransactionValidity, ValidTransaction, InvalidTransaction,
		TransactionSource, TransactionValidityError,
Gavin Wood's avatar
Gavin Wood committed
38
	},
39
};
40
use primitives::v1::ValidityError;
41

42
43
type CurrencyOf<T> = <<T as Config>::VestingSchedule as VestingSchedule<<T as frame_system::Config>::AccountId>>::Currency;
type BalanceOf<T> = <CurrencyOf<T> as Currency<<T as frame_system::Config>::AccountId>>::Balance;
Gav Wood's avatar
Gav Wood committed
44
45

/// Configuration trait.
46
pub trait Config: frame_system::Config {
Gav Wood's avatar
Gav Wood committed
47
	/// The overarching event type.
48
	type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
Gavin Wood's avatar
Gavin Wood committed
49
	type VestingSchedule: VestingSchedule<Self::AccountId, Moment=Self::BlockNumber>;
50
	type Prefix: Get<&'static [u8]>;
51
	type MoveClaimOrigin: EnsureOrigin<Self::Origin>;
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
	type WeightInfo: WeightInfo;
}

pub trait WeightInfo {
	fn claim() -> Weight;
	fn mint_claim() -> Weight;
	fn claim_attest() -> Weight;
	fn attest() -> Weight;
	fn move_claim() -> Weight;
}

pub struct TestWeightInfo;
impl WeightInfo for TestWeightInfo {
	fn claim() -> Weight { 0 }
	fn mint_claim() -> Weight { 0 }
	fn claim_attest() -> Weight { 0 }
	fn attest() -> Weight { 0 }
	fn move_claim() -> Weight { 0 }
Gav Wood's avatar
Gav Wood committed
70
71
}

Gavin Wood's avatar
Gavin Wood committed
72
/// The kind of a statement an account needs to make for a claim to be valid.
73
74
75
#[derive(Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum StatementKind {
Gavin Wood's avatar
Gavin Wood committed
76
77
78
79
	/// Statement required to be made by non-SAFT holders.
	Regular,
	/// Statement required to be made by SAFT holders.
	Saft,
80
81
82
83
84
85
}

impl StatementKind {
	/// Convert this to the (English) statement it represents.
	fn to_text(self) -> &'static [u8] {
		match self {
Gavin Wood's avatar
Gavin Wood committed
86
87
88
89
90
91
92
93
			StatementKind::Regular =>
				&b"I hereby agree to the terms of the statement whose SHA-256 multihash is \
				Qmc1XYqT6S39WNp2UeiRUrZichUWUPpGEThDE6dAb3f6Ny. (This may be found at the URL: \
				https://statement.polkadot.network/regular.html)"[..],
			StatementKind::Saft =>
				&b"I hereby agree to the terms of the statement whose SHA-256 multihash is \
				QmXEkMahfhHJPzT3RjkXiZVFi77ZeVeuxtAjhojGRNYckz. (This may be found at the URL: \
				https://statement.polkadot.network/saft.html)"[..],
94
95
96
97
98
99
		}
	}
}

impl Default for StatementKind {
	fn default() -> Self {
Gavin Wood's avatar
Gavin Wood committed
100
		StatementKind::Regular
101
102
103
	}
}

104
105
106
/// An Ethereum address (i.e. 20 bytes, used to represent an Ethereum account).
///
/// This gets serialized to the 0x-prefixed hex representation.
Gavin Wood's avatar
Gavin Wood committed
107
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug)]
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
pub struct EthereumAddress([u8; 20]);

#[cfg(feature = "std")]
impl Serialize for EthereumAddress {
	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
		let hex: String = rustc_hex::ToHex::to_hex(&self.0[..]);
		serializer.serialize_str(&format!("0x{}", hex))
	}
}

#[cfg(feature = "std")]
impl<'de> Deserialize<'de> for EthereumAddress {
	fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> {
		let base_string = String::deserialize(deserializer)?;
		let offset = if base_string.starts_with("0x") { 2 } else { 0 };
		let s = &base_string[offset..];
		if s.len() != 40 {
			Err(serde::de::Error::custom("Bad length of Ethereum address (should be 42 including '0x')"))?;
		}
		let raw: Vec<u8> = rustc_hex::FromHex::from_hex(s)
			.map_err(|e| serde::de::Error::custom(format!("{:?}", e)))?;
		let mut r = Self::default();
		r.0.copy_from_slice(&raw);
		Ok(r)
	}
}
134

135
136
#[derive(Encode, Decode, Clone)]
pub struct EcdsaSignature(pub [u8; 65]);
137

138
139
140
impl PartialEq for EcdsaSignature {
	fn eq(&self, other: &Self) -> bool {
		&self.0[..] == &other.0[..]
141
142
	}
}
Gav Wood's avatar
Gav Wood committed
143

144
145
impl sp_std::fmt::Debug for EcdsaSignature {
	fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result {
146
147
		write!(f, "EcdsaSignature({:?})", &self.0[..])
	}
148
149
}

Gav Wood's avatar
Gav Wood committed
150
151
decl_event!(
	pub enum Event<T> where
152
		Balance = BalanceOf<T>,
153
		AccountId = <T as frame_system::Config>::AccountId
Gav Wood's avatar
Gav Wood committed
154
	{
155
		/// Someone claimed some DOTs. [who, ethereum_address, amount]
156
		Claimed(AccountId, EthereumAddress, Balance),
Gav Wood's avatar
Gav Wood committed
157
158
159
	}
);

160
decl_error! {
161
	pub enum Error for Module<T: Config> {
162
163
164
165
		/// Invalid Ethereum signature.
		InvalidEthereumSignature,
		/// Ethereum address has no claim.
		SignerHasNoClaim,
166
167
		/// Account ID sending tx has no claim.
		SenderHasNoClaim,
Gavin Wood's avatar
Gavin Wood committed
168
169
170
		/// There's not enough in the pot to pay out some unvested amount. Generally implies a logic
		/// error.
		PotUnderflow,
171
172
		/// A needed statement was not included.
		InvalidStatement,
173
174
		/// The account already has a vested balance.
		VestedBalanceExists,
175
176
177
	}
}

Gav Wood's avatar
Gav Wood committed
178
179
180
181
decl_storage! {
	// A macro for the Storage trait, and its implementation, for this module.
	// This allows for type-safe usage of the Substrate storage database, so you can
	// keep things around between blocks.
182
	trait Store for Module<T: Config> as Claims {
183
		Claims get(fn claims) build(|config: &GenesisConfig<T>| {
184
			config.claims.iter().map(|(a, b, _, _)| (a.clone(), b.clone())).collect::<Vec<_>>()
185
		}): map hasher(identity) EthereumAddress => Option<BalanceOf<T>>;
186
		Total get(fn total) build(|config: &GenesisConfig<T>| {
187
			config.claims.iter().fold(Zero::zero(), |acc: BalanceOf<T>, &(_, b, _, _)| acc + b)
188
		}): BalanceOf<T>;
189
190
191
192
		/// Vesting schedule for a claim.
		/// First balance is the total amount that should be held for vesting.
		/// Second balance is how much should be unlocked per block.
		/// The block number is when the vesting should start.
193
		Vesting get(fn vesting) config():
194
			map hasher(identity) EthereumAddress
Gavin Wood's avatar
Gavin Wood committed
195
			=> Option<(BalanceOf<T>, BalanceOf<T>, T::BlockNumber)>;
196
197
198
199
200
201
202
203
204
205
206
207
208
209

		/// The statement kind that must be signed, if any.
		Signing build(|config: &GenesisConfig<T>| {
			config.claims.iter()
				.filter_map(|(a, _, _, s)| Some((a.clone(), s.clone()?)))
				.collect::<Vec<_>>()
		}): map hasher(identity) EthereumAddress => Option<StatementKind>;

		/// Pre-claimed Ethereum accounts, by the Account ID that they are claimed to.
		Preclaims build(|config: &GenesisConfig<T>| {
			config.claims.iter()
				.filter_map(|(a, _, i, _)| Some((i.clone()?, a.clone())))
				.collect::<Vec<_>>()
		}): map hasher(identity) T::AccountId => Option<EthereumAddress>;
Gav Wood's avatar
Gav Wood committed
210
211
	}
	add_extra_genesis {
212
		config(claims): Vec<(EthereumAddress, BalanceOf<T>, Option<T::AccountId>, Option<StatementKind>)>;
Gav Wood's avatar
Gav Wood committed
213
214
215
216
	}
}

decl_module! {
217
	pub struct Module<T: Config> for enum Call where origin: T::Origin {
218
219
		type Error = Error<T>;

220
221
222
		/// The Prefix that is used in signed Ethereum messages for this network
		const Prefix: &[u8] = T::Prefix::get();

Gav Wood's avatar
Gav Wood committed
223
		/// Deposit one of this module's events by using the default implementation.
thiolliere's avatar
thiolliere committed
224
		fn deposit_event() = default;
Gav Wood's avatar
Gav Wood committed
225

226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
		/// Make a claim to collect your DOTs.
		///
		/// The dispatch origin for this call must be _None_.
		///
		/// Unsigned Validation:
		/// A call to claim is deemed valid if the signature provided matches
		/// the expected signed message of:
		///
		/// > Ethereum Signed Message:
		/// > (configured prefix string)(address)
		///
		/// and `address` matches the `dest` account.
		///
		/// Parameters:
		/// - `dest`: The destination account to payout the claim.
		/// - `ethereum_signature`: The signature of an ethereum signed message
		///    matching the format described above.
		///
		/// <weight>
		/// The weight of this call is invariant over the input parameters.
246
		/// Weight includes logic to validate unsigned `claim` call.
247
248
249
		///
		/// Total Complexity: O(1)
		/// </weight>
250
		#[weight = T::WeightInfo::claim()]
251
252
		fn claim(origin, dest: T::AccountId, ethereum_signature: EcdsaSignature) {
			ensure_none(origin)?;
253

254
			let data = dest.using_encoded(to_ascii_hex);
255
			let signer = Self::eth_recover(&ethereum_signature, &data, &[][..])
256
				.ok_or(Error::<T>::InvalidEthereumSignature)?;
257
			ensure!(Signing::get(&signer).is_none(), Error::<T>::InvalidStatement);
258

259
			Self::process_claim(signer, dest)?;
260
		}
Gavin Wood's avatar
Gavin Wood committed
261

262
263
264
265
266
267
268
269
270
271
272
		/// Mint a new claim to collect DOTs.
		///
		/// The dispatch origin for this call must be _Root_.
		///
		/// Parameters:
		/// - `who`: The Ethereum address allowed to collect this claim.
		/// - `value`: The number of DOTs that will be claimed.
		/// - `vesting_schedule`: An optional vesting schedule for these DOTs.
		///
		/// <weight>
		/// The weight of this call is invariant over the input parameters.
273
		/// We assume worst case that both vesting and statement is being inserted.
274
275
276
		///
		/// Total Complexity: O(1)
		/// </weight>
277
		#[weight = T::WeightInfo::mint_claim()]
278
279
280
281
		fn mint_claim(origin,
			who: EthereumAddress,
			value: BalanceOf<T>,
			vesting_schedule: Option<(BalanceOf<T>, BalanceOf<T>, T::BlockNumber)>,
282
			statement: Option<StatementKind>,
283
		) {
Gavin Wood's avatar
Gavin Wood committed
284
285
286
287
			ensure_root(origin)?;

			<Total<T>>::mutate(|t| *t += value);
			<Claims<T>>::insert(who, value);
288
289
290
			if let Some(vs) = vesting_schedule {
				<Vesting<T>>::insert(who, vs);
			}
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
			if let Some(s) = statement {
				Signing::insert(who, s);
			}
		}

		/// Make a claim to collect your DOTs by signing a statement.
		///
		/// The dispatch origin for this call must be _None_.
		///
		/// Unsigned Validation:
		/// A call to `claim_attest` is deemed valid if the signature provided matches
		/// the expected signed message of:
		///
		/// > Ethereum Signed Message:
		/// > (configured prefix string)(address)(statement)
		///
		/// and `address` matches the `dest` account; the `statement` must match that which is
		/// expected according to your purchase arrangement.
		///
		/// Parameters:
		/// - `dest`: The destination account to payout the claim.
		/// - `ethereum_signature`: The signature of an ethereum signed message
		///    matching the format described above.
		/// - `statement`: The identity of the statement which is being attested to in the signature.
		///
		/// <weight>
		/// The weight of this call is invariant over the input parameters.
318
		/// Weight includes logic to validate unsigned `claim_attest` call.
319
320
321
		///
		/// Total Complexity: O(1)
		/// </weight>
322
		#[weight = T::WeightInfo::claim_attest()]
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
		fn claim_attest(origin,
			dest: T::AccountId,
			ethereum_signature: EcdsaSignature,
			statement: Vec<u8>,
		) {
			ensure_none(origin)?;

			let data = dest.using_encoded(to_ascii_hex);
			let signer = Self::eth_recover(&ethereum_signature, &data, &statement)
				.ok_or(Error::<T>::InvalidEthereumSignature)?;
			if let Some(s) = Signing::get(signer) {
				ensure!(s.to_text() == &statement[..], Error::<T>::InvalidStatement);
			}
			Self::process_claim(signer, dest)?;
		}

		/// Attest to a statement, needed to finalize the claims process.
		///
		/// WARNING: Insecure unless your chain includes `PrevalidateAttests` as a `SignedExtension`.
		///
		/// Unsigned Validation:
		/// A call to attest is deemed valid if the sender has a `Preclaim` registered
		/// and provides a `statement` which is expected for the account.
		///
		/// Parameters:
		/// - `statement`: The identity of the statement which is being attested to in the signature.
		///
		/// <weight>
351
352
353
		/// The weight of this call is invariant over the input parameters.
		/// Weight includes logic to do pre-validation on `attest` call.
		///
354
355
356
		/// Total Complexity: O(1)
		/// </weight>
		#[weight = (
357
			T::WeightInfo::attest(),
358
359
360
361
362
363
364
365
366
367
368
			DispatchClass::Normal,
			Pays::No
		)]
		fn attest(origin, statement: Vec<u8>) {
			let who = ensure_signed(origin)?;
			let signer = Preclaims::<T>::get(&who).ok_or(Error::<T>::SenderHasNoClaim)?;
			if let Some(s) = Signing::get(signer) {
				ensure!(s.to_text() == &statement[..], Error::<T>::InvalidStatement);
			}
			Self::process_claim(signer, who.clone())?;
			Preclaims::<T>::remove(&who);
Gavin Wood's avatar
Gavin Wood committed
369
		}
370

371
		#[weight = T::WeightInfo::move_claim()]
372
373
374
375
		fn move_claim(origin,
			old: EthereumAddress,
			new: EthereumAddress,
			maybe_preclaim: Option<T::AccountId>,
376
		) -> DispatchResultWithPostInfo {
377
378
379
380
381
382
383
384
			T::MoveClaimOrigin::try_origin(origin).map(|_| ()).or_else(ensure_root)?;

			Claims::<T>::take(&old).map(|c| Claims::<T>::insert(&new, c));
			Vesting::<T>::take(&old).map(|c| Vesting::<T>::insert(&new, c));
			Signing::take(&old).map(|c| Signing::insert(&new, c));
			maybe_preclaim.map(|preclaim| Preclaims::<T>::mutate(&preclaim, |maybe_o|
				if maybe_o.as_ref().map_or(false, |o| o == &old) { *maybe_o = Some(new) }
			));
385
			Ok(Pays::No.into())
386
		}
387
388
389
	}
}

390
391
392
393
394
395
396
397
398
399
400
/// Converts the given binary data into ASCII-encoded hex. It will be twice the length.
fn to_ascii_hex(data: &[u8]) -> Vec<u8> {
	let mut r = Vec::with_capacity(data.len() * 2);
	let mut push_nibble = |n| r.push(if n < 10 { b'0' + n } else { b'a' - 10 + n });
	for &b in data.iter() {
		push_nibble(b / 16);
		push_nibble(b % 16);
	}
	r
}

401
impl<T: Config> Module<T> {
402
	// Constructs the message that Ethereum RPC's `personal_sign` and `eth_sign` would sign.
403
	fn ethereum_signable_message(what: &[u8], extra: &[u8]) -> Vec<u8> {
404
		let prefix = T::Prefix::get();
405
		let mut l = prefix.len() + what.len() + extra.len();
406
407
408
409
410
411
412
413
414
		let mut rev = Vec::new();
		while l > 0 {
			rev.push(b'0' + (l % 10) as u8);
			l /= 10;
		}
		let mut v = b"\x19Ethereum Signed Message:\n".to_vec();
		v.extend(rev.into_iter().rev());
		v.extend_from_slice(&prefix[..]);
		v.extend_from_slice(what);
415
		v.extend_from_slice(extra);
416
417
418
419
420
		v
	}

	// Attempts to recover the Ethereum address from a message signature signed by using
	// the Ethereum RPC's `personal_sign` and `eth_sign`.
421
422
	fn eth_recover(s: &EcdsaSignature, what: &[u8], extra: &[u8]) -> Option<EthereumAddress> {
		let msg = keccak_256(&Self::ethereum_signable_message(what, extra));
423
		let mut res = EthereumAddress::default();
424
		res.0.copy_from_slice(&keccak_256(&secp256k1_ecdsa_recover(&s.0, &msg).ok()?[..])[12..]);
425
426
		Some(res)
	}
427
428
429
430
431
432
433

	fn process_claim(signer: EthereumAddress, dest: T::AccountId) -> DispatchResult {
		let balance_due = <Claims<T>>::get(&signer)
			.ok_or(Error::<T>::SignerHasNoClaim)?;

		let new_total = Self::total().checked_sub(&balance_due).ok_or(Error::<T>::PotUnderflow)?;

434
435
436
437
438
439
440
441
		let vesting = Vesting::<T>::get(&signer);
		if vesting.is_some() && T::VestingSchedule::vesting_balance(&dest).is_some() {
			return Err(Error::<T>::VestedBalanceExists.into())
		}

		// We first need to deposit the balance to ensure that the account exists.
		CurrencyOf::<T>::deposit_creating(&dest, balance_due);

442
		// Check if this claim should have a vesting schedule.
443
444
445
		if let Some(vs) = vesting {
			// This can only fail if the account already has a vesting schedule,
			// but this is checked above.
446
			T::VestingSchedule::add_vesting_schedule(&dest, vs.0, vs.1, vs.2)
447
				.expect("No other vesting schedule exists, as checked above; qed");
448
449
450
451
452
453
454
455
456
457
458
459
		}

		<Total<T>>::put(new_total);
		<Claims<T>>::remove(&signer);
		<Vesting<T>>::remove(&signer);
		Signing::remove(&signer);

		// Let's deposit an event to let the outside world know this happened.
		Self::deposit_event(RawEvent::Claimed(dest, signer, balance_due));

		Ok(())
	}
460
461
}

462
impl<T: Config> sp_runtime::traits::ValidateUnsigned for Module<T> {
463
464
	type Call = Call<T>;

465
	fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
466
467
		const PRIORITY: u64 = 100;

468
		let (maybe_signer, maybe_statement) = match call {
Shawn Tabrizi's avatar
Shawn Tabrizi committed
469
			// <weight>
470
			// The weight of this logic is included in the `claim` dispatchable.
Shawn Tabrizi's avatar
Shawn Tabrizi committed
471
			// </weight>
472
			Call::claim(account, ethereum_signature) => {
473
				let data = account.using_encoded(to_ascii_hex);
474
475
476
				(Self::eth_recover(&ethereum_signature, &data, &[][..]), None)
			}
			// <weight>
477
			// The weight of this logic is included in the `claim_attest` dispatchable.
478
479
480
481
482
483
484
			// </weight>
			Call::claim_attest(account, ethereum_signature, statement) => {
				let data = account.using_encoded(to_ascii_hex);
				(Self::eth_recover(&ethereum_signature, &data, &statement), Some(statement.as_slice()))
			}
			_ => return Err(InvalidTransaction::Call.into()),
		};
485

486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
		let signer = maybe_signer
			.ok_or(InvalidTransaction::Custom(ValidityError::InvalidEthereumSignature.into()))?;

		let e = InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into());
		ensure!(<Claims<T>>::contains_key(&signer), e);

		let e = InvalidTransaction::Custom(ValidityError::InvalidStatement.into());
		match Signing::get(signer) {
			None => ensure!(maybe_statement.is_none(), e),
			Some(s) => ensure!(Some(s.to_text()) == maybe_statement, e),
		}

		Ok(ValidTransaction {
			priority: PRIORITY,
			requires: vec![],
			provides: vec![("claims", signer).encode()],
			longevity: TransactionLongevity::max_value(),
			propagate: true,
		})
	}
}

/// Validate `attest` calls prior to execution. Needed to avoid a DoS attack since they are
/// otherwise free to place on chain.
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
511
512
pub struct PrevalidateAttests<T: Config + Send + Sync>(sp_std::marker::PhantomData<T>) where
	<T as frame_system::Config>::Call: IsSubType<Call<T>>;
513

514
515
impl<T: Config + Send + Sync> Debug for PrevalidateAttests<T> where
	<T as frame_system::Config>::Call: IsSubType<Call<T>>
516
517
518
519
520
521
522
523
524
525
526
527
{
	#[cfg(feature = "std")]
	fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
		write!(f, "PrevalidateAttests")
	}

	#[cfg(not(feature = "std"))]
	fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
		Ok(())
	}
}

528
529
impl<T: Config + Send + Sync> PrevalidateAttests<T> where
	<T as frame_system::Config>::Call: IsSubType<Call<T>>
530
531
532
533
534
535
536
{
	/// Create new `SignedExtension` to check runtime version.
	pub fn new() -> Self {
		Self(sp_std::marker::PhantomData)
	}
}

537
538
impl<T: Config + Send + Sync> SignedExtension for PrevalidateAttests<T> where
	<T as frame_system::Config>::Call: IsSubType<Call<T>>
539
540
{
	type AccountId = T::AccountId;
541
	type Call = <T as frame_system::Config>::Call;
542
543
544
545
546
547
548
549
550
	type AdditionalSigned = ();
	type Pre = ();
	const IDENTIFIER: &'static str = "PrevalidateAttests";

	fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
		Ok(())
	}

	// <weight>
551
	// The weight of this logic is included in the `attest` dispatchable.
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
	// </weight>
	fn validate(
		&self,
		who: &Self::AccountId,
		call: &Self::Call,
		_info: &DispatchInfoOf<Self::Call>,
		_len: usize,
	) -> TransactionValidity {
		if let Some(local_call) = call.is_sub_type() {
			if let Call::attest(attested_statement) = local_call {
				let signer = Preclaims::<T>::get(who)
					.ok_or(InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()))?;
				if let Some(s) = Signing::get(signer) {
					let e = InvalidTransaction::Custom(ValidityError::InvalidStatement.into());
					ensure!(&attested_statement[..] == s.to_text(), e);
				}
568
			}
Gav Wood's avatar
Gav Wood committed
569
		}
570
		Ok(ValidTransaction::default())
Gav Wood's avatar
Gav Wood committed
571
572
573
	}
}

574
575
576
577
578
579
580
581
582
583
584
585
586
#[cfg(any(test, feature = "runtime-benchmarks"))]
mod secp_utils {
	use super::*;
	use secp256k1;

	pub fn public(secret: &secp256k1::SecretKey) -> secp256k1::PublicKey {
		secp256k1::PublicKey::from_secret_key(secret)
	}
	pub fn eth(secret: &secp256k1::SecretKey) -> EthereumAddress {
		let mut res = EthereumAddress::default();
		res.0.copy_from_slice(&keccak_256(&public(secret).serialize()[1..65])[12..]);
		res
	}
587
	pub fn sig<T: Config>(secret: &secp256k1::SecretKey, what: &[u8], extra: &[u8]) -> EcdsaSignature {
588
		let msg = keccak_256(&<super::Module<T>>::ethereum_signable_message(&to_ascii_hex(what)[..], extra));
589
590
591
592
593
594
595
596
		let (sig, recovery_id) = secp256k1::sign(&secp256k1::Message::parse(&msg), secret);
		let mut r = [0u8; 65];
		r[0..64].copy_from_slice(&sig.serialize()[..]);
		r[64] = recovery_id.serialize();
		EcdsaSignature(r)
	}
}

Gav Wood's avatar
Gav Wood committed
597
598
599
#[cfg(test)]
mod tests {
	use secp256k1;
600
	use hex_literal::hex;
Gav Wood's avatar
Gav Wood committed
601
	use super::*;
602
	use secp_utils::*;
Gav Wood's avatar
Gav Wood committed
603

604
	use sp_core::H256;
605
	use parity_scale_codec::Encode;
Gav Wood's avatar
Gav Wood committed
606
	// The testing primitives are very useful for avoiding having to work with signatures
Black3HDF's avatar
Black3HDF committed
607
	// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
608
	use sp_runtime::{traits::{BlakeTwo256, IdentityLookup, Identity}, testing::Header};
Gavin Wood's avatar
Gavin Wood committed
609
	use frame_support::{
610
		impl_outer_origin, impl_outer_dispatch, assert_ok, assert_err, assert_noop, parameter_types,
611
612
		ord_parameter_types, weights::{Pays, GetDispatchInfo}, traits::ExistenceRequirement,
		dispatch::DispatchError::BadOrigin,
Gavin Wood's avatar
Gavin Wood committed
613
	};
614
	use pallet_balances;
615
	use super::Call as ClaimsCall;
Gav Wood's avatar
Gav Wood committed
616
617

	impl_outer_origin! {
618
		pub enum Origin for Test {}
Gav Wood's avatar
Gav Wood committed
619
	}
620
621
622
623
624
625

	impl_outer_dispatch! {
		pub enum Call for Test where origin: Origin {
			claims::Claims,
		}
	}
Gav Wood's avatar
Gav Wood committed
626
627
628
629
630
	// For testing the module, we construct most of a mock runtime. This means
	// first constructing a configuration type (`Test`) which `impl`s each of the
	// configuration traits of modules we want to use.
	#[derive(Clone, Eq, PartialEq)]
	pub struct Test;
631
	parameter_types! {
632
		pub const BlockHashCount: u32 = 250;
633
	}
634
	impl frame_system::Config for Test {
635
		type BaseCallFilter = ();
636
637
638
		type BlockWeights = ();
		type BlockLength = ();
		type DbWeight = ();
Gav Wood's avatar
Gav Wood committed
639
		type Origin = Origin;
640
		type Call = Call;
Gav Wood's avatar
Gav Wood committed
641
642
643
644
645
646
647
648
		type Index = u64;
		type BlockNumber = u64;
		type Hash = H256;
		type Hashing = BlakeTwo256;
		type AccountId = u64;
		type Lookup = IdentityLookup<u64>;
		type Header = Header;
		type Event = ();
649
		type BlockHashCount = BlockHashCount;
650
		type Version = ();
651
		type PalletInfo = ();
652
		type AccountData = pallet_balances::AccountData<u64>;
Gavin Wood's avatar
Gavin Wood committed
653
		type OnNewAccount = ();
654
		type OnKilledAccount = ();
655
		type SystemWeightInfo = ();
656
		type SS58Prefix = ();
Gav Wood's avatar
Gav Wood committed
657
	}
Gavin Wood's avatar
Gavin Wood committed
658
659

	parameter_types! {
Shawn Tabrizi's avatar
Shawn Tabrizi committed
660
		pub const ExistentialDeposit: u64 = 1;
Gavin Wood's avatar
Gavin Wood committed
661
662
	}

663
	impl pallet_balances::Config for Test {
Gav Wood's avatar
Gav Wood committed
664
		type Balance = u64;
Gavin Wood's avatar
Gavin Wood committed
665
		type Event = ();
666
		type DustRemoval = ();
Gavin Wood's avatar
Gavin Wood committed
667
		type ExistentialDeposit = ExistentialDeposit;
668
		type AccountStore = System;
669
		type MaxLocks = ();
670
		type WeightInfo = ();
Gav Wood's avatar
Gav Wood committed
671
	}
672

673
674
675
676
	parameter_types! {
		pub const MinVestedTransfer: u64 = 0;
	}

677
	impl pallet_vesting::Config for Test {
Gavin Wood's avatar
Gavin Wood committed
678
679
680
		type Event = ();
		type Currency = Balances;
		type BlockNumberToBalance = Identity;
681
		type MinVestedTransfer = MinVestedTransfer;
682
		type WeightInfo = ();
Gavin Wood's avatar
Gavin Wood committed
683
684
	}

685
	parameter_types!{
686
		pub Prefix: &'static [u8] = b"Pay RUSTs to the TEST account:";
687
	}
688
689
690
	ord_parameter_types! {
		pub const Six: u64 = 6;
	}
691

692
	impl Config for Test {
Gav Wood's avatar
Gav Wood committed
693
		type Event = ();
Gavin Wood's avatar
Gavin Wood committed
694
		type VestingSchedule = Vesting;
695
		type Prefix = Prefix;
696
		type MoveClaimOrigin = frame_system::EnsureSignedBy<Six, u64>;
697
		type WeightInfo = TestWeightInfo;
Gav Wood's avatar
Gav Wood committed
698
	}
699
700
701
	type System = frame_system::Module<Test>;
	type Balances = pallet_balances::Module<Test>;
	type Vesting = pallet_vesting::Module<Test>;
Gav Wood's avatar
Gav Wood committed
702
703
	type Claims = Module<Test>;

Gavin Wood's avatar
Gavin Wood committed
704
	fn alice() -> secp256k1::SecretKey {
705
		secp256k1::SecretKey::parse(&keccak_256(b"Alice")).unwrap()
Gav Wood's avatar
Gav Wood committed
706
	}
Gavin Wood's avatar
Gavin Wood committed
707
	fn bob() -> secp256k1::SecretKey {
708
		secp256k1::SecretKey::parse(&keccak_256(b"Bob")).unwrap()
Gav Wood's avatar
Gav Wood committed
709
	}
710
711
712
713
714
715
716
717
718
	fn dave() -> secp256k1::SecretKey {
		secp256k1::SecretKey::parse(&keccak_256(b"Dave")).unwrap()
	}
	fn eve() -> secp256k1::SecretKey {
		secp256k1::SecretKey::parse(&keccak_256(b"Eve")).unwrap()
	}
	fn frank() -> secp256k1::SecretKey {
		secp256k1::SecretKey::parse(&keccak_256(b"Frank")).unwrap()
	}
Gav Wood's avatar
Gav Wood committed
719
720
721

	// This function basically just builds a genesis storage key/value store according to
	// our desired mockup.
722
	pub fn new_test_ext() -> sp_io::TestExternalities {
723
		let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
Gav Wood's avatar
Gav Wood committed
724
		// We use default for brevity, but you can configure as desired if needed.
725
		pallet_balances::GenesisConfig::<Test>::default().assimilate_storage(&mut t).unwrap();
726
		GenesisConfig::<Test>{
727
728
			claims: vec![
				(eth(&alice()), 100, None, None),
Gavin Wood's avatar
Gavin Wood committed
729
730
				(eth(&dave()), 200, None, Some(StatementKind::Regular)),
				(eth(&eve()), 300, Some(42), Some(StatementKind::Saft)),
731
732
				(eth(&frank()), 400, Some(43), None),
			],
733
			vesting: vec![(eth(&alice()), (50, 10, 1))],
734
		}.assimilate_storage(&mut t).unwrap();
Gav Wood's avatar
Gav Wood committed
735
736
737
		t.into()
	}

738
739
740
741
	fn total_claims() -> u64 {
		100 + 200 + 300 + 400
	}

Gav Wood's avatar
Gav Wood committed
742
743
	#[test]
	fn basic_setup_works() {
744
		new_test_ext().execute_with(|| {
745
			assert_eq!(Claims::total(), total_claims());
Gavin Wood's avatar
Gavin Wood committed
746
			assert_eq!(Claims::claims(&eth(&alice())), Some(100));
747
748
749
			assert_eq!(Claims::claims(&eth(&dave())), Some(200));
			assert_eq!(Claims::claims(&eth(&eve())), Some(300));
			assert_eq!(Claims::claims(&eth(&frank())), Some(400));
thiolliere's avatar
thiolliere committed
750
			assert_eq!(Claims::claims(&EthereumAddress::default()), None);
751
			assert_eq!(Claims::vesting(&eth(&alice())), Some((50, 10, 1)));
Gav Wood's avatar
Gav Wood committed
752
753
754
		});
	}

755
756
757
758
759
760
761
762
763
	#[test]
	fn serde_works() {
		let x = EthereumAddress(hex!["0123456789abcdef0123456789abcdef01234567"]);
		let y = serde_json::to_string(&x).unwrap();
		assert_eq!(y, "\"0x0123456789abcdef0123456789abcdef01234567\"");
		let z: EthereumAddress = serde_json::from_str(&y).unwrap();
		assert_eq!(x, z);
	}

Gav Wood's avatar
Gav Wood committed
764
765
	#[test]
	fn claiming_works() {
766
		new_test_ext().execute_with(|| {
767
			assert_eq!(Balances::free_balance(42), 0);
768
			assert_ok!(Claims::claim(Origin::none(), 42, sig::<Test>(&alice(), &42u64.encode(), &[][..])));
Gav Wood's avatar
Gav Wood committed
769
			assert_eq!(Balances::free_balance(&42), 100);
770
			assert_eq!(Vesting::vesting_balance(&42), Some(50));
771
772
773
774
			assert_eq!(Claims::total(), total_claims() - 100);
		});
	}

775
776
777
778
779
780
	#[test]
	fn basic_claim_moving_works() {
		new_test_ext().execute_with(|| {
			assert_eq!(Balances::free_balance(42), 0);
			assert_noop!(Claims::move_claim(Origin::signed(1), eth(&alice()), eth(&bob()), None), BadOrigin);
			assert_ok!(Claims::move_claim(Origin::signed(6), eth(&alice()), eth(&bob()), None));
781
782
			assert_noop!(Claims::claim(Origin::none(), 42, sig::<Test>(&alice(), &42u64.encode(), &[][..])), Error::<Test>::SignerHasNoClaim);
			assert_ok!(Claims::claim(Origin::none(), 42, sig::<Test>(&bob(), &42u64.encode(), &[][..])));
783
784
785
786
787
788
789
790
791
792
793
			assert_eq!(Balances::free_balance(&42), 100);
			assert_eq!(Vesting::vesting_balance(&42), Some(50));
			assert_eq!(Claims::total(), total_claims() - 100);
		});
	}

	#[test]
	fn claim_attest_moving_works() {
		new_test_ext().execute_with(|| {
			assert_ok!(Claims::move_claim(Origin::signed(6), eth(&dave()), eth(&bob()), None));
			let s = sig::<Test>(&bob(), &42u64.encode(), StatementKind::Regular.to_text());
794
			assert_ok!(Claims::claim_attest(Origin::none(), 42, s, StatementKind::Regular.to_text().to_vec()));
795
796
797
798
799
800
801
802
803
804
805
806
807
			assert_eq!(Balances::free_balance(&42), 200);
		});
	}

	#[test]
	fn attest_moving_works() {
		new_test_ext().execute_with(|| {
			assert_ok!(Claims::move_claim(Origin::signed(6), eth(&eve()), eth(&bob()), Some(42)));
			assert_ok!(Claims::attest(Origin::signed(42), StatementKind::Saft.to_text().to_vec()));
			assert_eq!(Balances::free_balance(&42), 300);
		});
	}

808
809
810
	#[test]
	fn claiming_does_not_bypass_signing() {
		new_test_ext().execute_with(|| {
811
			assert_ok!(Claims::claim(Origin::none(), 42, sig::<Test>(&alice(), &42u64.encode(), &[][..])));
812
			assert_noop!(
813
				Claims::claim(Origin::none(), 42, sig::<Test>(&dave(), &42u64.encode(), &[][..])),
814
815
816
				Error::<Test>::InvalidStatement,
			);
			assert_noop!(
817
				Claims::claim(Origin::none(), 42, sig::<Test>(&eve(), &42u64.encode(), &[][..])),
818
819
				Error::<Test>::InvalidStatement,
			);
820
			assert_ok!(Claims::claim(Origin::none(), 42, sig::<Test>(&frank(), &42u64.encode(), &[][..])));
821
822
823
824
825
826
827
		});
	}

	#[test]
	fn attest_claiming_works() {
		new_test_ext().execute_with(|| {
			assert_eq!(Balances::free_balance(42), 0);
Gavin Wood's avatar
Gavin Wood committed
828
			let s = sig::<Test>(&dave(), &42u64.encode(), StatementKind::Saft.to_text());
829
			let r = Claims::claim_attest(Origin::none(), 42, s.clone(), StatementKind::Saft.to_text().to_vec());
830
831
			assert_noop!(r, Error::<Test>::InvalidStatement);

832
			let r = Claims::claim_attest(Origin::none(), 42, s, StatementKind::Regular.to_text().to_vec());
833
834
835
836
			assert_noop!(r, Error::<Test>::SignerHasNoClaim);
			// ^^^ we use ecdsa_recover, so an invalid signature just results in a random signer id
			// being recovered, which realistically will never have a claim.

Gavin Wood's avatar
Gavin Wood committed
837
			let s = sig::<Test>(&dave(), &42u64.encode(), StatementKind::Regular.to_text());
838
			assert_ok!(Claims::claim_attest(Origin::none(), 42, s, StatementKind::Regular.to_text().to_vec()));
839
840
841
			assert_eq!(Balances::free_balance(&42), 200);
			assert_eq!(Claims::total(), total_claims() - 200);

Gavin Wood's avatar
Gavin Wood committed
842
			let s = sig::<Test>(&dave(), &42u64.encode(), StatementKind::Regular.to_text());
843
			let r = Claims::claim_attest(Origin::none(), 42, s, StatementKind::Regular.to_text().to_vec());
844
845
846
847
848
849
850
851
			assert_noop!(r, Error::<Test>::SignerHasNoClaim);
		});
	}

	#[test]
	fn attesting_works() {
		new_test_ext().execute_with(|| {
			assert_eq!(Balances::free_balance(42), 0);
Gavin Wood's avatar
Gavin Wood committed
852
853
854
			assert_noop!(Claims::attest(Origin::signed(69), StatementKind::Saft.to_text().to_vec()), Error::<Test>::SenderHasNoClaim);
			assert_noop!(Claims::attest(Origin::signed(42), StatementKind::Regular.to_text().to_vec()), Error::<Test>::InvalidStatement);
			assert_ok!(Claims::attest(Origin::signed(42), StatementKind::Saft.to_text().to_vec()));
855
856
857
858
859
860
861
862
863
864
			assert_eq!(Balances::free_balance(&42), 300);
			assert_eq!(Claims::total(), total_claims() - 300);
		});
	}

	#[test]
	fn claim_cannot_clobber_preclaim() {
		new_test_ext().execute_with(|| {
			assert_eq!(Balances::free_balance(42), 0);
			// Alice's claim is 100
865
			assert_ok!(Claims::claim(Origin::none(), 42, sig::<Test>(&alice(), &42u64.encode(), &[][..])));
866
867
			assert_eq!(Balances::free_balance(&42), 100);
			// Eve's claim is 300 through Account 42
Gavin Wood's avatar
Gavin Wood committed
868
			assert_ok!(Claims::attest(Origin::signed(42), StatementKind::Saft.to_text().to_vec()));
869
870
871
872
873
874
875
876
877
			assert_eq!(Balances::free_balance(&42), 100 + 300);
			assert_eq!(Claims::total(), total_claims() - 400);
		});
	}

	#[test]
	fn valid_attest_transactions_are_free() {
		new_test_ext().execute_with(|| {
			let p = PrevalidateAttests::<Test>::new();
Gavin Wood's avatar
Gavin Wood committed
878
			let c = Call::Claims(ClaimsCall::attest(StatementKind::Saft.to_text().to_vec()));
879
880
881
882
883
884
885
886
887
888
889
			let di = c.get_dispatch_info();
			assert_eq!(di.pays_fee, Pays::No);
			let r = p.validate(&42, &c, &di, 20);
			assert_eq!(r, TransactionValidity::Ok(ValidTransaction::default()));
		});
	}

	#[test]
	fn invalid_attest_transactions_are_recognised() {
		new_test_ext().execute_with(|| {
			let p = PrevalidateAttests::<Test>::new();
Gavin Wood's avatar
Gavin Wood committed
890
			let c = Call::Claims(ClaimsCall::attest(StatementKind::Regular.to_text().to_vec()));
891
892
893
			let di = c.get_dispatch_info();
			let r = p.validate(&42, &c, &di, 20);
			assert!(r.is_err());
Gavin Wood's avatar
Gavin Wood committed
894
			let c = Call::Claims(ClaimsCall::attest(StatementKind::Saft.to_text().to_vec()));
895
896
897
898
899
900
901
902
903
904
905
			let di = c.get_dispatch_info();
			let r = p.validate(&69, &c, &di, 20);
			assert!(r.is_err());
		});
	}

	#[test]
	fn cannot_bypass_attest_claiming() {
		new_test_ext().execute_with(|| {
			assert_eq!(Balances::free_balance(42), 0);
			let s = sig::<Test>(&dave(), &42u64.encode(), &[]);
906
			let r = Claims::claim(Origin::none(), 42, s.clone());
907
			assert_noop!(r, Error::<Test>::InvalidStatement);
Gav Wood's avatar
Gav Wood committed
908
909
910
		});
	}

Gavin Wood's avatar
Gavin Wood committed
911
912
913
	#[test]
	fn add_claim_works() {
		new_test_ext().execute_with(|| {
914
			assert_noop!(
915
				Claims::mint_claim(Origin::signed(42), eth(&bob()), 200, None, None),
916
				sp_runtime::traits::BadOrigin,
917
			);
918
			assert_eq!(Balances::free_balance(42), 0);
919
			assert_noop!(
920
				Claims::claim(Origin::none(), 69, sig::<Test>(&bob(), &69u64.encode(), &[][..])),
921
				Error::<Test>::SignerHasNoClaim,
922
			);
923
			assert_ok!(Claims::mint_claim(Origin::root(), eth(&bob()), 200, None, None));
924
			assert_eq!(Claims::total(), total_claims() + 200);
925
			assert_ok!(Claims::claim(Origin::none(), 69, sig::<Test>(&bob(), &69u64.encode(), &[][..])));
926
			assert_eq!(Balances::free_balance(&69), 200);
927
			assert_eq!(Vesting::vesting_balance(&69), None);
928
			assert_eq!(Claims::total(), total_claims());
929
930
931
932
933
934
935
		});
	}

	#[test]
	fn add_claim_with_vesting_works() {
		new_test_ext().execute_with(|| {
			assert_noop!(
936
				Claims::mint_claim(Origin::signed(42), eth(&bob()), 200, Some((50, 10, 1)), None),
937
				sp_runtime::traits::BadOrigin,
938
			);
Gavin Wood's avatar
Gavin Wood committed
939
			assert_eq!(Balances::free_balance(42), 0);
Gavin Wood's avatar
Gavin Wood committed
940
			assert_noop!(
941
				Claims::claim(Origin::none(), 69, sig::<Test>(&bob(), &69u64.encode(), &[][..])),
942
				Error::<Test>::SignerHasNoClaim,
Gavin Wood's avatar
Gavin Wood committed
943
			);
944
945
			assert_ok!(Claims::mint_claim(Origin::root(), eth(&bob()), 200, Some((50, 10, 1)), None));
			assert_ok!(Claims::claim(Origin::none(), 69, sig::<Test>(&bob(), &69u64.encode(), &[][..])));
946
			assert_eq!(Balances::free_balance(&69), 200);
947
			assert_eq!(Vesting::vesting_balance(&69), Some(50));
948
949
950
951

			// Make sure we can not transfer the vested balance.
			assert_err!(
				<Balances as Currency<_>>::transfer(&69, &80, 180, ExistenceRequirement::AllowDeath),
952
				pallet_balances::Error::<Test, _>::LiquidityRestrictions,
953
			);
Gavin Wood's avatar
Gavin Wood committed
954
955
956
		});
	}

957
958
959
960
	#[test]
	fn add_claim_with_statement_works() {
		new_test_ext().execute_with(|| {
			assert_noop!(
Gavin Wood's avatar
Gavin Wood committed
961
				Claims::mint_claim(Origin::signed(42), eth(&bob()), 200, None, Some(StatementKind::Regular)),
962
963
964
				sp_runtime::traits::BadOrigin,
			);
			assert_eq!(Balances::free_balance(42), 0);
Gavin Wood's avatar
Gavin Wood committed
965
			let signature = sig::<Test>(&bob(), &69u64.encode(), StatementKind::Regular.to_text());
966
967
			assert_noop!(
				Claims::claim_attest(
968
					Origin::none(), 69, signature.clone(), StatementKind::Regular.to_text().to_vec()
969
970
971
				),
				Error::<Test>::SignerHasNoClaim
			);
972
			assert_ok!(Claims::mint_claim(Origin::root(), eth(&bob()), 200, None, Some(StatementKind::Regular)));
973
974
			assert_noop!(
				Claims::claim_attest(
975
					Origin::none(), 69, signature.clone(), vec![],
976
977
978
979
980
				),
				Error::<Test>::SignerHasNoClaim
			);
			assert_ok!(
				Claims::claim_attest(
981
					Origin::none(), 69, signature.clone(), StatementKind::Regular.to_text().to_vec()
982
983
984
985
986
987
				)
			);
			assert_eq!(Balances::free_balance(&69), 200);
		});
	}

988
989
	#[test]
	fn origin_signed_claiming_fail() {
990
		new_test_ext().execute_with(|| {
Gavin Wood's avatar
Gavin Wood committed
991
			assert_eq!(Balances::free_balance(42), 0);
Gavin Wood's avatar
Gavin Wood committed
992
			assert_err!(
993
				Claims::claim(Origin::signed(42), 42, sig::<Test>(&alice(), &42u64.encode(), &[][..])),
994
				sp_runtime::traits::BadOrigin,
Gavin Wood's avatar
Gavin Wood committed
995
			);
996
997
998
		});
	}

Gav Wood's avatar
Gav Wood committed
999
1000
	#[test]
	fn double_claiming_doesnt_work() {
For faster browsing, not all history is shown. View entire blame