Skip to content

Commit

Permalink
Fix SpentCoinState.Clone (#1369)
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored Feb 11, 2020
1 parent 54d0f29 commit 41250b4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
30 changes: 28 additions & 2 deletions neo.UnitTests/UT_SpentCointState.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.IO;
using Neo.Ledger;
using System.Collections.Generic;
using System.IO;
Expand All @@ -24,6 +25,31 @@ public void TransactionHash_Get()
uut.TransactionHash.Should().BeNull();
}

[TestMethod]
public void TestFromReplica()
{
uut.Items = new Dictionary<ushort, uint>();
uut.Items.Add(1, 3);

var a = ((ICloneable<SpentCoinState>)uut).Clone();
var b = new SpentCoinState();

((ICloneable<SpentCoinState>)b).FromReplica(uut);

CollectionAssert.AreEqual(a.Items.Keys, uut.Items.Keys);
CollectionAssert.AreEqual(a.Items.Values, uut.Items.Values);
CollectionAssert.AreEqual(b.Items.Keys, uut.Items.Keys);
CollectionAssert.AreEqual(b.Items.Values, uut.Items.Values);

a.Items.Clear();
b.Items.Clear();

CollectionAssert.AreNotEqual(a.Items.Keys, uut.Items.Keys);
CollectionAssert.AreNotEqual(b.Items.Keys, uut.Items.Keys);
CollectionAssert.AreNotEqual(a.Items.Values, uut.Items.Values);
CollectionAssert.AreNotEqual(b.Items.Values, uut.Items.Values);
}

[TestMethod]
public void TransactionHash_Set()
{
Expand Down Expand Up @@ -98,8 +124,8 @@ private void setupSpentCoinStateWithValues(SpentCoinState spentCoinState, out UI
[TestMethod]
public void DeserializeSCS()
{
byte[] dataArray = new byte[] { 0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 42, 3, 44, 45, 1, 42, 0, 0, 0, 0, 0 };
byte[] dataArray = new byte[] { 0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 42, 3, 44, 45, 1, 42, 0, 0, 0, 0, 0 };

using (Stream stream = new MemoryStream(dataArray))
{
using (BinaryReader reader = new BinaryReader(stream))
Expand Down
2 changes: 1 addition & 1 deletion neo/Ledger/SpentCoinState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void ICloneable<SpentCoinState>.FromReplica(SpentCoinState replica)
{
TransactionHash = replica.TransactionHash;
TransactionHeight = replica.TransactionHeight;
Items = replica.Items;
Items = new Dictionary<ushort, uint>(replica.Items);
}

public override void Serialize(BinaryWriter writer)
Expand Down

0 comments on commit 41250b4

Please sign in to comment.