Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
[ABO-90] Blueprint building should not increase SP (#331)
Browse files Browse the repository at this point in the history
* Fixed issue with build calculations
  • Loading branch information
DidacSF authored Aug 1, 2023
1 parent b25bca5 commit 8c8b19f
Showing 1 changed file with 93 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<T: Config> AvatarCombinator<T> {

generated_equippables.push(generated_equippable);

soul_points -= 1;
soul_points -= item_sp;
}

build_prop = build_prop.saturating_sub(15 - (level as u32 * 3));
Expand Down Expand Up @@ -773,8 +773,8 @@ mod test {
)
.expect("Should succeed in forging");

assert_eq!(sacrifice_output.len(), 10);
assert_eq!(sacrifice_output.iter().filter(|output| is_minted(output)).count(), 6);
assert_eq!(sacrifice_output.len(), 8);
assert_eq!(sacrifice_output.iter().filter(|output| is_minted(output)).count(), 4);
assert_eq!(sacrifice_output.iter().filter(|output| is_forged(output)).count(), 4);

if let LeaderForgeOutput::Forged((_, avatar), _) = leader_output {
Expand All @@ -795,7 +795,96 @@ mod test {
})
.sum::<SoulCount>();

assert_eq!(avatar.souls + soul_points, 987);
assert_eq!(avatar.souls + soul_points, 953);
} else {
panic!("LeaderForgeOutput should have been Forged!")
}
});
}

#[test]
fn test_build_prep_2() {
ExtBuilder::default().build().execute_with(|| {
let mut hash_provider = HashProvider::new_with_bytes([
0x4C, 0x0B, 0xF6, 0x8A, 0xFF, 0x3D, 0xAD, 0xB0, 0x01, 0x15, 0xE1, 0x7B, 0x90, 0x36,
0x38, 0x60, 0x55, 0x91, 0x25, 0x4D, 0x57, 0xFA, 0x57, 0x1D, 0x38, 0xB9, 0xC9, 0x99,
0x42, 0xEA, 0x20, 0x37,
]);

let hash_base = [
[
0x51, 0x63, 0x13, 0x0c, 0x00, 0xf0, 0x1e, 0x04, 0x01, 0x01, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
],
[
0x25, 0x00, 0x31, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
],
[
0x26, 0x00, 0x11, 0xb6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
],
[
0x28, 0x00, 0x41, 0xeb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
],
[
0x27, 0x00, 0x31, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
],
];

let avatar_fn = |souls: SoulCount| {
let mutate_fn = move |avatar: Avatar| {
let mut avatar = avatar;
avatar.souls = souls;
WrappedAvatar::new(avatar)
};

Some(mutate_fn)
};

let leader = create_random_avatar::<Test, _>(&ALICE, Some(hash_base[0]), avatar_fn(12));
let sac_1 = create_random_avatar::<Test, _>(&ALICE, Some(hash_base[1]), avatar_fn(624));
let sac_2 = create_random_avatar::<Test, _>(&ALICE, Some(hash_base[2]), avatar_fn(182));
let sac_3 = create_random_avatar::<Test, _>(&ALICE, Some(hash_base[3]), avatar_fn(940));
let sac_4 = create_random_avatar::<Test, _>(&ALICE, Some(hash_base[4]), avatar_fn(717));

let total_souls =
leader.1.get_souls() +
sac_1.1.get_souls() + sac_2.1.get_souls() +
sac_3.1.get_souls() + sac_4.1.get_souls();
assert_eq!(total_souls, 2475);

assert_eq!(
ForgerV2::<Test>::determine_forge_type(
&leader.1,
&[&sac_1.1, &sac_2.1, &sac_3.1, &sac_4.1]
),
ForgeType::Build
);

let (leader_output, _) = AvatarCombinator::<Test>::build_avatars(
leader,
vec![sac_1, sac_2, sac_3, sac_4],
1,
&mut hash_provider,
)
.expect("Should succeed in forging");

if let LeaderForgeOutput::Forged((_, avatar), _) = leader_output {
let item_type = DnaUtils::read_attribute::<ItemType>(&avatar, AvatarAttr::ItemType);
assert_eq!(item_type, ItemType::Blueprint);

assert_eq!(avatar.souls, 11);

let leader_quantity = DnaUtils::read_attribute_raw(&avatar, AvatarAttr::Quantity);
assert_eq!(leader_quantity, 11);
} else {
panic!("LeaderForgeOutput should have been Forged!")
}
Expand Down

0 comments on commit 8c8b19f

Please sign in to comment.