Пример #1
0
 /// <summary>
 /// Emits the opcodes for calling a contract dynamically.
 /// </summary>
 /// <param name="builder">The <see cref="ScriptBuilder"/> to be used.</param>
 /// <param name="scriptHash">The hash of the contract to be called.</param>
 /// <param name="method">The method to be called in the contract.</param>
 /// <param name="flags">The <see cref="CallFlags"/> for calling the contract.</param>
 /// <param name="args">The arguments for calling the contract.</param>
 /// <returns>The same instance as <paramref name="builder"/>.</returns>
 public static ScriptBuilder EmitDynamicCall(this ScriptBuilder builder, UInt160 scriptHash, string method, CallFlags flags, params object[] args)
 {
     builder.CreateArray(args);
     builder.EmitPush(flags);
     builder.EmitPush(method);
     builder.EmitPush(scriptHash);
     builder.EmitSysCall(ApplicationEngine.System_Contract_Call);
     return(builder);
 }
Пример #2
0
        public void TestEmitArray()
        {
            var expected = new BigInteger[] { 1, 2, 3 };
            var sb       = new ScriptBuilder();

            sb.CreateArray(expected);

            using var engine = ApplicationEngine.Create(TriggerType.Application, null, null);
            engine.LoadScript(sb.ToArray());
            Assert.AreEqual(VMState.HALT, engine.Execute());

            CollectionAssert.AreEqual(expected, engine.ResultStack.Pop <VM.Types.Array>().Select(u => u.GetInteger()).ToArray());

            expected = new BigInteger[] { };
            sb       = new ScriptBuilder();
            sb.CreateArray(expected);

            using var engine2 = ApplicationEngine.Create(TriggerType.Application, null, null);
            engine2.LoadScript(sb.ToArray());
            Assert.AreEqual(VMState.HALT, engine2.Execute());

            Assert.AreEqual(0, engine2.ResultStack.Pop <VM.Types.Array>().Count);
        }