Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize QuestReward deserialize #2022

Closed
wants to merge 118 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
f7b857e
Implement methods for ITradableFungibleItem on Inventory
boscohyun Jun 15, 2023
29a71de
Implement some methods of Currencies
boscohyun Jun 15, 2023
eba2211
Implement some methods of AccountStateViewExtensions
boscohyun Jun 15, 2023
a216662
Implement some methods to Addresses
boscohyun Jun 15, 2023
d3ea809
Enable nullable to InvalidActionFieldException
boscohyun Jun 15, 2023
a36f195
Introduce LoadIntoMyGaragesCostSheet
boscohyun Jun 15, 2023
5237347
Introduce FungibleItemGarage
boscohyun Jun 15, 2023
facc056
Introduce some exceptions
boscohyun Jun 15, 2023
a2822f5
Introduce copy constructor of ItemBase and Material
boscohyun Jun 15, 2023
e8d5aa8
Introduce GarageWallet address
boscohyun Jun 15, 2023
f51053c
Introduce LoadIntoMyGarages
boscohyun Jun 15, 2023
a12ecec
Merge pull request #1959 from boscohyun/feature/introduce-load-into-m…
boscohyun Jun 16, 2023
9bce9bf
Introduce DeliverToOthersGarages action
boscohyun Jun 16, 2023
d048138
Merge pull request #1961 from boscohyun/feature/introduce-deliver-to-…
boscohyun Jun 19, 2023
d569453
Introduce UnloadFromMyGarages action
boscohyun Jun 16, 2023
54f7f9c
Merge pull request #1962 from boscohyun/feature/introduce-unload-from…
boscohyun Jun 19, 2023
13060fd
update submodule-updater to bump release/* branches
area363 Jun 22, 2023
ecd0cda
Merge pull request #1978 from area363/update-submodule-updater
area363 Jun 22, 2023
8bd50ad
Merge branch 'development' into 2023q2-iap
boscohyun Jun 22, 2023
988fa1d
Add meta files
boscohyun Jun 22, 2023
7e10195
Bump libplanet to 2.2.0
greymistcube Jun 22, 2023
060e92d
Pass context for states in non-extension methods
greymistcube Jun 22, 2023
68b9b73
Pass dummy context for rest of the code
greymistcube Jun 22, 2023
f610a3d
Merge pull request #1979 from greymistcube/bump/libplanet-to-2.2.0
greymistcube Jun 23, 2023
edee027
Add new column IsEnhanceable to StatBuffSheet
tyrosine1153 Jun 27, 2023
81f5eca
Merge pull request #1981 from planetarium/feature/edit-statbuffsheet
tyrosine1153 Jun 27, 2023
1df2656
Rename garage action interfaces
boscohyun Jun 28, 2023
bdc072d
Change the IUnloadFromMyGarages interface
boscohyun Jun 28, 2023
a420d4b
Use gas in garage actions
boscohyun Jun 28, 2023
3a30699
Merge branch 'development' of github.com:planetarium/lib9c into devel…
ipdae Jun 28, 2023
c4f36de
Merge pull request #1984 from planetarium/development-merge-main
ipdae Jun 28, 2023
9a5b403
Introduce UnloadFromMyGaragesRecipientMail
boscohyun Jun 28, 2023
87e4ef0
Rename Mail.CleanUp2() to CleanUpV1()
boscohyun Jun 28, 2023
964e6af
Send UnloadFromMyGaragesRecipientMail to RecipientAvatarAddr in Unloa…
boscohyun Jun 28, 2023
af36b8e
Merge pull request #1985 from boscohyun/feature/add-mail-in-unload-fr…
boscohyun Jun 28, 2023
f3be4dc
Merge remote-tracking branch 'upstream/development' into 2023q2-iap
boscohyun Jun 30, 2023
5d39b5d
Apply Libplanet changes
boscohyun Jun 30, 2023
575abbd
Fix compile error
boscohyun Jun 30, 2023
2395fe4
Add CODEOWNERS
moreal Jun 30, 2023
331ac67
Merge pull request #1990 from planetarium/codeowners
moreal Jun 30, 2023
2f49a09
Bump libplanet to 2.3.0-candidate
greymistcube Jun 28, 2023
e9b7139
Accommodate libplanet 2.3.0 API changes
greymistcube Jun 28, 2023
dd1319c
Changed snapshot testing
greymistcube Jun 29, 2023
ada0b92
Bump to libplanet 2.3.0
greymistcube Jun 29, 2023
014bff4
Merge pull request #1988 from greymistcube/bump/libplanet-to-2.3.0
greymistcube Jul 3, 2023
bd19d2c
Removed unsupported methods
greymistcube Jul 3, 2023
17dd5bb
Merge pull request #1992 from greymistcube/refactor/remove-unrender
greymistcube Jul 3, 2023
e317aae
Bump libplanet to 2.4.0
greymistcube Jul 4, 2023
37b30ea
Accommodate API changes for libplanet 2.4.0
greymistcube Jul 4, 2023
bf9a70f
Merge pull request #1993 from greymistcube/bump/libplanet-to-2.4.0
greymistcube Jul 4, 2023
a973652
Rewrite attribute checking logic
greymistcube Jul 4, 2023
9e0282e
Merge pull request #1994 from greymistcube/chore/cleanup
greymistcube Jul 4, 2023
5c0faf9
Code cleanup
greymistcube Jul 4, 2023
3d4a94a
Renamed State to MockStateDelta; separated Delta to MockDelta
greymistcube Jul 4, 2023
4177b8e
Merge pull request #1995 from greymistcube/refactor/test-class
greymistcube Jul 4, 2023
c889d66
Introduce MockState
greymistcube Jul 4, 2023
d3f254e
Expose more properties for migration
greymistcube Jul 4, 2023
429bf14
Use MockState for tests
greymistcube Jul 4, 2023
dd9c1b2
Make `ITradableFungibleItem` to `IFungibleItem` on `UnloadFromMyGarag…
boscohyun Jul 4, 2023
86982dd
Merge pull request #1996 from greymistcube/feature/mock-state
greymistcube Jul 4, 2023
f2e1c33
Backup CreateAvatar8
ipdae Jul 3, 2023
1f69041
Increase mint crystal 50 -> 600_000
ipdae Jul 3, 2023
1095da2
Fix broken build
ipdae Jul 6, 2023
6f19462
Merge pull request #1991 from planetarium/improve/20230710-create-avatar
ipdae Jul 6, 2023
9cb4127
Modernize MockStateDelta
greymistcube Jul 4, 2023
f87093e
Merge pull request #1997 from greymistcube/refactor/update-mock-state…
greymistcube Jul 6, 2023
390ca4e
Do not wipe out empty garage to null
U-lis Jul 7, 2023
8a031d5
Merge pull request #1998 from U-lis/2023q2-iap
U-lis Jul 7, 2023
7668b4b
fix: delete `CostKind` column
boscohyun Jul 7, 2023
bd90fd5
Merge pull request #2001 from boscohyun/fix/delete-column
boscohyun Jul 7, 2023
c9796a6
Merge branch 'development' into 2023q2-iap
U-lis Jul 10, 2023
279314a
Apply Libplanet changes
U-lis Jul 10, 2023
e84a8f0
Merge pull request #2003 from planetarium/2023q2-iap
U-lis Jul 10, 2023
3f2bf5c
fix: apply Libplanet changes inside of `UNITY_EDITOR` constants
boscohyun Jul 10, 2023
4ddf794
Merge pull request #2005 from boscohyun/fix-compile-errors-in-unity-e…
boscohyun Jul 10, 2023
2e2f283
ci: Apply auto find options
Atralupus Jul 10, 2023
1614fa1
fix typo
Atralupus Jul 10, 2023
95c50f1
Merge pull request #2006 from Atralupus/ci/auto-find-release-branch
Atralupus Jul 10, 2023
4cd0657
Merge branch 'release/0.2.1' into merge-into-development
boscohyun Jul 11, 2023
852aba9
clean: replace to explicit class
boscohyun Jul 11, 2023
ea9648c
fix: apply new interface
boscohyun Jul 11, 2023
23e4eda
Merge pull request #2011 from boscohyun/merge-into-development
boscohyun Jul 11, 2023
e44722b
Implement delta
greymistcube Jul 12, 2023
9edcb30
Merge pull request #2014 from greymistcube/fix/formatters-accountstat…
greymistcube Jul 12, 2023
94468db
Fix crystal mint
ipdae Jul 13, 2023
8ad1d90
Merge pull request #2016 from planetarium/bugfix/create-avatar-crystal
ipdae Jul 13, 2023
97476b3
Bump libplanet to 2.4.1
greymistcube Jul 14, 2023
32a2c7d
Merge pull request #2019 from greymistcube/bump/libplanet-to-2.4.1
greymistcube Jul 17, 2023
991be39
Set obsolete create_avatar8
ipdae Jul 17, 2023
69f8f30
fix: mail type of `UnloadFromMyGaragesRecipientMail` to `Auction`
boscohyun Jul 17, 2023
0fe2f9f
Merge pull request #2020 from planetarium/obsolete-create-avatar-8
ipdae Jul 17, 2023
ddb70d8
Merge pull request #2021 from boscohyun/fix/mail-type-of-unloadfrommy…
boscohyun Jul 18, 2023
f76932c
Merge pull request #2018 from planetarium/improve/has-execute
U-lis Jul 19, 2023
7f72ea1
Merge pull request #2025 from planetarium/release/0.3.0
sonohoshi Jul 19, 2023
59d00ff
Clone skill target in buff, heal
ipdae Jul 20, 2023
de50ac0
Fix missing log event
ipdae Jul 20, 2023
66b96ea
Optimize QuestReward deserialize
ipdae Jul 18, 2023
3894266
Lazyload mail
ipdae Jul 19, 2023
e0d3a96
Fix QuestReward
ipdae Jul 19, 2023
3cac72d
Delete legacy BinaryFormatter test
ipdae Jul 19, 2023
44f61df
Fix mail lazyload
ipdae Jul 19, 2023
8dcadc4
Lazyload quest
ipdae Jul 21, 2023
2dc4313
Lazyload combination quests
ipdae Jul 21, 2023
04fa1a9
Lazyload market quest
ipdae Jul 21, 2023
87a5899
Lazyload item enhancement quest
ipdae Jul 21, 2023
0b3eadb
Lazyload ItemBase
ipdae Jul 21, 2023
0c3c971
Lazyload ItemUsable
ipdae Jul 21, 2023
4ab3207
Fix Typo
ipdae Jul 21, 2023
c543f7e
Fix InvalidBlockStateRootHashException
ipdae Jul 25, 2023
fdfd4b9
Log HAS Playcount, Remove Debug log
sky1045 Jul 25, 2023
e82b0a2
Remove invalid state exception logging from AccountStateExtensions
sky1045 Jul 25, 2023
8c2e1f8
Fix playcount log level
sky1045 Jul 25, 2023
61482df
Merge pull request #2032 from planetarium/feature/has_playcount
sky1045 Jul 25, 2023
eb4826c
HAS break down
ipdae Jul 25, 2023
5a32043
Fix elapsed format
ipdae Jul 25, 2023
9e5625e
Add blockindex to has total log
sky1045 Jul 26, 2023
f0be8cb
Add blockIndex to all HAS log
sky1045 Jul 27, 2023
30e6af4
Merge pull request #2034 from planetarium/fix/has-log-blockindex
sky1045 Jul 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 5 additions & 7 deletions .Lib9c.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,10 @@ bool buildStateReferences
)
{
IImmutableSet<Address> stateUpdatedAddresses = actionEvaluations
.SelectMany(a => a.OutputStates.StateUpdatedAddresses)
.SelectMany(a => a.OutputState.Delta.StateUpdatedAddresses)
.ToImmutableHashSet();
IImmutableSet<(Address, Currency)> updatedFungibleAssets = actionEvaluations
.SelectMany(a => a.OutputStates.UpdatedFungibleAssets
.SelectMany(kv => kv.Value.Select(c => (kv.Key, c))))
.SelectMany(a => a.OutputState.Delta.UpdatedFungibleAssets)
.ToImmutableHashSet();

if (!stateStore.ContainsStateRoot(block.StateRootHash))
Expand All @@ -185,15 +184,14 @@ private static ImmutableDictionary<string, IValue> GetTotalDelta(
Func<(Address, Currency), string> toFungibleAssetKey)
{
IImmutableSet<Address> stateUpdatedAddresses = actionEvaluations
.SelectMany(a => a.OutputStates.StateUpdatedAddresses)
.SelectMany(a => a.OutputState.Delta.StateUpdatedAddresses)
.ToImmutableHashSet();
IImmutableSet<(Address, Currency)> updatedFungibleAssets = actionEvaluations
.SelectMany(a => a.OutputStates.UpdatedFungibleAssets
.SelectMany(kv => kv.Value.Select(c => (kv.Key, c))))
.SelectMany(a => a.OutputState.Delta.UpdatedFungibleAssets)
.ToImmutableHashSet();

IAccountStateDelta lastStates = actionEvaluations.Count > 0
? actionEvaluations[actionEvaluations.Count - 1].OutputStates
? actionEvaluations[actionEvaluations.Count - 1].OutputState
: null;
ImmutableDictionary<string, IValue> totalDelta =
stateUpdatedAddresses.ToImmutableDictionary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void StageUnlockTest(string typeIdentifier, int expectedStage)

var state = action.Execute(new ActionContext
{
PreviousStates = _initialStateV2,
PreviousState = _initialStateV2,
Signer = _agentAddress,
BlockIndex = 0L
});
Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.DevExtensions.Tests/Action/Craft/UnlockRecipeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void UnlockRecipeTest_Equipment(ItemSubType targetType)

var stateV2 = action.Execute(new ActionContext
{
PreviousStates = _initialStateV2,
PreviousState = _initialStateV2,
Signer = _agentAddress,
BlockIndex = 0L,
});
Expand Down Expand Up @@ -91,7 +91,7 @@ public void UnlockRecipeTest_Consumable(ItemSubType targetType)

var stateV2 = action.Execute(new ActionContext
{
PreviousStates = _initialStateV2,
PreviousState = _initialStateV2,
Signer = _agentAddress,
BlockIndex = 0L,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class CreateOrReplaceAvatarTest

public CreateOrReplaceAvatarTest()
{
_initialStates = new Lib9c.Tests.Action.State();
_initialStates = new Lib9c.Tests.Action.MockStateDelta();

#pragma warning disable CS0618
var ncgCurrency = Currency.Legacy("NCG", 2, null);
Expand Down Expand Up @@ -443,7 +443,7 @@ private static void Execute(
crystalRandomBuff);
var nextStates = action.Execute(new ActionContext
{
PreviousStates = previousStates,
PreviousState = previousStates,
Signer = agentAddr,
Random = new TestRandom(),
Rehearsal = false,
Expand Down
9 changes: 4 additions & 5 deletions .Lib9c.DevExtensions.Tests/Action/FaucetCurrencyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ public FaucetCurrencyTest(ITestOutputHelper outputHelper)
_crystal = Currency.Legacy("CRYSTAL", 18, null);
#pragma warning restore CS0618

var balance =
ImmutableDictionary<(Address Address, Currency Currency), FungibleAssetValue>.Empty
.Add((GoldCurrencyState.Address, _ncg), _ncg * int.MaxValue);
_initialState = new Lib9c.Tests.Action.State(balance: balance);
_initialState = new MockStateDelta(
MockState.Empty
.AddBalance(GoldCurrencyState.Address, _ncg * int.MaxValue));

var goldCurrencyState = new GoldCurrencyState(_ncg);
_agentAddress = new PrivateKey().ToAddress();
Expand Down Expand Up @@ -67,7 +66,7 @@ int expectedCrystal
FaucetNcg = faucetNcg,
FaucetCrystal = faucetCrystal,
};
var state = action.Execute(new ActionContext { PreviousStates = _initialState });
var state = action.Execute(new ActionContext { PreviousState = _initialState });
AgentState agentState = state.GetAgentState(_agentAddress);
FungibleAssetValue expectedNcgAsset =
new FungibleAssetValue(_ncg, expectedNcg, 0);
Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.DevExtensions.Tests/Action/FaucetRuneTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public FaucetRuneTest(ITestOutputHelper outputHelper)
.WriteTo.TestOutput(outputHelper)
.CreateLogger();

_initialState = new Lib9c.Tests.Action.State();
_initialState = new Lib9c.Tests.Action.MockStateDelta();
var sheets = TableSheetsImporter.ImportSheets();
foreach (var (key, value) in sheets)
{
Expand Down Expand Up @@ -86,7 +86,7 @@ public void Execute_FaucetRune(List<FaucetRuneInfo> faucetRuneInfos)
AvatarAddress = _avatarAddress,
FaucetRuneInfos = faucetRuneInfos,
};
var states = action.Execute(new ActionContext { PreviousStates = _initialState });
var states = action.Execute(new ActionContext { PreviousState = _initialState });
foreach (var rune in faucetRuneInfos)
{
var expectedRune = RuneHelper.ToCurrency(
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.DevExtensions.Tests/Action/ManipulateStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ private IAccountStateDelta Manipulate(

return action.Execute(new ActionContext
{
PreviousStates = state,
PreviousState = state,
Signer = _agentAddress,
BlockIndex = int.MaxValue / 2
});
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.DevExtensions.Tests/Action/Stage/ClearStageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void ClearStage()

var state = action.Execute(new ActionContext
{
PreviousStates = _initialStateV2,
PreviousState = _initialStateV2,
Signer = _agentAddress,
BlockIndex = 0L,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void LoadPlainValue(IValue plainValue)
public IAccountStateDelta Execute(IActionContext context)
{
context.UseGas(1);
return context.PreviousStates;
return context.PreviousState;
}
}

Expand Down
17 changes: 10 additions & 7 deletions .Lib9c.Tests/Action/AccountStateDeltaExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public AccountStateDeltaExtensionsTest()
[InlineData(2, 2, 200, null)]
public void SetWorldBossKillReward(int level, int expectedRune, int expectedCrystal, Type exc)
{
IAccountStateDelta states = new State();
var context = new ActionContext();
IAccountStateDelta states = new MockStateDelta();
var rewardInfoAddress = new PrivateKey().ToAddress();
var rewardRecord = new WorldBossKillRewardRecord();
for (int i = 0; i < level; i++)
Expand Down Expand Up @@ -76,7 +77,7 @@ public void SetWorldBossKillReward(int level, int expectedRune, int expectedCrys

if (exc is null)
{
var nextState = states.SetWorldBossKillReward(rewardInfoAddress, rewardRecord, 0, bossState, runeWeightSheet, killRewardSheet, runeSheet, random, avatarAddress, _agentAddress);
var nextState = states.SetWorldBossKillReward(context, rewardInfoAddress, rewardRecord, 0, bossState, runeWeightSheet, killRewardSheet, runeSheet, random, avatarAddress, _agentAddress);
Assert.Equal(expectedRune * runeCurrency, nextState.GetBalance(avatarAddress, runeCurrency));
Assert.Equal(expectedCrystal * CrystalCalculator.CRYSTAL, nextState.GetBalance(_agentAddress, CrystalCalculator.CRYSTAL));
var nextRewardInfo = new WorldBossKillRewardRecord((List)nextState.GetState(rewardInfoAddress));
Expand All @@ -87,6 +88,7 @@ public void SetWorldBossKillReward(int level, int expectedRune, int expectedCrys
Assert.Throws(
exc,
() => states.SetWorldBossKillReward(
context,
rewardInfoAddress,
rewardRecord,
0,
Expand All @@ -104,7 +106,7 @@ public void SetWorldBossKillReward(int level, int expectedRune, int expectedCrys
[Fact]
public void SetCouponWallet()
{
IAccountStateDelta states = new State();
IAccountStateDelta states = new MockStateDelta();
var guid1 = new Guid("6856AE42-A820-4041-92B0-5D7BAA52F2AA");
var guid2 = new Guid("701BA698-CCB9-4FC7-B88F-7CB8C707D135");
var guid3 = new Guid("910296E7-34E4-45D7-9B4E-778ED61F278B");
Expand Down Expand Up @@ -166,18 +168,19 @@ public void Mead(int agentBalance)
var agentContractAddress = _agentAddress.GetPledgeAddress();
var mead = Currencies.Mead;
var price = RequestPledge.DefaultRefillMead * mead;
IAccountStateDelta states = new State()
ActionContext context = new ActionContext();
IAccountStateDelta states = new MockStateDelta()
.SetState(
agentContractAddress,
List.Empty.Add(patron.Serialize()).Add(true.Serialize()))
.MintAsset(patron, price);
.MintAsset(context, patron, price);

if (agentBalance > 0)
{
states = states.MintAsset(_agentAddress, agentBalance * mead);
states = states.MintAsset(context, _agentAddress, agentBalance * mead);
}

states = states.Mead(_agentAddress, 4);
states = states.Mead(context, _agentAddress, 4);
Assert.Equal(agentBalance * mead, states.GetBalance(patron, mead));
Assert.Equal(price, states.GetBalance(_agentAddress, mead));
}
Expand Down
46 changes: 23 additions & 23 deletions .Lib9c.Tests/Action/AccountStateViewExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public AccountStateViewExtensionsTest()
[Fact]
public void TryGetAvatarState()
{
var states = new State();
states = (State)states.SetState(_avatarAddress, _avatarState.Serialize());
var states = new MockStateDelta();
states = (MockStateDelta)states.SetState(_avatarAddress, _avatarState.Serialize());

Assert.True(states.TryGetAvatarState(_agentAddress, _avatarAddress, out var avatarState2));
Assert.Equal(_avatarAddress, avatarState2.address);
Expand All @@ -60,23 +60,23 @@ public void TryGetAvatarState()
[Fact]
public void TryGetAvatarStateEmptyAddress()
{
var states = new State();
var states = new MockStateDelta();

Assert.False(states.TryGetAvatarState(default, default, out _));
}

[Fact]
public void TryGetAvatarStateAddressKeyNotFoundException()
{
var states = new State().SetState(default, Dictionary.Empty);
var states = new MockStateDelta().SetState(default, Dictionary.Empty);

Assert.False(states.TryGetAvatarState(default, default, out _));
}

[Fact]
public void TryGetAvatarStateKeyNotFoundException()
{
var states = new State()
var states = new MockStateDelta()
.SetState(
default,
Dictionary.Empty
Expand All @@ -89,24 +89,24 @@ public void TryGetAvatarStateKeyNotFoundException()
[Fact]
public void TryGetAvatarStateInvalidCastException()
{
var states = new State().SetState(default, default(Text));
var states = new MockStateDelta().SetState(default, default(Text));

Assert.False(states.TryGetAvatarState(default, default, out _));
}

[Fact]
public void TryGetAvatarStateInvalidAddress()
{
var states = new State().SetState(default, _avatarState.Serialize());
var states = new MockStateDelta().SetState(default, _avatarState.Serialize());

Assert.False(states.TryGetAvatarState(Addresses.GameConfig, _avatarAddress, out _));
}

[Fact]
public void GetAvatarStateV2()
{
var states = new State();
states = (State)states
var states = new MockStateDelta();
states = (MockStateDelta)states
.SetState(_avatarAddress, _avatarState.SerializeV2())
.SetState(_avatarAddress.Derive(LegacyInventoryKey), _avatarState.inventory.Serialize())
.SetState(_avatarAddress.Derive(LegacyWorldInformationKey), _avatarState.worldInformation.Serialize())
Expand All @@ -124,13 +124,13 @@ public void GetAvatarStateV2()
[InlineData(LegacyQuestListKey)]
public void GetAvatarStateV2_Throw_FailedLoadStateException(string key)
{
var states = new State();
states = (State)states
var states = new MockStateDelta();
states = (MockStateDelta)states
.SetState(_avatarAddress, _avatarState.SerializeV2())
.SetState(_avatarAddress.Derive(LegacyInventoryKey), _avatarState.inventory.Serialize())
.SetState(_avatarAddress.Derive(LegacyWorldInformationKey), _avatarState.worldInformation.Serialize())
.SetState(_avatarAddress.Derive(LegacyQuestListKey), _avatarState.questList.Serialize());
states = (State)states.SetState(_avatarAddress.Derive(key), null);
states = (MockStateDelta)states.SetState(_avatarAddress.Derive(key), null);
var exc = Assert.Throws<FailedLoadStateException>(() => states.GetAvatarStateV2(_avatarAddress));
Assert.Contains(key, exc.Message);
}
Expand All @@ -140,15 +140,15 @@ public void GetAvatarStateV2_Throw_FailedLoadStateException(string key)
[InlineData(false)]
public void TryGetAvatarStateV2(bool backward)
{
var states = new State();
var states = new MockStateDelta();
if (backward)
{
states = (State)states
states = (MockStateDelta)states
.SetState(_avatarAddress, _avatarState.Serialize());
}
else
{
states = (State)states
states = (MockStateDelta)states
.SetState(_avatarAddress, _avatarState.SerializeV2())
.SetState(_avatarAddress.Derive(LegacyInventoryKey), _avatarState.inventory.Serialize())
.SetState(_avatarAddress.Derive(LegacyWorldInformationKey), _avatarState.worldInformation.Serialize())
Expand All @@ -164,16 +164,16 @@ public void TryGetAvatarStateV2(bool backward)
[InlineData(false)]
public void TryGetAgentAvatarStatesV2(bool backward)
{
var states = new State().SetState(_agentAddress, _agentState.Serialize());
var states = new MockStateDelta().SetState(_agentAddress, _agentState.Serialize());

if (backward)
{
states = (State)states
states = (MockStateDelta)states
.SetState(_avatarAddress, _avatarState.Serialize());
}
else
{
states = (State)states
states = (MockStateDelta)states
.SetState(_avatarAddress, _avatarState.SerializeV2())
.SetState(_avatarAddress.Derive(LegacyInventoryKey), _avatarState.inventory.Serialize())
.SetState(_avatarAddress.Derive(LegacyWorldInformationKey), _avatarState.worldInformation.Serialize())
Expand All @@ -187,7 +187,7 @@ public void TryGetAgentAvatarStatesV2(bool backward)
[Fact]
public void GetStatesAsDict()
{
IAccountStateDelta states = new State();
IAccountStateDelta states = new MockStateDelta();
var dict = new Dictionary<Address, IValue>
{
{ new PrivateKey().ToAddress(), Null.Value },
Expand All @@ -214,7 +214,7 @@ public void GetStatesAsDict()
[Fact]
public void GetSheets()
{
IAccountStateDelta states = new State();
IAccountStateDelta states = new MockStateDelta();
SheetsExtensionsTest.InitSheets(
states,
out _,
Expand All @@ -241,7 +241,7 @@ public void GetSheets()
[InlineData(true)]
public void GetCrystalCostState(bool exist)
{
IAccountStateDelta state = new State();
IAccountStateDelta state = new MockStateDelta();
int expectedCount = exist ? 1 : 0;
FungibleAssetValue expectedCrystal = exist
? 100 * CrystalCalculator.CRYSTAL
Expand Down Expand Up @@ -274,7 +274,7 @@ public void GetCrystalCostStates(long blockIndex, bool previousWeeklyExist)
Address previousCostAddress = Addresses.GetWeeklyCrystalCostAddress(weeklyIndex - 1);
Address beforePreviousCostAddress = Addresses.GetWeeklyCrystalCostAddress(weeklyIndex - 2);
var crystalCostState = new CrystalCostState(default, 100 * CrystalCalculator.CRYSTAL);
IAccountStateDelta state = new State()
IAccountStateDelta state = new MockStateDelta()
.SetState(dailyCostAddress, crystalCostState.Serialize())
.SetState(weeklyCostAddress, crystalCostState.Serialize())
.SetState(previousCostAddress, crystalCostState.Serialize())
Expand Down Expand Up @@ -304,7 +304,7 @@ public void GetCrystalCostStates(long blockIndex, bool previousWeeklyExist)
[Fact]
public void GetCouponWallet()
{
IAccountStateDelta states = new State();
IAccountStateDelta states = new MockStateDelta();
var guid1 = new Guid("6856AE42-A820-4041-92B0-5D7BAA52F2AA");
var guid2 = new Guid("701BA698-CCB9-4FC7-B88F-7CB8C707D135");
var guid3 = new Guid("910296E7-34E4-45D7-9B4E-778ED61F278B");
Expand Down
7 changes: 5 additions & 2 deletions .Lib9c.Tests/Action/ActionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public class ActionContext : IActionContext

public long BlockIndex { get; set; }

public int BlockProtocolVersion { get; set; }

public bool Rehearsal { get; set; }

public IAccountStateDelta PreviousStates { get; set; }
public IAccountStateDelta PreviousState { get; set; }

public IRandom Random { get; set; }

Expand All @@ -51,8 +53,9 @@ public IActionContext GetUnconsumedContext()
Miner = Miner,
BlockHash = BlockHash,
BlockIndex = BlockIndex,
BlockProtocolVersion = BlockProtocolVersion,
Rehearsal = Rehearsal,
PreviousStates = PreviousStates,
PreviousState = PreviousState,
Random = Random,
PreviousStateRootHash = PreviousStateRootHash,
};
Expand Down
Loading
Loading