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

Optimize #35

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
5 changes: 2 additions & 3 deletions src/neo/VM/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static ScriptBuilder CreateArray<T>(this ScriptBuilder sb, IReadOnlyList<
return sb.Emit(OpCode.PACK);
}

public static ScriptBuilder CreateMap<TKey, TValue>(this ScriptBuilder sb, IReadOnlyDictionary<TKey, TValue> map = null)
public static ScriptBuilder CreateMap<TKey, TValue>(this ScriptBuilder sb, IEnumerable<KeyValuePair<TKey, TValue>> map = null)
{
sb.Emit(OpCode.NEWMAP);
if (map != null)
Expand Down Expand Up @@ -132,8 +132,7 @@ public static ScriptBuilder EmitPush(this ScriptBuilder sb, ContractParameter pa
case ContractParameterType.Map:
{
var pairs = (IList<KeyValuePair<ContractParameter, ContractParameter>>)parameter.Value;
var map = new Dictionary<ContractParameter, ContractParameter>(pairs);
sb.CreateMap(map);
sb.CreateMap(pairs);
}
break;
default:
Expand Down
8 changes: 6 additions & 2 deletions tests/neo.UnitTests/VM/UT_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,14 @@ public void TestEmitPush2()
TestEmitPush2PublicKey();
TestEmitPush2String();
TestEmitPush2Array();
TestEmitPush2Map();
}

private void TestEmitPush2Map()
{
ScriptBuilder sb = new ScriptBuilder();
Action action = () => sb.EmitPush(new ContractParameter(ContractParameterType.Map));
action.Should().Throw<ArgumentException>();
sb.EmitPush(new ContractParameter(ContractParameterType.Map));
CollectionAssert.AreEqual(new[] { (byte)OpCode.NEWMAP }, sb.ToArray());
}

private void TestEmitPush2Array()
Expand Down