Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions NBitcoin.Tests/BIP38Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,28 @@ private void AssertSequenceEquals(LotSequence expected, LotSequence actual)
}


[Fact]
[Theory]
[InlineData(0, 0)]
[InlineData(1048575, 1024)]
[InlineData(1048575, 1025)]
[InlineData(1048575, 4095)]
[Trait("UnitTest", "UnitTest")]
public void CanParseLotSequence()
public void CanParseLotSequence(int lot, int sequenceNumber)
{
var sequence = new LotSequence(1048575, 1024);
var sequence = new LotSequence(lot, sequenceNumber);
var bytes = sequence.ToBytes();
var sequence2 = new LotSequence(bytes);
Assert.True(sequence.Lot == sequence2.Lot && sequence.Sequence == sequence.Sequence);
Assert.Equal(sequence.Lot, sequence2.Lot);
Assert.Equal(sequence.Sequence, sequence2.Sequence);
}

[Theory]
[InlineData(-1)]
[InlineData(4096)]
[Trait("UnitTest", "UnitTest")]
public void RejectsInvalidSequence(int sequence)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new LotSequence(0, sequence));
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions NBitcoin/BIP38/BitcoinPassphraseCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public LotSequence(int lot, int sequence)
{
if (lot > 1048575 || lot < 0)
throw new ArgumentOutOfRangeException("lot");
if (sequence > 1024 || sequence < 0)
if (sequence > 4095 || sequence < 0)
throw new ArgumentOutOfRangeException("sequence");

_Lot = lot;
Expand All @@ -93,7 +93,7 @@ public LotSequence(byte[] bytes)
((uint)_Bytes[3] << 0);

_Lot = (int)(lotSequence / 4096);
_Sequence = (int)(lotSequence - _Lot);
_Sequence = (int)(lotSequence % 4096);
}

private readonly int _Lot;
Expand Down
Loading