Ejemplo n.º 1
0
        public async Task CanNotScheduleUpdate()
        {
            await using var fxPayer = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 20_00_000_000);

            await using var fxTopic = await TestTopic.CreateAsync(_network);

            var newMemo = Generator.String(10, 100);
            var tex     = await Assert.ThrowsAsync <TransactionException>(async() =>
            {
                await fxTopic.Client.UpdateTopicAsync(new UpdateTopicParams
                {
                    Topic     = fxTopic.Record.Topic,
                    Memo      = newMemo,
                    Signatory = new Signatory(
                        fxTopic.AdminPrivateKey,
                        new PendingParams
                    {
                        PendingPayer = fxPayer
                    })
                });
            });

            Assert.Equal(ResponseCode.ScheduledTransactionNotInWhitelist, tex.Status);
            Assert.StartsWith("Unable to schedule transaction, status: ScheduledTransactionNotInWhitelist", tex.Message);
        }
Ejemplo n.º 2
0
        public async Task SubmittingMessagesCanReturnRecord()
        {
            await using var fx = await TestTopic.CreateAsync(_network);

            var expectedSequenceNumber = Generator.Integer(10, 20);

            for (int i = 0; i < expectedSequenceNumber; i++)
            {
                var message      = Encoding.ASCII.GetBytes(Generator.String(10, 100));
                var submitParams = new SubmitMessageParams
                {
                    Topic             = fx.Record.Topic,
                    Segment           = Encoding.ASCII.GetBytes(Generator.String(120, 199)),
                    Index             = 1,
                    TotalSegmentCount = 1,
                    Signatory         = fx.ParticipantPrivateKey
                };

                var messageRecord = await fx.Client.SubmitMessageWithRecordAsync(submitParams);

                Assert.Equal(ResponseCode.Success, messageRecord.Status);
                Assert.Equal((ulong)(i + 1), messageRecord.SequenceNumber);
                Assert.Equal(3ul, messageRecord.RunningHashVersion);
                Assert.False(messageRecord.RunningHash.IsEmpty);
                Assert.False(messageRecord.Hash.IsEmpty);
                Assert.NotNull(messageRecord.Concensus);
                Assert.Empty(messageRecord.Memo);
                Assert.InRange(messageRecord.Fee, 0UL, ulong.MaxValue);
            }
            var info = await fx.Client.GetTopicInfoAsync(fx.Record.Topic);

            Assert.Equal((ulong)expectedSequenceNumber, info.SequenceNumber);
        }
Ejemplo n.º 3
0
        public async Task CannotUpdateAfterMadeImmutable()
        {
            await using var fx = await TestTopic.CreateAsync(_network);

            await fx.Client.UpdateTopicAsync(new UpdateTopicParams
            {
                Topic         = fx.Record.Topic,
                Signatory     = fx.AdminPrivateKey,
                Administrator = Endorsement.None,
                RenewAccount  = Address.None
            });

            var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
            {
                await fx.Client.UpdateTopicAsync(new UpdateTopicParams
                {
                    Topic     = fx.Record.Topic,
                    Signatory = fx.AdminPrivateKey,
                    Memo      = Generator.String(10, 100)
                });
            });

            Assert.Equal(ResponseCode.Unauthorized, tex.Status);
            Assert.StartsWith("Unable to update Topic, status: Unauthorized", tex.Message);
        }
Ejemplo n.º 4
0
        public async Task SubmitMessageToDeletedTopicRaisesError()
        {
            await using var fx = await TestTopic.CreateAsync(_network);

            var receipt = await fx.Client.DeleteTopicAsync(fx.Record.Topic, fx.AdminPrivateKey);

            Assert.Equal(ResponseCode.Success, receipt.Status);

            var message = Encoding.ASCII.GetBytes(Generator.String(10, 100));

            var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
            {
                var submitParams = new SubmitMessageParams
                {
                    Topic             = fx.Record.Topic,
                    Segment           = Encoding.ASCII.GetBytes(Generator.String(120, 199)),
                    Index             = 1,
                    TotalSegmentCount = 1,
                    Signatory         = fx.ParticipantPrivateKey
                };
                await fx.Client.SubmitMessageAsync(submitParams);
            });

            Assert.Equal(ResponseCode.InvalidTopicId, tex.Status);
            Assert.StartsWith("Submit Message failed, status: InvalidTopicId", tex.Message);
        }
Ejemplo n.º 5
0
        public async Task ParentTransactionIsNOtEnforcedForSecondSegment()
        {
            await using var fx = await TestTopic.CreateAsync(_network);

            var message  = Encoding.ASCII.GetBytes(Generator.String(10, 100));
            var receipt1 = await fx.Client.SubmitMessageAsync(new SubmitMessageParams
            {
                Topic             = fx.Record.Topic,
                Segment           = message,
                Index             = 1,
                TotalSegmentCount = 2,
                Signatory         = fx.ParticipantPrivateKey
            });

            Assert.Equal(ResponseCode.Success, receipt1.Status);

            var receipt2 = await fx.Client.SubmitMessageAsync(new SubmitMessageParams
            {
                Topic             = fx.Record.Topic,
                Segment           = message,
                ParentTxId        = fx.Client.CreateNewTxId(),
                Index             = 2,
                TotalSegmentCount = 2,
                Signatory         = fx.ParticipantPrivateKey
            });

            Assert.Equal(ResponseCode.Success, receipt2.Status);
        }
Ejemplo n.º 6
0
        public async Task CanSubmitMessageToOpenTopic()
        {
            await using var fx = await TestTopic.CreateAsync(_network, fx =>
            {
                fx.Params.Participant = null;
            });

            var message      = Encoding.ASCII.GetBytes(Generator.String(10, 100));
            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 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.Null(info.Participant);
            Assert.True(info.AutoRenewPeriod > TimeSpan.MinValue);
            Assert.Equal(fx.TestAccount.Record.Address, info.RenewAccount);
        }
Ejemplo n.º 7
0
    public async Task CanUpdateMemo()
    {
        await using var fx = await TestTopic.CreateAsync(_network);

        var newMemo = Generator.String(10, 100);
        var receipt = await fx.Client.UpdateTopicAsync(new UpdateTopicParams
        {
            Topic     = fx.Record.Topic,
            Signatory = fx.AdminPrivateKey,
            Memo      = newMemo,
        });

        Assert.Equal(ResponseCode.Success, receipt.Status);

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

        Assert.Equal(newMemo, info.Memo);
        Assert.NotEmpty(info.RunningHash.ToArray());
        Assert.Equal(0UL, 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);
        AssertHg.NotEmpty(info.Ledger);
    }
Ejemplo n.º 8
0
    public async Task CanUpdateAutoRenewAccountToAliasAccountDefect()
    {
        // Data corruption bug when using the Alias form to update a renew account.
        var testFailException = (await Assert.ThrowsAsync <TransactionException>(CanUpdateAutoRenewAccountToAliasAccount));

        Assert.StartsWith("Unable to update Topic, status: InvalidAutorenewAccount", testFailException.Message);

        //[Fact(DisplayName = "Update Topic: Can Update Auto Renew Account to Alias Account")]
        async Task CanUpdateAutoRenewAccountToAliasAccount()
        {
            await using var fxTopic = await TestTopic.CreateAsync(_network);

            await using var fxAccount = await TestAliasAccount.CreateAsync(_network);

            var infoBefore = await fxTopic.Client.GetTopicInfoAsync(fxTopic.Record.Topic);

            Assert.Equal(fxTopic.TestAccount.Record.Address, infoBefore.RenewAccount);

            await fxTopic.Client.UpdateTopicAsync(new UpdateTopicParams
            {
                Topic        = fxTopic.Record.Topic,
                Signatory    = new Signatory(fxTopic.AdminPrivateKey, fxAccount.PrivateKey),
                RenewAccount = fxAccount.Alias
            });

            var infoAfter = await fxTopic.Client.GetTopicInfoAsync(fxTopic.Record.Topic);

            Assert.Equal(fxAccount.CreateRecord.Address, infoAfter.RenewAccount);
        }
    }
Ejemplo n.º 9
0
        public async Task CanUpdateMemoWithRecord()
        {
            await using var fx = await TestTopic.CreateAsync(_network);

            var newMemo = Generator.String(10, 100);
            var record  = await fx.Client.UpdateTopicWithRecordAsync(new UpdateTopicParams
            {
                Topic     = fx.Record.Topic,
                Signatory = fx.AdminPrivateKey,
                Memo      = newMemo,
            });

            Assert.Equal(ResponseCode.Success, record.Status);
            Assert.False(record.Hash.IsEmpty);
            Assert.NotNull(record.Concensus);
            Assert.Empty(record.Memo);
            Assert.InRange(record.Fee, 0UL, ulong.MaxValue);
            Assert.Equal(_network.Payer, record.Id.Address);

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

            Assert.Equal(newMemo, info.Memo);
            Assert.NotEqual(ReadOnlyMemory <byte> .Empty, info.RunningHash);
            Assert.Equal(0UL, 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);
        }
Ejemplo n.º 10
0
    public async Task CanCreateATopicWithAliasRenewAccountDefect()
    {
        // Creating a topic with a renewal account using its alias address has not yet been
        // implemented by the network, although it will accept the transaction.
        var testFailException = (await Assert.ThrowsAsync <TransactionException>(CanCreateATopicWithAliasRenewAccount));

        Assert.StartsWith("Unable to create Consensus Topic, status: InvalidAutorenewAccount", testFailException.Message);

        //[Fact(DisplayName = "Create Topic: Can Create Topic with Alias Renew Account")]
        async Task CanCreateATopicWithAliasRenewAccount()
        {
            await using var fxRenew = await TestAliasAccount.CreateAsync(_network);

            await using var fx = await TestTopic.CreateAsync(_network, fx =>
            {
                fx.Params.RenewAccount = fxRenew.Alias;
                fx.Signatory           = new Signatory(fx.AdminPrivateKey, fx.ParticipantPrivateKey, fxRenew.PrivateKey);
            });

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

            Assert.Equal(fx.Memo, info.Memo);
            Assert.NotEmpty(info.RunningHash.ToArray());
            Assert.Equal(0UL, 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(fxRenew.CreateRecord.Address, info.RenewAccount);
            // NETWORK V0.21.0 UNSUPPORTED vvvv
            // NOT IMPLEMENTED YET
            Assert.Empty(info.Ledger.ToArray());
            // NETWORK V0.21.0 UNSUPPORTED ^^^^
        }
    }
Ejemplo n.º 11
0
        public async Task CanCallWithRecordPayerSignatory()
        {
            SubmitMessageRecord record = null;

            await using var fx = await TestTopic.CreateAsync(_network);

            var expectedSequenceNumber = Generator.Integer(10, 20);

            for (int i = 0; i < expectedSequenceNumber; i++)
            {
                var message = Encoding.ASCII.GetBytes(Generator.String(10, 100));
                record = await fx.Client.SubmitMessageWithRecordAsync(fx.Record.Topic, message, ctx => ctx.Signatory = new Signatory(fx.ParticipantPrivateKey, _network.PrivateKey));

                Assert.Equal(ResponseCode.Success, record.Status);
                Assert.Equal((ulong)i + 1, record.SequenceNumber);
                Assert.False(record.RunningHash.IsEmpty);
                Assert.False(record.Hash.IsEmpty);
                Assert.NotNull(record.Concensus);
                Assert.Empty(record.Memo);
                Assert.InRange(record.Fee, 0UL, ulong.MaxValue);
                Assert.Equal(_network.Payer, record.Id.Address);
            }

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

            Assert.Equal((ulong)expectedSequenceNumber, info.SequenceNumber);
            Assert.Equal((ulong)expectedSequenceNumber, record.SequenceNumber);
            Assert.Equal(info.RunningHash.ToArray(), record.RunningHash.ToArray());
        }
Ejemplo n.º 12
0
    public async Task CanUpdateAutoRenewAccount()
    {
        await using var fxTopic = await TestTopic.CreateAsync(_network);

        await using var fxAccount = await TestAccount.CreateAsync(_network);

        await fxTopic.Client.UpdateTopicAsync(new UpdateTopicParams
        {
            Topic        = fxTopic.Record.Topic,
            Signatory    = new Signatory(fxTopic.AdminPrivateKey, fxAccount.PrivateKey),
            RenewAccount = fxAccount.Record.Address
        });

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

        Assert.Equal(fxTopic.Memo, info.Memo);
        Assert.NotEmpty(info.RunningHash.ToArray());
        Assert.Equal(0UL, info.SequenceNumber);
        Assert.True(info.Expiration > DateTime.MinValue);
        Assert.Equal(new Endorsement(fxTopic.AdminPublicKey), info.Administrator);
        Assert.Equal(new Endorsement(fxTopic.ParticipantPublicKey), info.Participant);
        Assert.True(info.AutoRenewPeriod > TimeSpan.MinValue);
        Assert.Equal(fxAccount.Record.Address, info.RenewAccount);
        AssertHg.NotEmpty(info.Ledger);
    }
    public async Task CanCallGetRecord()
    {
        await using var fx = await TestTopic.CreateAsync(_network);
        var message = Encoding.ASCII.GetBytes(Generator.String(1200, 1990));
        var segmentSize = Generator.Integer(100, 200);
        var expectedCount = message.Length / segmentSize + 1;
        var receipts = await fx.Client.SubmitLargeMessageAsync(fx.Record.Topic, message, segmentSize, fx.ParticipantPrivateKey);
        Assert.Equal(expectedCount, receipts.Length);
        for (int i = 0; i < expectedCount; i++)
        {
            var receipt = receipts[i];
            Assert.Equal(ResponseCode.Success, receipt.Status);
            Assert.Equal((ulong)(i + 1), receipt.SequenceNumber);
            Assert.False(receipt.RunningHash.IsEmpty);
            Assert.Equal(3ul, receipt.RunningHashVersion);

            var genericRecord = await fx.Client.GetTransactionRecordAsync(receipt.Id);
            var messageRecord = Assert.IsType<SubmitMessageRecord>(genericRecord);
            Assert.Equal(ResponseCode.Success, messageRecord.Status);
            Assert.Equal((ulong)(i + 1), messageRecord.SequenceNumber);
            Assert.Equal(3ul, messageRecord.RunningHashVersion);
            Assert.Equal(receipt.Id, messageRecord.Id);
            Assert.Equal(receipt.RunningHash.ToArray(), messageRecord.RunningHash.ToArray());
            Assert.False(messageRecord.Hash.IsEmpty);
            Assert.NotNull(messageRecord.Concensus);
            Assert.Empty(messageRecord.Memo);
            Assert.InRange(messageRecord.Fee, 0UL, ulong.MaxValue);
        }
        var info = await fx.Client.GetTopicInfoAsync(fx.Record.Topic);
        Assert.Equal((ulong)expectedCount, info.SequenceNumber);
    }
Ejemplo n.º 14
0
        public void PublishSubscribeTest()
        {
            MyBroker.Reset();

            string identifier1 = "topic1";
            string identifier2 = "topic2";

            Publisher <string> publisher1 = new Publisher <string>("Publisher1");
            Publisher <string> publisher2 = new Publisher <string>("Publisher2");

            Subscriber <string> subscriber1 = new TestSubscriber("Subscriber1");
            Subscriber <string> subscriber2 = new TestSubscriber("Subscriber2");
            Subscriber <string> subscriber3 = new TestSubscriber("Subscriber3");
            Subscriber <string> subscriber4 = new TestSubscriber("Subscriber4");

            MyBroker.Instance.Register(publisher1, identifier1);
            MyBroker.Instance.Register(publisher1, identifier2);
            MyBroker.Instance.Register(publisher2, identifier2);

            MyBroker.Instance.Subscribe(subscriber1, identifier1);
            MyBroker.Instance.Subscribe(subscriber2, identifier2);
            MyBroker.Instance.Subscribe(subscriber3, identifier1);
            MyBroker.Instance.Subscribe(subscriber3, identifier2);
            MyBroker.Instance.Subscribe(subscriber4, identifier2);

            TestTopic testTopic1;
            TestTopic testTopic2;

            MyBroker.Instance.Publish(publisher1, testTopic1 = new TestTopic(identifier1, "(testTopic1)" + GetCallSite()));
            MyBroker.Instance.Publish(publisher2, testTopic2 = new TestTopic(identifier2, "(testTopic2)" + GetCallSite()));

            Assert.IsTrue(testTopic1.Notifications == 2);
            Assert.IsTrue(testTopic2.Notifications == 3);

            MyBroker.Instance.Unsubscribe();

            MyBroker.Instance.Subscribe(subscriber1, identifier1, publisher1);
            MyBroker.Instance.Subscribe(subscriber1, identifier2, publisher1);
            MyBroker.Instance.Subscribe(subscriber2, identifier1, publisher2);
            MyBroker.Instance.Subscribe(subscriber3, identifier2, publisher1);
            MyBroker.Instance.Subscribe(subscriber4, identifier2, publisher2);

            MyBroker.Instance.Publish(publisher1, testTopic1 = new TestTopic(identifier1, "(testTopic1)" + GetCallSite()));

            Assert.IsTrue(testTopic1.Notifications == 1);

            MyBroker.Instance.Publish(publisher1, testTopic2 = new TestTopic(identifier2, "(testTopic2)" + GetCallSite()));

            Assert.IsTrue(testTopic2.Notifications == 2);

            MyBroker.Instance.Publish(publisher2, testTopic2 = new TestTopic(identifier2, "(testTopic2)" + GetCallSite()));

            Assert.IsTrue(testTopic2.Notifications == 1);
        }
Ejemplo n.º 15
0
            public override void Notify(ITopic <string> topic, IPublisher <string> notifier)
            {
                TestTopic testTopic = (TestTopic)topic;

                Debug.WriteLine(
                    "Subscriber " + Name +
                    " Received Notification from Publisher " + notifier.Name +
                    " for Topic (" + testTopic.Identifier + "," + testTopic.Data + ")");

                testTopic.Notifications++;
            }
Ejemplo n.º 16
0
        public async Task CanCreateATopicAsync()
        {
            await using var fx = await TestTopic.CreateAsync(_network);

            var pex = await Assert.ThrowsAsync <PrecheckException>(async() =>
            {
                await fx.Client.GetAccountBalanceAsync(fx.Record.Topic);
            });

            Assert.Equal(ResponseCode.InvalidAccountId, pex.Status);
            Assert.StartsWith("Transaction Failed Pre-Check: InvalidAccountId", pex.Message);
        }
Ejemplo n.º 17
0
        public async Task TopicAddressForTokenSymbolRaisesError()
        {
            await using var fx = await TestTopic.CreateAsync(_network);

            var pex = await Assert.ThrowsAsync <PrecheckException>(async() =>
            {
                await fx.Client.GetTokenInfoAsync(fx.Record.Topic);
            });

            Assert.Equal(ResponseCode.InvalidTokenId, pex.Status);
            Assert.StartsWith("Transaction Failed Pre-Check: InvalidTokenId", pex.Message);
        }
Ejemplo n.º 18
0
        public async Task CallingDeleteWithoutAdminKeyRaisesError()
        {
            await using var fx = await TestTopic.CreateAsync(_network);

            var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
            {
                await fx.Client.DeleteTopicAsync(fx.Record.Topic);
            });

            Assert.Equal(ResponseCode.InvalidSignature, tex.Status);
            Assert.StartsWith("Unable to Delete Topic, status: InvalidSignature", tex.Message);
        }
    public async Task SubmitMessageWithoutMessageRaisesError()
    {
        await using var fx = await TestTopic.CreateAsync(_network);
        var message = Encoding.ASCII.GetBytes(Generator.String(1200, 1990));
        var segmentSize = Generator.Integer(100, 200);

        var aore = await Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () =>
        {
            await fx.Client.SubmitLargeMessageAsync(fx.Record.Topic, null, segmentSize, fx.ParticipantPrivateKey);
        });
        Assert.Equal("message", aore.ParamName);
        Assert.StartsWith("Topic Message can not be empty.", aore.Message);
    }
Ejemplo n.º 20
0
        public async Task CreateWithNullMemoRaisesError()
        {
            var ane = await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await TestTopic.CreateAsync(_network, fx =>
                {
                    fx.Params.Memo = null;
                });
            });

            Assert.Equal("Memo", ane.ParamName);
            Assert.StartsWith("Memo can not be null.", ane.Message);
        }
    public async Task SubmitMessageWithoutTopicRaisesError()
    {
        await using var fx = await TestTopic.CreateAsync(_network);
        var message = Encoding.ASCII.GetBytes(Generator.String(1200, 1990));
        var segmentSize = Generator.Integer(100, 200);

        var ane = await Assert.ThrowsAsync<ArgumentNullException>(async () =>
        {
            await fx.Client.SubmitLargeMessageAsync(null, message, segmentSize);
        });
        Assert.Equal("topic", ane.ParamName);
        Assert.StartsWith("Topic Address is missing. Please check that it is not null.", ane.Message);
    }
Ejemplo n.º 22
0
        public async Task CanCreateATopicWithInvalidRenewPeriodRaisesError()
        {
            var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
            {
                await TestTopic.CreateAsync(_network, fx =>
                {
                    fx.Params.RenewPeriod = TimeSpan.FromDays(1);
                });
            });

            Assert.Equal(ResponseCode.AutorenewDurationNotInRange, tex.Status);
            Assert.StartsWith("Unable to create Consensus Topic, status: AutorenewDurationNotInRange", tex.Message);
        }
Ejemplo n.º 23
0
        public async Task CanCreateATopicWithMissingSignaturesRaisesError()
        {
            var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
            {
                await TestTopic.CreateAsync(_network, fx =>
                {
                    fx.Params.Signatory = null;
                });
            });

            Assert.Equal(ResponseCode.InvalidSignature, tex.Status);
            Assert.StartsWith("Unable to create Consensus Topic, status: InvalidSignature", tex.Message);
        }
Ejemplo n.º 24
0
        public async Task CanCreateATopicWithNoAdministratorAndAutoRenewAccountRaisesError()
        {
            var ane = await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await TestTopic.CreateAsync(_network, fx =>
                {
                    fx.Params.Administrator = null;
                });
            });

            Assert.Equal("Administrator", ane.ParamName);
            Assert.StartsWith("The Administrator endorssement must not be null if RenewAccount is specified.", ane.Message);
        }
Ejemplo n.º 25
0
        public async Task SubmitMessageWithoutKeyRaisesError()
        {
            await using var fx = await TestTopic.CreateAsync(_network);

            var message = Encoding.ASCII.GetBytes(Generator.String(10, 100));

            var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
            {
                await fx.Client.SubmitMessageAsync(fx.Record.Topic, message);
            });

            Assert.Equal(ResponseCode.InvalidSignature, tex.Status);
            Assert.StartsWith("Submit Message failed, status: InvalidSignature", tex.Message);
        }
    public async Task CanScheduleSubmitSingleSegmentedMessage()
    {
        await using var fxPayer = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 20_00_000_000);

        await using var fxTopic = await TestTopic.CreateAsync(_network);

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

        Assert.Equal(ResponseCode.Success, schedulingReceipt.Status);
        Assert.Equal(0ul, schedulingReceipt.SequenceNumber);
        Assert.True(schedulingReceipt.RunningHash.IsEmpty);
        Assert.Equal(0ul, schedulingReceipt.RunningHashVersion);

        var counterReceipt = await fxPayer.Client.SignPendingTransactionAsync(schedulingReceipt.Pending.Id, fxPayer);

        var pendingReceipt = await fxPayer.Client.GetReceiptAsync(schedulingReceipt.Pending.TxId);

        Assert.Equal(ResponseCode.Success, pendingReceipt.Status);

        var messageReceipt = Assert.IsType <SubmitMessageReceipt>(pendingReceipt);

        Assert.Equal(1ul, messageReceipt.SequenceNumber);
        Assert.False(messageReceipt.RunningHash.IsEmpty);
        Assert.Equal(3ul, messageReceipt.RunningHashVersion);

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

        Assert.Equal(fxTopic.Memo, info.Memo);
        Assert.NotEmpty(info.RunningHash.ToArray());
        Assert.Equal(1UL, info.SequenceNumber);
        Assert.True(info.Expiration > DateTime.MinValue);
        Assert.Equal(new Endorsement(fxTopic.AdminPublicKey), info.Administrator);
        Assert.Equal(new Endorsement(fxTopic.ParticipantPublicKey), info.Participant);
        Assert.True(info.AutoRenewPeriod > TimeSpan.MinValue);
        Assert.Equal(fxTopic.TestAccount.Record.Address, info.RenewAccount);
        AssertHg.NotEmpty(info.Ledger);
    }
Ejemplo n.º 27
0
        public async Task CanGetCreateTopicReceipt()
        {
            await using var fx = await TestTopic.CreateAsync(_network);

            var receipt = await fx.Client.GetReceiptAsync(fx.Record.Id);

            var topicReceipt = Assert.IsType <CreateTopicReceipt>(receipt);

            Assert.Equal(fx.Record.Id, topicReceipt.Id);
            Assert.Equal(fx.Record.Status, topicReceipt.Status);
            Assert.Equal(fx.Record.CurrentExchangeRate, topicReceipt.CurrentExchangeRate);
            Assert.Equal(fx.Record.NextExchangeRate, topicReceipt.NextExchangeRate);
            Assert.Equal(fx.Record.Topic, topicReceipt.Topic);
        }
    public async Task SubmitMessageWithInvalidTopicRaisesError()
    {
        await using var fx = await TestTopic.CreateAsync(_network);
        var message = Encoding.ASCII.GetBytes(Generator.String(1200, 1990));
        var segmentSize = Generator.Integer(100, 200);

        var tex = await Assert.ThrowsAsync<TransactionException>(async () =>
        {
            await fx.Client.SubmitLargeMessageAsync(Address.None, message, segmentSize, fx.ParticipantPrivateKey);
        });
        Assert.Equal(ResponseCode.InvalidTopicId, tex.Status);
        Assert.Equal(ResponseCode.InvalidTopicId, tex.Receipt.Status);
        Assert.StartsWith("Submit Message failed, status: InvalidTopicId", tex.Message);
    }
Ejemplo n.º 29
0
        public async Task CanScheduleASubmitLargeSegmentedMessage()
        {
            await using var fxTopic = await TestTopic.CreateAsync(_network);

            var message       = Encoding.ASCII.GetBytes(Generator.String(1200, 1990));
            var segmentSize   = Generator.Integer(100, 200);
            var expectedCount = message.Length / segmentSize + 1;

            await using var fxPayer = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 20_00_000_000 *(ulong)expectedCount);

            var receipts = await fxTopic.Client.SubmitLargeMessageAsync(
                fxTopic.Record.Topic,
                message,
                segmentSize,
                new Signatory(
                    fxTopic.ParticipantPrivateKey,
                    new PendingParams
            {
                PendingPayer = fxPayer
            }));

            Assert.Equal(expectedCount, receipts.Length);
            for (int i = 0; i < expectedCount; i++)
            {
                var receipt = receipts[i];
                Assert.Equal(ResponseCode.Success, receipt.Status);
                Assert.Equal(0UL, receipt.SequenceNumber);
                Assert.True(receipt.RunningHash.IsEmpty);
                Assert.Equal(0ul, receipt.RunningHashVersion);
                Assert.NotNull(receipt.Pending);
                var executed = await fxPayer.Client.SignPendingTransactionAsync(receipt.Pending.Id, fxPayer);

                Assert.Equal(ResponseCode.Success, executed.Status);
                var record = await fxPayer.Client.GetTransactionRecordAsync(receipt.Pending.TxId);

                Assert.Equal(ResponseCode.Success, record.Status);
            }

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

            Assert.Equal(fxTopic.Memo, info.Memo);
            Assert.NotEqual(ReadOnlyMemory <byte> .Empty, info.RunningHash);
            Assert.Equal((ulong)expectedCount, info.SequenceNumber);
            Assert.True(info.Expiration > DateTime.MinValue);
            Assert.Equal(new Endorsement(fxTopic.AdminPublicKey), info.Administrator);
            Assert.Equal(new Endorsement(fxTopic.ParticipantPublicKey), info.Participant);
            Assert.True(info.AutoRenewPeriod > TimeSpan.MinValue);
            Assert.Equal(fxTopic.TestAccount.Record.Address, info.RenewAccount);
        }
Ejemplo n.º 30
0
        public async Task CanDeleteTopic()
        {
            await using var fx = await TestTopic.CreateAsync(_network);

            var record = await fx.Client.DeleteTopicAsync(fx.Record.Topic, fx.AdminPrivateKey);

            Assert.Equal(ResponseCode.Success, record.Status);

            var pex = await Assert.ThrowsAsync <PrecheckException>(async() =>
            {
                var info = await fx.Client.GetTopicInfoAsync(fx.Record.Topic);
            });

            Assert.Equal(ResponseCode.InvalidTopicId, pex.Status);
        }