Skip to content

Commit

Permalink
fix broken unit tests about ActionPoint hard-forking
Browse files Browse the repository at this point in the history
  • Loading branch information
sonohoshi committed Apr 1, 2024
1 parent f377b88 commit ec37aad
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .Lib9c.Tests/Action/CancelProductRegistrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public CancelProductRegistrationTest(ITestOutputHelper outputHelper)
.SetLegacyState(GoldCurrencyState.Address, _goldCurrencyState.Serialize())
.SetAgentState(_agentAddress, agentState)
.SetLegacyState(Addresses.Shop, new ShopState().Serialize())
.SetAvatarState(_avatarAddress, avatarState);
.SetAvatarState(_avatarAddress, avatarState)
.SetActionPoint(_avatarAddress, DailyReward.ActionPointMax);
}

[Theory]
Expand Down
1 change: 0 additions & 1 deletion .Lib9c.Tests/Action/HackAndSlashSweepTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,6 @@ public void ExecuteDuplicatedException(int slotIndex, int runeId, int slotIndex2
{
worldInformation =
new WorldInformation(0, _initialState.GetSheet<WorldSheet>(), 25),
actionPoint = 120,
level = 3,
};
var itemRow = _tableSheets.MaterialItemSheet.Values.First(r =>
Expand Down
7 changes: 3 additions & 4 deletions .Lib9c.Tests/Action/ReRegisterProductTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public ReRegisterProductTest(ITestOutputHelper outputHelper)
.SetLegacyState(Addresses.Shop, shopState.Serialize())
.SetAgentState(_agentAddress, agentState)
.SetLegacyState(Addresses.GameConfig, _gameConfigState.Serialize())
.SetLegacyState(_avatarAddress, MigrationAvatarState.LegacySerializeV1(_avatarState));
.SetLegacyState(_avatarAddress, MigrationAvatarState.LegacySerializeV1(_avatarState))
.SetActionPoint(_avatarAddress, DailyReward.ActionPointMax);
}

[Theory]
Expand Down Expand Up @@ -296,9 +297,7 @@ bool fromPreviousAction
Assert.Equal(productId, product.ProductId);
Assert.Equal(productType, product.Type);
Assert.Equal(order.Price, product.Price);

var nextAvatarState = actualState.GetAvatarState(_avatarAddress);
Assert.Equal(_gameConfigState.ActionPointMax - ReRegisterProduct.CostAp, nextAvatarState.actionPoint);
Assert.Equal(DailyReward.ActionPointMax - ReRegisterProduct.CostAp, actualState.GetActionPoint(_avatarAddress));
}

[Fact]
Expand Down
5 changes: 3 additions & 2 deletions .Lib9c.Tests/Action/RegisterProductTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public RegisterProductTest()
.SetLegacyState(Addresses.GetSheetAddress<MaterialItemSheet>(), _tableSheets.MaterialItemSheet.Serialize())
.SetLegacyState(Addresses.GameConfig, _gameConfigState.Serialize())
.SetAgentState(_agentAddress, agentState)
.SetAvatarState(AvatarAddress, _avatarState);
.SetAvatarState(AvatarAddress, _avatarState)
.SetActionPoint(AvatarAddress, DailyReward.ActionPointMax);
}

public static IEnumerable<object[]> Execute_Validate_MemberData()
Expand Down Expand Up @@ -251,7 +252,7 @@ public void Execute()

var nextAvatarState = nextState.GetAvatarState(AvatarAddress);
Assert.Empty(nextAvatarState.inventory.Items);
Assert.Equal(_gameConfigState.ActionPointMax - RegisterProduct.CostAp, nextAvatarState.actionPoint);
Assert.Equal(DailyReward.ActionPointMax - RegisterProduct.CostAp, nextState.GetActionPoint(AvatarAddress));

var marketState = new MarketState(nextState.GetLegacyState(Addresses.Market));
Assert.Contains(AvatarAddress, marketState.AvatarAddresses);
Expand Down
3 changes: 2 additions & 1 deletion .Lib9c.Tests/Action/Scenario/AuraScenarioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public AuraScenarioTest()
rankingMapAddress
);
avatarState.inventory.AddItem(_aura);
_initialState = _initialState.SetAvatarState(avatarAddress, avatarState);
_initialState = _initialState.SetAvatarState(avatarAddress, avatarState)
.SetActionPoint(avatarAddress, DailyReward.ActionPointMax);
}

_currency = Currency.Legacy("NCG", 2, minters: null);
Expand Down
3 changes: 2 additions & 1 deletion .Lib9c.Tests/Action/Scenario/CollectionScenarioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public CollectionScenarioTest()
rankingMapAddress
);
_initialState = _initialState.SetAvatarState(
avatarAddress, avatarState, true, true, true, true);
avatarAddress, avatarState, true, true, true, true)
.SetActionPoint(avatarAddress, DailyReward.ActionPointMax);
}

var currency = Currency.Legacy("NCG", 2, minters: null);
Expand Down
18 changes: 10 additions & 8 deletions .Lib9c.Tests/Action/Scenario/MarketScenarioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ public MarketScenarioTest(ITestOutputHelper outputHelper)
.SetLegacyState(Addresses.GetSheetAddress<ArenaSheet>(), _tableSheets.ArenaSheet.Serialize())
.SetAgentState(_sellerAgentAddress, agentState)
.SetAvatarState(_sellerAvatarAddress, _sellerAvatarState)
.SetActionPoint(_sellerAvatarAddress, DailyReward.ActionPointMax)
.SetAgentState(_sellerAgentAddress2, agentState2)
.SetAvatarState(_sellerAvatarAddress2, _sellerAvatarState2)
.SetActionPoint(_sellerAvatarAddress2, DailyReward.ActionPointMax)
.SetAgentState(_buyerAgentAddress, agentState3)
.SetAvatarState(_buyerAvatarAddress, buyerAvatarState);
}
Expand Down Expand Up @@ -170,7 +172,7 @@ public void Register_And_Buy()
var nextState = action.Execute(ctx);
var nextAvatarState = nextState.GetAvatarState(_sellerAvatarAddress);
Assert.Empty(nextAvatarState.inventory.Items);
Assert.Equal(_gameConfigState.ActionPointMax - RegisterProduct.CostAp, nextAvatarState.actionPoint);
Assert.Equal(DailyReward.ActionPointMax - RegisterProduct.CostAp, nextState.GetActionPoint(_sellerAvatarAddress));

var productsState =
new ProductsState((List)nextState.GetLegacyState(ProductsState.DeriveAddress(_sellerAvatarAddress)));
Expand Down Expand Up @@ -245,7 +247,7 @@ public void Register_And_Buy()
var nextState2 = action2.Execute(ctx);
var nextAvatarState2 = nextState2.GetAvatarState(_sellerAvatarAddress2);
Assert.Empty(nextAvatarState2.inventory.Items);
Assert.Equal(_gameConfigState.ActionPointMax - RegisterProduct.CostAp, nextAvatarState2.actionPoint);
Assert.Equal(DailyReward.ActionPointMax - RegisterProduct.CostAp, nextState2.GetActionPoint(_sellerAvatarAddress2));

var productList2 =
new ProductsState((List)nextState2.GetLegacyState(ProductsState.DeriveAddress(_sellerAvatarAddress2)));
Expand Down Expand Up @@ -404,7 +406,7 @@ public void Register_And_Cancel()

var nextAvatarState = nextState.GetAvatarState(_sellerAvatarAddress);
Assert.Empty(nextAvatarState.inventory.Items);
Assert.Equal(_gameConfigState.ActionPointMax - RegisterProduct.CostAp, nextAvatarState.actionPoint);
Assert.Equal(DailyReward.ActionPointMax - RegisterProduct.CostAp, nextState.GetActionPoint(_sellerAvatarAddress));

var marketState = new MarketState(nextState.GetLegacyState(Addresses.Market));
Assert.Contains(_sellerAvatarAddress, marketState.AvatarAddresses);
Expand Down Expand Up @@ -500,8 +502,8 @@ public void Register_And_Cancel()
}

Assert.Equal(
_gameConfigState.ActionPointMax - RegisterProduct.CostAp - CancelProductRegistration.CostAp,
latestAvatarState.actionPoint);
DailyReward.ActionPointMax - RegisterProduct.CostAp - CancelProductRegistration.CostAp,
latestState.GetActionPoint(_sellerAvatarAddress));

var sellProductList = new ProductsState((List)latestState.GetLegacyState(productsStateAddress));
Assert.Empty(sellProductList.ProductIds);
Expand Down Expand Up @@ -578,7 +580,7 @@ public void Register_And_ReRegister()

var nextAvatarState = nextState.GetAvatarState(_sellerAvatarAddress);
Assert.Empty(nextAvatarState.inventory.Items);
Assert.Equal(_gameConfigState.ActionPointMax - RegisterProduct.CostAp, nextAvatarState.actionPoint);
Assert.Equal(DailyReward.ActionPointMax - RegisterProduct.CostAp, nextState.GetActionPoint(_sellerAvatarAddress));

var marketState = new MarketState(nextState.GetLegacyState(Addresses.Market));
Assert.Contains(_sellerAvatarAddress, marketState.AvatarAddresses);
Expand Down Expand Up @@ -702,7 +704,7 @@ public void Register_And_ReRegister()
var latestState = action2.Execute(ctx);

var latestAvatarState = latestState.GetAvatarState(_sellerAvatarAddress);
Assert.Equal(_gameConfigState.ActionPointMax - RegisterProduct.CostAp - ReRegisterProduct.CostAp, latestAvatarState.actionPoint);
Assert.Equal(DailyReward.ActionPointMax - RegisterProduct.CostAp - ReRegisterProduct.CostAp, latestState.GetActionPoint(_sellerAvatarAddress));
var inventoryItem = Assert.Single(latestAvatarState.inventory.Items);
Assert.Equal(1, inventoryItem.count);
Assert.IsType<TradableMaterial>(inventoryItem.item);
Expand Down Expand Up @@ -838,7 +840,7 @@ public void ReRegister_Order()
}

var nextAvatarState = nextState.GetAvatarState(_sellerAvatarAddress);
Assert.Equal(_gameConfigState.ActionPointMax - ReRegisterProduct.CostAp, nextAvatarState.actionPoint);
Assert.Equal(DailyReward.ActionPointMax - ReRegisterProduct.CostAp, nextState.GetActionPoint(_sellerAvatarAddress));
Assert.Empty(nextAvatarState.inventory.Items);

foreach (var shopAddress in shopAddressList)
Expand Down
3 changes: 2 additions & 1 deletion .Lib9c.Tests/Action/Scenario/RuneScenarioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public void Craft_And_Unlock_And_Equip()
.SetLegacyState(
Addresses.GoldCurrency,
new GoldCurrencyState(Currency.Legacy("NCG", 2, minters: null)).Serialize())
.SetLegacyState(gameConfigState.address, gameConfigState.Serialize());
.SetLegacyState(gameConfigState.address, gameConfigState.Serialize())
.SetActionPoint(avatarAddress, DailyReward.ActionPointMax);
foreach (var (key, value) in sheets)
{
initialState = initialState
Expand Down
1 change: 1 addition & 0 deletions .Lib9c.Tests/Action/Scenario/WorldUnlockScenarioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public WorldUnlockScenarioTest()
.SetLegacyState(_weeklyArenaState.address, _weeklyArenaState.Serialize())
.SetAgentState(_agentAddress, agentState)
.SetAvatarState(_avatarAddress, avatarState)
.SetActionPoint(_avatarAddress, DailyReward.ActionPointMax)
.SetLegacyState(_rankingMapAddress, new RankingMapState(_rankingMapAddress).Serialize())
.SetLegacyState(gameConfigState.address, gameConfigState.Serialize());

Expand Down
3 changes: 2 additions & 1 deletion .Lib9c.Tests/Action/SellCancellationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public SellCancellationTest(ITestOutputHelper outputHelper)
.SetAgentState(_agentAddress, agentState)
.SetLegacyState(Addresses.Shop, new ShopState().Serialize())
.SetLegacyState(Addresses.GameConfig, _gameConfigState.Serialize())
.SetLegacyState(_avatarAddress, MigrationAvatarState.LegacySerializeV1(avatarState));
.SetLegacyState(_avatarAddress, MigrationAvatarState.LegacySerializeV1(avatarState))
.SetActionPoint(_avatarAddress, DailyReward.ActionPointMax);
}

[Theory]
Expand Down

0 comments on commit ec37aad

Please sign in to comment.