public void TestFromJson()
        {
            var    snapshot = TestBlockchain.GetTestSnapshot();
            Action action   = () => ContractParametersContext.Parse("{\"type\":\"wrongType\",\"data\":\"00000000007c97764845172d827d3c863743293931a691271a0000000000000000000000000000000000000000000100\",\"items\":{\"0x1bd5c777ec35768892bd3daab60fb7a1cb905066\":{\"script\":\"21026ff03b949241ce1dadd43519e6960e0a85b41a69a05c328103aa2bce1594ca1650680a906ad4\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"01\"}]}}}", snapshot);

            action.Should().Throw <FormatException>();
        }
Example #2
0
        public void ApplicationEngineReusedStorage_PartialReuse()
        {
            var key      = new byte[] { (byte)OpCode.PUSH1 };
            var oldValue = new byte[] { (byte)OpCode.PUSH1 };
            var value    = new byte[] { (byte)OpCode.PUSH1, (byte)OpCode.PUSH1 };

            byte[] script = CreatePutScript(key, value);

            ContractState contractState = TestUtils.GetContract(script);

            StorageKey  skey  = TestUtils.GetStorageKey(contractState.Id, key);
            StorageItem sItem = TestUtils.GetStorageItem(oldValue);

            var snapshot = TestBlockchain.GetTestSnapshot();

            snapshot.Add(skey, sItem);
            snapshot.AddContract(script.ToScriptHash(), contractState);

            using ApplicationEngine ae = ApplicationEngine.Create(TriggerType.Application, null, snapshot);
            Debugger debugger = new(ae);

            ae.LoadScript(script);
            debugger.StepInto();
            debugger.StepInto();
            debugger.StepInto();
            var setupPrice = ae.GasConsumed;

            debugger.StepInto();
            debugger.StepInto();
            (ae.GasConsumed - setupPrice).Should().Be((1 + (oldValue.Length / 4) + value.Length - oldValue.Length) * ae.StoragePrice + (1 << 15) * 30);
        }
Example #3
0
        public void TestNotify()
        {
            var snapshot = TestBlockchain.GetTestSnapshot();

            using var engine = ApplicationEngine.Create(TriggerType.Application, null, snapshot, settings: TestBlockchain.TheNeoSystem.Settings);
            engine.LoadScript(System.Array.Empty <byte>());
            ApplicationEngine.Notify += Test_Notify1;
            const string notifyEvent = "TestEvent";

            engine.SendNotification(UInt160.Zero, notifyEvent, new Array());
            eventName.Should().Be(notifyEvent);

            ApplicationEngine.Notify += Test_Notify2;
            engine.SendNotification(UInt160.Zero, notifyEvent, new Array());
            eventName.Should().Be(null);

            eventName = notifyEvent;
            ApplicationEngine.Notify -= Test_Notify1;
            engine.SendNotification(UInt160.Zero, notifyEvent, new Array());
            eventName.Should().Be(null);

            ApplicationEngine.Notify -= Test_Notify2;
            engine.SendNotification(UInt160.Zero, notifyEvent, new Array());
            eventName.Should().Be(null);
        }
        public void TestStorage_Find()
        {
            var snapshot = TestBlockchain.GetTestSnapshot();
            var state    = TestUtils.GetContract();

            var storageItem = new StorageItem
            {
                Value = new byte[] { 0x01, 0x02, 0x03, 0x04 }
            };
            var storageKey = new StorageKey
            {
                Id  = state.Id,
                Key = new byte[] { 0x01 }
            };

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

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

            var iterator = engine.Find(new StorageContext
            {
                Id         = state.Id,
                IsReadOnly = false
            }, new byte[] { 0x01 }, FindOptions.ValuesOnly);

            iterator.Next();
            var ele = iterator.Value();

            ele.GetSpan().ToHexString().Should().Be(storageItem.Value.ToHexString());
        }
Example #5
0
        public void System_Runtime_GasLeft()
        {
            var snapshot = TestBlockchain.GetTestSnapshot();

            using (var script = new ScriptBuilder())
            {
                script.Emit(OpCode.NOP);
                script.EmitSysCall(ApplicationEngine.System_Runtime_GasLeft);
                script.Emit(OpCode.NOP);
                script.EmitSysCall(ApplicationEngine.System_Runtime_GasLeft);
                script.Emit(OpCode.NOP);
                script.Emit(OpCode.NOP);
                script.Emit(OpCode.NOP);
                script.EmitSysCall(ApplicationEngine.System_Runtime_GasLeft);

                // Execute

                var engine = ApplicationEngine.Create(TriggerType.Application, null, snapshot, gas: 100_000_000);
                engine.LoadScript(script.ToArray());
                Assert.AreEqual(engine.Execute(), VMState.HALT);

                // Check the results

                CollectionAssert.AreEqual
                (
                    engine.ResultStack.Select(u => (int)u.GetInteger()).ToArray(),
                    new int[] { 99_999_490, 99_998_980, 99_998_410 }
        public void TestSetup()
        {
            TestBlockchain.InitializeMockNeoSystem();

            var rand       = new Random();
            var mockWallet = new Mock <Wallet>();

            mockWallet.Setup(p => p.GetAccount(It.IsAny <UInt160>())).Returns <UInt160>(p => new TestWalletAccount(p));

            // Create dummy validators

            _validatorKeys = new KeyPair[7];
            for (int x = 0; x < _validatorKeys.Length; x++)
            {
                var pk = new byte[32];
                rand.NextBytes(pk);

                _validatorKeys[x] = new KeyPair(pk);
            }

            _context = new ConsensusContext(mockWallet.Object, TestBlockchain.GetStore())
            {
                Validators = _validatorKeys.Select(u => u.PublicKey).ToArray()
            };
            _context.Reset(0);
        }
        public void TestContract_Update_Invalid()
        {
            var nefFile = new NefFile()
            {
                Script   = new byte[] { 0x01 },
                Compiler = "",
                Tokens   = System.Array.Empty <MethodToken>()
            };

            nefFile.CheckSum = NefFile.ComputeChecksum(nefFile);

            var snapshot = TestBlockchain.GetTestSnapshot();

            Assert.ThrowsException <InvalidOperationException>(() => snapshot.UpdateContract(null, null, new byte[] { 0x01 }));
            Assert.ThrowsException <InvalidOperationException>(() => snapshot.UpdateContract(null, nefFile.ToArray(), null));
            Assert.ThrowsException <ArgumentException>(() => snapshot.UpdateContract(null, null, null));

            nefFile = new NefFile()
            {
                Script   = new byte[0],
                Compiler = "",
                Tokens   = System.Array.Empty <MethodToken>()
            };
            nefFile.CheckSum = NefFile.ComputeChecksum(nefFile);

            Assert.ThrowsException <InvalidOperationException>(() => snapshot.UpdateContract(null, nefFile.ToArray(), new byte[] { 0x01 }));
            Assert.ThrowsException <InvalidOperationException>(() => snapshot.UpdateContract(null, nefFile.ToArray(), new byte[0]));
        }
Example #8
0
        public void TestDuplicateOracle()
        {
            // Fake balance
            var snapshot = TestBlockchain.GetTestSnapshot();

            ApplicationEngine engine  = ApplicationEngine.Create(TriggerType.Application, null, snapshot, settings: TestBlockchain.TheNeoSystem.Settings, gas: long.MaxValue);
            BigInteger        balance = NativeContract.GAS.BalanceOf(snapshot, UInt160.Zero);

            NativeContract.GAS.Burn(engine, UInt160.Zero, balance);
            NativeContract.GAS.Mint(engine, UInt160.Zero, 8, false);

            // Test
            TransactionVerificationContext verificationContext = new TransactionVerificationContext();
            var tx = CreateTransactionWithFee(1, 2);

            tx.Attributes = new TransactionAttribute[] { new OracleResponse()
                                                         {
                                                             Code = OracleResponseCode.ConsensusUnreachable, Id = 1, Result = new byte[0]
                                                         } };
            verificationContext.CheckTransaction(tx, snapshot).Should().BeTrue();
            verificationContext.AddTransaction(tx);

            tx            = CreateTransactionWithFee(2, 1);
            tx.Attributes = new TransactionAttribute[] { new OracleResponse()
                                                         {
                                                             Code = OracleResponseCode.ConsensusUnreachable, Id = 1, Result = new byte[0]
                                                         } };
            verificationContext.CheckTransaction(tx, snapshot).Should().BeFalse();
        }
Example #9
0
        private static ApplicationEngine GetEngine(bool hasContainer = false, bool hasSnapshot = false)
        {
            var tx       = TestUtils.GetTransaction();
            var snapshot = TestBlockchain.GetStore().GetSnapshot().Clone();
            ApplicationEngine engine;

            if (hasContainer && hasSnapshot)
            {
                engine = new ApplicationEngine(TriggerType.Application, tx, snapshot, 0);
            }
            else if (hasContainer && !hasSnapshot)
            {
                engine = new ApplicationEngine(TriggerType.Application, tx, null, 0);
            }
            else if (!hasContainer && hasSnapshot)
            {
                engine = new ApplicationEngine(TriggerType.Application, null, snapshot, 0);
            }
            else
            {
                engine = new ApplicationEngine(TriggerType.Application, null, null, 0);
            }
            engine.LoadScript(new byte[] { 0x01 });
            return(engine);
        }
Example #10
0
        public void TestContract_Destroy()
        {
            var snapshot    = TestBlockchain.GetTestSnapshot();
            var state       = TestUtils.GetContract();
            var scriptHash  = UInt160.Parse("0xcb9f3b7c6fb1cf2c13a40637c189bdd066a272b4");
            var storageItem = new StorageItem
            {
                Value = new byte[] { 0x01, 0x02, 0x03, 0x04 }
            };

            var storageKey = new StorageKey
            {
                Id  = 0x43000000,
                Key = new byte[] { 0x01 }
            };

            snapshot.AddContract(scriptHash, state);
            snapshot.Add(storageKey, storageItem);
            snapshot.DestroyContract(scriptHash);
            snapshot.Find(BitConverter.GetBytes(0x43000000)).Any().Should().BeFalse();

            //storages are removed
            state = TestUtils.GetContract();
            snapshot.AddContract(scriptHash, state);
            snapshot.DestroyContract(scriptHash);
            snapshot.Find(BitConverter.GetBytes(0x43000000)).Any().Should().BeFalse();
        }
Example #11
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));
        }
Example #12
0
        public void TestStorage_Delete()
        {
            var engine     = GetEngine(false, true);
            var snapshot   = TestBlockchain.GetTestSnapshot();
            var state      = TestUtils.GetContract();
            var storageKey = new StorageKey
            {
                Id  = 0x42000000,
                Key = new byte[] { 0x01 }
            };
            var storageItem = new StorageItem
            {
                Value = new byte[] { 0x01, 0x02, 0x03, 0x04 }
            };

            snapshot.AddContract(state.Hash, state);
            snapshot.Add(storageKey, storageItem);
            engine = ApplicationEngine.Create(TriggerType.Application, null, snapshot);
            engine.LoadScript(new byte[] { 0x01 });
            var key            = new byte[] { 0x01 };
            var storageContext = new StorageContext
            {
                Id         = state.Id,
                IsReadOnly = false
            };

            engine.Delete(storageContext, key);

            //context is readonly
            storageContext.IsReadOnly = true;
            Assert.ThrowsException <ArgumentException>(() => engine.Delete(storageContext, key));
        }
Example #13
0
        public void TestStorage_Put()
        {
            var engine = GetEngine(false, true);

            //CheckStorageContext fail
            var key            = new byte[] { 0x01 };
            var value          = new byte[] { 0x02 };
            var state          = TestUtils.GetContract();
            var storageContext = new StorageContext
            {
                Id         = state.Id,
                IsReadOnly = false
            };

            engine.Put(storageContext, key, value);

            //key.Length > MaxStorageKeySize
            key   = new byte[ApplicationEngine.MaxStorageKeySize + 1];
            value = new byte[] { 0x02 };
            Assert.ThrowsException <ArgumentException>(() => engine.Put(storageContext, key, value));

            //value.Length > MaxStorageValueSize
            key   = new byte[] { 0x01 };
            value = new byte[ushort.MaxValue + 1];
            Assert.ThrowsException <ArgumentException>(() => engine.Put(storageContext, key, value));

            //context.IsReadOnly
            key   = new byte[] { 0x01 };
            value = new byte[] { 0x02 };
            storageContext.IsReadOnly = true;
            Assert.ThrowsException <ArgumentException>(() => engine.Put(storageContext, key, value));

            //storage value is constant
            var snapshot = TestBlockchain.GetTestSnapshot();

            var storageKey = new StorageKey
            {
                Id  = state.Id,
                Key = new byte[] { 0x01 }
            };
            var storageItem = new StorageItem
            {
                Value = new byte[] { 0x01, 0x02, 0x03, 0x04 }
            };

            snapshot.AddContract(state.Hash, state);
            snapshot.Add(storageKey, storageItem);
            engine = ApplicationEngine.Create(TriggerType.Application, null, snapshot);
            engine.LoadScript(new byte[] { 0x01 });
            key   = new byte[] { 0x01 };
            value = new byte[] { 0x02 };
            storageContext.IsReadOnly = false;
            engine.Put(storageContext, key, value);

            //value length == 0
            key   = new byte[] { 0x01 };
            value = System.Array.Empty <byte>();
            engine.Put(storageContext, key, value);
        }
Example #14
0
        public void TestParse()
        {
            var snapshot = TestBlockchain.GetTestSnapshot();
            var ret      = ContractParametersContext.Parse("{\"type\":\"Neo.Network.P2P.Payloads.Transaction\",\"data\":\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFmUJDLobcPtqo9vZKIdjXsd8fVGwEAARI=\",\"items\":{\"0xbecaad15c0ea585211faf99738a4354014f177f2\":{\"script\":\"IQJv8DuUkkHOHa3UNRnmlg4KhbQaaaBcMoEDqivOFZTKFmh0dHaq\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"AQ==\"}],\"signatures\":{\"03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c\":\"AQ==\"}}},\"network\":" + ProtocolSettings.Default.Network + "}", snapshot);

            ret.ScriptHashes[0].ToString().Should().Be("0x1bd5c777ec35768892bd3daab60fb7a1cb905066");
            ((Transaction)ret.Verifiable).Script.ToHexString().Should().Be(new byte[] { 18 }.ToHexString());
        }
Example #15
0
            protected override async Task <TestBlockchain> Build(ISpecProvider?specProvider = null, UInt256?initialValues = null)
            {
                TestBlockchain chain = await base.Build(specProvider, initialValues);

                AccountAbstractionRpcModule = new AccountAbstractionRpcModule(UserOperationPool, new [] { new Address(_accountAbstractionConfig.EntryPointContractAddress) });

                return(chain);
            }
Example #16
0
        public void TestParse()
        {
            var snapshot = TestBlockchain.GetTestSnapshot();
            var ret      = ContractParametersContext.Parse("{\"type\":\"Neo.Network.P2P.Payloads.Transaction\",\"hex\":\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFmUJDLobcPtqo9vZKIdjXsd8fVGwEAARI=\",\"items\":{\"0xbecaad15c0ea585211faf99738a4354014f177f2\":{\"script\":\"IQJv8DuUkkHOHa3UNRnmlg4KhbQaaaBcMoEDqivOFZTKFmh0dHaq\",\"parameters\":[{\"type\":\"Signature\",\"value\":\"AQ==\"}]}}}", snapshot);

            ret.ScriptHashes[0].ToString().Should().Be("0x1bd5c777ec35768892bd3daab60fb7a1cb905066");
            ((Transaction)ret.Verifiable).Script.ToHexString().Should().Be(new byte[] { 18 }.ToHexString());
        }
            protected override async Task <TestBlockchain> Build(ISpecProvider?specProvider = null, UInt256?initialValues = null)
            {
                TestBlockchain chain = await base.Build(specProvider, initialValues);

                await chain.BlockchainProcessor.StopAsync(true);

                return(chain);
            }
Example #18
0
        public void TestGetComplete()
        {
            var         snapshot = TestBlockchain.GetTestSnapshot();
            Transaction tx       = TestUtils.GetTransaction(UInt160.Parse("0x1bd5c777ec35768892bd3daab60fb7a1cb905066"));
            var         context  = new ContractParametersContext(snapshot, tx);

            context.Completed.Should().BeFalse();
        }
            protected override async Task <TestBlockchain> Build(ISpecProvider specProvider = null, UInt256?initialValues = null)
            {
                TestBlockchain chain = await base.Build(specProvider, initialValues);

                PruningDb  = (IFullPruningDb)DbProvider.StateDb;
                FullPruner = new FullTestPruner(PruningDb, PruningTrigger, PruningConfig, BlockTree, StateReader, LogManager);
                return(chain);
            }
Example #20
0
        public void Json_Serialize()
        {
            var snapshot = TestBlockchain.GetTestSnapshot();

            // Good

            using (var script = new ScriptBuilder())
            {
                script.EmitDynamicCall(NativeContract.StdLib.Hash, "jsonSerialize", 5);
                script.EmitDynamicCall(NativeContract.StdLib.Hash, "jsonSerialize", true);
                script.EmitDynamicCall(NativeContract.StdLib.Hash, "jsonSerialize", "test");
                script.EmitDynamicCall(NativeContract.StdLib.Hash, "jsonSerialize", new object[] { null });
                script.EmitDynamicCall(NativeContract.StdLib.Hash, "jsonSerialize", new ContractParameter(ContractParameterType.Map)
                {
                    Value = new List <KeyValuePair <ContractParameter, ContractParameter> >()
                    {
                        { new KeyValuePair <ContractParameter, ContractParameter>(
                              new ContractParameter(ContractParameterType.String)
                            {
                                Value = "key"
                            },
                              new ContractParameter(ContractParameterType.String)
                            {
                                Value = "value"
                            }) }
                    }
                });

                using (var engine = ApplicationEngine.Create(TriggerType.Application, null, snapshot, settings: TestBlockchain.TheNeoSystem.Settings))
                {
                    engine.LoadScript(script.ToArray());

                    Assert.AreEqual(engine.Execute(), VMState.HALT);
                    Assert.AreEqual(5, engine.ResultStack.Count);

                    Assert.IsTrue(engine.ResultStack.Pop <ByteString>().GetString() == "{\"key\":\"value\"}");
                    Assert.IsTrue(engine.ResultStack.Pop <ByteString>().GetString() == "null");
                    Assert.IsTrue(engine.ResultStack.Pop <ByteString>().GetString() == "\"test\"");
                    Assert.IsTrue(engine.ResultStack.Pop <ByteString>().GetString() == "1");
                    Assert.IsTrue(engine.ResultStack.Pop <ByteString>().GetString() == "5");
                }
            }

            // Error

            using (var script = new ScriptBuilder())
            {
                script.EmitDynamicCall(NativeContract.StdLib.Hash, "jsonSerialize");

                using (var engine = ApplicationEngine.Create(TriggerType.Application, null, snapshot, settings: TestBlockchain.TheNeoSystem.Settings))
                {
                    engine.LoadScript(script.ToArray());

                    Assert.AreEqual(engine.Execute(), VMState.FAULT);
                    Assert.AreEqual(0, engine.ResultStack.Count);
                }
            }
        }
        public void Init()
        {
            _store = TestBlockchain.GetStore();
            var snapshot = _store.GetSnapshot();

            _block  = Blockchain.GenesisBlock;
            _engine = new TestEngine(snapshot: snapshot);
            _engine.AddEntryScript("./TestClasses/Contract_Blockchain.cs");
        }
Example #22
0
        public void TestAddSignature()
        {
            var         snapshot     = TestBlockchain.GetTestSnapshot();
            var         singleSender = UInt160.Parse("0x4bc1b25796f4a13fa3cc7538168d86f7d3bc5356");
            Transaction tx           = TestUtils.GetTransaction(singleSender);

            //singleSign

            var context = new ContractParametersContext(snapshot, tx);

            context.AddSignature(contract, key.PublicKey, new byte[] { 0x01 }).Should().BeTrue();

            var contract1 = Contract.CreateSignatureContract(key.PublicKey);

            contract1.ParameterList = new ContractParameterType[0];
            context = new ContractParametersContext(snapshot, tx);
            context.AddSignature(contract1, key.PublicKey, new byte[] { 0x01 }).Should().BeFalse();

            contract1.ParameterList = new[] { ContractParameterType.Signature, ContractParameterType.Signature };
            Action action1 = () => context.AddSignature(contract1, key.PublicKey, new byte[] { 0x01 });

            action1.Should().Throw <NotSupportedException>();

            //multiSign

            byte[] privateKey2 = new byte[] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02 };
            var key2 = new KeyPair(privateKey2);
            var multiSignContract = Contract.CreateMultiSigContract(2,
                                                                    new ECPoint[]
            {
                key.PublicKey,
                key2.PublicKey
            });
            var multiSender = UInt160.Parse("0x7eae53e544e3c1507bfa7892d4793b8784be4c31");

            tx      = TestUtils.GetTransaction(multiSender);
            context = new ContractParametersContext(snapshot, tx);
            context.AddSignature(multiSignContract, key.PublicKey, new byte[] { 0x01 }).Should().BeTrue();
            context.AddSignature(multiSignContract, key2.PublicKey, new byte[] { 0x01 }).Should().BeTrue();

            tx      = TestUtils.GetTransaction(singleSender);
            context = new ContractParametersContext(snapshot, tx);
            context.AddSignature(multiSignContract, key.PublicKey, new byte[] { 0x01 }).Should().BeFalse();

            tx      = TestUtils.GetTransaction(multiSender);
            context = new ContractParametersContext(snapshot, tx);
            byte[] privateKey3 = new byte[] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03 };
            var key3 = new KeyPair(privateKey3);

            context.AddSignature(multiSignContract, key3.PublicKey, new byte[] { 0x01 }).Should().BeFalse();
        }
Example #23
0
        public void TestSetup()
        {
            TestBlockchain.InitializeMockNeoSystem();
            _snapshot = Blockchain.Singleton.GetSnapshot();

            ApplicationEngine engine = ApplicationEngine.Create(TriggerType.OnPersist, null, _snapshot, new Block(), 0);

            NativeContract.ContractManagement.OnPersist(engine);
        }
Example #24
0
        public void TestSetup()
        {
            TestBlockchain.InitializeMockNeoSystem();

            _snapshot        = TestBlockchain.GetTestSnapshot();
            _persistingBlock = new Block {
                Header = new Header()
            };
        }
Example #25
0
 public void TestSetup()
 {
     _snapshot        = TestBlockchain.GetTestSnapshot();
     _persistingBlock = new Block
     {
         Header       = new Header(),
         Transactions = Array.Empty <Transaction>()
     };
 }
Example #26
0
 public void TestSetup()
 {
     TestBlockchain.InitializeMockNeoSystem();
     _snapshot = Blockchain.Singleton.GetSnapshot();
     _snapshot.PersistingBlock = new Block()
     {
         Index = 0
     };
 }
Example #27
0
        public void TestAddSignature()
        {
            var         snapshot     = TestBlockchain.GetTestSnapshot();
            var         singleSender = UInt160.Parse("0x902e0d38da5e513b6d07c1c55b85e77d3dce8063");
            Transaction tx           = TestUtils.GetTransaction(singleSender);

            //singleSign

            var context = new ContractParametersContext(snapshot, tx);

            context.AddSignature(contract, key.PublicKey, new byte[] { 0x01 }).Should().BeTrue();

            var contract1 = Contract.CreateSignatureContract(key.PublicKey);

            contract1.ParameterList = Array.Empty <ContractParameterType>();
            context = new ContractParametersContext(snapshot, tx);
            context.AddSignature(contract1, key.PublicKey, new byte[] { 0x01 }).Should().BeFalse();

            contract1.ParameterList = new[] { ContractParameterType.Signature, ContractParameterType.Signature };
            Action action1 = () => context.AddSignature(contract1, key.PublicKey, new byte[] { 0x01 });

            action1.Should().Throw <NotSupportedException>();

            //multiSign

            byte[] privateKey2 = new byte[] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02 };
            var key2 = new KeyPair(privateKey2);
            var multiSignContract = Contract.CreateMultiSigContract(2,
                                                                    new ECPoint[]
            {
                key.PublicKey,
                key2.PublicKey
            });
            var multiSender = UInt160.Parse("0xf76b51bc6605ac3cfcd188173af0930507f51210");

            tx      = TestUtils.GetTransaction(multiSender);
            context = new ContractParametersContext(snapshot, tx);
            context.AddSignature(multiSignContract, key.PublicKey, new byte[] { 0x01 }).Should().BeTrue();
            context.AddSignature(multiSignContract, key2.PublicKey, new byte[] { 0x01 }).Should().BeTrue();

            tx      = TestUtils.GetTransaction(singleSender);
            context = new ContractParametersContext(snapshot, tx);
            context.AddSignature(multiSignContract, key.PublicKey, new byte[] { 0x01 }).Should().BeFalse();

            tx      = TestUtils.GetTransaction(multiSender);
            context = new ContractParametersContext(snapshot, tx);
            byte[] privateKey3 = new byte[] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03 };
            var key3 = new KeyPair(privateKey3);

            context.AddSignature(multiSignContract, key3.PublicKey, new byte[] { 0x01 }).Should().BeFalse();
        }
Example #28
0
        public void TestAddSignature()
        {
            var         snapshot     = TestBlockchain.GetTestSnapshot();
            var         singleSender = UInt160.Parse("0x282646ee0afa5508bb999318f35074b84a17c9f0");
            Transaction tx           = TestUtils.GetTransaction(singleSender);

            //singleSign

            var context = new ContractParametersContext(snapshot, tx);

            context.AddSignature(contract, key.PublicKey, new byte[] { 0x01 }).Should().BeTrue();

            var contract1 = Contract.CreateSignatureContract(key.PublicKey);

            contract1.ParameterList = new ContractParameterType[0];
            context = new ContractParametersContext(snapshot, tx);
            context.AddSignature(contract1, key.PublicKey, new byte[] { 0x01 }).Should().BeFalse();

            contract1.ParameterList = new[] { ContractParameterType.Signature, ContractParameterType.Signature };
            Action action1 = () => context.AddSignature(contract1, key.PublicKey, new byte[] { 0x01 });

            action1.Should().Throw <NotSupportedException>();

            //multiSign

            byte[] privateKey2 = new byte[] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02 };
            var key2 = new KeyPair(privateKey2);
            var multiSignContract = Contract.CreateMultiSigContract(2,
                                                                    new ECPoint[]
            {
                key.PublicKey,
                key2.PublicKey
            });
            var multiSender = UInt160.Parse("0x3593816cc1085a6328fea2b899c24d78cd0ba372");

            tx      = TestUtils.GetTransaction(multiSender);
            context = new ContractParametersContext(snapshot, tx);
            context.AddSignature(multiSignContract, key.PublicKey, new byte[] { 0x01 }).Should().BeTrue();
            context.AddSignature(multiSignContract, key2.PublicKey, new byte[] { 0x01 }).Should().BeTrue();

            tx      = TestUtils.GetTransaction(singleSender);
            context = new ContractParametersContext(snapshot, tx);
            context.AddSignature(multiSignContract, key.PublicKey, new byte[] { 0x01 }).Should().BeFalse();

            tx      = TestUtils.GetTransaction(multiSender);
            context = new ContractParametersContext(snapshot, tx);
            byte[] privateKey3 = new byte[] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                                              0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03 };
            var key3 = new KeyPair(privateKey3);

            context.AddSignature(multiSignContract, key3.PublicKey, new byte[] { 0x01 }).Should().BeFalse();
        }
Example #29
0
 public void TestSetup()
 {
     TestBlockchain.InitializeMockNeoSystem();
     _snapshot        = Blockchain.Singleton.GetSnapshot();
     _persistingBlock = new Block()
     {
         Index = 0, Transactions = Array.Empty <Transaction>(), ConsensusData = new ConsensusData()
     };
 }
Example #30
0
        public void TestSetup()
        {
            _snapshot = TestBlockchain.GetTestSnapshot();

            ApplicationEngine engine = ApplicationEngine.Create(TriggerType.OnPersist, null, _snapshot, new Block {
                Header = new Header()
            }, settings: TestBlockchain.TheNeoSystem.Settings, gas: 0);

            NativeContract.ContractManagement.OnPersist(engine);
        }