Skip to content
Snippets Groups Projects
Unverified Commit 95de08ba authored by bgallois's avatar bgallois
Browse files

upgrade tests

parent 35cedf7c
No related branches found
No related tags found
No related merge requests found
Pipeline #40343 failed
......@@ -25,7 +25,7 @@ pub struct Client {
wot: RustyWebOfTrust,
pub pool_len: usize,
}
pub type AccountId = subxt::ext::sp_runtime::AccountId32;
pub type AccountId = sp_runtime::AccountId32;
pub type IdtyIndex = u32;
pub type H256 = subxt::utils::H256;
......
......@@ -103,6 +103,7 @@ impl ShouldEndSession<u64> for TestShouldEndSession {
}
impl pallet_session::Config for Test {
type DisablingStrategy = ();
type Keys = MockSessionKeys;
type NextSessionRotation = ();
type RuntimeEvent = RuntimeEvent;
......
......@@ -51,7 +51,16 @@ impl From<[u8; 32]> for AccountId32Mock {
}
/// Test signature that impl From<ed25519::Signature> (required to compile pallet identity)
#[derive(Clone, codec::Decode, Debug, Eq, codec::Encode, PartialEq, scale_info::TypeInfo)]
#[derive(
Clone,
codec::DecodeWithMemTracking,
codec::Decode,
Debug,
Eq,
codec::Encode,
PartialEq,
scale_info::TypeInfo,
)]
pub struct TestSignature(SubtrateTestSignature);
impl From<sp_core::ed25519::Signature> for TestSignature {
fn from(_: sp_core::ed25519::Signature) -> Self {
......@@ -143,6 +152,7 @@ impl ShouldEndSession<u64> for TestShouldEndSession {
}
impl pallet_session::Config for Test {
type DisablingStrategy = ();
type Keys = MockSessionKeys;
type NextSessionRotation = ();
type RuntimeEvent = RuntimeEvent;
......
......@@ -45,7 +45,16 @@ impl From<[u8; 32]> for AccountId32Mock {
}
/// Test signature that impl From<ed25519::Signature> (required to compile pallet identity)
#[derive(Clone, codec::Decode, Debug, Eq, codec::Encode, PartialEq, scale_info::TypeInfo)]
#[derive(
Clone,
codec::DecodeWithMemTracking,
codec::Decode,
Debug,
Eq,
codec::Encode,
PartialEq,
scale_info::TypeInfo,
)]
pub struct TestSignature(SubtrateTestSignature);
impl TestSignature {
......
......@@ -22,7 +22,7 @@ use common::*;
use frame_support::{assert_noop, assert_ok, traits::StoredMap};
use gdev_runtime::*;
use sp_core::Encode;
use sp_keyring::AccountKeyring;
use sp_keyring::sr25519::Keyring;
use sp_runtime::MultiAddress;
/// test currency transfer
......@@ -32,24 +32,24 @@ use sp_runtime::MultiAddress;
fn test_transfer() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![
(AccountKeyring::Alice.to_account_id(), 10_000),
(AccountKeyring::Eve.to_account_id(), 10_000),
(Keyring::Alice.to_account_id(), 10_000),
(Keyring::Eve.to_account_id(), 10_000),
])
.build()
.execute_with(|| {
// Alice gives 500 to Eve
assert_ok!(Balances::transfer_allow_death(
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
AccountKeyring::Eve.to_account_id().into(),
frame_system::RawOrigin::Signed(Keyring::Alice.to_account_id()).into(),
Keyring::Eve.to_account_id().into(),
500
));
// check amounts
assert_eq!(
Balances::free_balance(AccountKeyring::Alice.to_account_id()),
Balances::free_balance(Keyring::Alice.to_account_id()),
10_000 - 500
);
assert_eq!(
Balances::free_balance(AccountKeyring::Eve.to_account_id()),
Balances::free_balance(Keyring::Eve.to_account_id()),
10_000 + 500
);
})
......@@ -59,14 +59,14 @@ fn test_transfer() {
#[test]
fn test_transfer_not_enough() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![(AccountKeyring::Alice.to_account_id(), 599)])
.with_initial_balances(vec![(Keyring::Alice.to_account_id(), 599)])
.build()
.execute_with(|| {
run_to_block(1);
assert_noop!(
Balances::transfer_allow_death(
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
AccountKeyring::Dave.to_account_id().into(),
frame_system::RawOrigin::Signed(Keyring::Alice.to_account_id()).into(),
Keyring::Dave.to_account_id().into(),
500
),
sp_runtime::TokenError::Frozen // frozen because trying to transfer more than liquid
......@@ -79,15 +79,15 @@ fn test_transfer_not_enough() {
#[test]
fn test_transfer_underflow() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![(AccountKeyring::Alice.to_account_id(), 400)])
.with_initial_balances(vec![(Keyring::Alice.to_account_id(), 400)])
.build()
.execute_with(|| {
run_to_block(1);
assert_eq!(Balances::total_issuance(), 400);
assert_noop!(
Balances::transfer_allow_death(
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
AccountKeyring::Dave.to_account_id().into(),
frame_system::RawOrigin::Signed(Keyring::Alice.to_account_id()).into(),
Keyring::Dave.to_account_id().into(),
500 // larger than total issuance
),
sp_runtime::ArithmeticError::Underflow
......@@ -101,16 +101,16 @@ fn test_transfer_underflow() {
fn test_transfer_funds_unavailable() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![
(AccountKeyring::Alice.to_account_id(), 499),
(AccountKeyring::Bob.to_account_id(), 200),
(Keyring::Alice.to_account_id(), 499),
(Keyring::Bob.to_account_id(), 200),
])
.build()
.execute_with(|| {
run_to_block(1);
assert_noop!(
Balances::transfer_allow_death(
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
AccountKeyring::Dave.to_account_id().into(),
frame_system::RawOrigin::Signed(Keyring::Alice.to_account_id()).into(),
Keyring::Dave.to_account_id().into(),
500
),
sp_runtime::TokenError::FundsUnavailable
......@@ -122,16 +122,16 @@ fn test_transfer_funds_unavailable() {
#[test]
fn test_transfer_all_linked_no_member() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![(AccountKeyring::Alice.to_account_id(), 5_000)])
.with_initial_balances(vec![(Keyring::Alice.to_account_id(), 5_000)])
.build()
.execute_with(|| {
run_to_block(1);
let genesis_hash = System::block_hash(0);
let alice = AccountKeyring::Alice.to_account_id();
let ferdie = AccountKeyring::Ferdie.to_account_id();
let alice = Keyring::Alice.to_account_id();
let ferdie = Keyring::Ferdie.to_account_id();
let payload = (b"link", genesis_hash, 1u32, ferdie.clone()).encode();
let signature = AccountKeyring::Ferdie.sign(&payload);
let signature = Keyring::Ferdie.sign(&payload);
assert_ok!(Balances::transfer_allow_death(
frame_system::RawOrigin::Signed(alice.clone()).into(),
......@@ -150,7 +150,7 @@ fn test_transfer_all_linked_no_member() {
);
assert_ok!(Balances::transfer_all(
frame_system::RawOrigin::Signed(ferdie.clone()).into(),
AccountKeyring::Bob.to_account_id().into(),
Keyring::Bob.to_account_id().into(),
false
),);
assert_eq!(Balances::free_balance(ferdie.clone()), 0);
......
......@@ -25,7 +25,7 @@ use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_consensus_babe::{AuthorityId as BabeId, Slot, VrfInput, VrfProof};
use sp_consensus_grandpa::AuthorityId as GrandpaId;
use sp_core::{crypto::IsWrappedBy, sr25519, Encode, Pair, Public, H256};
use sp_keyring::AccountKeyring;
use sp_keyring::sr25519::Keyring;
use sp_membership::MembershipData;
use sp_runtime::{
generic::SignedPayload,
......@@ -488,7 +488,7 @@ pub fn get_unchecked_extrinsic(
call: RuntimeCall,
era: u64,
block: u64,
signer: AccountKeyring,
signer: Keyring,
tip: Balance,
nonce: u32,
) -> gdev_runtime::UncheckedExtrinsic {
......
This diff is collapsed.
......@@ -28,7 +28,7 @@ use frame_support::{
};
use gdev_runtime::*;
use sp_core::Encode;
use sp_keyring::AccountKeyring;
use sp_keyring::sr25519::Keyring;
/// test currency transfer with extrinsic
// the signer account should pay fees and a tip
......@@ -37,18 +37,18 @@ use sp_keyring::AccountKeyring;
fn test_transfer_xt() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![
(AccountKeyring::Alice.to_account_id(), 10_000),
(AccountKeyring::Eve.to_account_id(), 10_000),
(Keyring::Alice.to_account_id(), 10_000),
(Keyring::Eve.to_account_id(), 10_000),
])
.build()
.execute_with(|| {
let call = RuntimeCall::Balances(BalancesCall::transfer_allow_death {
dest: AccountKeyring::Eve.to_account_id().into(),
dest: Keyring::Eve.to_account_id().into(),
value: 500,
});
// 1 cĞD of tip
let xt = get_unchecked_extrinsic(call, 4u64, 8u64, AccountKeyring::Alice, 1u64, 0);
let xt = get_unchecked_extrinsic(call, 4u64, 8u64, Keyring::Alice, 1u64, 0);
// let info = xt.get_dispatch_info();
// println!("dispatch info:\n\t {:?}\n", info);
......@@ -57,11 +57,11 @@ fn test_transfer_xt() {
assert_ok!(Executive::apply_extrinsic(xt));
// check amounts
assert_eq!(
Balances::free_balance(AccountKeyring::Alice.to_account_id()),
Balances::free_balance(Keyring::Alice.to_account_id()),
10_000 - 500 - 3 // initial - transfered - fees
);
assert_eq!(
Balances::free_balance(AccountKeyring::Eve.to_account_id()),
Balances::free_balance(Keyring::Eve.to_account_id()),
10_000 + 500 // initial + transfered
);
assert_eq!(Balances::free_balance(Treasury::account_id()), 100 + 3);
......@@ -73,18 +73,18 @@ fn test_transfer_xt() {
fn test_refund_queue() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![
(AccountKeyring::Alice.to_account_id(), 10_000),
(AccountKeyring::Eve.to_account_id(), 10_000),
(Keyring::Alice.to_account_id(), 10_000),
(Keyring::Eve.to_account_id(), 10_000),
])
.build()
.execute_with(|| {
let call = RuntimeCall::Balances(BalancesCall::transfer_allow_death {
dest: AccountKeyring::Eve.to_account_id().into(),
dest: Keyring::Eve.to_account_id().into(),
value: 500,
});
// 1 cĞD of tip
let xt = get_unchecked_extrinsic(call, 4u64, 8u64, AccountKeyring::Alice, 1u64, 0);
let xt = get_unchecked_extrinsic(call, 4u64, 8u64, Keyring::Alice, 1u64, 0);
assert_ok!(Executive::apply_extrinsic(xt));
// check that refund was added to the queue
......@@ -93,7 +93,7 @@ fn test_refund_queue() {
.first()
.expect("a refund should have been added to the queue"),
&pallet_quota::pallet::Refund {
account: AccountKeyring::Alice.to_account_id(),
account: Keyring::Alice.to_account_id(),
identity: 1u32,
amount: 2u64
}
......@@ -106,18 +106,18 @@ fn test_refund_queue() {
fn test_refund_on_idle() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![
(AccountKeyring::Alice.to_account_id(), 10_000),
(AccountKeyring::Eve.to_account_id(), 10_000),
(Keyring::Alice.to_account_id(), 10_000),
(Keyring::Eve.to_account_id(), 10_000),
])
.build()
.execute_with(|| {
let call = RuntimeCall::Balances(BalancesCall::transfer_allow_death {
dest: AccountKeyring::Eve.to_account_id().into(),
dest: Keyring::Eve.to_account_id().into(),
value: 500,
});
// 1 cĞD of tip
let xt = get_unchecked_extrinsic(call, 4u64, 8u64, AccountKeyring::Alice, 1u64, 0);
let xt = get_unchecked_extrinsic(call, 4u64, 8u64, Keyring::Alice, 1u64, 0);
assert_ok!(Executive::apply_extrinsic(xt));
// call on_idle to activate refund
......@@ -125,7 +125,7 @@ fn test_refund_on_idle() {
// check that refund event existed
System::assert_has_event(RuntimeEvent::Quota(pallet_quota::Event::Refunded {
who: AccountKeyring::Alice.to_account_id(),
who: Keyring::Alice.to_account_id(),
identity: 1u32,
amount: 1u64,
}));
......@@ -133,7 +133,7 @@ fn test_refund_on_idle() {
// check that refund queue is empty
assert!(pallet_quota::RefundQueue::<Runtime>::get().is_empty());
assert_eq!(
Balances::free_balance(AccountKeyring::Alice.to_account_id()),
Balances::free_balance(Keyring::Alice.to_account_id()),
10_000 - 500 - 1 - 2 + 1 // initial - transfered - tip - fees + refunded fees
);
})
......@@ -144,17 +144,17 @@ fn test_refund_on_idle() {
fn test_no_refund() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![
(AccountKeyring::Alice.to_account_id(), 10_000),
(AccountKeyring::Eve.to_account_id(), 10_000),
(Keyring::Alice.to_account_id(), 10_000),
(Keyring::Eve.to_account_id(), 10_000),
])
.build()
.execute_with(|| {
// Eve → Alice
let call = RuntimeCall::Balances(BalancesCall::transfer_allow_death {
dest: AccountKeyring::Alice.to_account_id().into(),
dest: Keyring::Alice.to_account_id().into(),
value: 500,
});
let xt = get_unchecked_extrinsic(call, 4u64, 8u64, AccountKeyring::Eve, 1u64, 0);
let xt = get_unchecked_extrinsic(call, 4u64, 8u64, Keyring::Eve, 1u64, 0);
assert_ok!(Executive::apply_extrinsic(xt));
// check that refund queue is empty
assert!(pallet_quota::RefundQueue::<Runtime>::get().is_empty());
......@@ -167,16 +167,16 @@ fn test_no_refund() {
fn test_refund_reaped_linked_account() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![
(AccountKeyring::Alice.to_account_id(), 10_000),
(AccountKeyring::Ferdie.to_account_id(), 10_000),
(Keyring::Alice.to_account_id(), 10_000),
(Keyring::Ferdie.to_account_id(), 10_000),
])
.build()
.execute_with(|| {
let genesis_hash = System::block_hash(0);
let alice = AccountKeyring::Alice.to_account_id();
let ferdie = AccountKeyring::Ferdie.to_account_id();
let alice = Keyring::Alice.to_account_id();
let ferdie = Keyring::Ferdie.to_account_id();
let payload = (b"link", genesis_hash, 1u32, ferdie.clone()).encode();
let signature = AccountKeyring::Ferdie.sign(&payload);
let signature = Keyring::Ferdie.sign(&payload);
// Ferdie's account can be linked to Alice identity
assert_ok!(Identity::link_account(
......@@ -191,10 +191,10 @@ fn test_refund_reaped_linked_account() {
// transfer_all call to extrinsic
let call = RuntimeCall::Balances(BalancesCall::transfer_all {
dest: AccountKeyring::Alice.to_account_id().into(),
dest: Keyring::Alice.to_account_id().into(),
keep_alive: false,
});
let xt = get_unchecked_extrinsic(call, 4u64, 8u64, AccountKeyring::Ferdie, 0u64, 0);
let xt = get_unchecked_extrinsic(call, 4u64, 8u64, Keyring::Ferdie, 0u64, 0);
assert_ok!(Executive::apply_extrinsic(xt));
assert_eq!(Balances::free_balance(ferdie.clone()), 0);
......@@ -213,8 +213,8 @@ fn test_refund_reaped_linked_account() {
fn test_no_member_no_refund() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![
(AccountKeyring::Alice.to_account_id(), 10_000),
(AccountKeyring::Bob.to_account_id(), 10_000),
(Keyring::Alice.to_account_id(), 10_000),
(Keyring::Bob.to_account_id(), 10_000),
])
.build()
.execute_with(|| {
......@@ -223,7 +223,7 @@ fn test_no_member_no_refund() {
idty_index: 2u32,
genesis_hash: System::block_hash(0),
};
let signature = AccountKeyring::Bob.sign(
let signature = Keyring::Bob.sign(
&(
pallet_identity::REVOCATION_PAYLOAD_PREFIX,
revocation_payload,
......@@ -231,9 +231,9 @@ fn test_no_member_no_refund() {
.encode(),
);
assert_ok!(Identity::revoke_identity(
RuntimeOrigin::signed(AccountKeyring::Bob.to_account_id()),
RuntimeOrigin::signed(Keyring::Bob.to_account_id()),
2,
AccountKeyring::Bob.to_account_id(),
Keyring::Bob.to_account_id(),
signature.into()
));
assert_eq!(
......@@ -243,17 +243,17 @@ fn test_no_member_no_refund() {
pallet_identity::IdtyStatus::Revoked
);
let call = RuntimeCall::Balances(BalancesCall::transfer_allow_death {
dest: AccountKeyring::Ferdie.to_account_id().into(),
dest: Keyring::Ferdie.to_account_id().into(),
value: 500,
});
let xt = get_unchecked_extrinsic(call, 4u64, 8u64, AccountKeyring::Bob, 0u64, 0);
let xt = get_unchecked_extrinsic(call, 4u64, 8u64, Keyring::Bob, 0u64, 0);
assert_ok!(Executive::apply_extrinsic(xt));
assert!(pallet_quota::RefundQueue::<Runtime>::get().is_empty());
// Unconfirmed identities are not eligible for a refund
assert_ok!(Identity::create_identity(
RuntimeOrigin::signed(AccountKeyring::Alice.to_account_id()),
AccountKeyring::Ferdie.to_account_id(),
RuntimeOrigin::signed(Keyring::Alice.to_account_id()),
Keyring::Ferdie.to_account_id(),
));
assert_eq!(
pallet_identity::Identities::<Runtime>::get(&5)
......@@ -262,17 +262,16 @@ fn test_no_member_no_refund() {
pallet_identity::IdtyStatus::Unconfirmed
);
let call = RuntimeCall::Balances(BalancesCall::transfer_allow_death {
dest: AccountKeyring::Alice.to_account_id().into(),
dest: Keyring::Alice.to_account_id().into(),
value: 500,
});
let xt =
get_unchecked_extrinsic(call.clone(), 4u64, 8u64, AccountKeyring::Ferdie, 0u64, 0);
let xt = get_unchecked_extrinsic(call.clone(), 4u64, 8u64, Keyring::Ferdie, 0u64, 0);
assert_ok!(Executive::apply_extrinsic(xt));
assert!(pallet_quota::RefundQueue::<Runtime>::get().is_empty());
// Unvalidated identities are not eligible for a refund
assert_ok!(Identity::confirm_identity(
RuntimeOrigin::signed(AccountKeyring::Ferdie.to_account_id()),
RuntimeOrigin::signed(Keyring::Ferdie.to_account_id()),
"ferdie".into(),
));
assert_eq!(
......@@ -281,8 +280,7 @@ fn test_no_member_no_refund() {
.status,
pallet_identity::IdtyStatus::Unvalidated
);
let xt =
get_unchecked_extrinsic(call.clone(), 4u64, 8u64, AccountKeyring::Ferdie, 0u64, 1);
let xt = get_unchecked_extrinsic(call.clone(), 4u64, 8u64, Keyring::Ferdie, 0u64, 1);
assert_ok!(Executive::apply_extrinsic(xt));
assert!(pallet_quota::RefundQueue::<Runtime>::get().is_empty());
......@@ -295,11 +293,10 @@ fn test_no_member_no_refund() {
pallet_identity::IdtyStatus::NotMember
);
let call = RuntimeCall::Balances(BalancesCall::transfer_allow_death {
dest: AccountKeyring::Bob.to_account_id().into(),
dest: Keyring::Bob.to_account_id().into(),
value: 500,
});
let xt =
get_unchecked_extrinsic(call.clone(), 4u64, 8u64, AccountKeyring::Alice, 0u64, 0);
let xt = get_unchecked_extrinsic(call.clone(), 4u64, 8u64, Keyring::Alice, 0u64, 0);
assert_ok!(Executive::apply_extrinsic(xt));
assert!(pallet_quota::RefundQueue::<Runtime>::get().is_empty());
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment