Skip to content

Commit

Permalink
Remove states instead setting Null.Value
Browse files Browse the repository at this point in the history
* Renamed all occurrances of "SetLegaceState(_, Null.Value)" to "RemoveLegaceState(_)"

* Updated Test files to Assert Null instead of Null.Value

---------

Co-authored-by: Lee Dogeon <dev.moreal@gmail.com>
  • Loading branch information
TheMarvelFan and moreal authored Oct 11, 2024
1 parent af750ed commit 1f53d2e
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ private static void Execute(
Addresses.GetSkillStateAddressFromAvatarAddress(avatarAddr.Value);
if (action.CrystalRandomBuff is null)
{
Assert.Equal(Null.Value, nextStates.GetLegacyState(crystalRandomSkillAddr));
Assert.Null(nextStates.GetLegacyState(crystalRandomSkillAddr));
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions .Lib9c.Tests/Action/ClaimStakeRewardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public void Execute_Throw_FailedLoadStateException_When_Staking_State_Null()
0));

var stakeAddr = StakeStateV2.DeriveAddress(AgentAddr);
var previousState = _initialState.SetLegacyState(stakeAddr, Null.Value);
var previousState = _initialState.RemoveLegacyState(stakeAddr);
Assert.Throws<FailedLoadStateException>(() =>
Execute(
previousState,
Expand Down Expand Up @@ -447,7 +447,7 @@ public void Execute_Throw_FailedLoadStateException_When_Sheet_Null()
// NOTE: Set StakeRegularFixedRewardSheetTable to Null
var sheetAddr = Addresses.GetSheetAddress(
stakeStateV2.Contract.StakeRegularFixedRewardSheetTableName);
prevState = prevState.SetLegacyState(sheetAddr, Null.Value);
prevState = prevState.RemoveLegacyState(sheetAddr);
Assert.Throws<FailedLoadStateException>(() =>
Execute(
prevState,
Expand All @@ -462,7 +462,7 @@ public void Execute_Throw_FailedLoadStateException_When_Sheet_Null()
// NOTE: Set StakeRegularRewardSheetTableName to Null
sheetAddr = Addresses.GetSheetAddress(
stakeStateV2.Contract.StakeRegularRewardSheetTableName);
prevState = prevState.SetLegacyState(sheetAddr, Null.Value);
prevState = prevState.RemoveLegacyState(sheetAddr);
Assert.Throws<FailedLoadStateException>(() =>
Execute(
prevState,
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/EndPledgeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Execute(int balance)
Signer = patron,
PreviousState = states,
});
Assert.Equal(Null.Value, nextState.GetLegacyState(agent.GetPledgeAddress()));
Assert.Null(nextState.GetLegacyState(agent.GetPledgeAddress()));
Assert.Equal(mead * 0, nextState.GetBalance(agent, mead));
if (balance > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void Execute_Throws_Exception()
SenderAgentAddr,
fungibleId);
var previousStatesWithNullGarageState =
_previousStates.SetLegacyState(garageAddr, Null.Value);
_previousStates.RemoveLegacyState(garageAddr);
Assert.Throws<StateNullException>(() => Execute(
SenderAgentAddr,
0,
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/Garages/UnloadFromMyGaragesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void Execute_Throws_Exception()
AgentAddr,
fungibleId);
var previousStatesWithNullGarageState =
_previousStates.SetLegacyState(garageAddr, Null.Value);
_previousStates.RemoveLegacyState(garageAddr);
Assert.Throws<StateNullException>(() => Execute(
AgentAddr,
0,
Expand Down
6 changes: 3 additions & 3 deletions .Lib9c.Tests/Action/Scenario/MarketScenarioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public void Register_And_Buy()
var sellProductList = new ProductsState((List)latestState.GetLegacyState(ProductsState.DeriveAddress(productInfo.AvatarAddress)));
var productId = productInfo.ProductId;
Assert.Empty(sellProductList.ProductIds);
Assert.Equal(Null.Value, latestState.GetLegacyState(Product.DeriveAddress(productId)));
Assert.Null(latestState.GetLegacyState(Product.DeriveAddress(productId)));
var product = ProductFactory.DeserializeProduct((List)nextState2.GetLegacyState(Product.DeriveAddress(productId)));
switch (product)
{
Expand Down Expand Up @@ -508,7 +508,7 @@ public void Register_And_Cancel()

foreach (var productAddress in action2.ProductInfos.Select(productInfo => Product.DeriveAddress(productInfo.ProductId)))
{
Assert.Equal(Null.Value, latestState.GetLegacyState(productAddress));
Assert.Null(latestState.GetLegacyState(productAddress));
var product = ProductFactory.DeserializeProduct((List)nextState.GetLegacyState(productAddress));
switch (product)
{
Expand Down Expand Up @@ -1097,7 +1097,7 @@ public void HardFork()
var sellProductList = new ProductsState((List)tradedState.GetLegacyState(ProductsState.DeriveAddress(productInfo.AvatarAddress)));
var productId = productInfo.ProductId;
Assert.Empty(sellProductList.ProductIds);
Assert.Equal(Null.Value, tradedState.GetLegacyState(Product.DeriveAddress(productId)));
Assert.Null(tradedState.GetLegacyState(Product.DeriveAddress(productId)));
var product = ProductFactory.DeserializeProduct((List)nextState.GetLegacyState(Product.DeriveAddress(productId)));
switch (product)
{
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/Stake2Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void Execute()
BlockIndex = StakeState.LockupInterval,
});

Assert.Equal(Null.Value, states.GetLegacyState(stakeState.address));
Assert.Null(states.GetLegacyState(stakeState.address));
Assert.Equal(_currency * 0, states.GetBalance(stakeState.address, _currency));
Assert.Equal(_currency * 100, states.GetBalance(_signerAddress, _currency));
}
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.DevExtensions/Action/CreateOrReplaceAvatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ public IWorld Execute(
Addresses.GetSkillStateAddressFromAvatarAddress(avatarAddr);
if (CrystalRandomBuff is null)
{
states = states.SetLegacyState(crystalRandomSkillAddr, Null.Value);
states = states.RemoveLegacyState(crystalRandomSkillAddr);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Lib9c/Action/BuyProduct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private IWorld Buy(IActionContext context, IProductInfo productInfo, Address sel
var receipt = new ProductReceipt(productId, sellerAvatarAddress, buyerAvatarState.address, product.Price,
context.BlockIndex);
states = states
.SetLegacyState(productAddress, Null.Value)
.RemoveLegacyState(productAddress)
.SetLegacyState(productsStateAddress, productsState.Serialize())
.SetAvatarState(sellerAvatarAddress, sellerAvatarState)
.SetLegacyState(ProductReceipt.DeriveAddress(productId), receipt.Serialize())
Expand Down
2 changes: 1 addition & 1 deletion Lib9c/Action/CancelProductRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public static IWorld Cancel(

var mail = new ProductCancelMail(context.BlockIndex, productId, context.BlockIndex, productId, product);
avatarState.Update(mail);
states = states.SetLegacyState(productAddress, Null.Value);
states = states.RemoveLegacyState(productAddress);
return states;
}

Expand Down
2 changes: 1 addition & 1 deletion Lib9c/Action/EndPledge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override IWorld Execute(IActionContext context)
{
states = states.TransferAsset(context, AgentAddress, signer, balance);
}
return states.SetLegacyState(contractAddress, Null.Value);
return states.RemoveLegacyState(contractAddress);
}

throw new FailedLoadStateException("failed to find pledge.");
Expand Down
2 changes: 1 addition & 1 deletion Lib9c/Action/MigrateMonsterCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public override IWorld Execute(IActionContext context)

var ended = DateTimeOffset.UtcNow;
Log.Debug("{AddressesHex}MigrateMonsterCollection Total Executed Time: {Elapsed}", addressesHex, ended - started);
return states.SetLegacyState(monsterCollectionState.address, Null.Value)
return states.RemoveLegacyState(monsterCollectionState.address)
.SetLegacyState(migratedStakeStateAddress, migratedStakeState.SerializeV2())
.TransferAsset(
context,
Expand Down
2 changes: 1 addition & 1 deletion Lib9c/Action/Stake2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public override IWorld Execute(IActionContext context)
if (stakeState.IsCancellable(context.BlockIndex))
{
return states
.SetLegacyState(stakeState.address, Null.Value)
.RemoveLegacyState(stakeState.address)
.TransferAsset(context, stakeState.address, context.Signer, stakedBalance);
}
}
Expand Down

0 comments on commit 1f53d2e

Please sign in to comment.