private void ValidateMosaicSupplyChangeTx(MosaicSupplyChangeTransaction transaction, string transactionDTO) { var tx = JsonConvert.DeserializeObject <MosaicSupplyChangeTransactionInfoDTO>(transactionDTO); Assert.AreEqual(tx.Transaction.MosaicId, transaction.MosaicId.Id); Assert.AreEqual(tx.Transaction.Delta, transaction.Delta); Assert.AreEqual(tx.Transaction.Direction, transaction.SupplyType.GetValue()); }
public async Task <MosaicId> CreateMosaic(Account account) { var nonce = MosaicNonce.CreateRandom(); var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey); var mosaicDefinitionTransaction = MosaicDefinitionTransaction.Create( nonce, mosaicId, Deadline.Create(), MosaicProperties.Create( supplyMutable: true, transferable: true, levyMutable: false, divisibility: 0, duration: 1000 ), NetworkType); var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create( Deadline.Create(), mosaicDefinitionTransaction.MosaicId, MosaicSupplyType.INCREASE, 1000000, NetworkType); var aggregateTransaction = AggregateTransaction.CreateComplete( Deadline.Create(), new List <Transaction> { mosaicDefinitionTransaction.ToAggregate(account.PublicAccount), mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount) }, NetworkType); var signedTransaction = account.Sign(aggregateTransaction, GenerationHash); WatchForFailure(signedTransaction); var tx = SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(3000)); await SiriusClient.TransactionHttp.Announce(signedTransaction); var result = await tx; return(mosaicId); }
public async Task MosaicSupplyIncreaseTransction() { var signer = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var transaction = MosaicSupplyChangeTransaction.Create( NetworkType.Types.MIJIN_TEST, Deadline.CreateHours(2), new MosaicId("happy:test2"), MosaicSupplyType.Type.INCREASE, (ulong)new Random().Next(100000000, 1100000000) ).SignWith(signer); await new TransactionHttp("http://" + Config.Domain + ":3000").Announce(transaction); var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)).Take(1); Assert.AreEqual(signer.PublicKeyString, status.Signer.PublicKey); }
public async Task MosaicSupplyIncreaseShouldFailImmutableSupply() { var signer = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var transaction = MosaicSupplyChangeTransaction.Create( NetworkType.Types.MIJIN_TEST, Deadline.CreateHours(2), new MosaicId("happy:test3"), MosaicSupplyType.Type.INCREASE, 10000) .SignWith(signer); await new TransactionHttp(host).Announce(transaction); listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(signer.PublicKeyString, NetworkType.Types.MIJIN_TEST)).Subscribe(e => Console.WriteLine(e.TransactionInfo.Hash)); var status = await listener.TransactionStatus(Address.CreateFromPublicKey(signer.PublicKeyString, NetworkType.Types.MIJIN_TEST)).Where(e => e.Hash == transaction.Hash).Take(1); Assert.AreEqual("Failure_Mosaic_Supply_Immutable", status.Status); }
public async Task MosaicSupplyDecreaseTransction() { var signer = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var transaction = MosaicSupplyChangeTransaction.Create( NetworkType.Types.MIJIN_TEST, Deadline.CreateHours(2), new MosaicId("happy:test2"), MosaicSupplyType.Type.DECREASE, 10000) .SignWith(signer); await new TransactionHttp("http://" + Config.Domain + ":3000").Announce(transaction); listener.TransactionStatus(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)) .Subscribe(e => Console.WriteLine(e.Status)); var status = await listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)).Take(1); Assert.AreEqual("B974668ABED344BE9C35EE257ACC246117EFFED939EAF42391AE995912F985FE", status.Signer.PublicKey); }
public async Task Should_Add_Metadata_To_Mosaic() { var account = await Fixture.GenerateAccountWithCurrency(10000); Log.WriteLine($"Company Account {account.Address.Plain} \r\n Private Key: {account.PrivateKey} \r\n Public Key {account.PublicKey}"); var nonce = MosaicNonce.CreateRandom(); var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey); var mosaicDefinitionTransaction = MosaicDefinitionTransaction.Create( nonce, mosaicId, Deadline.Create(), MosaicProperties.Create( supplyMutable: true, transferable: true, levyMutable: false, divisibility: 6, duration: 0 ), Fixture.NetworkType); Log.WriteLine($"Going to create mosaic {mosaicDefinitionTransaction.MosaicId.HexId}"); var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create( Deadline.Create(), mosaicDefinitionTransaction.MosaicId, MosaicSupplyType.INCREASE, 1000, Fixture.NetworkType); var aggregateTransactiontx = AggregateTransaction.CreateComplete( Deadline.Create(), new List <Transaction> { mosaicDefinitionTransaction.ToAggregate(account.PublicAccount), mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount) }, Fixture.NetworkType); var aggregateTransactionsigned = account.Sign(aggregateTransactiontx, Fixture.GenerationHash); await Fixture.SiriusWebSocketClient.Listener.Open(); Log.WriteLine($"Going to announce aggregate transaction: {aggregateTransactionsigned.Hash}"); await Fixture.SiriusClient.TransactionHttp.Announce(aggregateTransactionsigned); var metadatatrx = MosaicMetadataTransaction.Create( Deadline.Create(), account.PublicAccount, mosaicDefinitionTransaction.MosaicId, "test_mosaic", "1", "", Fixture.NetworkType); var aggregateTransaction = AggregateTransaction.CreateBonded( Deadline.Create(), new List <Transaction> { metadatatrx.ToAggregate(account.PublicAccount), }, Fixture.NetworkType); var aggregateTrxsigned = account.Sign(aggregateTransaction, Fixture.GenerationHash); Fixture.WatchForFailure(aggregateTransactionsigned); var hashLockTransaction = HashLockTransaction.Create( Deadline.Create(), //new Mosaic(new MosaicId("0BB1469B94E6FEF8"), 10), NetworkCurrencyMosaic.CreateRelative(10), (ulong)3650, aggregateTrxsigned, Fixture.NetworkType); var hashLockTransactionSigned = account.Sign(hashLockTransaction, Fixture.GenerationHash); Log.WriteLine($"Going to announce hashlock transaction: {hashLockTransactionSigned.Hash}"); await Fixture.SiriusClient.TransactionHttp.Announce(hashLockTransactionSigned); var hashLocktx = Fixture.SiriusWebSocketClient.Listener .ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(500)); Fixture.WatchForFailure(hashLockTransactionSigned); var hashLockConfirmed = await hashLocktx; Log.WriteLine($"Request confirmed with hash lock transaction {hashLockConfirmed.TransactionInfo.Hash}"); Log.WriteLine($"Going to announce aggregate transaction {aggregateTransactionsigned.Hash}"); await Fixture.SiriusClient.TransactionHttp.AnnounceAggregateBonded(aggregateTransactionsigned); Fixture.WatchForFailure(aggregateTransactionsigned); var aggregateTrntx = Fixture.SiriusWebSocketClient.Listener .ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(500)); var MosaicMetadataDetail = await Fixture.SiriusClient.MetadataHttp.SearchMetadata(new MetadataQueryParams(1, Order.ASC, 1, Address.CreateFromRawAddress(account.Address.ToString()), null, null, null)); Log.WriteLine($"Metadata mosaic {MosaicMetadataDetail}"); }
public async Task Should_Link_Namespace_To_Mosaic() { #region Create mosaic var account = await Fixture.GenerateAccountWithCurrency(1500); var nonce = MosaicNonce.CreateRandom(); var mosaicDefinitionTransaction = MosaicDefinitionTransaction.Create( nonce, MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey), Deadline.Create(), MosaicProperties.Create( supplyMutable: true, transferable: true, levyMutable: false, divisibility: 0, duration: 1000 ), Fixture.NetworkType); var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create( Deadline.Create(), mosaicDefinitionTransaction.MosaicId, MosaicSupplyType.INCREASE, 1000000, Fixture.NetworkType); var aggregateTransaction = AggregateTransaction.CreateComplete( Deadline.Create(), new List <Transaction> { mosaicDefinitionTransaction.ToAggregate(account.PublicAccount), mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount) }, Fixture.NetworkType); var signedTransaction = account.Sign(aggregateTransaction, Fixture.GenerationHash); Log.WriteLine($"Going to announce transaction {signedTransaction.Hash}"); var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(3000)); await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction); var result = await tx; Log.WriteLine($"Request confirmed with transaction {result.TransactionInfo.Hash}"); var mosaicInfo = await Fixture.SiriusClient.MosaicHttp.GetMosaic(mosaicDefinitionTransaction.MosaicId); mosaicInfo.Should().NotBeNull(); mosaicInfo.Divisibility.Should().Be(0); mosaicInfo.Duration.Should().Be(1000); mosaicInfo.IsLevyMutable.Should().BeFalse(); mosaicInfo.IsSupplyMutable.Should().BeTrue(); mosaicInfo.IsTransferable.Should().BeTrue(); mosaicInfo.Supply.Should().Be(1000000); #endregion #region register new namespace var namespaceName = "nsp" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 6); var registerNamespaceTransaction = RegisterNamespaceTransaction.CreateRootNamespace( Deadline.Create(), namespaceName, 100, Fixture.NetworkType ); var registeredNsSignedTransaction = account.Sign(registerNamespaceTransaction, Fixture.GenerationHash); tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(3000)); await Fixture.SiriusClient.TransactionHttp.Announce(registeredNsSignedTransaction); Log.WriteLine( $"Registered namespace {namespaceName} for account {account.Address.Plain} with transaction {registeredNsSignedTransaction.Hash}"); result = await tx; Log.WriteLine($"Request confirmed with transaction {result.TransactionInfo.Hash}"); var expectedId = new NamespaceId(namespaceName); var nsInfo = await Fixture.SiriusClient.NamespaceHttp.GetNamespace(expectedId); Log.WriteLine( $"Retrieved namespace {namespaceName} successfully. The namespace HexId {nsInfo.Id.HexId}"); nsInfo.Should().NotBeNull(); #endregion #region Link namespace to the mosaic var mosaicAliasTransaction = AliasTransaction.CreateForMosaic( mosaicInfo.MosaicId, nsInfo.Id, AliasActionType.LINK, Deadline.Create(), Fixture.NetworkType ); tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1); var aliasSignedTransaction = account.Sign(mosaicAliasTransaction, Fixture.GenerationHash); Fixture.WatchForFailure(aliasSignedTransaction); await Fixture.SiriusClient.TransactionHttp.Announce(aliasSignedTransaction); result = await tx; Log.WriteLine($"Request confirmed with transaction {result.TransactionInfo.Hash}"); nsInfo = await Fixture.SiriusClient.NamespaceHttp.GetNamespace(expectedId); nsInfo.Should().NotBeNull(); nsInfo.HasAlias.Should().BeTrue(); nsInfo.Alias.Type.Should().BeEquivalentTo(AliasType.MOSAIC_ID); nsInfo.Alias.MosaicId.HexId.Should().BeEquivalentTo(mosaicInfo.MosaicId.HexId); #endregion #region Send mosaic using namespace alias to recipient var newAccount = Account.GenerateNewAccount(Fixture.NetworkType); var transferTransaction = TransferTransaction.Create( Deadline.Create(), Recipient.From(newAccount.Address), new List <Mosaic>() { new Mosaic(nsInfo.Id, 10) }, PlainMessage.Create("Send some mosaic to new address"), Fixture.NetworkType); var tx2 = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(newAccount.Address).Take(1) .Timeout(TimeSpan.FromSeconds(3000)); var nsSignedTransferTransaction = account.Sign(transferTransaction, Fixture.GenerationHash); Fixture.WatchForFailure(nsSignedTransferTransaction); await Fixture.SiriusClient.TransactionHttp.Announce(nsSignedTransferTransaction); var result2 = await tx2; Log.WriteLine($"Request confirmed with transaction {result2.TransactionInfo.Hash}"); var newAccountInfo = await Fixture.SiriusClient.AccountHttp.GetAccountInfo(newAccount.Address); Log.WriteLine($"Account {newAccountInfo.Address.Plain} with mosaic {newAccountInfo.Mosaics[0]} after transfer to the namespace alias"); var expectedMosaicAmount = Convert.ToUInt64(10); newAccountInfo.Mosaics[0].Id.Id.Should().Be(mosaicInfo.MosaicId.Id); newAccountInfo.Mosaics[0]?.Amount.Should().Be(expectedMosaicAmount); #endregion }
public async Task Should_Create_Mosaic() { var account = Fixture.SeedAccount; var nonce = MosaicNonce.CreateRandom(); var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey); var mosaicDefinitionTransaction = MosaicDefinitionTransaction.Create( nonce, mosaicId, Deadline.Create(), MosaicProperties.Create( supplyMutable: true, transferable: true, levyMutable: false, divisibility: 0, duration: 1000 ), Fixture.NetworkType); Log.WriteLine($"Going to create mosaic {mosaicId}"); var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create( Deadline.Create(), mosaicDefinitionTransaction.MosaicId, MosaicSupplyType.INCREASE, 1000000, Fixture.NetworkType); var aggregateTransaction = AggregateTransaction.CreateComplete( Deadline.Create(), new List <Transaction> { mosaicDefinitionTransaction.ToAggregate(account.PublicAccount), mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount) }, Fixture.NetworkType); var signedTransaction = account.Sign(aggregateTransaction, Fixture.GenerationHash); Fixture.WatchForFailure(signedTransaction); Log.WriteLine($"Going to announce transaction {signedTransaction.Hash}"); var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1) .Timeout(TimeSpan.FromSeconds(3000)); await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction); var result = await tx; Log.WriteLine($"Request confirmed with transaction {result.TransactionInfo.Hash}"); var mosaicInfo = await Fixture.SiriusClient.MosaicHttp.GetMosaic(mosaicDefinitionTransaction.MosaicId); Log.WriteLine($"Mosaic created {mosaicInfo}"); mosaicInfo.Should().NotBeNull(); mosaicInfo.Divisibility.Should().Be(0); mosaicInfo.Duration.Should().Be(1000); mosaicInfo.IsLevyMutable.Should().BeFalse(); mosaicInfo.IsSupplyMutable.Should().BeTrue(); mosaicInfo.IsTransferable.Should().BeTrue(); mosaicInfo.Supply.Should().Be(1000000); }
public async Task Should_Create_Levy_WithPercentageFee() { var account = Fixture.SeedAccount; var nonce = MosaicNonce.CreateRandom(); var mosaicId = MosaicId.CreateFromNonce(nonce, account.PublicAccount.PublicKey); var mosaicDefinitionTransaction = MosaicDefinitionTransaction.Create( nonce, mosaicId, Deadline.Create(), MosaicProperties.Create( supplyMutable: true, transferable: true, levyMutable: false, divisibility: 0, duration: 0 ), Fixture.NetworkType); Log.WriteLine($"Going to create mosaic {mosaicDefinitionTransaction.MosaicId.HexId}"); Log.WriteLine($"{account.PublicAccount.PublicKey}"); Log.WriteLine($"{account.PublicAccount.Address}"); var mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.Create( Deadline.Create(), mosaicDefinitionTransaction.MosaicId, MosaicSupplyType.INCREASE, 1000000, Fixture.NetworkType); var aggregateTransaction = AggregateTransaction.CreateComplete( Deadline.Create(), new List <Transaction> { mosaicDefinitionTransaction.ToAggregate(account.PublicAccount), mosaicSupplyChangeTransaction.ToAggregate(account.PublicAccount) }, Fixture.NetworkType); var signedTransaction = account.Sign(aggregateTransaction, Fixture.GenerationHash); Fixture.WatchForFailure(signedTransaction); Log.WriteLine($"Going to announce transaction {signedTransaction.Hash}"); await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction); var recipient = Account.GenerateNewAccount(Fixture.NetworkType); var mosaic_Id = new MosaicId(mosaicId.HexId); Log.WriteLine($"Mosaic Id: {mosaic_Id.HexId}"); var mosaicLevy = ModifyMosaicLevyTransaction.Create( Deadline.Create(), mosaicDefinitionTransaction.MosaicId, MosaicLevy.CreateWithPercentageFee( Recipient.From(recipient.Address), mosaicDefinitionTransaction.MosaicId, 200), Fixture.NetworkType); var signedTransaction_mosaicLevy = account.Sign(mosaicLevy, Fixture.GenerationHash); Fixture.WatchForFailure(signedTransaction_mosaicLevy); var tx_Levy = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1).Timeout(TimeSpan.FromSeconds(3000)); await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction_mosaicLevy); var result_levy = await tx_Levy; Log.WriteLine($"Request confirmed with transaction {result_levy.TransactionInfo.Hash}"); }