Beispiel #1
0
        public void GenerateCode_InputIsEmpty_NotSuccessful()
        {
            #region Arrange

            string input = null;

            #endregion

            #region Act

            CodeGeneratorService service = new CodeGeneratorService {
            };
            CodeGenerationResult result  = service.GenerateCode(input);

            #endregion

            #region Assert

            Assert.IsNotNull(result);
            Assert.IsFalse(result.IsSuccessful);
            Assert.IsNotNull(result.Error);
            Assert.IsTrue(result.Error.ToLower().Contains("empty"));
            Assert.IsNull(result.Code);

            #endregion
        }
        private int RunCommand()
        {
            var contractByteCode =
                "0x6060604052604051602080610213833981016040528080519060200190919050505b806000600050819055505b506101d88061003b6000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806361325dbc1461004f578063c23f4e3e1461007b578063c6888fa1146100b05761004d565b005b61006560048080359060200190919050506100dc565b6040518082815260200191505060405180910390f35b61009a60048080359060200190919080359060200190919050506100f2565b6040518082815260200191505060405180910390f35b6100c66004808035906020019091905050610104565b6040518082815260200191505060405180910390f35b6000600060005054820290506100ed565b919050565b600081830290506100fe565b92915050565b600060006000505482029050805080827f51ae5c4fa89d1aa731ff280d425357e6e5c838c6fc8ed6ca0139ea31716bbd5760405180905060405180910390a360405180807f48656c6c6f20776f726c64000000000000000000000000000000000000000000815260200150600b019050604051809103902081837f74053123e4f45ba0f8cbf86301034a4ab00cdc75cd155a0df7c5d815bd97dcb533604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a48090506101d3565b91905056";

            var abi =
                @"[{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply1"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""},{""name"":""b"",""type"":""uint256""}],""name"":""multiply2"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""uint256""},{""name"":""e"",""type"":""uint256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""uint256""}],""type"":""constructor""},{""anonymous"":false,""inputs"":[{""indexed"":true,""name"":""a"",""type"":""uint256""},{""indexed"":true,""name"":""result"",""type"":""uint256""}],""name"":""Multiplied"",""type"":""event""},{""anonymous"":false,""inputs"":[{""indexed"":true,""name"":""a"",""type"":""uint256""},{""indexed"":true,""name"":""result"",""type"":""uint256""},{""indexed"":true,""name"":""sender"",""type"":""string""},{""indexed"":false,""name"":""hello"",""type"":""address""}],""name"":""MultipliedLog"",""type"":""event""}]";

            var model = new ServiceModel(abi, contractByteCode, "sample", "SampleNamespace");

            var fileName = model.ContractName + "Service.cs";

            CodeGeneratorService.GenerateFileAsync("Service", model, fileName).Wait();

            return(1);
        }
        private int RunCommand()
        {
            var abiFile = _abiFile.Value();

            if (string.IsNullOrWhiteSpace(abiFile))
            {
                System.Console.WriteLine("A abi file needs was not specified");
                return(1);
            }

            var binFile = _binFile.Value();

            if (string.IsNullOrWhiteSpace(binFile))
            {
                System.Console.WriteLine("A bin file needs was not specified");
                return(1);
            }

            var contractName = _contractName.Value();

            if (string.IsNullOrWhiteSpace(contractName))
            {
                contractName = ServiceModel.DEFAULT_CONTRACTNAME;
            }
            var namespaceName = _namespaceName.Value();

            if (string.IsNullOrWhiteSpace(namespaceName))
            {
                namespaceName = ServiceModel.DEFAULT_NAMESPACE;
            }

            var abi      = "";
            var byteCode = "";

            if (!File.Exists(abiFile))
            {
                System.Console.WriteLine(("Abi file not found"));
                return(1);
            }

            if (!File.Exists(binFile))
            {
                System.Console.WriteLine(("Bin file not found"));
                return(1);
            }

            using (var file = File.OpenText(abiFile))
            {
                abi = file.ReadToEnd();
            }

            using (var file = File.OpenText(binFile))
            {
                byteCode = file.ReadToEnd();
            }

            CodeGeneratorService.GenerateFileAsync("Service.cshtml",
                                                   new ServiceModel(abi, byteCode, contractName, namespaceName), contractName + "Service.cs").Wait();

            return(0);
        }
        private int RunCommand()
        {
            var abiFile = _abiFile.Value();

            if (string.IsNullOrWhiteSpace(abiFile))
            {
                System.Console.WriteLine("A abi file needs was not specified");
                return(1);
            }

            var binFile = _binFile.Value();

            if (string.IsNullOrWhiteSpace(binFile))
            {
                System.Console.WriteLine("A bin file needs was not specified");
                return(1);
            }

            var functionName = _functionName.Value();

            var namespaceName = _namespaceName.Value();

            if (string.IsNullOrWhiteSpace(namespaceName))
            {
                namespaceName = ServiceModel.DEFAULT_NAMESPACE;
            }

            var abi      = "";
            var byteCode = "";

            if (!File.Exists(abiFile))
            {
                System.Console.WriteLine(("Abi file not found"));
                return(1);
            }

            if (!File.Exists(binFile))
            {
                System.Console.WriteLine(("Bin file not found"));
                return(1);
            }

            using (var file = File.OpenText(abiFile))
            {
                abi = file.ReadToEnd();
            }

            using (var file = File.OpenText(binFile))
            {
                byteCode = file.ReadToEnd();
            }

            string directoryPath = null;

            if (!Directory.Exists("FunctionMessages"))
            {
                directoryPath = Directory.CreateDirectory("FunctionMessages").FullName;
            }
            else
            {
                directoryPath = Path.Combine(Directory.GetCurrentDirectory(), "FunctionMessages");
            }

            if (!String.IsNullOrEmpty(functionName))
            {
                var model = new CQSMessageModel(abi, byteCode, functionName, namespaceName);
                CodeGeneratorService.GenerateFileAsync("Generators.CQS.CQSMessage.cshtml",
                                                       model, Path.Combine(directoryPath, model.GetFunctionMessageName() + ".cs")).Wait();
            }
            else
            {
                var model = new CQSMessageModel(abi, byteCode, namespaceName);
                foreach (var function in model.Contract.Functions)
                {
                    model.FunctionName = function.Name;
                    CodeGeneratorService.GenerateFileAsync("Generators.CQS.CQSMessage.cshtml",
                                                           model, Path.Combine(directoryPath, model.GetFunctionMessageName() + ".cs")).Wait();
                }
            }
            return(0);
        }