Skip to content

Commit

Permalink
Renamed State to StateDelta; separated Delta
Browse files Browse the repository at this point in the history
  • Loading branch information
greymistcube committed Jul 4, 2023
1 parent 5c0faf9 commit 405717b
Show file tree
Hide file tree
Showing 269 changed files with 727 additions and 710 deletions.
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.StateDelta();

#pragma warning disable CS0618
var ncgCurrency = Currency.Legacy("NCG", 2, null);
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.DevExtensions.Tests/Action/FaucetCurrencyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public FaucetCurrencyTest(ITestOutputHelper outputHelper)
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 Lib9c.Tests.Action.StateDelta(balances: balance);

var goldCurrencyState = new GoldCurrencyState(_ncg);
_agentAddress = new PrivateKey().ToAddress();
Expand Down
2 changes: 1 addition & 1 deletion .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.StateDelta();
var sheets = TableSheetsImporter.ImportSheets();
foreach (var (key, value) in sheets)
{
Expand Down
6 changes: 3 additions & 3 deletions .Lib9c.Tests/Action/AccountStateDeltaExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public AccountStateDeltaExtensionsTest()
public void SetWorldBossKillReward(int level, int expectedRune, int expectedCrystal, Type exc)
{
var context = new ActionContext();
IAccountStateDelta states = new State();
IAccountStateDelta states = new StateDelta();
var rewardInfoAddress = new PrivateKey().ToAddress();
var rewardRecord = new WorldBossKillRewardRecord();
for (int i = 0; i < level; i++)
Expand Down Expand Up @@ -106,7 +106,7 @@ public void SetWorldBossKillReward(int level, int expectedRune, int expectedCrys
[Fact]
public void SetCouponWallet()
{
IAccountStateDelta states = new State();
IAccountStateDelta states = new StateDelta();
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 @@ -169,7 +169,7 @@ public void Mead(int agentBalance)
var mead = Currencies.Mead;
var price = RequestPledge.DefaultRefillMead * mead;
ActionContext context = new ActionContext();
IAccountStateDelta states = new State()
IAccountStateDelta states = new StateDelta()
.SetState(
agentContractAddress,
List.Empty.Add(patron.Serialize()).Add(true.Serialize()))
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 StateDelta();
states = (StateDelta)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 StateDelta();

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

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

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

[Fact]
public void TryGetAvatarStateKeyNotFoundException()
{
var states = new State()
var states = new StateDelta()
.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 StateDelta().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 StateDelta().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 StateDelta();
states = (StateDelta)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 StateDelta();
states = (StateDelta)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 = (StateDelta)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 StateDelta();
if (backward)
{
states = (State)states
states = (StateDelta)states
.SetState(_avatarAddress, _avatarState.Serialize());
}
else
{
states = (State)states
states = (StateDelta)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 StateDelta().SetState(_agentAddress, _agentState.Serialize());

if (backward)
{
states = (State)states
states = (StateDelta)states
.SetState(_avatarAddress, _avatarState.Serialize());
}
else
{
states = (State)states
states = (StateDelta)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 StateDelta();
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 StateDelta();
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 StateDelta();
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 StateDelta()
.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 StateDelta();
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
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/ActionContextExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static IEnumerable<object[]> IsPreviewNetTestcases()
[MemberData(nameof(IsMainNetTestcases))]
public void IsMainNet(GoldCurrencyState goldCurrencyState, bool expected)
{
var state = new State().SetState(Addresses.GoldCurrency, goldCurrencyState.Serialize());
var state = new StateDelta().SetState(Addresses.GoldCurrency, goldCurrencyState.Serialize());
IActionContext context = new ActionContext
{
PreviousState = state,
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/ActionEvaluationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ActionEvaluationTest()
#pragma warning restore CS0618
_signer = new PrivateKey().ToAddress();
_sender = new PrivateKey().ToAddress();
_states = new State()
_states = new StateDelta()
.SetState(_signer, (Text)"ANYTHING")
.SetState(default, Dictionary.Empty.Add("key", "value"))
.MintAsset(context, _signer, _currency * 10000);
Expand Down
12 changes: 6 additions & 6 deletions .Lib9c.Tests/Action/ActivateAccount0Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Execute()
var privateKey = new PrivateKey();
(ActivationKey activationKey, PendingActivationState pendingActivation) =
ActivationKey.Create(privateKey, nonce);
var state = new State(ImmutableDictionary<Address, IValue>.Empty
var state = new StateDelta(ImmutableDictionary<Address, IValue>.Empty
.Add(ActivatedAccountsState.Address, new ActivatedAccountsState().Serialize())
.Add(pendingActivation.address, pendingActivation.Serialize()));

Expand Down Expand Up @@ -50,7 +50,7 @@ public void Rehearsal()
ActivateAccount0 action = activationKey.CreateActivateAccount0(nonce);
IAccountStateDelta nextState = action.Execute(new ActionContext()
{
PreviousState = new State(),
PreviousState = new StateDelta(),
Signer = default,
Rehearsal = true,
BlockIndex = 1,
Expand All @@ -72,7 +72,7 @@ public void ExecuteWithInvalidSignature()
var privateKey = new PrivateKey();
(ActivationKey activationKey, PendingActivationState pendingActivation) =
ActivationKey.Create(privateKey, nonce);
var state = new State(ImmutableDictionary<Address, IValue>.Empty
var state = new StateDelta(ImmutableDictionary<Address, IValue>.Empty
.Add(ActivatedAccountsState.Address, new ActivatedAccountsState().Serialize())
.Add(pendingActivation.address, pendingActivation.Serialize())
);
Expand All @@ -99,7 +99,7 @@ public void ExecuteWithNonExistsPending()
ActivationKey.Create(privateKey, nonce);

// state에는 pendingActivation에 해당하는 대기가 없는 상태를 가정합니다.
var state = new State(ImmutableDictionary<Address, IValue>.Empty
var state = new StateDelta(ImmutableDictionary<Address, IValue>.Empty
.Add(ActivatedAccountsState.Address, new ActivatedAccountsState().Serialize()));

ActivateAccount0 action = activationKey.CreateActivateAccount0(nonce);
Expand All @@ -123,7 +123,7 @@ public void ExecuteWithNonExistsAccounts()
ActivationKey.Create(privateKey, nonce);

// state가 올바르게 초기화되지 않은 상태를 가정합니다.
var state = new State();
var state = new StateDelta();

ActivateAccount0 action = activationKey.CreateActivateAccount0(nonce);
Assert.Throws<ActivatedAccountsDoesNotExistsException>(() =>
Expand All @@ -144,7 +144,7 @@ public void ForbidReusingActivationKey()
var privateKey = new PrivateKey();
(ActivationKey activationKey, PendingActivationState pendingActivation) =
ActivationKey.Create(privateKey, nonce);
var state = new State(ImmutableDictionary<Address, IValue>.Empty
var state = new StateDelta(ImmutableDictionary<Address, IValue>.Empty
.Add(ActivatedAccountsState.Address, new ActivatedAccountsState().Serialize())
.Add(pendingActivation.address, pendingActivation.Serialize()));

Expand Down
8 changes: 4 additions & 4 deletions .Lib9c.Tests/Action/ActivateAccountTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ public void Execute(bool invalid, bool pendingExist, bool alreadyActivated, Type
ActivationKey.Create(privateKey, nonce);

Address activatedAddress = default(Address).Derive(ActivationKey.DeriveKey);
var state = new State();
var state = new StateDelta();

if (pendingExist)
{
state = (State)state.SetState(pendingActivation.address, pendingActivation.Serialize());
state = (StateDelta)state.SetState(pendingActivation.address, pendingActivation.Serialize());
}

if (alreadyActivated)
{
state = (State)state.SetState(activatedAddress, true.Serialize());
state = (StateDelta)state.SetState(activatedAddress, true.Serialize());
}

ActivateAccount action = activationKey.CreateActivateAccount(invalid ? new byte[] { 0x00 } : nonce);
Expand Down Expand Up @@ -75,7 +75,7 @@ public void Rehearsal()
Address activatedAddress = default(Address).Derive(ActivationKey.DeriveKey);
IAccountStateDelta nextState = action.Execute(new ActionContext()
{
PreviousState = new State(),
PreviousState = new StateDelta(),
Signer = default,
Rehearsal = true,
BlockIndex = 1,
Expand Down
8 changes: 4 additions & 4 deletions .Lib9c.Tests/Action/AddActivatedAccount0Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class AddActivatedAccount0Test
public void Execute()
{
var admin = new Address("8d9f76aF8Dc5A812aCeA15d8bf56E2F790F47fd7");
var state = new State(
var state = new StateDelta(
ImmutableDictionary<Address, IValue>.Empty
.Add(AdminState.Address, new AdminState(admin, 100).Serialize())
.Add(ActivatedAccountsState.Address, new ActivatedAccountsState().Serialize())
Expand Down Expand Up @@ -44,7 +44,7 @@ public void Execute()
public void Rehearsal()
{
var admin = new Address("8d9f76aF8Dc5A812aCeA15d8bf56E2F790F47fd7");
var state = new State(
var state = new StateDelta(
ImmutableDictionary<Address, IValue>.Empty
.Add(AdminState.Address, new AdminState(admin, 100).Serialize())
.Add(ActivatedAccountsState.Address, new ActivatedAccountsState().Serialize())
Expand Down Expand Up @@ -75,7 +75,7 @@ public void Rehearsal()
public void ExecuteWithNonExistsAccounts()
{
var admin = new Address("8d9f76aF8Dc5A812aCeA15d8bf56E2F790F47fd7");
var state = new State();
var state = new StateDelta();
var newComer = new Address("399bddF9F7B6d902ea27037B907B2486C9910730");
var action = new AddActivatedAccount0(newComer);

Expand All @@ -95,7 +95,7 @@ public void ExecuteWithNonExistsAccounts()
public void CheckPermission()
{
var admin = new Address("8d9f76aF8Dc5A812aCeA15d8bf56E2F790F47fd7");
var state = new State(
var state = new StateDelta(
ImmutableDictionary<Address, IValue>.Empty
.Add(AdminState.Address, new AdminState(admin, 100).Serialize())
.Add(ActivatedAccountsState.Address, new ActivatedAccountsState().Serialize())
Expand Down
6 changes: 3 additions & 3 deletions .Lib9c.Tests/Action/AddActivatedAccountTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public class AddActivatedAccountTest
public void Execute(bool isAdmin, long blockIndex, bool alreadyActivated, Type exc)
{
var admin = new Address("8d9f76aF8Dc5A812aCeA15d8bf56E2F790F47fd7");
var state = new State(
var state = new StateDelta(
ImmutableDictionary<Address, IValue>.Empty
.Add(AdminState.Address, new AdminState(admin, 100).Serialize())
);
var newComer = new Address("399bddF9F7B6d902ea27037B907B2486C9910730");
var activatedAddress = newComer.Derive(ActivationKey.DeriveKey);
if (alreadyActivated)
{
state = (State)state.SetState(activatedAddress, true.Serialize());
state = (StateDelta)state.SetState(activatedAddress, true.Serialize());
}

var action = new AddActivatedAccount(newComer);
Expand Down Expand Up @@ -61,7 +61,7 @@ public void Execute(bool isAdmin, long blockIndex, bool alreadyActivated, Type e
public void Rehearsal()
{
var admin = new Address("8d9f76aF8Dc5A812aCeA15d8bf56E2F790F47fd7");
var state = new State(
var state = new StateDelta(
ImmutableDictionary<Address, IValue>.Empty
.Add(AdminState.Address, new AdminState(admin, 100).Serialize())
);
Expand Down
Loading

0 comments on commit 405717b

Please sign in to comment.