Substrate 3.0 (#232)

* Update substrate deps to 3.0.0 and 0.9.0

* Update substrate wasm tools

* Fixing errors for 3.0.0 compat

* Fixing more errors for 3.0.0 compat

* Use MultiAddress for test runtime

* Fmt

* Fix node test

* Pin Funty

* Update AccountInfo struct

* Add comment about funty pin
This commit is contained in:
Andrew Jones
2021-02-17 16:45:05 +00:00
committed by GitHub
parent 51c48f223a
commit 2c8e5211aa
17 changed files with 218 additions and 191 deletions
+8
View File
@@ -98,6 +98,12 @@ pub enum RuntimeError {
/// Module error.
#[error("Runtime module error: {0}")]
Module(ModuleError),
/// At least one consumer is remaining so the account cannot be destroyed.
#[error("At least one consumer is remaining so the account cannot be destroyed.")]
ConsumerRemaining,
/// There are no providers so the account cannot be created.
#[error("There are no providers so the account cannot be created.")]
NoProviders,
/// Bad origin.
#[error("Bad origin: throw by ensure_signed, ensure_root or ensure_none.")]
BadOrigin,
@@ -130,6 +136,8 @@ impl RuntimeError {
}
DispatchError::BadOrigin => Ok(Self::BadOrigin),
DispatchError::CannotLookup => Ok(Self::CannotLookup),
DispatchError::ConsumerRemaining => Ok(Self::ConsumerRemaining),
DispatchError::NoProviders => Ok(Self::NoProviders),
DispatchError::Other(msg) => Ok(Self::Other(msg.into())),
}
}
+11 -7
View File
@@ -182,13 +182,14 @@ mod tests {
env_logger::try_init().ok();
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
let bob = PairSigner::<TestRuntime, _>::new(AccountKeyring::Bob.pair());
let bob_address = bob.account_id().clone().into();
let (client, _) = test_client().await;
let alice_pre = client.account(alice.account_id(), None).await.unwrap();
let bob_pre = client.account(bob.account_id(), None).await.unwrap();
let event = client
.transfer_and_watch(&alice, &bob.account_id(), 10_000)
.transfer_and_watch(&alice, &bob_address, 10_000)
.await
.expect("sending an xt works")
.transfer()
@@ -269,15 +270,17 @@ mod tests {
#[async_std::test]
async fn test_transfer_error() {
env_logger::try_init().ok();
let alice = PairSigner::new(AccountKeyring::Alice.pair());
let hans = PairSigner::new(Pair::generate().0);
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
let alice_addr = alice.account_id().clone().into();
let hans = PairSigner::<TestRuntime, _>::new(Pair::generate().0);
let hans_address = hans.account_id().clone().into();
let (client, _) = test_client().await;
client
.transfer_and_watch(&alice, hans.account_id(), 100_000_000_000)
.transfer_and_watch(&alice, &hans_address, 100_000_000_000)
.await
.unwrap();
let res = client
.transfer_and_watch(&hans, alice.account_id(), 100_000_000_000)
.transfer_and_watch(&hans, &alice_addr, 100_000_000_000)
.await;
if let Err(Error::Runtime(RuntimeError::Module(error))) = res {
let error2 = ModuleError {
@@ -293,15 +296,16 @@ mod tests {
#[async_std::test]
async fn test_transfer_subscription() {
env_logger::try_init().ok();
let alice = PairSigner::new(AccountKeyring::Alice.pair());
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
let bob = AccountKeyring::Bob.to_account_id();
let bob_addr = bob.clone().into();
let (client, _) = test_client().await;
let sub = client.subscribe_events().await.unwrap();
let mut decoder = EventsDecoder::<TestRuntime>::new(client.metadata().clone());
decoder.with_balances();
let mut sub = EventSubscription::<TestRuntime>::new(sub, decoder);
sub.filter_event::<TransferEvent<_>>();
client.transfer(&alice, &bob, 10_000).await.unwrap();
client.transfer(&alice, &bob_addr, 10_000).await.unwrap();
let raw = sub.next().await.unwrap().unwrap();
let event = TransferEvent::<TestRuntime>::decode(&mut &raw.data[..]).unwrap();
assert_eq!(
+4 -2
View File
@@ -75,11 +75,12 @@ mod tests {
async fn test_sudo() {
env_logger::try_init().ok();
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
let bob = AccountKeyring::Bob.to_account_id().clone().into();
let (client, _) = test_client().await;
let call = client
.encode(TransferCall {
to: &AccountKeyring::Bob.to_account_id(),
to: &bob,
amount: 10_000,
})
.unwrap();
@@ -98,11 +99,12 @@ mod tests {
async fn test_sudo_unchecked_weight() {
env_logger::try_init().ok();
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
let bob = AccountKeyring::Bob.to_account_id().into();
let (client, _) = test_client().await;
let call = client
.encode(TransferCall {
to: &AccountKeyring::Bob.to_account_id(),
to: &bob,
amount: 10_000,
})
.unwrap();
+4 -1
View File
@@ -127,7 +127,10 @@ pub struct AccountInfo<T: System> {
pub nonce: T::Index,
/// The number of other modules that currently depend on this account's existence. The account
/// cannot be reaped until this is zero.
pub refcount: RefCount,
pub consumers: RefCount,
/// The number of other modules that allow this account to exist. The account may not be reaped
/// until this is zero.
pub providers: RefCount,
/// The additional data that belongs to this account. Used to store the balance(s) in a lot of
/// chains.
pub data: T::AccountData,
+2 -2
View File
@@ -186,7 +186,7 @@ impl System for DefaultNodeRuntime {
type Hash = sp_core::H256;
type Hashing = BlakeTwo256;
type AccountId = <<MultiSignature as Verify>::Signer as IdentifyAccount>::AccountId;
type Address = pallet_indices::address::Address<Self::AccountId, u32>;
type Address = sp_runtime::MultiAddress<Self::AccountId, u32>;
type Header = Header<Self::BlockNumber, BlakeTwo256>;
type Extrinsic = OpaqueExtrinsic;
type AccountData = AccountData<<Self as Balances>::Balance>;
@@ -225,7 +225,7 @@ impl System for NodeTemplateRuntime {
type Hash = sp_core::H256;
type Hashing = BlakeTwo256;
type AccountId = <<MultiSignature as Verify>::Signer as IdentifyAccount>::AccountId;
type Address = Self::AccountId;
type Address = sp_runtime::MultiAddress<Self::AccountId, u32>;
type Header = Header<Self::BlockNumber, BlakeTwo256>;
type Extrinsic = OpaqueExtrinsic;
type AccountData = AccountData<<Self as Balances>::Balance>;