Skip to content

Commit

Permalink
Merge pull request #2708 from planetarium/release/1.15.0
Browse files Browse the repository at this point in the history
Release/1.15.0
  • Loading branch information
ipdae authored Jul 29, 2024
2 parents a5dd5bd + fef54f5 commit 570818f
Show file tree
Hide file tree
Showing 97 changed files with 7,262 additions and 2,243 deletions.
4 changes: 2 additions & 2 deletions .Lib9c.Benchmarks/Lib9c.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\.Libplanet\Libplanet.RocksDBStore\Libplanet.RocksDBStore.csproj" />
<ProjectReference Include="..\.Libplanet\Libplanet\Libplanet.csproj" />
<ProjectReference Include="..\.Libplanet\src\Libplanet.RocksDBStore\Libplanet.RocksDBStore.csproj" />
<ProjectReference Include="..\.Libplanet\src\Libplanet\Libplanet.csproj" />
<ProjectReference Include="..\Lib9c\Lib9c.csproj" />
<ProjectReference Include="..\Lib9c.Policy\Lib9c.Policy.csproj" />
<ProjectReference Include="..\Libplanet.Crypto.Secp256k1\Libplanet.Crypto.Secp256k1.csproj" />
Expand Down
9 changes: 9 additions & 0 deletions .Lib9c.Tests/Action/ActionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Lib9c.Tests.Action
using Libplanet.Common;
using Libplanet.Crypto;
using Libplanet.Types.Blocks;
using Libplanet.Types.Evidence;
using Libplanet.Types.Tx;

public class ActionContext : IActionContext
Expand All @@ -18,6 +19,8 @@ public class ActionContext : IActionContext

private IReadOnlyList<ITransaction> _txs = null;

private IReadOnlyList<EvidenceBase> _evs = null;

public BlockHash? GenesisHash { get; set; }

public Address Signer { get; set; }
Expand Down Expand Up @@ -46,6 +49,12 @@ public IReadOnlyList<ITransaction> Txs
set => _txs = value;
}

public IReadOnlyList<EvidenceBase> Evidence
{
get => _evs ?? ImmutableList<EvidenceBase>.Empty;
set => _evs = value;
}

public void UseGas(long gas)
{
_gasUsed += gas;
Expand Down
62 changes: 34 additions & 28 deletions .Lib9c.Tests/Action/AdventureBoss/ClaimAdventureBossRewardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ public static IEnumerable<object[]> GetWantedTestData()
ItemReward = new Dictionary<int, int>
{
{ 600201, 168 },
{ 600202, 0 },
{ 600202, 18 },
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
{
{ 20001, 14 },
{ 20001, 0 },
{ 30001, 0 },
},
},
Expand All @@ -147,12 +147,12 @@ public static IEnumerable<object[]> GetWantedTestData()
{
600201, 168
}, // (200*1.2) * 0.7 / 0.5 * (120/240)
{ 600202, 0 },
{ 600202, 18 }, // (200*1.2) * 0.3 / 2 * (120/240)
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
{
{ 20001, 14 }, // (200*1.2) * 0.3 / 2.5 * (120/240)
{ 20001, 0 },
{ 30001, 0 },
},
},
Expand All @@ -169,12 +169,12 @@ public static IEnumerable<object[]> GetWantedTestData()
{
600201, 140
}, // (300*1.2) * 0.7 / 0.5 * (100/360)
{ 600202, 0 },
{ 600202, 15 }, // (300*1.2) * 0.3 / 2 * (100/360)
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
{
{ 20001, 11 }, // (300*1.2) * 0.3 / 2.5 * (100/360)
{ 20001, 0 },
{ 30001, 0 },
},
},
Expand All @@ -190,8 +190,8 @@ public static IEnumerable<object[]> GetExploreTestData()
NcgReward = (5 + 15) * NCG, // 5NCG for raffle, 15NCG for 15% distribution
ItemReward = new Dictionary<int, int>
{
{ 600201, 0 },
{ 600202, 66 }, // 100AP / 1.5 ratio * 100% contribution
{ 600201, 80 }, // 100AP * 0.4 Exchange / 0.5 ratio * 100% contribution
{ 600202, 0 },
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
Expand All @@ -215,8 +215,10 @@ public static IEnumerable<object[]> GetExploreTestData()
),
ItemReward = new Dictionary<int, int>
{
{ 600201, 0 },
{ 600202, 66 }, // total 200 AP / 1.5 ratio * 50% contribution
{
600201, 79
}, // total 200 AP * 0.4 Exchange / 0.5 ratio * 50% contribution
{ 600202, 0 },
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
Expand All @@ -237,8 +239,10 @@ public static IEnumerable<object[]> GetExploreTestData()
NcgReward = 15 * NCG,
ItemReward = new Dictionary<int, int>
{
{ 600201, 0 },
{ 600202, 66 }, // Total 200 AP / 1.5 Ratio * 50% Contribution
{
600201, 79
}, // Total 200 AP * 0.4 Exchange / 1.5 Ratio * 50% Contribution
{ 600202, 0 },
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
Expand All @@ -258,8 +262,8 @@ public static IEnumerable<object[]> GetExploreTestData()
NcgReward = 5 * NCG,
ItemReward = new Dictionary<int, int>
{
{ 600201, 0 },
{ 600202, 66 },
{ 600201, 80 },
{ 600202, 0 },
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
Expand All @@ -282,12 +286,12 @@ public static IEnumerable<object[]> GetPrevRewardTestData()
ItemReward = new Dictionary<int, int>
{
{ 600201, 168 },
{ 600202, 0 },
{ 600202, 18 },
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
{
{ 20001, 14 },
{ 20001, 0 },
{ 30001, 0 },
},
},
Expand All @@ -300,8 +304,8 @@ public static IEnumerable<object[]> GetPrevRewardTestData()
NcgReward = 20 * NCG, // 5NCG for explore raffle, 15NCG for 15% distribution
ItemReward = new Dictionary<int, int>
{
{ 600201, 0 },
{ 600202, 66 },
{ 600201, 80 },
{ 600202, 0 },
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
Expand All @@ -320,13 +324,13 @@ public static IEnumerable<object[]> GetPrevRewardTestData()
NcgReward = 20 * NCG,
ItemReward = new Dictionary<int, int>
{
{ 600201, 168 },
{ 600202, 66 },
{ 600201, 248 },
{ 600202, 18 },
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
{
{ 20001, 14 },
{ 20001, 0 },
{ 30001, 0 },
},
},
Expand Down Expand Up @@ -438,13 +442,13 @@ public void WantedMultipleSeason()
NcgReward = 0 * NCG, // No Raffle Reward
FavReward = new Dictionary<int, int>
{
{ 20001, 28 },
{ 20001, 0 },
{ 30001, 0 },
},
ItemReward = new Dictionary<int, int>
{
{ 600201, 336 },
{ 600202, 0 },
{ 600202, 36 },
{ 600203, 0 },
},
};
Expand Down Expand Up @@ -708,8 +712,10 @@ public void ExploreMultipleSeason()
},
ItemReward = new Dictionary<int, int>
{
{ 600201, 0 },
{ 600202, 132 }, // (100 AP / 1.5 Ratio * 100% contribution) for season 1 and 3
{
600201, 160
}, // (100 AP * 0.4 Exchange / 0.5 Ratio * 100% contribution) for season 1 and 3
{ 600202, 0 },
{ 600203, 0 },
},
};
Expand Down Expand Up @@ -831,13 +837,13 @@ public void AllReward()
NcgReward = 20 * NCG,
FavReward = new Dictionary<int, int>
{
{ 20001, 14 },
{ 20001, 0 },
{ 30001, 0 },
},
ItemReward = new Dictionary<int, int>
{
{ 600201, 168 },
{ 600202, 66 },
{ 600201, 248 },
{ 600202, 18 },
{ 600203, 0 },
},
};
Expand Down
73 changes: 52 additions & 21 deletions .Lib9c.Tests/Action/AdventureBoss/ExploreAdventureBossTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,58 +98,79 @@ public static IEnumerable<object[]> GetExecuteMemberData()
// No AP potion at all
yield return new object[]
{
0, 5, 0, 0, 0, null, new (int, int)[] { },
0, 5, 0, 0, 0, null, new (int, int)[] { }, new (int, int)[] { },
};
// Start from bottom, goes to 5
yield return new object[]
{
0, 5, 5, 10, 5, null,
0, 5, 5, 20, 10, null, // 2 potions per floor
new[]
{
(600301, 76), // 50 first Reward + 26 floor reward
(600302, 50), // 50 first reward
(600303, 0),
(600301, 10), // 10 floor reward
(600302, 30), // 10+5+5+5+5 first reward
(600303, 4), // 2+2 first reward
(600304, 0),
},
new[]
{
(10033, 5), // 5 first reward
(10034, 8), // 5 first reward + 3 floor reward
},
};
// Start from bottom, goes to 3 because of potion
yield return new object[]
{
0, 5, 3, 3, 0, null, new[]
0, 5, 3, 6, 0, null, new[]
{
(600301, 47), // 30 first reward + 17 floor reward
(600302, 30), // 30 first reward
(600303, 0),
(600301, 7), // 7 floor reward
(600302, 20), // 10+5+5 first reward
(600303, 4), // 2+2 first reward
(600304, 0),
},
new[]
{
(10033, 0),
(10034, 0),
},
};
// Start from 3, goes to 5 because of locked floor
yield return new object[]
{
2, 5, 5, 5, 2, null, new[]
2, 5, 5, 10, 4, null, new[]
{
(600301, 40), // 30 first reward + 10 floor reward
(600302, 39), // 30 first reward + 9 floor reward
(600303, 0),
(600301, 4), // 4 floor reward
(600302, 15), // 5+5+5 first reward
(600303, 2), // 2 first reward
(600304, 0),
},
new[]
{
(10033, 8), // 5 first reward + 3 floor reward
(10034, 5), // 5 first reward
},
};
// Start from 6, goes to 10
// Start from 6, goes to 9
yield return new object[]
{
5, 10, 10, 10, 5, null,
5, 10, 9, 20, 10, null,
new[]
{
(600301, 72), // 50 first reward + 22 floor reward
(600302, 50), // 50 first reward
(600303, 0),
(600203, 5), // 5 first reward
(600301, 0),
(600302, 5), // 5 floor reward
(600303, 15), // 5+5+5 first reward
(600304, 0),
},
new[]
{
(10033, 8), // 5 first reward + 3 floor reward
(10034, 3), // 3 floor reward
},
};
// Start from 20, cannot enter
yield return new object[]
{
20, 20, 20, 10, 10, typeof(InvalidOperationException), null,
20, 20, 20, 10, 10, typeof(InvalidOperationException), null, null,
};
}

Expand All @@ -162,7 +183,8 @@ public void Execute(
int initialPotion,
int expectedPotion,
Type exc,
(int, int)[] expectedRewards
(int, int)[] expectedItemRewards,
(int, int)[] expectedFavRewards
)
{
// Settings
Expand All @@ -179,6 +201,7 @@ public void Execute(
var sheets = state.GetSheets(sheetTypes: new[]
{
typeof(MaterialItemSheet),
typeof(RuneSheet),
});
var materialSheet = sheets.GetSheet<MaterialItemSheet>();
var materialRow =
Expand Down Expand Up @@ -275,7 +298,7 @@ public void Execute(
Assert.Equal(expectedFloor, explorer.Floor);

var inventory = state.GetInventoryV2(TesterAvatarAddress);
foreach (var (id, amount) in expectedRewards)
foreach (var (id, amount) in expectedItemRewards)
{
if (amount == 0)
{
Expand All @@ -287,6 +310,14 @@ public void Execute(
}
}

var runeSheet = sheets.GetSheet<RuneSheet>();
foreach (var (id, amount) in expectedFavRewards)
{
var ticker = runeSheet.Values.First(rune => rune.Id == id).Ticker;
var currency = Currencies.GetRune(ticker);
Assert.Equal(amount, state.GetBalance(TesterAvatarAddress, currency).RawValue);
}

itemSlotState =
state.TryGetLegacyState(itemSlotStateAddress, out rawItemSlotState)
? new ItemSlotState(rawItemSlotState)
Expand Down
6 changes: 3 additions & 3 deletions .Lib9c.Tests/Action/AdventureBoss/SweepAdventureBossTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ public static IEnumerable<object[]> GetExecuteMemberData()
};
yield return new object[]
{
1, 100, 98, null, new[] { (600301, 8), (600302, 0), (600303, 0), (600304, 0), },
1, 100, 99, null, new[] { (600301, 3), (600302, 0), (600303, 0), (600304, 0), },
};
yield return new object[]
{
1, 0, 0, typeof(NotEnoughMaterialException), null,
};
yield return new object[]
{
10, 10, 10, typeof(NotEnoughMaterialException), null,
10, 1, 1, typeof(NotEnoughMaterialException), null,
};
yield return new object[]
{
20, 40, 0, null, new[] { (600301, 67), (600302, 67), (600303, 0), (600304, 0), },
20, 20, 0, null, new[] { (600301, 9), (600302, 10), (600303, 8), (600304, 8), },
};
}

Expand Down
Loading

0 comments on commit 570818f

Please sign in to comment.