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

Add CreateStandardMultisigAccount #2343

Merged
merged 8 commits into from
Feb 17, 2021
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
6 changes: 6 additions & 0 deletions src/neo/SmartContract/ApplicationEngine.Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ partial class ApplicationEngine
/// Warning: check first that input public key is valid, before creating the script.
/// </summary>
public static readonly InteropDescriptor System_Contract_CreateStandardAccount = Register("System.Contract.CreateStandardAccount", nameof(CreateStandardAccount), 1 << 8, CallFlags.None);
public static readonly InteropDescriptor System_Contract_CreateMultisigAccount = Register("System.Contract.CreateMultisigAccount", nameof(CreateMultisigAccount), 1 << 8, CallFlags.None);
public static readonly InteropDescriptor System_Contract_NativeOnPersist = Register("System.Contract.NativeOnPersist", nameof(NativeOnPersist), 0, CallFlags.WriteStates);
public static readonly InteropDescriptor System_Contract_NativePostPersist = Register("System.Contract.NativePostPersist", nameof(NativePostPersist), 0, CallFlags.WriteStates);

Expand Down Expand Up @@ -86,6 +87,11 @@ protected internal UInt160 CreateStandardAccount(ECPoint pubKey)
return Contract.CreateSignatureRedeemScript(pubKey).ToScriptHash();
}

protected internal UInt160 CreateMultisigAccount(int m, ECPoint[] pubKeys)
{
return Contract.CreateMultiSigRedeemScript(m, pubKeys).ToScriptHash();
}

protected internal void NativeOnPersist()
{
if (Trigger != TriggerType.OnPersist)
Expand Down
12 changes: 1 addition & 11 deletions src/neo/VM/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,7 @@ public static ScriptBuilder EmitDynamicCall(this ScriptBuilder sb, UInt160 scrip

public static ScriptBuilder EmitDynamicCall(this ScriptBuilder sb, UInt160 scriptHash, string operation, CallFlags flags, params object[] args)
{
if (args.Length == 0)
{
sb.Emit(OpCode.NEWARRAY0);
}
else
{
for (int i = args.Length - 1; i >= 0; i--)
sb.EmitPush(args[i]);
sb.EmitPush(args.Length);
sb.Emit(OpCode.PACK);
}
sb.CreateArray(args);
sb.EmitPush(flags);
sb.EmitPush(operation);
sb.EmitPush(scriptHash);
Expand Down
50 changes: 50 additions & 0 deletions tests/neo.UnitTests/SmartContract/UT_ApplicationEngine.Contract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.SmartContract;
using Neo.VM;
using System.Linq;

namespace Neo.UnitTests.SmartContract
{
public partial class UT_ApplicationEngine
{
[TestMethod]
public void TestCreateStandardAccount()
{
var settings = ProtocolSettings.Default;
using var engine = ApplicationEngine.Create(TriggerType.Application, null, null, settings: TestBlockchain.TheNeoSystem.Settings, gas: 1100_00000000);

using var script = new ScriptBuilder();
script.EmitSysCall(ApplicationEngine.System_Contract_CreateStandardAccount, settings.StandbyCommittee[0].EncodePoint(true));
engine.LoadScript(script.ToArray());

Assert.AreEqual(VMState.HALT, engine.Execute());

var result = engine.ResultStack.Pop();
new UInt160(result.GetSpan()).Should().Be(Contract.CreateSignatureRedeemScript(settings.StandbyCommittee[0]).ToScriptHash());
}

[TestMethod]
public void TestCreateStandardMultisigAccount()
{
var settings = ProtocolSettings.Default;
using var engine = ApplicationEngine.Create(TriggerType.Application, null, null, settings: TestBlockchain.TheNeoSystem.Settings, gas: 1100_00000000);

using var script = new ScriptBuilder();
script.EmitSysCall(ApplicationEngine.System_Contract_CreateMultisigAccount, new object[]
{
2,
3,
settings.StandbyCommittee[0].EncodePoint(true),
settings.StandbyCommittee[1].EncodePoint(true),
settings.StandbyCommittee[2].EncodePoint(true)
});
engine.LoadScript(script.ToArray());

Assert.AreEqual(VMState.HALT, engine.Execute());

var result = engine.ResultStack.Pop();
new UInt160(result.GetSpan()).Should().Be(Contract.CreateMultiSigRedeemScript(2, settings.StandbyCommittee.Take(3).ToArray()).ToScriptHash());
}
}
}
2 changes: 1 addition & 1 deletion tests/neo.UnitTests/SmartContract/UT_ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Neo.UnitTests.SmartContract
{
[TestClass]
public class UT_ApplicationEngine
public partial class UT_ApplicationEngine
{
private string eventName = null;

Expand Down