Ejemplo n.º 1
0
        public void TestContract_Call()
        {
            var    snapshot = TestBlockchain.GetTestSnapshot();
            string method   = "method";
            var    args     = new VM.Types.Array {
                0, 1
            };
            var state = TestUtils.GetContract(method, args.Count);

            snapshot.AddContract(state.Hash, state);
            var engine = ApplicationEngine.Create(TriggerType.Application, null, snapshot);

            engine.LoadScript(new byte[] { 0x01 });

            engine.CallContract(state.Hash, method, CallFlags.All, args);
            engine.CurrentContext.EvaluationStack.Pop().Should().Be(args[0]);
            engine.CurrentContext.EvaluationStack.Pop().Should().Be(args[1]);

            state.Manifest.Permissions[0].Methods = WildcardContainer <string> .Create("a");

            Assert.ThrowsException <InvalidOperationException>(() => engine.CallContract(state.Hash, method, CallFlags.All, args));

            state.Manifest.Permissions[0].Methods = WildcardContainer <string> .CreateWildcard();

            engine.CallContract(state.Hash, method, CallFlags.All, args);

            Assert.ThrowsException <InvalidOperationException>(() => engine.CallContract(UInt160.Zero, method, CallFlags.All, args));
        }
Ejemplo n.º 2
0
        public void TestContract_Call()
        {
            var snapshot = Blockchain.Singleton.GetSnapshot();
            var state    = TestUtils.GetContract("method");

            state.Manifest.Features = ContractFeatures.HasStorage;
            byte[] method = Encoding.UTF8.GetBytes("method");
            var    args   = new VM.Types.Array {
                0, 1
            };

            snapshot.Contracts.Add(state.ScriptHash, state);
            var engine = new ApplicationEngine(TriggerType.Application, null, snapshot, 0);

            engine.LoadScript(new byte[] { 0x01 });

            engine.CurrentContext.EvaluationStack.Push(args);
            engine.CurrentContext.EvaluationStack.Push(method);
            engine.CurrentContext.EvaluationStack.Push(state.ScriptHash.ToArray());
            InteropService.Invoke(engine, InteropService.Contract.Call).Should().BeTrue();
            engine.CurrentContext.EvaluationStack.Pop().Should().Be(args[0]);
            engine.CurrentContext.EvaluationStack.Pop().Should().Be(args[1]);

            state.Manifest.Permissions[0].Methods = WildcardContainer <string> .Create("a");

            engine.CurrentContext.EvaluationStack.Push(args);
            engine.CurrentContext.EvaluationStack.Push(method);
            engine.CurrentContext.EvaluationStack.Push(state.ScriptHash.ToArray());
            InteropService.Invoke(engine, InteropService.Contract.Call).Should().BeFalse();
            state.Manifest.Permissions[0].Methods = WildcardContainer <string> .CreateWildcard();

            engine.CurrentContext.EvaluationStack.Push(args);
            engine.CurrentContext.EvaluationStack.Push(method);
            engine.CurrentContext.EvaluationStack.Push(state.ScriptHash.ToArray());
            InteropService.Invoke(engine, InteropService.Contract.Call).Should().BeTrue();

            engine.CurrentContext.EvaluationStack.Push(args);
            engine.CurrentContext.EvaluationStack.Push(method);
            engine.CurrentContext.EvaluationStack.Push(UInt160.Zero.ToArray());
            InteropService.Invoke(engine, InteropService.Contract.Call).Should().BeFalse();
        }