Skip to content

Commit

Permalink
Merge pull request #3101 from planetarium/chore/remove-warnings
Browse files Browse the repository at this point in the history
Remove nullable warnings
  • Loading branch information
ipdae authored Dec 27, 2024
2 parents d4bffc3 + 29727bc commit 85d94f0
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 3 additions & 3 deletions .Lib9c.DevExtensions.Tests/Action/ManipulateStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -187,7 +187,7 @@ public static IEnumerable<object[]> 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),
};
}
Expand Down Expand Up @@ -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)
{
Expand Down
27 changes: 22 additions & 5 deletions .Lib9c.Miner.Tests/CustomActionsDeserializableValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,24 @@ public IWorld Execute(IActionContext context)

private class MockTransaction : ITransaction
{
private IImmutableSet<Address>? _updatedAddresses;
private PublicKey? _publicKey;
private byte[]? _signature;

public long Nonce { get; init; }
public Address Signer { get; init; }
public IImmutableSet<Address> UpdatedAddresses { get; init; }
public IImmutableSet<Address> 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!);
Expand All @@ -70,20 +83,24 @@ 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<IValue>? 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);
}

public bool Equals(ITxSigningMetadata? other)
{
return Nonce == other.Nonce &&
return Nonce == other?.Nonce &&
Signer.Equals(other.Signer) &&
PublicKey.Equals(other.PublicKey);
}
Expand Down
23 changes: 19 additions & 4 deletions Lib9c.Policy/NCStagePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public NCStagePolicy(TimeSpan txLifeTime, int quotaPerSigner, IAccessControlServ
_accessControlService = accessControlService;
}

public Transaction Get(BlockChain blockChain, TxId id, bool filtered = true)
public Transaction? Get(BlockChain blockChain, TxId id, bool filtered = true)
=> _impl.Get(blockChain, id, filtered);

public long GetNextTxNonce(BlockChain blockChain, Address address)
Expand Down Expand Up @@ -79,9 +79,9 @@ public IEnumerable<Transaction> Iterate(BlockChain blockChain, bool filtered = t
txQuotaPerSigner = _quotaPerSigner;
}

if (s.Count > txQuotaPerSigner)
if (s.Count > txQuotaPerSigner && s.Max is { } max)
{
s.Remove(s.Max);
s.Remove(max);
}
}

Expand Down Expand Up @@ -141,8 +141,23 @@ public bool Unstage(BlockChain blockChain, TxId id)

private class TxComparer : IComparer<Transaction>
{
public int Compare(Transaction x, Transaction y)
public int Compare(Transaction? x, Transaction? y)
{
if (x == null && y == null)
{
return 0;
}

if (x == null)
{
return -1;
}

if (y == null)
{
return 1;
}

if (x.Nonce < y.Nonce)
{
return -1;
Expand Down
6 changes: 3 additions & 3 deletions Lib9c.Policy/Policy/BlockPolicySource.Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal static bool IsAdminTransaction(BlockChain blockChain, Transaction trans
: null;
}

private static InvalidBlockBytesLengthException ValidateTransactionsBytesRaw(
private static InvalidBlockBytesLengthException? ValidateTransactionsBytesRaw(
Block block,
IVariableSubPolicy<long> maxTransactionsBytesPolicy)
{
Expand All @@ -108,7 +108,7 @@ private static InvalidBlockBytesLengthException ValidateTransactionsBytesRaw(
return null;
}

private static BlockPolicyViolationException ValidateTxCountPerBlockRaw(
private static BlockPolicyViolationException? ValidateTxCountPerBlockRaw(
Block block,
IVariableSubPolicy<int> minTransactionsPerBlockPolicy,
IVariableSubPolicy<int> maxTransactionsPerBlockPolicy)
Expand Down Expand Up @@ -138,7 +138,7 @@ private static BlockPolicyViolationException ValidateTxCountPerBlockRaw(
return null;
}

private static BlockPolicyViolationException ValidateTxCountPerSignerPerBlockRaw(
private static BlockPolicyViolationException? ValidateTxCountPerSignerPerBlockRaw(
Block block,
IVariableSubPolicy<int> maxTransactionsPerSignerPerBlockPolicy)
{
Expand Down
4 changes: 2 additions & 2 deletions Lib9c.Policy/Policy/DebugPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public DebugPolicy()
new Reward(), new Refund(),
}.ToImmutableArray());

public TxPolicyViolationException ValidateNextBlockTx(
public TxPolicyViolationException? ValidateNextBlockTx(
BlockChain blockChain, Transaction transaction)
{
return null;
}

public BlockPolicyViolationException ValidateNextBlock(
public BlockPolicyViolationException? ValidateNextBlock(
BlockChain blockChain, Block nextBlock)
{
return null;
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.Policy/Policy/SpannedSubPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SpannedSubPolicy<T>
/// <exception cref="ArgumentOutOfRangeException">If an invalid value is given for either
/// <paramref name="startIndex"/> or <paramref name="endIndex"/>.</exception>
public SpannedSubPolicy(
long startIndex, long? endIndex, Predicate<long> filter, T value)
long startIndex, long? endIndex, Predicate<long>? filter, T value)
{
if (startIndex < 0)
{
Expand Down
4 changes: 2 additions & 2 deletions Lib9c.Policy/Policy/VariableSubPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public IVariableSubPolicy<T> Add(SpannedSubPolicy<T> spannedSubPolicy)
BindingFlags.Instance | BindingFlags.NonPublic,
null,
new object[] { this, spannedSubPolicy },
null);
null)!;
}
catch (TargetInvocationException tie)
{
Expand Down Expand Up @@ -135,7 +135,7 @@ private Func<long, T> ToGetter()
/// </remarks>
private void Validate()
{
SpannedSubPolicy<T> prev = null;
SpannedSubPolicy<T>? prev = null;
foreach (SpannedSubPolicy<T> next in SpannedSubPolicies)
{
if (prev is SpannedSubPolicy<T> _prev)
Expand Down

0 comments on commit 85d94f0

Please sign in to comment.