Skip to content

Commit

Permalink
Fix state judgement (#222)
Browse files Browse the repository at this point in the history
* Fix judgement

* Use adjust()

* Format
  • Loading branch information
boundless-forest authored Jan 18, 2023
1 parent 8f08de1 commit ca2dd66
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
5 changes: 5 additions & 0 deletions tool/state-processor/src/adjust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ impl Adjust for Unbonding {

impl Adjust for Registration {
fn adjust(&mut self) {
self.judgements.iter_mut().for_each(|(_, judgement)| {
if let Judgement::FeePaid(ref mut amount) = judgement {
amount.adjust();
}
});
self.deposit.adjust();
}
}
Expand Down
2 changes: 1 addition & 1 deletion tool/state-processor/src/identity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
1. take `Identity::IdentityOf`, `Identity::Registrars`, `Identity::SuperOf` and `Identity::SuperOf`
2. free super_id's reservation
3. adjust identities' deposit and judgement decimal
4. set `AccountMigration::IdentityOf`
4. set `AccountMigration::Identities`
5. truncate registrar account id and adjust registrars fee decimal
6. set `Identity::Registrars
4 changes: 2 additions & 2 deletions tool/state-processor/src/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ impl<S> Processor<S> {
log::info!("adjust identities' deposit and judgement decimal");
identities.iter_mut().for_each(|(_, v)| v.adjust());

log::info!("set `AccountMigration::IdentityOf`");
log::info!("set `AccountMigration::Identities`");
{
let ik = item_key(b"AccountMigration", b"IdentityOf");
let ik = item_key(b"AccountMigration", b"Identities");

self.shell_state.insert_map(identities, |h| format!("{ik}{h}"));
}
Expand Down
21 changes: 13 additions & 8 deletions tool/state-processor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,9 @@ fn proxy_reserved_adjust() {
#[test]
fn identities_adjust() {
run_test(|tester| {
// https://crab.subscan.io/account/5CcRAW3d6vi4Vq2BX9EeynS1rj7bqoZ5EPwPiLiJ422FsEbC
// https://crab.subscan.io/account/5Ct3V8cbYgJiUoQQhYMyyWChL5YwJnZ4yak7MKegNkpPptAP
let test_addr: [u8; 32] = hex_n_into_unchecked::<_, _, 32>(
"0x182fa92d7f04c79c541d5f117223fcb9f83f2e830c3c187f2622176ed68c3c1a",
"0x241a9c2aa8a83e1c5f02fc2b7112bd1873249a8e55a4f919c7d42cf1164be35c",
);

let mut registration = Registration::default();
Expand All @@ -715,20 +715,25 @@ fn identities_adjust() {
&mut registration,
);
assert_ne!(registration.deposit, 0);
assert_eq!(registration.info.display, Data::Raw(b"COLD STORAGE CAPITAL".to_vec()));
assert_eq!(registration.info.email, Data::Raw(b"rbarraza@coldstoragecapital.com".to_vec()));
assert_eq!(registration.info.twitter, Data::Raw(b"@coldstoragecap".to_vec()));
assert_eq!(registration.info.display, Data::Raw(b"iskulbukolPH".to_vec()));
assert_eq!(registration.info.email, Data::Raw(b"pjdamondamon@gmail.com".to_vec()));
assert_eq!(registration.info.twitter, Data::Raw(b"@DPedroJuan".to_vec()));

// after migrated
let mut migrated_registration = Registration::default();
tester.shell_state.get_value(
b"AccountMigration",
b"IdentityOf",
b"Identities",
&two_x64_concat_to_string(test_addr.encode()),
&mut migrated_registration,
);
assert_eq!(migrated_registration.deposit, registration.deposit * GWEI);
assert_eq!(migrated_registration.judgements.len(), 0);
registration.judgements.iter().zip(migrated_registration.judgements.iter()).for_each(
|((_, r), (_, m_r))| match (r, m_r) {
(Judgement::FeePaid(a), Judgement::FeePaid(m_a)) => assert_eq!(a * GWEI, *m_a),
_ => assert_eq!(*r, *m_r),
},
);
assert_eq!(migrated_registration.info.display, registration.info.display);
assert_eq!(migrated_registration.info.email, registration.info.email);
assert_eq!(migrated_registration.info.twitter, registration.info.twitter);
Expand All @@ -748,7 +753,7 @@ fn registrars_adjust() {

rs.iter().zip(migrated_rs.iter()).for_each(|(r, m_r)| match (r, m_r) {
(Some(r), Some(m_r)) => {
assert_eq!(r.account, m_r.account[..20]);
assert_eq!(r.account[..20], m_r.account);
assert_eq!(r.fee * GWEI, m_r.fee);
assert_eq!(r.fields, m_r.fields);
},
Expand Down
2 changes: 1 addition & 1 deletion tool/state-processor/src/type_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl Decode for Registration {
Ok(Self { judgements, deposit, info })
}
}
#[derive(Debug, Encode, Decode)]
#[derive(Debug, PartialEq, Eq, Encode, Decode)]
pub enum Judgement {
Unknown,
FeePaid(u128),
Expand Down

0 comments on commit ca2dd66

Please sign in to comment.