Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename bytearray to bytestring #1524

Merged
merged 2 commits into from
Apr 1, 2020
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
4 changes: 2 additions & 2 deletions src/neo/SmartContract/BinarySerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static StackItem Deserialize(BinaryReader reader, uint maxArraySize, uin
case StackItemType.Integer:
deserialized.Push(new BigInteger(reader.ReadVarBytes(Integer.MaxSize)));
break;
case StackItemType.ByteArray:
case StackItemType.ByteString:
deserialized.Push(reader.ReadVarBytes((int)maxItemSize));
break;
case StackItemType.Buffer:
Expand Down Expand Up @@ -142,7 +142,7 @@ private static void Serialize(StackItem item, BinaryWriter writer, uint maxSize)
case Integer integer:
writer.WriteVarBytes(integer.Span);
break;
case ByteArray bytes:
case ByteString bytes:
writer.WriteVarBytes(bytes.Span);
break;
case Buffer buffer:
Expand Down
4 changes: 2 additions & 2 deletions src/neo/SmartContract/JsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static JObject Serialize(StackItem item)
{
return array.Select(p => Serialize(p)).ToArray();
}
case ByteArray buffer:
case ByteString buffer:
{
return Convert.ToBase64String(buffer.GetSpan());
}
Expand Down Expand Up @@ -87,7 +87,7 @@ public static byte[] SerializeToByteArray(StackItem item, uint maxSize)
case JsonTokenType.EndArray:
writer.WriteEndArray();
break;
case ByteArray buffer:
case ByteString buffer:
writer.WriteStringValue(Convert.ToBase64String(buffer.GetSpan()));
break;
case Integer num:
Expand Down
2 changes: 1 addition & 1 deletion src/neo/VM/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private static ContractParameter ToParameter(StackItem item, List<(StackItem, Co
Value = item.ToBoolean()
};
break;
case ByteArray array:
case ByteString array:
parameter = new ContractParameter
{
Type = ContractParameterType.ByteArray,
Expand Down
2 changes: 1 addition & 1 deletion src/neo/neo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.2.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.1" />
<PackageReference Include="Neo.VM" Version="3.0.0-CI00211" />
<PackageReference Include="Neo.VM" Version="3.0.0-CI00214" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static string Symbol(this NativeContract contract)
engine.Execute().Should().Be(VMState.HALT);

var result = engine.ResultStack.Pop();
result.Should().BeOfType(typeof(VM.Types.ByteArray));
result.Should().BeOfType(typeof(VM.Types.ByteString));

return result.GetString();
}
Expand All @@ -186,7 +186,7 @@ public static string Name(this NativeContract contract)
engine.Execute().Should().Be(VMState.HALT);

var result = engine.ResultStack.Pop();
result.Should().BeOfType(typeof(VM.Types.ByteArray));
result.Should().BeOfType(typeof(VM.Types.ByteString));

return result.GetString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class UT_PrimitiveWrapper
[TestMethod]
public void TestGeneratorAndDispose()
{
ByteArrayWrapper arrayWrapper = new ByteArrayWrapper(new ByteArray(new byte[0]));
ByteArrayWrapper arrayWrapper = new ByteArrayWrapper(new ByteString(new byte[0]));
Assert.IsNotNull(arrayWrapper);
Action action = () => arrayWrapper.Dispose();
action.Should().NotThrow<Exception>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public void TestKeyAndValueAndNext()
list.Add((storageKey, storageItem));
StorageIterator storageIterator = new StorageIterator(list.GetEnumerator());
storageIterator.Next();
Assert.AreEqual(new ByteArray(new byte[1]), storageIterator.Key());
Assert.AreEqual(new ByteArray(new byte[1]), storageIterator.Value());
Assert.AreEqual(new ByteString(new byte[1]), storageIterator.Key());
Assert.AreEqual(new ByteString(new byte[1]), storageIterator.Value());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ internal static void CheckBalance(byte[] account, DataCache<StorageKey, StorageI
var st = (VM.Types.Struct)BinarySerializer.Deserialize(trackable.Item.Value, 16, 32);

st.Count.Should().Be(3);
st.Select(u => u.GetType()).ToArray().Should().BeEquivalentTo(new Type[] { typeof(VM.Types.Integer), typeof(VM.Types.Integer), typeof(VM.Types.ByteArray) }); // Balance
st.Select(u => u.GetType()).ToArray().Should().BeEquivalentTo(new Type[] { typeof(VM.Types.Integer), typeof(VM.Types.Integer), typeof(VM.Types.ByteString) }); // Balance

st[0].GetBigInteger().Should().Be(balance); // Balance
st[1].GetBigInteger().Should().Be(height); // BalanceHeight
Expand Down
4 changes: 2 additions & 2 deletions tests/neo.UnitTests/SmartContract/Native/UT_NativeContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public void TestInvoke()
sb2.EmitSysCall("test".ToInteropMethodHash());
engine2.LoadScript(sb2.ToArray());

ByteArray method1 = new ByteArray(System.Text.Encoding.Default.GetBytes("wrongMethod"));
ByteString method1 = new ByteString(System.Text.Encoding.Default.GetBytes("wrongMethod"));
VMArray args1 = new VMArray();
engine2.CurrentContext.EvaluationStack.Push(args1);
engine2.CurrentContext.EvaluationStack.Push(method1);
testNativeContract.Invoke(engine2).Should().BeFalse();

ByteArray method2 = new ByteArray(System.Text.Encoding.Default.GetBytes("onPersist"));
ByteString method2 = new ByteString(System.Text.Encoding.Default.GetBytes("onPersist"));
VMArray args2 = new VMArray();
engine2.CurrentContext.EvaluationStack.Push(args2);
engine2.CurrentContext.EvaluationStack.Push(method2);
Expand Down
2 changes: 1 addition & 1 deletion tests/neo.UnitTests/SmartContract/UT_BinarySerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void TestSerialize()
[TestMethod]
public void TestDeserializeStackItem()
{
StackItem stackItem1 = new ByteArray(new byte[5]);
StackItem stackItem1 = new ByteString(new byte[5]);
byte[] byteArray1 = BinarySerializer.Serialize(stackItem1, MaxItemSize);
StackItem result1 = BinarySerializer.Deserialize(byteArray1, 2048, (uint)byteArray1.Length);
Assert.AreEqual(stackItem1, result1);
Expand Down
2 changes: 1 addition & 1 deletion tests/neo.UnitTests/SmartContract/UT_InteropService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public void TestBlockchain_GetContract()
InteropService.Invoke(engine, InteropService.Blockchain.GetContract).Should().BeTrue();
var stackItems = ((VM.Types.Array)engine.CurrentContext.EvaluationStack.Pop()).ToArray();
stackItems.Length.Should().Be(3);
stackItems[0].GetType().Should().Be(typeof(ByteArray));
stackItems[0].GetType().Should().Be(typeof(ByteString));
stackItems[0].GetSpan().ToHexString().Should().Be(state.Script.ToHexString());
stackItems[1].ToBoolean().Should().BeFalse();
stackItems[2].ToBoolean().Should().BeFalse();
Expand Down
14 changes: 7 additions & 7 deletions tests/neo.UnitTests/SmartContract/UT_Syscalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void System_Blockchain_GetBlock()

Assert.AreEqual(engine.Execute(), VMState.HALT);
Assert.AreEqual(1, engine.ResultStack.Count);
Assert.IsInstanceOfType(engine.ResultStack.Peek(), typeof(ByteArray));
Assert.IsInstanceOfType(engine.ResultStack.Peek(), typeof(ByteString));
Assert.AreEqual(engine.ResultStack.Pop().GetSpan().ToHexString(),
"5b22366b4139757552614430373634585358466c706674686b436b5954702f6e34623878715057476c6a6659303d222c332c22414141414141414141414141414141414141414141414141414141414141414141414141414141414141413d222c22414141414141414141414141414141414141414141414141414141414141414141414141414141414141413d222c322c302c224141414141414141414141414141414141414141414141414141413d222c315d");
Assert.AreEqual(0, engine.ResultStack.Count);
Expand Down Expand Up @@ -194,11 +194,11 @@ public void Json_Serialize()
Assert.AreEqual(engine.Execute(), VMState.HALT);
Assert.AreEqual(5, engine.ResultStack.Count);

Assert.IsTrue(engine.ResultStack.TryPop<ByteArray>(out var m) && m.GetString() == "{\"key\":\"dmFsdWU=\"}");
Assert.IsTrue(engine.ResultStack.TryPop<ByteArray>(out var n) && n.GetString() == "null");
Assert.IsTrue(engine.ResultStack.TryPop<ByteArray>(out var s) && s.GetString() == "\"dGVzdA==\"");
Assert.IsTrue(engine.ResultStack.TryPop<ByteArray>(out var b) && b.GetString() == "true");
Assert.IsTrue(engine.ResultStack.TryPop<ByteArray>(out var i) && i.GetString() == "5");
Assert.IsTrue(engine.ResultStack.TryPop<ByteString>(out var m) && m.GetString() == "{\"key\":\"dmFsdWU=\"}");
Assert.IsTrue(engine.ResultStack.TryPop<ByteString>(out var n) && n.GetString() == "null");
Assert.IsTrue(engine.ResultStack.TryPop<ByteString>(out var s) && s.GetString() == "\"dGVzdA==\"");
Assert.IsTrue(engine.ResultStack.TryPop<ByteString>(out var b) && b.GetString() == "true");
Assert.IsTrue(engine.ResultStack.TryPop<ByteString>(out var i) && i.GetString() == "5");
}
}

Expand Down Expand Up @@ -259,7 +259,7 @@ public void System_ExecutionEngine_GetScriptContainer()

Assert.AreEqual(engine.Execute(), VMState.HALT);
Assert.AreEqual(1, engine.ResultStack.Count);
Assert.IsInstanceOfType(engine.ResultStack.Peek(), typeof(ByteArray));
Assert.IsInstanceOfType(engine.ResultStack.Peek(), typeof(ByteString));
Assert.AreEqual(engine.ResultStack.Pop().GetSpan().ToHexString(),
@"5b225c75303032426b53415959527a4c4b69685a676464414b50596f754655737a63544d7867445a6572584a3172784c37303d222c362c342c222f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f383d222c332c322c352c2241513d3d225d");
Assert.AreEqual(0, engine.ResultStack.Count);
Expand Down
2 changes: 1 addition & 1 deletion tests/neo.UnitTests/VM/UT_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ private void TestToParameter2Integer()

private void TestToParameter2ByteArray()
{
StackItem item = new VM.Types.ByteArray(new byte[] { 0x00 });
StackItem item = new VM.Types.ByteString(new byte[] { 0x00 });
ContractParameter parameter = VM.Helper.ToParameter(item);
Assert.AreEqual(ContractParameterType.ByteArray, parameter.Type);
Assert.AreEqual(Encoding.Default.GetString(new byte[] { 0x00 }), Encoding.Default.GetString((byte[])parameter.Value));
Expand Down