Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

Commit

Permalink
fix: Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
upa-r-upa committed Mar 18, 2024
1 parent 7acd872 commit 03c303d
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 291 deletions.
2 changes: 1 addition & 1 deletion backend/app/Savor22b.Tests/Action/CancelFoodActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class CancelFoodActionTests : ActionTests

RootState beforeRootState = new RootState(
beforeInventoryState,
new DungeonState(),
new UserDungeonState(),
new VillageState(new HouseState(1, 1, 1, beforeKitchenState))
);

Expand Down
2 changes: 1 addition & 1 deletion backend/app/Savor22b.Tests/Action/CreateFoodActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ ImmutableList<int> FoodIDList

RootState rootState = new RootState(
inventoryState,
new DungeonState(),
new UserDungeonState(),
new VillageState(new HouseState(1, 1, 1, resultKitchenState))
);

Expand Down
100 changes: 37 additions & 63 deletions backend/app/Savor22b.Tests/Action/HarvestingSeedActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,39 @@ namespace Savor22b.Tests.Action;

public class HarvestingSeedActionTests : ActionTests
{

public HarvestingSeedActionTests()
{
}
public HarvestingSeedActionTests() { }

[Fact]
public void Execute_Success_Normal()
{
IAccountStateDelta beforeState = new DummyState();
RootState beforeRootState = new RootState(
new InventoryState(),
new DungeonState(),
new VillageState(
new HouseState(
1, 1, 1, new KitchenState()
)
)
new UserDungeonState(),
new VillageState(new HouseState(1, 1, 1, new KitchenState()))
);

beforeRootState.VillageState!.UpdateHouseFieldState(0, new HouseFieldState(
Guid.NewGuid(),
1,
1,
5
));

beforeState = beforeState.SetState(
SignerAddress(),
beforeRootState.Serialize()
beforeRootState.VillageState!.UpdateHouseFieldState(
0,
new HouseFieldState(Guid.NewGuid(), 1, 1, 5)
);

beforeState = beforeState.SetState(SignerAddress(), beforeRootState.Serialize());

var random = new DummyRandom(1);
HarvestingSeedAction action = new HarvestingSeedAction(
0,
Guid.NewGuid()
HarvestingSeedAction action = new HarvestingSeedAction(0, Guid.NewGuid());

IAccountStateDelta state = action.Execute(
new DummyActionContext
{
PreviousStates = beforeState,
Signer = SignerAddress(),
Random = random,
Rehearsal = false,
BlockIndex = 6,
}
);

IAccountStateDelta state = action.Execute(new DummyActionContext
{
PreviousStates = beforeState,
Signer = SignerAddress(),
Random = random,
Rehearsal = false,
BlockIndex = 6,
});

var rootStateEncoded = state.GetState(SignerAddress());

RootState rootState = rootStateEncoded is Bencodex.Types.Dictionary bdict
Expand All @@ -64,50 +51,37 @@ public void Execute_Success_Normal()
Assert.Equal(1, rootState.InventoryState.RefrigeratorStateList.Count);
}


[Fact]
public void Execute_Success_AfterRemoveWeed()
{
IAccountStateDelta beforeState = new DummyState();
RootState beforeRootState = new RootState(
new InventoryState(),
new DungeonState(),
new VillageState(
new HouseState(
1, 1, 1, new KitchenState()
)
)
new UserDungeonState(),
new VillageState(new HouseState(1, 1, 1, new KitchenState()))
);

beforeRootState.VillageState!.UpdateHouseFieldState(0, new HouseFieldState(
Guid.NewGuid(),
1,
1,
10,
4,
1
));

beforeState = beforeState.SetState(
SignerAddress(),
beforeRootState.Serialize()
beforeRootState.VillageState!.UpdateHouseFieldState(
0,
new HouseFieldState(Guid.NewGuid(), 1, 1, 10, 4, 1)
);

beforeState = beforeState.SetState(SignerAddress(), beforeRootState.Serialize());

var random = new DummyRandom(1);
HarvestingSeedAction action = new HarvestingSeedAction(
0,
Guid.NewGuid()
HarvestingSeedAction action = new HarvestingSeedAction(0, Guid.NewGuid());

IAccountStateDelta state = action.Execute(
new DummyActionContext
{
PreviousStates = beforeState,
Signer = SignerAddress(),
Random = random,
Rehearsal = false,
BlockIndex = 10,
}
);

IAccountStateDelta state = action.Execute(new DummyActionContext
{
PreviousStates = beforeState,
Signer = SignerAddress(),
Random = random,
Rehearsal = false,
BlockIndex = 10,
});

var rootStateEncoded = state.GetState(SignerAddress());

RootState rootState = rootStateEncoded is Bencodex.Types.Dictionary bdict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ namespace Savor22b.Tests.Action;

public class InstallKitchenEquipmentActionTests : ActionTests
{
public InstallKitchenEquipmentActionTests()
{
}
public InstallKitchenEquipmentActionTests() { }

[Theory]
[InlineData(1)]
Expand All @@ -27,32 +25,32 @@ public void Execute_Success_NormalCase(int spaceNumber)
new InventoryState(
ImmutableList<SeedState>.Empty,
ImmutableList<RefrigeratorState>.Empty,
ImmutableList<KitchenEquipmentState>.Empty.Add(new KitchenEquipmentState(Guid.NewGuid(), 1, 1)),
ImmutableList<KitchenEquipmentState>.Empty.Add(
new KitchenEquipmentState(Guid.NewGuid(), 1, 1)
),
ImmutableList<ItemState>.Empty
),
new DungeonState(),
new VillageState(
new HouseState(
1, 1, 1, new KitchenState()
)
)
new UserDungeonState(),
new VillageState(new HouseState(1, 1, 1, new KitchenState()))
);

beforeState = beforeState.SetState(
SignerAddress(),
beforeRootState.Serialize()
);
beforeState = beforeState.SetState(SignerAddress(), beforeRootState.Serialize());

var action = new InstallKitchenEquipmentAction(beforeRootState.InventoryState.KitchenEquipmentStateList[0].StateID, spaceNumber);
var action = new InstallKitchenEquipmentAction(
beforeRootState.InventoryState.KitchenEquipmentStateList[0].StateID,
spaceNumber
);

var afterState = action.Execute(new DummyActionContext
{
PreviousStates = beforeState,
Signer = SignerAddress(),
Random = random,
Rehearsal = false,
BlockIndex = 1,
});
var afterState = action.Execute(
new DummyActionContext
{
PreviousStates = beforeState,
Signer = SignerAddress(),
Random = random,
Rehearsal = false,
BlockIndex = 1,
}
);

var afterRootStateEncoded = afterState.GetState(SignerAddress());
RootState afterRootState = afterRootStateEncoded is Bencodex.Types.Dictionary bdict
Expand All @@ -62,25 +60,44 @@ public void Execute_Success_NormalCase(int spaceNumber)
Assert.Single(afterRootState.InventoryState.KitchenEquipmentStateList);
Assert.Equal(
beforeRootState.InventoryState.KitchenEquipmentStateList[0].StateID,
afterRootState.InventoryState.KitchenEquipmentStateList[0].StateID);
afterRootState.InventoryState.KitchenEquipmentStateList[0].StateID
);

if (spaceNumber == 1)
{
Assert.Equal(
beforeRootState.InventoryState.KitchenEquipmentStateList[0].StateID,
afterRootState.VillageState!.HouseState.KitchenState.FirstApplianceSpace.InstalledKitchenEquipmentStateId);
afterRootState
.VillageState!
.HouseState
.KitchenState
.FirstApplianceSpace
.InstalledKitchenEquipmentStateId
);
}
else if (spaceNumber == 2)
{
Assert.Equal(
beforeRootState.InventoryState.KitchenEquipmentStateList[0].StateID,
afterRootState.VillageState!.HouseState.KitchenState.SecondApplianceSpace.InstalledKitchenEquipmentStateId);
afterRootState
.VillageState!
.HouseState
.KitchenState
.SecondApplianceSpace
.InstalledKitchenEquipmentStateId
);
}
else if (spaceNumber == 3)
{
Assert.Equal(
beforeRootState.InventoryState.KitchenEquipmentStateList[0].StateID,
afterRootState.VillageState!.HouseState.KitchenState.ThirdApplianceSpace.InstalledKitchenEquipmentStateId);
afterRootState
.VillageState!
.HouseState
.KitchenState
.ThirdApplianceSpace
.InstalledKitchenEquipmentStateId
);
}
else
{
Expand All @@ -100,31 +117,26 @@ public void Execute_Failure_NotHaveKitchenEquipment()
ImmutableList<KitchenEquipmentState>.Empty,
ImmutableList<ItemState>.Empty
),
new DungeonState(),
new VillageState(
new HouseState(
1, 1, 1, new KitchenState()
)
)
new UserDungeonState(),
new VillageState(new HouseState(1, 1, 1, new KitchenState()))
);

beforeState = beforeState.SetState(
SignerAddress(),
beforeRootState.Serialize()
);
beforeState = beforeState.SetState(SignerAddress(), beforeRootState.Serialize());

var action = new InstallKitchenEquipmentAction(Guid.NewGuid(), 1);

Assert.Throws<NotHaveRequiredException>(() =>
{
action.Execute(new DummyActionContext
{
PreviousStates = beforeState,
Signer = SignerAddress(),
Random = random,
Rehearsal = false,
BlockIndex = 1,
});
action.Execute(
new DummyActionContext
{
PreviousStates = beforeState,
Signer = SignerAddress(),
Random = random,
Rehearsal = false,
BlockIndex = 1,
}
);
});
}

Expand All @@ -140,27 +152,26 @@ public void Execute_Failure_NotPlacedHouse()
ImmutableList<KitchenEquipmentState>.Empty,
ImmutableList<ItemState>.Empty
),
new DungeonState(),
new UserDungeonState(),
null
);

beforeState = beforeState.SetState(
SignerAddress(),
beforeRootState.Serialize()
);
beforeState = beforeState.SetState(SignerAddress(), beforeRootState.Serialize());

var action = new InstallKitchenEquipmentAction(Guid.NewGuid(), 1);

Assert.Throws<InvalidVillageStateException>(() =>
{
action.Execute(new DummyActionContext
{
PreviousStates = beforeState,
Signer = SignerAddress(),
Random = random,
Rehearsal = false,
BlockIndex = 1,
});
action.Execute(
new DummyActionContext
{
PreviousStates = beforeState,
Signer = SignerAddress(),
Random = random,
Rehearsal = false,
BlockIndex = 1,
}
);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ private IAccountStateDelta createStateForRelocationHouse()
prevGlobalUserHouseState.UserHouse.Add("1,0,0", SignerAddress());

VillageState villageState = new VillageState(new HouseState(1, 0, 0, new KitchenState()));
RootState prevRootState = new RootState(new InventoryState(), new DungeonState(), villageState);
RootState prevRootState = new RootState(
new InventoryState(),
new UserDungeonState(),
villageState
);

state = state.MintAsset(
SignerAddress(),
Expand Down Expand Up @@ -141,7 +145,7 @@ private IAccountStateDelta createStateForInProgressReplaceHouse()
VillageState villageState = new VillageState(new HouseState(1, 0, 0, new KitchenState()));
RootState prevRootState = new RootState(
new InventoryState(),
new DungeonState(),
new UserDungeonState(),
villageState,
new RelocationState(1, 90, 1, 0, 0)
);
Expand Down
Loading

0 comments on commit 03c303d

Please sign in to comment.