-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #940 from longfin/bugfix/serialization-exc-2
Serializable InsufficientBalanceException
- Loading branch information
Showing
8 changed files
with
197 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Libplanet.Tests/Action/InsufficientBalanceExceptionTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.IO; | ||
using System.Runtime.Serialization.Formatters.Binary; | ||
using Libplanet.Action; | ||
using Xunit; | ||
|
||
namespace Libplanet.Tests.Action | ||
{ | ||
public class InsufficientBalanceExceptionTest | ||
{ | ||
[Fact] | ||
public void Serializable() | ||
{ | ||
var minter = new Address(new byte[] | ||
{ | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, | ||
}); | ||
var account = new Address(new byte[] | ||
{ | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, | ||
}); | ||
|
||
var currency = new Currency("PLT", minter); | ||
var exc = new InsufficientBalanceException(account, currency, 99, "for testing"); | ||
|
||
var formatter = new BinaryFormatter(); | ||
using (var ms = new MemoryStream()) | ||
{ | ||
formatter.Serialize(ms, exc); | ||
|
||
ms.Seek(0, SeekOrigin.Begin); | ||
var deserialized = (InsufficientBalanceException)formatter.Deserialize(ms); | ||
Assert.Equal("for testing", deserialized.Message); | ||
Assert.Equal(account, deserialized.Address); | ||
Assert.Equal(currency.Hash, deserialized.Currency.Hash); | ||
Assert.Equal(99, deserialized.Balance); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters