Ejemplo n.º 1
0
        public void TestContract_CallEx()
        {
            var snapshot = Blockchain.Singleton.GetSnapshot();

            string method = "method";
            var    args   = new VM.Types.Array {
                0, 1
            };
            var state = TestUtils.GetContract(method, args.Count);

            state.Manifest.Features = ContractFeatures.HasStorage;
            snapshot.Contracts.Add(state.ScriptHash, state);


            foreach (var flags in new CallFlags[] { CallFlags.None, CallFlags.AllowCall, CallFlags.AllowModifyStates, CallFlags.All })
            {
                var engine = new ApplicationEngine(TriggerType.Application, null, snapshot, 0, true);
                engine.LoadScript(new byte[] { 0x01 });

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

                // Contract doesn't exists
                Assert.ThrowsException <InvalidOperationException>(() => engine.CallContractEx(UInt160.Zero, method, args, CallFlags.All));

                // Call with rights
                engine.CallContractEx(state.ScriptHash, method, args, flags);
                engine.CurrentContext.EvaluationStack.Pop().Should().Be(args[0]);
                engine.CurrentContext.EvaluationStack.Pop().Should().Be(args[1]);
            }
        }