Skip to content

Commit

Permalink
Remove warnings from Nethermind.Core.Test (NethermindEth#6113)
Browse files Browse the repository at this point in the history
* Remove warnings from `Nethermind.Core.Test`

* Treat warnings as errors
  • Loading branch information
emlautarom1 authored Sep 20, 2023
1 parent e610878 commit aad88ee
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/Nethermind/Nethermind.Core.Test/Builders/ReceiptBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ReceiptBuilder WithTxType(TxType txType)
return this;
}

public ReceiptBuilder WithTransactionHash(Keccak hash)
public ReceiptBuilder WithTransactionHash(Keccak? hash)
{
TestObject.TxHash = hash;
return this;
Expand All @@ -60,7 +60,7 @@ public ReceiptBuilder WithBlockNumber(long number)
return this;
}

public ReceiptBuilder WithBlockHash(Keccak hash)
public ReceiptBuilder WithBlockHash(Keccak? hash)
{
TestObject.BlockHash = hash;
return this;
Expand All @@ -84,7 +84,7 @@ public ReceiptBuilder WithBloom(Bloom bloom)
return this;
}

public ReceiptBuilder WithError(string error)
public ReceiptBuilder WithError(string? error)
{
TestObjectInternal.Error = error;
return this;
Expand All @@ -102,13 +102,13 @@ public ReceiptBuilder WithSender(Address sender)
return this;
}

public ReceiptBuilder WithContractAddress(Address contractAddress)
public ReceiptBuilder WithContractAddress(Address? contractAddress)
{
TestObjectInternal.ContractAddress = contractAddress;
return this;
}

public ReceiptBuilder WithRecipient(Address recipient)
public ReceiptBuilder WithRecipient(Address? recipient)
{
TestObjectInternal.Recipient = recipient;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static Rlp BlockInfoEncodeDeprecated(BlockInfo? item, bool chainWithFinal
stream.Encode(item.IsFinalized);
}

return new Rlp(stream.Data);
return new Rlp(stream.Data!);
}
}
}
28 changes: 13 additions & 15 deletions src/Nethermind/Nethermind.Core.Test/Encoding/TxDecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void CanCorrectlyCalculateTxHash_when_called_concurrently((Transaction Tx

Keccak expectedHash = Keccak.Compute(rlp.Bytes);

Transaction decodedTx = decoder.Decode(new RlpStream(rlp.Bytes));
Transaction decodedTx = decoder.Decode(new RlpStream(rlp.Bytes))!;

decodedTx.SetPreHash(rlp.Bytes);

Expand Down Expand Up @@ -149,7 +149,7 @@ public void ValueDecoderContext_DecodeWithMemorySlice_ShouldUseSameBuffer((Trans
rlpStream.Position = 0;
Transaction? decoded = _txDecoder.Decode(ref decoderContext);

byte[] data1 = decoded.Data.Value.ToArray();
byte[] data1 = decoded!.Data!.Value.ToArray();
data1.AsSpan().Fill(1);
rlpStream.Data.AsSpan().Fill(1);

Expand All @@ -162,7 +162,7 @@ public void Roundtrip_yolo_v3((string IncomingRlpHex, Keccak Hash) testCase)
TestContext.Out.WriteLine($"Testing {testCase.Hash}");
RlpStream incomingTxRlp = Bytes.FromHexString(testCase.IncomingRlpHex).AsRlpStream();

Transaction decoded = _txDecoder.Decode(incomingTxRlp);
Transaction decoded = _txDecoder.Decode(incomingTxRlp)!;
decoded.CalculateHash().Should().Be(testCase.Hash);

RlpStream ourRlpOutput = new(incomingTxRlp.Length * 2);
Expand All @@ -178,10 +178,10 @@ public void CalculateHash_and_tx_hash_after_decoding_return_the_same_value(
{
TestContext.Out.WriteLine($"Testing {testCase.Hash}");
RlpStream incomingTxRlp = Bytes.FromHexString(testCase.IncomingRlpHex).AsRlpStream();
Transaction decoded = _txDecoder.Decode(incomingTxRlp);
Transaction decoded = _txDecoder.Decode(incomingTxRlp)!;
Rlp encodedForTreeRoot = _txDecoder.Encode(decoded, RlpBehaviors.SkipTypedWrapping);

decoded.CalculateHash().Should().Be(decoded.Hash);
decoded.CalculateHash().Should().Be(decoded.Hash!);
decoded.Hash.Should().Be(Keccak.Compute(encodedForTreeRoot.Bytes));
}

Expand All @@ -190,7 +190,7 @@ public void Hash_calculation_do_not_change_after_roundtrip((string IncomingRlpHe
{
TestContext.Out.WriteLine($"Testing {testCase.Hash}");
RlpStream incomingTxRlp = Bytes.FromHexString(testCase.IncomingRlpHex).AsRlpStream();
Transaction decoded = _txDecoder.Decode(incomingTxRlp);
Transaction decoded = _txDecoder.Decode(incomingTxRlp)!;
Rlp encodedForTreeRoot = _txDecoder.Encode(decoded, RlpBehaviors.SkipTypedWrapping);
decoded.Hash.Should().Be(Keccak.Compute(encodedForTreeRoot.Bytes));
}
Expand All @@ -200,7 +200,7 @@ public void Hash_calculation_do_not_change_after_roundtrip2((string IncomingRlpH
{
TestContext.Out.WriteLine($"Testing {testCase.Hash}");
RlpStream incomingTxRlp = Bytes.FromHexString(testCase.IncomingRlpHex).AsRlpStream();
Transaction decoded = _txDecoder.Decode(incomingTxRlp);
Transaction decoded = _txDecoder.Decode(incomingTxRlp)!;
Rlp encodedForTreeRoot = _txDecoder.Encode(decoded, RlpBehaviors.SkipTypedWrapping);
decoded.Hash.Should().Be(Keccak.Compute(encodedForTreeRoot.Bytes));
}
Expand All @@ -226,14 +226,12 @@ private void ValueDecoderContext_return_the_same_transaction_as_rlp_stream(
RlpStream incomingTxRlp = Bytes.FromHexString(testCase.IncomingRlpHex).AsRlpStream();
Span<byte> spanIncomingTxRlp = Bytes.FromHexString(testCase.IncomingRlpHex).AsSpan();
Rlp.ValueDecoderContext decoderContext = new(spanIncomingTxRlp);
Transaction decodedByValueDecoderContext = _txDecoder.Decode(ref decoderContext,
wrapping ? RlpBehaviors.SkipTypedWrapping : RlpBehaviors.None);
Transaction decoded = _txDecoder.Decode(incomingTxRlp,
wrapping ? RlpBehaviors.SkipTypedWrapping : RlpBehaviors.None);
Rlp encoded = _txDecoder.Encode(decoded!);
Rlp encodedWithDecodedByValueDecoderContext = _txDecoder.Encode(decodedByValueDecoderContext!);
decoded!.Hash.Should().Be(testCase.Hash);
decoded!.Hash.Should().Be(decodedByValueDecoderContext!.Hash);
Transaction decodedByValueDecoderContext = _txDecoder.Decode(ref decoderContext, wrapping ? RlpBehaviors.SkipTypedWrapping : RlpBehaviors.None)!;
Transaction decoded = _txDecoder.Decode(incomingTxRlp, wrapping ? RlpBehaviors.SkipTypedWrapping : RlpBehaviors.None)!;
Rlp encoded = _txDecoder.Encode(decoded);
Rlp encodedWithDecodedByValueDecoderContext = _txDecoder.Encode(decodedByValueDecoderContext);
decoded.Hash.Should().Be(testCase.Hash);
decoded.Hash.Should().Be(decodedByValueDecoderContext.Hash!);
Assert.That(encodedWithDecodedByValueDecoderContext.Bytes, Is.EqualTo(encoded.Bytes));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task Test_Threshold(int minSize, int maxSize, int startingSize, Ada
{
AdaptiveRequestSizer sizer = new(minSize, maxSize, startingSize);

await sizer.Run((async requestSize => (requestSize, direction)));
await sizer.Run((requestSize => Task.FromResult((requestSize, direction))));

sizer.RequestSize.Should().Be(afterRequestSize);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Nethermind/Nethermind.Core.Test/RlpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Serializing_sequence_with_one_int_regression()
[Explicit("That was a regression test but now it is failing again and cannot find the reason we needed this behaviour in the first place. Sync works all fine. Leaving it here as it may resurface - make sure to add more explanation to it in such case.")]
public void Serializing_object_int_regression()
{
Rlp output = Rlp.Encode(new Rlp[] { Rlp.Encode(1) });
Rlp output = Rlp.Encode(new[] { Rlp.Encode(1) });
Assert.That(output.Bytes, Is.EqualTo(new byte[] { 1 }));
}

Expand All @@ -64,7 +64,7 @@ public void Length_of_uint()
public void Long_negative()
{
Rlp output = Rlp.Encode(-1L);
var context = new RlpStream(output.Bytes);
RlpStream context = new RlpStream(output.Bytes);
long value = context.DecodeLong();

Assert.That(value, Is.EqualTo(-1L));
Expand All @@ -73,7 +73,7 @@ public void Long_negative()
[Test]
public void Empty_byte_array()
{
byte[] bytes = new byte[0];
byte[] bytes = Array.Empty<byte>();
Rlp rlp = Rlp.Encode(bytes);
Rlp rlpSpan = Rlp.Encode(bytes.AsSpan());
Rlp expectedResult = new(new byte[] { 128 });
Expand Down Expand Up @@ -241,7 +241,7 @@ public void RlpContextWithSliceMemory_shouldNotCopyUnderlyingData(bool sliceValu
{
Memory<byte>? slice = context.DecodeByteArrayMemory();
slice.Should().NotBeNull();
MemoryMarshal.TryGetArray(slice.Value, out ArraySegment<byte> segment);
MemoryMarshal.TryGetArray(slice!.Value, out ArraySegment<byte> segment);

bool isACopy = (segment.Offset == 0 && segment.Count == slice.Value.Length);
isACopy.Should().NotBe(sliceValue);
Expand Down

0 comments on commit aad88ee

Please sign in to comment.