Пример #1
0
        public async Task CanSubmitSingleSegmentedMessage()
        {
            await using var fx = await TestTopic.CreateAsync(_network);

            var submitParams = new SubmitMessageParams
            {
                Topic             = fx.Record.Topic,
                Segment           = Encoding.ASCII.GetBytes(Generator.String(120, 199)),
                Index             = 1,
                TotalSegmentCount = 1,
                Signatory         = fx.ParticipantPrivateKey
            };
            var receipt = await fx.Client.SubmitMessageAsync(submitParams);

            Assert.Equal(ResponseCode.Success, receipt.Status);
            Assert.Equal(1ul, receipt.SequenceNumber);
            Assert.False(receipt.RunningHash.IsEmpty);
            Assert.Equal(3ul, receipt.RunningHashVersion);
            var txId = receipt.Id;

            var info = await fx.Client.GetTopicInfoAsync(fx.Record.Topic);

            Assert.Equal(fx.Memo, info.Memo);
            Assert.NotEqual(ReadOnlyMemory <byte> .Empty, info.RunningHash);
            Assert.Equal(1UL, info.SequenceNumber);
            Assert.True(info.Expiration > DateTime.MinValue);
            Assert.Equal(new Endorsement(fx.AdminPublicKey), info.Administrator);
            Assert.Equal(new Endorsement(fx.ParticipantPublicKey), info.Participant);
            Assert.True(info.AutoRenewPeriod > TimeSpan.MinValue);
            Assert.Equal(fx.TestAccount.Record.Address, info.RenewAccount);

            await Task.Delay(7000); // give the beta net time to sync

            TopicMessage topicMessage = null;

            using var ctx          = new CancellationTokenSource();
            await using var mirror = _network.NewMirror();
            try
            {
                var subscribeTask = mirror.SubscribeTopicAsync(new SubscribeTopicParams
                {
                    Topic         = fx.Record.Topic,
                    Starting      = DateTime.UtcNow.AddHours(-1),
                    MessageWriter = new TopicMessageWriterAdapter(m =>
                    {
                        topicMessage = m;
                        ctx.Cancel();
                    }),
                    CancellationToken = ctx.Token
                });

                ctx.CancelAfter(5000);

                await subscribeTask;

                if (topicMessage == null)
                {
                    _network.Output?.WriteLine("INDETERMINATE TEST - MIRROR NODE DID NOT RETURN TOPIC IN ALLOWED TIME");
                }
                else
                {
                    Assert.Equal(submitParams.Topic, topicMessage.Topic);
                    Assert.Equal(1ul, topicMessage.SequenceNumber);
                    Assert.Equal(receipt.RunningHash.ToArray(), topicMessage.RunningHash.ToArray());
                    Assert.Equal(submitParams.Segment.ToArray(), topicMessage.Messsage.ToArray());
                    Assert.NotNull(topicMessage.SegmentInfo);
                    Assert.Equal(txId, topicMessage.SegmentInfo.ParentTxId);
                    Assert.Equal(1, topicMessage.SegmentInfo.Index);
                    Assert.Equal(1, topicMessage.SegmentInfo.TotalSegmentCount);
                }
            }
            catch (MirrorException mex) when(mex.Code == MirrorExceptionCode.TopicNotFound)
            {
                _network.Output?.WriteLine("INDETERMINATE TEST - MIRROR NODE DID NOT RECEIVE TOPIC CREATE IN ALLOWED TIME");
                return;
            }
        }
Пример #2
0
 /// <summary>
 /// Sends a segment of a message to the network for a given consensus topic.
 /// The caller of this method is responsible for managing the segment of the
 /// message and associated metadata.
 /// </summary>
 /// <param name="submitParams">
 /// Details of the message segment to upload, including the metadata
 /// corresponding to this segment.
 /// </param>
 /// <param name="configure">
 /// Optional callback method providing an opportunity to modify
 /// the execution configuration for just this method call.
 /// It is executed prior to submitting the request to the network.
 /// </param>
 /// <returns>
 /// A Submit Message Receipt indicating success, includes information
 /// about the sequence number of the message and its running hash.
 /// </returns>
 /// <exception cref="ArgumentOutOfRangeException">If required arguments are missing.</exception>
 /// <exception cref="InvalidOperationException">If required context configuration is missing.</exception>
 /// <exception cref="PrecheckException">If the gateway node create rejected the request upon submission.</exception>
 /// <exception cref="ConsensusException">If the network was unable to come to consensus before the duration of the transaction expired.</exception>
 /// <exception cref="TransactionException">If the network rejected the create request as invalid or had missing data.</exception>
 public async Task <SubmitMessageReceipt> SubmitMessageAsync(SubmitMessageParams submitParams, Action <IContext>?configure = null)
 {
     return(new SubmitMessageReceipt(await SubmitMessageImplementationAsync(submitParams.Topic, submitParams.Segment, true, submitParams.ParentTxId, submitParams.Index, submitParams.TotalSegmentCount, submitParams.Signatory, configure, false).ConfigureAwait(false)));
 }
Пример #3
0
        public async Task CanSubmitBogusSegmentedMessageMetadata()
        {
            await using var fx = await TestTopic.CreateAsync(_network);

            var parentTx     = fx.Client.CreateNewTxId();
            var submitParams = new SubmitMessageParams
            {
                Topic             = fx.Record.Topic,
                Segment           = Encoding.ASCII.GetBytes(Generator.String(120, 199)),
                ParentTxId        = parentTx,
                Index             = 100,
                TotalSegmentCount = 200,
                Signatory         = fx.ParticipantPrivateKey
            };
            var receipt = await fx.Client.SubmitMessageAsync(submitParams);

            Assert.Equal(ResponseCode.Success, receipt.Status);
            Assert.Equal(1ul, receipt.SequenceNumber);
            Assert.False(receipt.RunningHash.IsEmpty);
            Assert.Equal(3ul, receipt.RunningHashVersion);

            var info = await fx.Client.GetTopicInfoAsync(fx.Record.Topic);

            Assert.Equal(fx.Memo, info.Memo);
            Assert.NotEqual(ReadOnlyMemory <byte> .Empty, info.RunningHash);
            Assert.Equal(1UL, info.SequenceNumber);
            Assert.True(info.Expiration > DateTime.MinValue);
            Assert.Equal(new Endorsement(fx.AdminPublicKey), info.Administrator);
            Assert.Equal(new Endorsement(fx.ParticipantPublicKey), info.Participant);
            Assert.True(info.AutoRenewPeriod > TimeSpan.MinValue);
            Assert.Equal(fx.TestAccount.Record.Address, info.RenewAccount);

            await Task.Delay(7000); // give the beta net time to sync

            try
            {
                await using var mirror = _network.NewMirror();
                var topicMessages = await TopicMessageCapture.CaptureOrTimeoutAsync(mirror, fx.Record.Topic, 1, 7000);

                if (topicMessages.Length == 0)
                {
                    _network.Output?.WriteLine("INDETERMINATE TEST - MIRROR NODE DID NOT RETURN TOPIC IN ALLOWED TIME");
                }
                else
                {
                    var topicMessage = topicMessages[0];
                    Assert.Equal(submitParams.Topic, topicMessage.Topic);
                    Assert.Equal(1ul, topicMessage.SequenceNumber);
                    Assert.Equal(receipt.RunningHash.ToArray(), topicMessage.RunningHash.ToArray());
                    Assert.Equal(submitParams.Segment.ToArray(), topicMessage.Messsage.ToArray());
                    Assert.NotNull(topicMessage.SegmentInfo);
                    Assert.Equal(parentTx, topicMessage.SegmentInfo.ParentTxId);
                    Assert.Equal(100, topicMessage.SegmentInfo.Index);
                    Assert.Equal(200, topicMessage.SegmentInfo.TotalSegmentCount);
                }
            }
            catch (MirrorException mex) when(mex.Code == MirrorExceptionCode.TopicNotFound)
            {
                _network.Output?.WriteLine("INDETERMINATE TEST - MIRROR NODE DID NOT RECEIVE TOPIC CREATE IN ALLOWED TIME");
                return;
            }
        }