Skip to content

Commit

Permalink
Fix a bug when serializing default address
Browse files Browse the repository at this point in the history
  • Loading branch information
longfin committed Jul 24, 2019
1 parent 19078be commit b96ade5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ To be released.

- Fixed a bug where the `LiteDBStore.IterateStagedTransactionIds()` returns
duplicated transaction ids. [[#366]]
- Fixed a bug that `NullReferenceException` occurred when serializing default
`Address`. [[#TBD]]


[#343]: https://github.com/planetarium/libplanet/pull/343
Expand Down
17 changes: 16 additions & 1 deletion Libplanet.Tests/AddressTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void Equals_()
}

[Fact]
public void CanSerializeAndDeserialize()
public void SerializeAndDeserialize()
{
// Serialize and deserialize to and from memory
var expectedAddress = new Address(
Expand All @@ -223,6 +223,21 @@ public void CanSerializeAndDeserialize()
Assert.Equal(deserializedAddress, expectedAddress);
}

[Fact]
public void SerializeAndDeserializeWithDefault()
{
var defaultAddress = default(Address);
BinaryFormatter formatter = new BinaryFormatter();

using (var memoryStream = new MemoryStream())
{
formatter.Serialize(memoryStream, defaultAddress);
memoryStream.Seek(0, SeekOrigin.Begin);
var deserializedAddress = (Address)formatter.Deserialize(memoryStream);
Assert.Equal(default, deserializedAddress);
}
}

[Fact]
public void Compare()
{
Expand Down
2 changes: 1 addition & 1 deletion Libplanet/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void GetObjectData(
SerializationInfo info,
StreamingContext context)
{
info.AddValue("address", _byteArray.ToArray());
info.AddValue("address", ToByteArray());
}

int IComparable<Address>.CompareTo(Address other)
Expand Down
1 change: 1 addition & 0 deletions Libplanet/Blockchain/BlockChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ public AddressStateMap GetStates(
).GetValueOrDefault(a)
).ToArray();

var l = new List<int>();
_rwlock.EnterWriteLock();

try
Expand Down

0 comments on commit b96ade5

Please sign in to comment.