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

Commit

Permalink
[ABO-218] Bugfix forging higher tier avatars in logic V1 (#383)
Browse files Browse the repository at this point in the history
* FIxed forging issue for season 1
  • Loading branch information
DidacSF authored Jan 8, 2024
1 parent 3ff694b commit 4b7235e
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 25 deletions.
118 changes: 95 additions & 23 deletions pallets/ajuna-awesome-avatars/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,8 +1463,9 @@ mod forging {
use super::*;
use sp_runtime::testing::H256;

fn create_avatar_for_bob(dna: &[u8]) -> AvatarIdOf<Test> {
let avatar = Avatar::default().season_id(SEASON_ID).dna(dna);
fn create_avatar_for_bob(dna: &[u8], with_souls: SoulCount) -> AvatarIdOf<Test> {
let mut avatar = Avatar::default().season_id(SEASON_ID).dna(dna);
avatar.souls = with_souls;
if avatar.rarity() == RarityTier::Legendary as u8 {
CurrentSeasonStatus::<Test>::mutate(|status| status.max_tier_avatars += 1);
}
Expand Down Expand Up @@ -1509,33 +1510,104 @@ mod forging {
let dna_after = [0x33, 0x35, 0x34, 0x30, 0x15, 0x35, 0x31, 0x30, 0x32, 0x33, 0x33];
assert_eq!(expected_upgraded_components(&dna_before, &dna_after), 2);

let leader_id = create_avatar_for_bob(&dna_before);
let leader_id = create_avatar_for_bob(&dna_before, 100);
let sacrifice_ids = [
create_avatar_for_bob(&[
0x10, 0x10, 0x14, 0x11, 0x13, 0x31, 0x10, 0x10, 0x13, 0x14, 0x14,
]),
create_avatar_for_bob(&[
0x14, 0x12, 0x14, 0x31, 0x12, 0x15, 0x12, 0x31, 0x12, 0x33, 0x10,
]),
create_avatar_for_bob(&[
0x12, 0x15, 0x32, 0x12, 0x33, 0x15, 0x12, 0x34, 0x15, 0x13, 0x13,
]),
create_avatar_for_bob(&[
0x33, 0x34, 0x33, 0x31, 0x35, 0x33, 0x10, 0x35, 0x11, 0x32, 0x15,
]),
create_avatar_for_bob(
&[0x10, 0x10, 0x14, 0x11, 0x13, 0x31, 0x10, 0x10, 0x13, 0x14, 0x14],
12,
),
create_avatar_for_bob(
&[0x14, 0x12, 0x14, 0x31, 0x12, 0x15, 0x12, 0x31, 0x12, 0x33, 0x10],
13,
),
create_avatar_for_bob(
&[0x12, 0x15, 0x32, 0x12, 0x33, 0x15, 0x12, 0x34, 0x15, 0x13, 0x13],
30,
),
create_avatar_for_bob(
&[0x33, 0x34, 0x33, 0x31, 0x35, 0x33, 0x10, 0x35, 0x11, 0x32, 0x15],
17,
),
];

let sacrifice_souls: SoulCount =
sacrifice_ids.iter().map(|id| Avatars::<Test>::get(id).unwrap().1.souls).sum();
let leader_souls = Avatars::<Test>::get(leader_id).unwrap().1.souls;

assert_ok!(AAvatars::forge(
RuntimeOrigin::signed(BOB),
leader_id,
sacrifice_ids.to_vec()
));
let leader = Avatars::<Test>::get(leader_id).unwrap().1;
assert_eq!(leader.souls, leader_souls + sacrifice_souls);
assert_eq!(leader.dna.to_vec(), dna_after.to_vec());
assert_eq!(leader.rarity(), RarityTier::Common as u8);
});
}

#[test]
fn forge_works_for_season_1_with_high_tier_leader() {
let season = Season::default()
.early_start(100)
.start(200)
.end(150_000)
.max_tier_forges(100)
.max_variations(6)
.max_components(11)
.min_sacrifices(1)
.max_sacrifices(4)
.tiers(&[RarityTier::Common, RarityTier::Rare, RarityTier::Legendary])
.single_mint_probs(&[95, 5])
.batch_mint_probs(&[80, 20])
.base_prob(20)
.per_period(20)
.periods(12);

ExtBuilder::default()
.seasons(&[(SEASON_ID, season)])
.mint_cooldown(5)
.build()
.execute_with(|| {
run_to_block(15_792);

let leader_dna = [0x33, 0x35, 0x34, 0x30, 0x35, 0x35, 0x31, 0x30, 0x32, 0x33, 0x33];

let leader_id = create_avatar_for_bob(&leader_dna, 100);
let sacrifice_ids = [
create_avatar_for_bob(
&[0x10, 0x10, 0x14, 0x11, 0x13, 0x31, 0x10, 0x10, 0x13, 0x14, 0x14],
12,
),
create_avatar_for_bob(
&[0x14, 0x12, 0x14, 0x31, 0x12, 0x15, 0x12, 0x31, 0x12, 0x33, 0x10],
13,
),
create_avatar_for_bob(
&[0x12, 0x15, 0x32, 0x12, 0x33, 0x15, 0x12, 0x34, 0x15, 0x13, 0x13],
30,
),
create_avatar_for_bob(
&[0x33, 0x34, 0x33, 0x31, 0x35, 0x33, 0x10, 0x35, 0x11, 0x32, 0x15],
17,
),
];

let sacrifice_souls: SoulCount =
sacrifice_ids.iter().map(|id| Avatars::<Test>::get(id).unwrap().1.souls).sum();
let leader_souls = Avatars::<Test>::get(leader_id).unwrap().1.souls;

assert_ok!(AAvatars::forge(
RuntimeOrigin::signed(BOB),
leader_id,
sacrifice_ids.to_vec()
));
let leader = Avatars::<Test>::get(leader_id).unwrap().1;
assert_eq!(leader.souls, leader_souls + sacrifice_souls);
assert_eq!(leader.rarity(), RarityTier::Rare as u8);
});
}

#[test]
fn forge_should_work() {
let season = Season::default()
Expand Down Expand Up @@ -1722,10 +1794,10 @@ mod forging {

let mut max_tier_avatars = 0;
let common_avatar_ids = [
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x12]),
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x13]),
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x13]),
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x13]),
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x12], 0),
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x13], 0),
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x13], 0),
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x13], 0),
];

// `max_tier_avatars` increases when a legendary is forged
Expand All @@ -1741,10 +1813,10 @@ mod forging {

// `max_tier_avatars` decreases when legendaries are sacrificed
let legendary_avatar_ids = [
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x52]),
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x52]),
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x52]),
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x52]),
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x52], 0),
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x52], 0),
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x52], 0),
create_avatar_for_bob(&[0x51, 0x52, 0x53, 0x54, 0x55, 0x54, 0x53, 0x52], 0),
];
max_tier_avatars += 4;
assert_eq!(CurrentSeasonStatus::<Test>::get().max_tier_avatars, max_tier_avatars);
Expand Down
5 changes: 3 additions & 2 deletions pallets/ajuna-awesome-avatars/src/types/avatar/versions/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ impl<T: Config> ForgerV1<T> {
matches += 1;
matched_components.extend(matching_components.iter());
}

souls.saturating_accrue(other.souls)
}

souls.saturating_accrue(other.souls);

Ok((matched_components, matches, souls))
},
)
Expand Down

0 comments on commit 4b7235e

Please sign in to comment.