Exemplo n.º 1
0
        public void TestInvoke()
        {
            var snapshot = Blockchain.Singleton.GetSnapshot();
            ApplicationEngine engine1 = new ApplicationEngine(TriggerType.Application, null, snapshot, 0);

            ScriptBuilder sb1 = new ScriptBuilder();

            sb1.EmitSysCall("null".ToInteropMethodHash());
            engine1.LoadScript(sb1.ToArray());
            testNativeContract.Invoke(engine1).Should().BeFalse();

            ApplicationEngine engine2 = new ApplicationEngine(TriggerType.Application, null, snapshot, 0);

            ScriptBuilder sb2 = new ScriptBuilder();
            sb2.EmitSysCall("test".ToInteropMethodHash());
            engine2.LoadScript(sb2.ToArray());

            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();

            ByteString method2 = new ByteString(System.Text.Encoding.Default.GetBytes("onPersist"));
            VMArray args2 = new VMArray();
            engine2.CurrentContext.EvaluationStack.Push(args2);
            engine2.CurrentContext.EvaluationStack.Push(method2);
            testNativeContract.Invoke(engine2).Should().BeTrue();
        }
Exemplo n.º 2
0
        public void TestInvoke()
        {
            var snapshot             = Blockchain.Singleton.GetSnapshot();
            ApplicationEngine engine = ApplicationEngine.Create(TriggerType.OnPersist, null, snapshot, null, 0);

            engine.LoadScript(testNativeContract.Script, configureState: p => p.ScriptHash = testNativeContract.Hash);

            ByteString method1 = new ByteString(System.Text.Encoding.Default.GetBytes("wrongMethod"));

            engine.CurrentContext.EvaluationStack.Push(method1);
            Assert.ThrowsException <KeyNotFoundException>(() => testNativeContract.Invoke(engine));

            ByteString method2 = new ByteString(System.Text.Encoding.Default.GetBytes("helloWorld"));

            engine.CurrentContext.EvaluationStack.Push(method2);
            testNativeContract.Invoke(engine);
        }
Exemplo n.º 3
0
        public void TestInvoke()
        {
            var snapshot             = Blockchain.Singleton.GetSnapshot();
            ApplicationEngine engine = new ApplicationEngine(TriggerType.System, null, snapshot, 0);

            engine.LoadScript(testNativeContract.Script);

            ByteString method1 = new ByteString(System.Text.Encoding.Default.GetBytes("wrongMethod"));
            VMArray    args1   = new VMArray();

            engine.CurrentContext.EvaluationStack.Push(args1);
            engine.CurrentContext.EvaluationStack.Push(method1);
            testNativeContract.Invoke(engine).Should().BeFalse();

            ByteString method2 = new ByteString(System.Text.Encoding.Default.GetBytes("onPersist"));
            VMArray    args2   = new VMArray();

            engine.CurrentContext.EvaluationStack.Push(args2);
            engine.CurrentContext.EvaluationStack.Push(method2);
            testNativeContract.Invoke(engine).Should().BeTrue();
        }
Exemplo n.º 4
0
        public void TestInvoke()
        {
            var snapshot             = Blockchain.Singleton.GetSnapshot();
            ApplicationEngine engine = ApplicationEngine.Create(TriggerType.System, null, snapshot, 0);

            engine.LoadScript(testNativeContract.Script);

            ByteString method1 = new ByteString(System.Text.Encoding.Default.GetBytes("wrongMethod"));
            VMArray    args1   = new VMArray();

            engine.CurrentContext.EvaluationStack.Push(args1);
            engine.CurrentContext.EvaluationStack.Push(method1);
            Assert.ThrowsException <KeyNotFoundException>(() => testNativeContract.Invoke(engine));

            ByteString method2 = new ByteString(System.Text.Encoding.Default.GetBytes("onPersist"));
            VMArray    args2   = new VMArray();

            engine.CurrentContext.EvaluationStack.Push(args2);
            engine.CurrentContext.EvaluationStack.Push(method2);
            testNativeContract.Invoke(engine);
        }