Пример #1
0
        public void SendTranscationWithReceiptDecodeTest()
        {
            var              contractService  = new ContractService(BaseConfig.DefaultUrl, BaseConfig.DefaultRpcId, BaseConfig.DefaultChainId, BaseConfig.DefaultGroupId, privateKey);
            string           contractAddress  = "0x149d743274d91eeea8f646901fc8dd79551dccda";//上面测试部署合约得到合约地址
            var              inputsParameters = new[] { BuildParams.CreateParam("string", "n") };
            var              paramsValue      = new object[] { "123" };
            string           functionName     = "set";//调用合约方法
            ReceiptResultDto receiptResultDto = contractService.SendTranscationWithReceipt(abi, contractAddress, functionName, inputsParameters, paramsValue);

            Assert.NotEmpty(receiptResultDto.Output);
            Assert.NotEmpty(receiptResultDto.Input);
            Assert.NotEmpty(receiptResultDto.Logs);
            var solidityAbi = new SolidityABI(abi);
            var inputList   = solidityAbi.InputDecode(functionName, receiptResultDto.Input);

            Assert.True(inputList[0].Parameter.Name == "n" && inputList[0].Result.ToString() == "123");

            string eventName    = "SetEvent";
            var    eventList    = solidityAbi.EventDecode(eventName, receiptResultDto.Logs);
            var    eventpramas1 = eventList[0].Event.Find(x => x.Parameter.Name == "paramsStr");
            var    eventpramas2 = eventList[0].Event.Find(x => x.Parameter.Name == "operationTimeStamp");

            Assert.True(eventpramas1.Result.ToString() == "123");
            Assert.NotNull(eventpramas2.Result);
        }
Пример #2
0
        public void GetContructorParamsTest()
        {
            //var data = "0x2dc9".HexToBigInteger(true);
            var contractService = new ContractService(BaseConfig.DefaultUrl, BaseConfig.DefaultRpcId, BaseConfig.DefaultChainId, BaseConfig.DefaultGroupId, privateKey);

            string contractAddress      = "0x1be74c68f3fec43b2360dd7456748121e1216960";//上面测试部署合约得到合约地址
            var    funcInputsParameters = new[] { BuildParams.CreateParam("uint256", "temp") };
            var    funcParamsValue      = new object[] { 1 };
            string functionName         = "get";//调用合约方法

            ReceiptResultDto receiptResultDto = contractService.CallRequest(contractAddress, abi, functionName, funcInputsParameters, funcParamsValue);

            Assert.NotEmpty(receiptResultDto.Output);
            var solidityAbi = new SolidityABI(abi);
            var outputList  = solidityAbi.OutputDecode(functionName, receiptResultDto.Output);

            Assert.Equal("123", outputList[0].Result);
        }