Skip to content

Commit

Permalink
Merge pull request #3033 from eugene-doobu/feature/code-sweep-dev-ext…
Browse files Browse the repository at this point in the history
…ensions

code sweep dev extensions
  • Loading branch information
eugene-doobu authored Dec 18, 2024
2 parents af4013a + 0d7f6d5 commit cb44a7e
Show file tree
Hide file tree
Showing 27 changed files with 511 additions and 485 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Bencodex.Types;
using Lib9c.DevExtensions.Action.Craft;
using Lib9c.Tests;
using Lib9c.Tests.Action;
Expand All @@ -7,8 +6,6 @@
using Libplanet.Action.State;
using Libplanet.Crypto;
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Model;
using Nekoyume.Module;
using Xunit;

Expand Down Expand Up @@ -45,14 +42,14 @@ public void StageUnlockTest(string typeIdentifier, int expectedStage)
var action = new UnlockCraftAction
{
AvatarAddress = _avatarAddress,
ActionType = new ActionTypeAttribute(typeIdentifier)
ActionType = new ActionTypeAttribute(typeIdentifier),
};

var state = action.Execute(new ActionContext
{
PreviousState = _initialStateV2,
Signer = _agentAddress,
BlockIndex = 0L
BlockIndex = 0L,
});

var avatarState = state.GetAvatarState(_avatarAddress);
Expand Down
12 changes: 7 additions & 5 deletions .Lib9c.DevExtensions.Tests/Action/CreateOrReplaceAvatarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ public CreateOrReplaceAvatarTest()
(200000, 1),
(201010, 2),
},
new[] { 40100000 },
new[] { 40100000, },
new[]
{
(10001, 0),
(20001, 1),
(30001, 10),
},
(1, new[] { 1, 2, 3 }),
(1, new[] { 1, 2, 3, }),
};
}

Expand Down Expand Up @@ -221,7 +221,7 @@ public static IEnumerable<object?[]>
0, 0, "AB", 0, 0, 0, 0, 1,
null,
null,
new[] { -1 },
new[] { -1, },
null,
null,
};
Expand Down Expand Up @@ -273,7 +273,7 @@ public static IEnumerable<object?[]>
null,
null,
null,
(0, new[] { -1 }),
(0, new[] { -1, }),
};
}

Expand Down Expand Up @@ -304,6 +304,7 @@ public void Serialize(
equipments.Add((row.ResultEquipmentId, data.level));
}
}

var action = new CreateOrReplaceAvatar(
avatarIndex,
name,
Expand Down Expand Up @@ -371,6 +372,7 @@ public void Execute_Success(
equipments.Add((row.ResultEquipmentId, data.level));
}
}

var agentAddr = new PrivateKey().Address;
Execute(
_initialStates,
Expand Down Expand Up @@ -521,7 +523,7 @@ private static void Execute(
Assert.Contains(
equipment.StatsMap.GetAdditionalStats(false),
stat => stat.statType == statOption.Key &&
stat.additionalValue == statOption.Value);
stat.additionalValue == statOption.Value);
}

var skillOptions = options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ namespace Lib9c.DevExtensions.Tests.Action.Factory
{
public class CreateOrReplaceAvatarFactoryTest
{
private readonly TableSheets _tableSheets;

public CreateOrReplaceAvatarFactoryTest()
{
_tableSheets = new TableSheets(TableSheetsImporter.ImportSheets());
}
private readonly TableSheets _tableSheets = new TableSheets(TableSheetsImporter.ImportSheets());

[Theory]
[MemberData(
Expand Down Expand Up @@ -50,9 +45,7 @@ public void TryGetByBlockIndex_Success(
}

var (e, r) = CreateOrReplaceAvatarFactory
.TryGetByBlockIndex(
blockIndex,
avatarIndex,
.TryGetByBlockIndex(avatarIndex,
name,
hair,
lens,
Expand All @@ -73,14 +66,7 @@ public void TryGetByBlockIndex_Success(
Assert.Equal(ear, r.Ear);
Assert.Equal(tail, r.Tail);
Assert.Equal(level, r.Level);
if (equipments is null)
{
Assert.Empty(r.Equipments);
}
else
{
Assert.True(equipments.SequenceEqual(r.Equipments));
}
Assert.True(equipments.SequenceEqual(r.Equipments));

if (foods is null)
{
Expand Down Expand Up @@ -142,9 +128,7 @@ public void TryGetByBlockIndex_Failure(
(int stageId, int[] crystalRandomBuffIds)? crystalRandomBuff)
{
var (e, r) = CreateOrReplaceAvatarFactory
.TryGetByBlockIndex(
blockIndex,
avatarIndex,
.TryGetByBlockIndex(avatarIndex,
name,
hair,
lens,
Expand Down
12 changes: 6 additions & 6 deletions .Lib9c.DevExtensions.Tests/Action/FaucetCurrencyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ int expectedCrystal
FaucetNcg = faucetNcg,
FaucetCrystal = faucetCrystal,
};
var state = action.Execute(new ActionContext { PreviousState = _initialState });
AgentState agentState = state.GetAgentState(_agentAddress);
FungibleAssetValue expectedNcgAsset =
var state = action.Execute(new ActionContext { PreviousState = _initialState, });
var agentState = state.GetAgentState(_agentAddress);
var expectedNcgAsset =
new FungibleAssetValue(_ncg, expectedNcg, 0);
FungibleAssetValue ncg = state.GetBalance(_agentAddress, state.GetGoldCurrency());
var ncg = state.GetBalance(_agentAddress, state.GetGoldCurrency());
Assert.Equal(expectedNcgAsset, ncg);

FungibleAssetValue expectedCrystalAsset =
var expectedCrystalAsset =
new FungibleAssetValue(_crystal, expectedCrystal, 0);
FungibleAssetValue crystal = state.GetBalance(_agentAddress, _crystal);
var crystal = state.GetBalance(_agentAddress, _crystal);
Assert.Equal(expectedCrystalAsset, crystal);
}
}
Expand Down
22 changes: 16 additions & 6 deletions .Lib9c.DevExtensions.Tests/Action/FaucetRuneTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public FaucetRuneTest(ITestOutputHelper outputHelper)
var tableSheets = new TableSheets(sheets);
_runeSheet = _initialState.GetSheet<RuneSheet>();

Address agentAddress = new PrivateKey().Address;
var agentAddress = new PrivateKey().Address;
_avatarAddress = new PrivateKey().Address;
var agentState = new AgentState(agentAddress);
var avatarState = AvatarState.Create(
Expand All @@ -58,8 +58,8 @@ public FaucetRuneTest(ITestOutputHelper outputHelper)
agentState.avatarAddresses.Add(0, _avatarAddress);

_initialState = _initialState
.SetAgentState(agentAddress, agentState)
.SetAvatarState(_avatarAddress, avatarState);
.SetAgentState(agentAddress, agentState)
.SetAvatarState(_avatarAddress, avatarState);
}

[Theory]
Expand All @@ -71,7 +71,7 @@ public void Execute_FaucetRune(List<FaucetRuneInfo> faucetRuneInfos)
AvatarAddress = _avatarAddress,
FaucetRuneInfos = faucetRuneInfos,
};
var states = action.Execute(new ActionContext { PreviousState = _initialState });
var states = action.Execute(new ActionContext { PreviousState = _initialState, });
foreach (var rune in faucetRuneInfos)
{
var expectedRune = RuneHelper.ToCurrency(
Expand Down Expand Up @@ -113,9 +113,19 @@ private class FaucetRuneInfoGenerator : IEnumerable<object[]>
},
};

public IEnumerator<object[]> GetEnumerator() => _data.GetEnumerator();
/// <summary>
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns>data for each test case</returns>
public IEnumerator<object[]> GetEnumerator()
{
return _data.GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}
}
Loading

0 comments on commit cb44a7e

Please sign in to comment.