Skip to content

Commit

Permalink
AuthorMapping: fix self key rotation (#1086)
Browse files Browse the repository at this point in the history
* Test that shows the problem

* fix

* version
  • Loading branch information
JoshOrndorff authored Dec 16, 2021
1 parent 20a3849 commit 3820b18
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pallets/author-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "pallet-author-mapping"
authors = [ "PureStake" ]
description = "Maps AuthorIds to AccountIds Useful for associating consensus authors with in-runtime accounts"
edition = "2018"
version = "2.0.4"
version = "2.0.5"

[dependencies]
log = { version = "0.4", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion pallets/author-mapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ pub mod pallet {
Error::<T>::NotYourAssociation
);

MappingWithDeposit::<T>::insert(&new_author_id, &stored_info);
MappingWithDeposit::<T>::remove(&old_author_id);
MappingWithDeposit::<T>::insert(&new_author_id, &stored_info);

<Pallet<T>>::deposit_event(Event::AuthorRotated(new_author_id, stored_info.account));

Expand Down
23 changes: 18 additions & 5 deletions pallets/author-mapping/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,21 @@ fn registered_author_cannot_be_rotated_by_non_owner() {
})
}

//TODO Test ideas in case we bring back the narc extrinsic
// unstaked account can be narced after period
// unstaked account cannot be narced before period
// staked account can be narced after period
// staked account cannot be narced before period
#[test]
fn rotating_to_the_same_author_id_leaves_registration_in_tact() {
ExtBuilder::default()
.with_balances(vec![(1, 1000)])
.with_mappings(vec![(TestAuthor::Alice.into(), 1)])
.build()
.execute_with(|| {
assert_ok!(AuthorMapping::update_association(
Origin::signed(1),
TestAuthor::Alice.into(),
TestAuthor::Alice.into()
));
assert_eq!(
AuthorMapping::account_id_of(&TestAuthor::Alice.into()),
Some(1)
);
})
}

0 comments on commit 3820b18

Please sign in to comment.