Skip to content

Commit

Permalink
Fix js generated leaf test issue
Browse files Browse the repository at this point in the history
  • Loading branch information
justinphamnz committed Oct 28, 2023
1 parent 2fa8e65 commit 175bab1
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pallets/reward/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ fn test_claim_hash(who: AccountId, balance: Balance) -> Hash {
keccak_256(&keccak_256(&leaf)).into()
}

fn test_claim_hash_account_u128(who: u128, balance: Balance) -> Hash {
let mut leaf: Vec<u8> = who.encode();
leaf.extend(balance.encode());

keccak_256(&keccak_256(&leaf)).into()
}

fn test_claim_nft_hash(who: AccountId, token: (ClassId, TokenId)) -> Hash {
let mut leaf: Vec<u8> = who.encode();
leaf.extend(token.0.encode());
Expand Down Expand Up @@ -2247,7 +2254,10 @@ fn js_encoded_data_matches_blockchain_encoded_data() {

assert_eq!(
leaf,
vec![2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
vec![
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 10, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
); // SCALE encoding for [2u128, 10u128]
});
}
Expand All @@ -2258,22 +2268,22 @@ fn js_generated_leafs_match_blockchain_generated_leafs() {
let bob_hash = Hash::from_slice(&hex!(
"64b39d59f54b02b6d862584c58735a0d3ff7c8d1ee46250809f4c244ca13d5ca"
));
assert_eq!(test_claim_hash(BOB, 10), bob_hash);
assert_eq!(test_claim_hash_account_u128(2, 10), bob_hash);

let charlie_hash = Hash::from_slice(&hex!(
"d90b5864238131f03c065e80a5e0c04aadb2493984702ef3bb279dcd3cb8ac7d"
));
assert_eq!(test_claim_hash(CHARLIE, 25), charlie_hash);
assert_eq!(test_claim_hash_account_u128(3, 25), charlie_hash);

let donna_hash = Hash::from_slice(&hex!(
"77ead2ce9a216ed6ac05f5d8a2c7d12373428794b33d56f65163073769976208"
));
assert_eq!(test_claim_hash(DONNA, 50), donna_hash);
assert_eq!(test_claim_hash_account_u128(4, 50), donna_hash);

let eva_hash = Hash::from_slice(&hex!(
"7ecf6a4f9809680533d36217de280ae07964f4c65595308405e2c860bc52d4bf"
));
assert_eq!(test_claim_hash(EVA, 75), eva_hash);
assert_eq!(test_claim_hash_account_u128(5, 75), eva_hash);
});
}

Expand Down

0 comments on commit 175bab1

Please sign in to comment.