Skip to content

Commit

Permalink
Merge branch 'development' into feature/custom-craft
Browse files Browse the repository at this point in the history
  • Loading branch information
U-lis committed Jul 30, 2024
2 parents d4a7afd + 912fbcd commit 42bfdce
Show file tree
Hide file tree
Showing 99 changed files with 4,690 additions and 2,120 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
2 changes: 1 addition & 1 deletion .Lib9c.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void Main(string[] args)
IKeyValueStore stateKeyValueStore = new RocksDBKeyValueStore(Path.Combine(storePath, "states"));
var stateStore = new TrieStateStore(stateKeyValueStore);
var actionEvaluator = new ActionEvaluator(
_ => policy.BlockAction,
policy.PolicyActionsRegistry,
stateStore,
new NCActionLoader());
var chain = new BlockChain(
Expand Down
7 changes: 6 additions & 1 deletion .Lib9c.Plugin/PluginActionEvaluator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Immutable;
using System.Security.Cryptography;
using Lib9c.Plugin.Shared;
using Libplanet.Action;
Expand All @@ -18,7 +19,11 @@ public PluginActionEvaluator(IPluginKeyValueStore keyValueStore)
{
var stateStore = new TrieStateStore(new WrappedKeyValueStore(keyValueStore));
_actionEvaluator = new ActionEvaluator(
_ => new RewardGold(),
new PolicyActionsRegistry(
beginBlockActions: ImmutableArray<IAction>.Empty,
endBlockActions: new IAction[] { new RewardGold() }.ToImmutableArray(),
beginTxActions: ImmutableArray<IAction>.Empty,
endTxActions: ImmutableArray<IAction>.Empty),
stateStore,
new NCActionLoader());
}
Expand Down
11 changes: 10 additions & 1 deletion .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 All @@ -38,14 +41,20 @@ public class ActionContext : IActionContext

public HashDigest<SHA256>? PreviousStateRootHash { get; set; }

public bool BlockAction { get; }
public bool IsPolicyAction { get; }

public IReadOnlyList<ITransaction> Txs
{
get => _txs ?? ImmutableList<ITransaction>.Empty;
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, 69), // 50 first Reward + 19 floor reward
(600302, 50), // 50 first reward
(600303, 7), // 7 floor reward
(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, 47), // 30 first reward + 17 floor reward
(600302, 30), // 30 first 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, 76), // 50 first reward + 26 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
Loading

0 comments on commit 42bfdce

Please sign in to comment.