Esempio n. 1
0
        private void TestSetPhasingOnlyControl()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                var votingModel            = VotingModel.Account;
                var controlQuorum          = 1;
                var byPublicKey            = CreateTransaction.CreateTransactionByPublicKey();
                var controlMinBalance      = 1000;
                var controlMinBalanceModel = VotingModel.Nqt;
                var controlMaxFees         = Amount.CreateAmountFromNxt(1000);

                var phasingOnlyControl = _service.SetPhasingOnlyControl(votingModel, controlQuorum,
                                                                        byPublicKey, controlMinBalance, controlMinBalanceModel, null,
                                                                        new[] { TestSettings.Account2.AccountRs }, controlMaxFees).Result;

                var attachment = (AccountControlSetPhasingOnlyAttachment)phasingOnlyControl.Transaction.Attachment;

                AssertEquals((int)votingModel, (int)attachment.PhasingVotingModel, nameof(attachment.PhasingVotingModel));
                AssertEquals(controlQuorum, attachment.PhasingQuorum, nameof(attachment.PhasingQuorum));
                AssertEquals(controlMinBalance, attachment.PhasingMinBalance, nameof(attachment.PhasingMinBalance));
                AssertEquals((int)controlMinBalanceModel, (int)attachment.PhasingMinBalanceModel, nameof(attachment.PhasingMinBalanceModel));
                AssertEquals(controlMaxFees.Nqt, attachment.ControlMaxFees.Nqt, nameof(attachment.ControlMaxFees));
                AssertEquals(1, attachment.PhasingWhitelist.Count(), "attachment.PhasingWhitelist.Count()");
                AssertEquals(attachment.PhasingWhitelist.Single(), TestSettings.Account2.AccountId, nameof(attachment.PhasingWhitelist));
            }
        }
        private void TestDeleteAccountProperty()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                var reply = _service.DeleteAccountProperty(CreateTransaction.CreateTransactionByPublicKey(), "testkey1").Result;

                var attachment = (MessagingAccountPropertyDeleteAttachment)reply.Transaction.Attachment;
                AssertEquals(940296349549404868, attachment.Property, nameof(attachment.Property));
            }
        }
        private void TestCalculateFullHash()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                var unsignedSendMoney = _accountService.SendMoney(CreateTransaction.CreateTransactionByPublicKey(), TestSettings.Account2.AccountRs, Amount.OneNqt).Result;
                var signedTransaction = _transactionService.SignTransaction(new TransactionParameter(unsignedSendMoney.UnsignedTransactionBytes), TestSettings.SecretPhrase1).Result;
                var signatureHash     = signedTransaction.Transaction.SignatureHash;

                var calculateFullHash = _transactionService.CalculateFullHash(new BinaryHexString(signatureHash), unsignedSendMoney.UnsignedTransactionBytes).Result;
                AssertEquals(signedTransaction.FullHash.ToHexString(), calculateFullHash.FullHash.ToHexString(), "FullHash");
            }
        }
        internal void TestUploadTaggedData()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                var parameters = CreateTransaction.CreateTransactionByPublicKey();

                var transaction = _taggedDataService.UploadTaggedData(Name, Data, parameters, null, Description, Tags, Channel, Type, IsText,
                                                                      Filename).Result.Transaction;
                var attachment = (TaggedDataUploadAttachment)transaction.Attachment;

                VerifyMembers(attachment);
            }
        }
Esempio n. 5
0
        private void TestDeleteAssetShares()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                var quantityQnt            = 1;
                var deleteAssetSharesReply = _service.DeleteAssetShares(TestSettings.ExistingAssetId, quantityQnt,
                                                                        CreateTransaction.CreateTransactionByPublicKey()).Result;

                var attachment = (ColoredCoinsDeleteAttachment)deleteAssetSharesReply.Transaction.Attachment;

                AssertEquals(TestSettings.ExistingAssetId, attachment.AssetId, nameof(attachment.AssetId));
                AssertEquals(quantityQnt, attachment.QuantityQnt, nameof(attachment.QuantityQnt));
            }
        }
        private void SendPrunableMessage()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                const string expected   = "Hello World!";
                var          parameters = CreateTransaction.CreateTransactionByPublicKey(Amount.CreateAmountFromNxt(3));
                parameters.Message = new CreateTransactionParameters.UnencryptedMessage(expected, true);
                var sendMessageResult = _messageService.SendMessage(parameters).Result;
                var actual            = sendMessageResult.Transaction.Message;

                AssertEquals(expected, actual.MessageText, nameof(actual.MessageText));
                AssertIsTrue(actual.IsText, nameof(actual.IsText));
                AssertIsTrue(actual.IsPrunable, nameof(actual.IsPrunable));
            }
        }
        private void SendUnencryptedData()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                byte[] expected   = { 4, 7, 1, 64, 23, 91, 1, 45, 23 };
                var    parameters = CreateTransaction.CreateTransactionByPublicKey(Amount.CreateAmountFromNxt(3));
                parameters.Message = new CreateTransactionParameters.UnencryptedMessage(expected);
                var sendMessageResult = _messageService.SendMessage(parameters).Result;
                var actual            = sendMessageResult.Transaction.Message;

                AssertEquals(expected, actual.Data.ToBytes().ToArray(), nameof(actual.Data));
                AssertIsFalse(actual.IsText, nameof(actual.IsText));
                AssertIsFalse(actual.IsPrunable, nameof(actual.IsPrunable));
            }
        }
        private void TestExtendTaggedData()

        {
            using (Logger = new TestsessionLogger(_logger))
            {
                var parameters = CreateTransaction.CreateTransactionByPublicKey();

                var transaction = _taggedDataService.ExtendTaggedData(TestSettings.TaggedDataTransactionId, parameters, Name, Data, null,
                                                                      Description, Tags, Channel, Type, IsText, Filename).Result.Transaction;
                var attachment = (TaggedDataExtendAttachment)transaction.Attachment;

                VerifyMembers(attachment);
                AssertEquals(TestSettings.TaggedDataTransactionId, attachment.TaggedDataId, "TaggedDataId");
            }
        }
        private void TestSignTransaction()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                var amount            = Amount.OneNqt;
                var recipient         = TestSettings.Account2.AccountRs;
                var unsignedSendMoney = _accountService.SendMoney(CreateTransaction.CreateTransactionByPublicKey(), recipient, amount).Result;

                var signedTransaction = _transactionService.SignTransaction(new TransactionParameter(unsignedSendMoney.UnsignedTransactionBytes), TestSettings.SecretPhrase1).Result;

                var transaction = signedTransaction.Transaction;
                AssertEquals(transaction.Amount.Nqt, Amount.OneNqt.Nqt, "Amount");
                AssertEquals(transaction.RecipientRs, recipient, "RecipientRs");
            }
        }
        private void TestSetAccountProperty()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                var property = "key1";
                var value    = "supersecret";

                var accountProperty = _service.SetAccountProperty(CreateTransaction.CreateTransactionByPublicKey(), property, value).Result;
                var attachment      = (MessagingAccountPropertyAttachment)accountProperty.Transaction.Attachment;

                // ReSharper disable once PossibleInvalidOperationException
                AssertEquals(accountProperty.Transaction.Recipient.Value, TestSettings.Account1.AccountId, "recipient");
                AssertEquals(property, attachment.Property, nameof(attachment.Property));
                AssertEquals(value, attachment.Value, nameof(attachment.Value));
            }
        }
        private void SendEncryptedMessageToSelfByPublicKey()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                const string expected   = "Hello World!";
                var          parameters = CreateTransaction.CreateTransactionByPublicKey(Amount.CreateAmountFromNxt(3));
                parameters.EncryptedMessageToSelf = new CreateTransactionParameters.MessageToBeEncryptedToSelf(expected, true);
                var sendMesageResult = _messageService.SendMessage(parameters).Result;
                var actual           = sendMesageResult.Transaction.EncryptToSelfMessage;

                AssertIsTrue(actual.IsCompressed, nameof(actual.IsCompressed));
                AssertIsTrue(actual.IsText, nameof(actual.IsText));
                AssertEquals(expected, actual.MessageToEncrypt, nameof(actual.MessageToEncrypt));
                AssertIsNull(actual.Data, nameof(actual.Data));
                AssertIsNull(actual.Nonce, nameof(actual.Nonce));
            }
        }
        private void TestShufflingProcess()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                var expectedAmount = Amount.CreateAmountFromNxt(10);
                const int expectedParticipantCount = 3;
                const int expectedRegistrationPeriod = 720;

                var create = _shufflingService.ShufflingCreate(expectedAmount, expectedParticipantCount, expectedRegistrationPeriod, 
                    CreateTransaction.CreateTransactionByPublicKey()).Result;

                var attachment = (ShufflingCreationAttachment) create.Transaction.Attachment;

                AssertEquals(expectedAmount.Nqt, attachment.Amount.Nqt, nameof(attachment.Amount));
                AssertEquals(0, attachment.HoldingId, nameof(attachment.HoldingId));
                AssertEquals((int)HoldingType.Nxt, (int)attachment.HoldingType, nameof(attachment.HoldingType));
                AssertEquals(expectedParticipantCount, attachment.ParticipantCount, nameof(attachment.ParticipantCount));
                AssertEquals(expectedRegistrationPeriod, attachment.RegistrationPeriod, nameof(attachment.RegistrationPeriod));
            }
        }
        private void SendEncryptedDataByPublicKey()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                byte[] bytes      = { 4, 7, 1, 64, 23, 91, 1, 45, 23 };
                var    expected   = new BinaryHexString(bytes);
                var    parameters = CreateTransaction.CreateTransactionByPublicKey(Amount.CreateAmountFromNxt(3));
                parameters.EncryptedMessage = new CreateTransactionParameters.MessageToBeEncrypted(bytes, true);
                var sendMesageResult = _messageService.SendMessage(parameters, TestSettings.Account2.AccountRs).Result;
                var actual           = sendMesageResult.Transaction.EncryptedMessage;

                AssertIsFalse(actual.IsPrunable, nameof(actual.IsPrunable));
                AssertIsTrue(actual.IsCompressed, nameof(actual.IsCompressed));
                AssertIsFalse(actual.IsText, nameof(actual.IsText));
                AssertEquals(expected.ToHexString(), actual.MessageToEncrypt, nameof(actual.MessageToEncrypt));
                AssertIsNull(actual.Data, nameof(actual.Data));
                AssertIsNull(actual.EncryptedMessageHash, nameof(actual.EncryptedMessageHash));
                AssertIsNull(actual.Nonce, nameof(actual.Nonce));
            }
        }
        private void SendAlreadyEncryptedMessage()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                var nonce     = _localMessageService.CreateNonce();
                var encrypted = _localMessageService.EncryptTextTo(TestSettings.Account2.PublicKey, "Hello World!", nonce, true, TestSettings.SecretPhrase1);

                var parameters = CreateTransaction.CreateTransactionByPublicKey(Amount.CreateAmountFromNxt(3));
                parameters.EncryptedMessage = new CreateTransactionParameters.AlreadyEncryptedMessage(encrypted, nonce, true, true);
                var sendMesageResult = _messageService.SendMessage(parameters, TestSettings.Account2.AccountRs).Result;
                var actual           = sendMesageResult.Transaction.EncryptedMessage;

                AssertIsFalse(actual.IsPrunable, nameof(actual.IsPrunable));
                AssertIsTrue(actual.IsCompressed, nameof(actual.IsCompressed));
                AssertIsTrue(actual.IsText, nameof(actual.IsText));
                AssertIsNull(actual.MessageToEncrypt, nameof(actual.MessageToEncrypt));
                AssertIsNull(actual.EncryptedMessageHash, nameof(actual.EncryptedMessageHash));
                AssertEquals(encrypted.ToHexString(), actual.Data.ToHexString(), nameof(actual.Data));
                AssertEquals(nonce.ToHexString(), actual.Nonce.ToHexString(), nameof(actual.Nonce));
            }
        }