From 1d78c304678c8f8489c94daf989fa0e47fdf8561 Mon Sep 17 00:00:00 2001 From: s2quake Date: Thu, 26 Dec 2024 10:22:05 +0900 Subject: [PATCH] chore: Remove warnings from test code --- .../Action/CreateOrReplaceAvatarTest.cs | 2 +- .../Action/ManipulateStateTest.cs | 6 ++--- ...ustomActionsDeserializableValidatorTest.cs | 27 +++++++++++++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.Lib9c.DevExtensions.Tests/Action/CreateOrReplaceAvatarTest.cs b/.Lib9c.DevExtensions.Tests/Action/CreateOrReplaceAvatarTest.cs index dabab140b0..34cadeec75 100644 --- a/.Lib9c.DevExtensions.Tests/Action/CreateOrReplaceAvatarTest.cs +++ b/.Lib9c.DevExtensions.Tests/Action/CreateOrReplaceAvatarTest.cs @@ -466,7 +466,7 @@ private static void Execute( RandomSeed = 0, BlockIndex = blockIndex, }); - var agent = nextStates.GetAgentState(agentAddr); + var agent = nextStates.GetAgentState(agentAddr)!; Assert.Single(agent.avatarAddresses); Assert.True(agent.avatarAddresses.ContainsKey(action.AvatarIndex)); avatarAddr ??= agent.avatarAddresses[action.AvatarIndex]; diff --git a/.Lib9c.DevExtensions.Tests/Action/ManipulateStateTest.cs b/.Lib9c.DevExtensions.Tests/Action/ManipulateStateTest.cs index 3887982e34..1aa650a5a4 100644 --- a/.Lib9c.DevExtensions.Tests/Action/ManipulateStateTest.cs +++ b/.Lib9c.DevExtensions.Tests/Action/ManipulateStateTest.cs @@ -29,7 +29,7 @@ public class ManipulateStateTest private static readonly Address AdminAddr = new PrivateKey().Address; // See also InitializeUtil.cs - private static readonly Currency Ncg = Currency.Legacy( + private static readonly Currency Ncg = Currency.Uncapped( "NCG", 2, null @@ -187,7 +187,7 @@ public static IEnumerable FetchWorldInfo() yield return new object[] { - tableSheets.WorldSheet.OrderedList.Last(world => world.Id < 100).StageEnd, + tableSheets.WorldSheet.OrderedList!.Last(world => world.Id < 100).StageEnd, new WorldInformation(0L, worldSheet, true), }; } @@ -421,7 +421,7 @@ private void TestAvatarState( private void TestInventoryState(IWorld state, Inventory targetInventory) { - var inventoryState = new Inventory((List)state.GetAccount(Addresses.Inventory).GetState(_avatarAddress)); + var inventoryState = new Inventory((List)state.GetAccount(Addresses.Inventory).GetState(_avatarAddress)!); Assert.Equal(targetInventory.Items.Count, inventoryState.Items.Count); foreach (var item in targetInventory.Items) { diff --git a/.Lib9c.Miner.Tests/CustomActionsDeserializableValidatorTest.cs b/.Lib9c.Miner.Tests/CustomActionsDeserializableValidatorTest.cs index cf58ed01d1..5731873a69 100644 --- a/.Lib9c.Miner.Tests/CustomActionsDeserializableValidatorTest.cs +++ b/.Lib9c.Miner.Tests/CustomActionsDeserializableValidatorTest.cs @@ -56,11 +56,24 @@ public IWorld Execute(IActionContext context) private class MockTransaction : ITransaction { + private IImmutableSet
? _updatedAddresses; + private PublicKey? _publicKey; + private byte[]? _signature; + public long Nonce { get; init; } public Address Signer { get; init; } - public IImmutableSet
UpdatedAddresses { get; init; } + public IImmutableSet
UpdatedAddresses + { + get => _updatedAddresses + ?? throw new InvalidOperationException("UpdatedAddresses is not set."); + init => _updatedAddresses = value; + } public DateTimeOffset Timestamp { get; init; } - public PublicKey PublicKey { get; init; } + public PublicKey PublicKey + { + get => _publicKey ?? throw new InvalidOperationException("PublicKey is not set."); + init => _publicKey = value; + } public BlockHash? GenesisHash { get; init; } public TxActionList Actions => new(SystemAction is { } sa ? new IValue[]{ sa } : CustomActions!); @@ -70,12 +83,16 @@ private class MockTransaction : ITransaction public long? GasLimit => null; public TxId Id { get; init; } - public byte[] Signature { get; init; } + public byte[] Signature + { + get => _signature ?? throw new InvalidOperationException("Signature is not set."); + init => _signature = value; + } public IValue? SystemAction { get; init; } public IImmutableList? CustomActions { get; init; } public bool Equals(ITxInvoice? other) { - return UpdatedAddresses.Equals(other.UpdatedAddresses) && + return UpdatedAddresses.Equals(other?.UpdatedAddresses) && Timestamp.Equals(other.Timestamp) && Nullable.Equals(GenesisHash, other.GenesisHash) && Actions.Equals(other.Actions); @@ -83,7 +100,7 @@ public bool Equals(ITxInvoice? other) public bool Equals(ITxSigningMetadata? other) { - return Nonce == other.Nonce && + return Nonce == other?.Nonce && Signer.Equals(other.Signer) && PublicKey.Equals(other.PublicKey); }