コード例 #1
0
        public override TradeMessage QueryMappedState2(Complex3Input input)
        {
            var message = State.Complex4Info[input.From][input.PairA][input.To][input.PairB];

            if (message == null)
            {
                return(new TradeMessage());
            }

            return(new TradeMessage
            {
                FromAmount = message.FromAmount,
                ToAmount = message.ToAmount,
                Timestamp = message.Timestamp
            });
        }
コード例 #2
0
ファイル: TestContract.cs プロジェクト: zhxymh/AElf
        public override TradeMessage TestMapped1State(Complex3Input input)
        {
            var tradeMessage = State.Complex4Info[input.From][input.PairA][input.To][input.PairB];

            if (tradeMessage == null)
            {
                State.Complex4Info[input.From][input.PairA][input.To][input.PairB] = input.TradeDetails;

                return(input.TradeDetails);
            }

            tradeMessage.FromAmount += input.TradeDetails.FromAmount;
            tradeMessage.ToAmount   += input.TradeDetails.ToAmount;

            State.Complex4Info[input.From][input.PairA][input.To][input.PairB] = tradeMessage;

            return(tradeMessage);
        }
コード例 #3
0
        public override Empty TestMapped2State(Complex3Input input)
        {
            var tradeMessage = State.Complex4Info[input.From][input.PairA][input.To][input.PairB];

            if (tradeMessage == null)
            {
                State.Complex4Info[input.From][input.PairA][input.To][input.PairB] = input.TradeDetails;
            }
            else
            {
                tradeMessage.FromAmount += input.TradeDetails.FromAmount;
                tradeMessage.ToAmount   += input.TradeDetails.ToAmount;

                State.Complex4Info[input.From][input.PairA][input.To][input.PairB] = tradeMessage;
            }

            return(new Empty());
        }
コード例 #4
0
        public override Empty TestMapped2State(Complex3Input input)
        {
            var tradeMessage = State.Complex4Info[input.From][input.PairA][input.To][input.PairB];

            if (tradeMessage == null)
            {
                input.TradeDetails.Timestamp = Context.CurrentBlockTime;
                State.Complex4Info[input.From][input.PairA][input.To][input.PairB] = input.TradeDetails;
            }
            else
            {
                tradeMessage.FromAmount = tradeMessage.FromAmount.Add(input.TradeDetails.FromAmount);
                tradeMessage.ToAmount   = tradeMessage.ToAmount.Add(input.TradeDetails.ToAmount);
                tradeMessage.Timestamp  = Context.CurrentBlockTime;

                State.Complex4Info[input.From][input.PairA][input.To][input.PairB] = tradeMessage;
            }

            return(new Empty());
        }
コード例 #5
0
ファイル: TestContract.cs プロジェクト: woxihuanjia/AElf
        public override TradeMessage TestMapped1State(Complex3Input input)
        {
            var tradeMessage = State.Complex4Info[input.From][input.PairA][input.To][input.PairB];

            if (tradeMessage == null)
            {
                input.TradeDetails.Timestamp = DateTime.UtcNow.ToTimestamp();
                State.Complex4Info[input.From][input.PairA][input.To][input.PairB] = input.TradeDetails;

                return(input.TradeDetails);
            }
            else
            {
                tradeMessage.FromAmount += input.TradeDetails.FromAmount;
                tradeMessage.ToAmount   += input.TradeDetails.ToAmount;
                tradeMessage.Timestamp   = DateTime.UtcNow.ToTimestamp();

                State.Complex4Info[input.From][input.PairA][input.To][input.PairB] = tradeMessage;

                return(tradeMessage);
            }
        }
コード例 #6
0
        public async Task TestMappedStateSizeLimit()
        {
            var stateSizeLimit = SmartContractConstants.StateSizeLimit;

            {
                var str      = Encoding.UTF8.GetString(new byte[stateSizeLimit]);
                var txResult = await TestBasicSecurityContractStub.TestMappedState.SendWithExceptionAsync(
                    new ProtobufInput
                {
                    ProtobufValue = new ProtobufMessage
                    {
                        StringValue = str
                    }
                });

                txResult.TransactionResult.Error.ShouldContain($"exceeds limit of {stateSizeLimit}");

                await TestBasicSecurityContractStub.TestMappedState.SendAsync(new ProtobufInput
                {
                    ProtobufValue = new ProtobufMessage
                    {
                        Int64Value = 1
                    }
                });

                var queryResult = await TestBasicSecurityContractStub.QueryMappedState.CallAsync(new ProtobufInput
                {
                    ProtobufValue = new ProtobufMessage
                    {
                        Int64Value = 1
                    }
                });

                queryResult.Int64Value.ShouldBe(1);

                (await TestBasicSecurityContractStub.QueryMappedState.CallAsync(new ProtobufInput
                {
                    ProtobufValue = new ProtobufMessage
                    {
                        Int64Value = 2
                    }
                })).ShouldBe(new ProtobufMessage());
            }

            {
                var str      = Encoding.UTF8.GetString(new byte[stateSizeLimit]);
                var txResult = await TestBasicSecurityContractStub.TestMapped1State.SendWithExceptionAsync(
                    new ProtobufInput
                {
                    ProtobufValue = new ProtobufMessage
                    {
                        StringValue = str
                    }
                });

                txResult.TransactionResult.Error.ShouldContain($"exceeds limit of {stateSizeLimit}");

                var str1    = Encoding.UTF8.GetString(new byte[10]);
                var message = new ProtobufMessage
                {
                    BoolValue   = true,
                    Int64Value  = 1,
                    StringValue = str1
                };
                await TestBasicSecurityContractStub.TestMapped1State.SendAsync(new ProtobufInput
                {
                    ProtobufValue = message
                });

                var queryResult = await TestBasicSecurityContractStub.QueryMappedState1.CallAsync(new ProtobufInput
                {
                    ProtobufValue = message
                });

                queryResult.ShouldBe(message);

                (await TestBasicSecurityContractStub.QueryMappedState1.CallAsync(new ProtobufInput
                {
                    ProtobufValue = new ProtobufMessage
                    {
                        BoolValue = true,
                        Int64Value = 2,
                        StringValue = str1
                    }
                })).ShouldBe(new ProtobufMessage());
            }

            {
                var str      = Encoding.UTF8.GetString(new byte[stateSizeLimit]);
                var txResult = await TestBasicSecurityContractStub.TestMapped2State.SendWithExceptionAsync(
                    new ProtobufInput
                {
                    ProtobufValue = new ProtobufMessage
                    {
                        StringValue = str
                    }
                });

                await TestBasicSecurityContractStub.TestMapped2State.SendAsync(new ProtobufInput
                {
                    ProtobufValue = new ProtobufMessage
                    {
                    }
                });

                txResult.TransactionResult.Error.ShouldContain($"exceeds limit of {stateSizeLimit}");

                var str1    = Encoding.UTF8.GetString(new byte[10]);
                var message = new ProtobufMessage
                {
                    BoolValue   = true,
                    Int64Value  = 1,
                    StringValue = str1
                };

                await TestBasicSecurityContractStub.TestMapped2State.SendAsync(new ProtobufInput
                {
                    ProtobufValue = message
                });

                var queryResult = await TestBasicSecurityContractStub.QueryMappedState2.CallAsync(new ProtobufInput
                {
                    ProtobufValue = message
                });

                queryResult.ShouldBe(message);

                (await TestBasicSecurityContractStub.QueryMappedState2.CallAsync(new ProtobufInput
                {
                    ProtobufValue = new ProtobufMessage
                    {
                        BoolValue = true,
                        Int64Value = 2,
                        StringValue = str1
                    }
                })).ShouldBe(new ProtobufMessage());
            }

            {
                var str     = Encoding.UTF8.GetString(new byte[stateSizeLimit]);
                var message = new TradeMessage
                {
                    FromAmount = 1024
                };

                var txResult = await TestBasicSecurityContractStub.TestMapped3State.SendWithExceptionAsync(
                    new Complex3Input
                {
                    TradeDetails = new TradeMessage
                    {
                        FromAmount = 1,
                        Memo       = str
                    }
                });

                txResult.TransactionResult.Error.ShouldContain($"exceeds limit of {stateSizeLimit}");

                var str1 = Encoding.UTF8.GetString(new byte[10]);

                var complex3Input = new Complex3Input
                {
                    From         = str1,
                    To           = str1,
                    TradeDetails = message
                };
                await TestBasicSecurityContractStub.TestMapped3State.SendAsync(complex3Input);

                var queryResult = await TestBasicSecurityContractStub.QueryMappedState3.CallAsync(complex3Input);

                queryResult.FromAmount.ShouldBe(message.FromAmount);

                (await TestBasicSecurityContractStub.QueryMappedState3.CallAsync(new Complex3Input
                {
                    From = str1,
                    To = str1,
                    PairA = str1,
                    TradeDetails = message
                })).ShouldBe(new TradeMessage());
            }
        }
コード例 #7
0
        public override TradeMessage QueryMappedState3(Complex3Input input)
        {
            var tradeMessage = State.Complex5Info[input.From][input.PairA][input.To][input.PairB];

            return(tradeMessage ?? new TradeMessage());
        }