public async Task CanUpdateMemo() { await using var test = await TestFile.CreateAsync(_network); var newMemo = Generator.Code(30); var updateRecord = await test.Client.UpdateFileAsync(new UpdateFileParams { File = test.Record.File, Memo = newMemo, Signatory = test.CreateParams.Signatory }); Assert.Equal(ResponseCode.Success, updateRecord.Status); var info = await test.Client.GetFileInfoAsync(test.Record.File); Assert.NotNull(info); Assert.Equal(test.Record.File, info.File); Assert.Equal(newMemo, info.Memo); Assert.Equal(test.CreateParams.Contents.Length, info.Size); Assert.Equal(test.CreateParams.Expiration, info.Expiration); Assert.Equal(new Endorsement[] { test.PublicKey }, info.Endorsements); Assert.False(info.Deleted); AssertHg.NotEmpty(info.Ledger); }
public async Task CanNotDeleteAnImutableFileAsync() { await using var test = await TestFile.CreateAsync(_network, fx => { fx.CreateParams.Endorsements = Array.Empty <Endorsement>(); }); var tex = await Assert.ThrowsAsync <TransactionException>(async() => { await test.Client.DeleteFileWithRecordAsync(test.Record.File, test.CreateParams.Signatory); }); Assert.Equal(ResponseCode.Unauthorized, tex.Status); Assert.StartsWith("Unable to delete file, status: Unauthorized", tex.Message); var info = await test.Client.GetFileInfoAsync(test.Record.File); Assert.NotNull(info); Assert.Equal(test.Record.File, info.File); Assert.Equal(test.CreateParams.Contents.Length, info.Size); Assert.Equal(test.CreateParams.Expiration, info.Expiration); Assert.Empty(info.Endorsements); Assert.False(info.Deleted); AssertHg.NotEmpty(info.Ledger); }
public async Task CanCreateATopicWithReceiptAsync() { await using var client = _network.NewClient(); var receipt = await client.CreateTopicAsync(new CreateTopicParams { Memo = "Receipt Version" }); Assert.NotNull(receipt); Assert.NotNull(receipt.Topic); Assert.True(receipt.Topic.AccountNum > 0); Assert.Equal(ResponseCode.Success, receipt.Status); var info = await client.GetTopicInfoAsync(receipt.Topic); Assert.Equal("Receipt Version", info.Memo); Assert.NotEmpty(info.RunningHash.ToArray()); Assert.Equal(0UL, info.SequenceNumber); Assert.True(info.Expiration > DateTime.MinValue); Assert.Null(info.Administrator); Assert.Null(info.Participant); Assert.True(info.AutoRenewPeriod > TimeSpan.MinValue); Assert.Null(info.RenewAccount); AssertHg.NotEmpty(info.Ledger); }
public async Task CanGetInfoForAccountAsync() { await using var client = _network.NewClient(); var account = _network.Payer; var info = await client.GetAccountInfoAsync(account); Assert.NotNull(info.Address); Assert.Equal(account.RealmNum, info.Address.RealmNum); Assert.Equal(account.ShardNum, info.Address.ShardNum); Assert.Equal(account.AccountNum, info.Address.AccountNum); Assert.NotNull(info.SmartContractId); Assert.False(info.Deleted); Assert.NotNull(info.Proxy); Assert.Equal(new Address(0, 0, 0), info.Proxy); Assert.Equal(0, info.ProxiedToAccount); Assert.Equal(new Endorsement(_network.PublicKey), info.Endorsement); Assert.True(info.Balance > 0); Assert.False(info.ReceiveSignatureRequired); Assert.True(info.AutoRenewPeriod.TotalSeconds > 0); Assert.True(info.Expiration > DateTime.MinValue); Assert.Equal(0, info.AssetCount); Assert.Equal(0, info.AutoAssociationLimit); Assert.Equal(Alias.None, info.Alias); AssertHg.NotEmpty(info.Ledger); }
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.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); }
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()); AssertHg.NotEmpty(info.Ledger); }
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 CanUpdateMultiplePropertiesInOneCall() { await using var fx = await GreetingContract.CreateAsync(_network); var(newPublicKey, newPrivateKey) = Generator.KeyPair(); var newExpiration = Generator.TruncatedFutureDate(2400, 4800); var newEndorsement = new Endorsement(newPublicKey); var updatedSignatory = new Signatory(_network.Signatory, newPrivateKey); var newMemo = Generator.Code(50); fx.Client.Configure(ctx => ctx.Signatory = updatedSignatory); var record = await fx.Client.UpdateContractWithRecordAsync(new UpdateContractParams { Contract = fx.ContractRecord.Contract, Expiration = newExpiration, Administrator = newEndorsement, Memo = newMemo, Signatory = fx.PrivateKey }); var info = await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract); Assert.NotNull(info); Assert.Equal(fx.ContractRecord.Contract, info.Contract); Assert.Equal(fx.ContractRecord.Contract, info.Address); Assert.Equal(newExpiration, info.Expiration); Assert.Equal(newEndorsement, info.Administrator); Assert.Equal(fx.ContractParams.RenewPeriod, info.RenewPeriod); Assert.Equal(newMemo, info.Memo); Assert.Equal((ulong)fx.ContractParams.InitialBalance, info.Balance); AssertHg.NotEmpty(info.Ledger); }
public async Task CanUpdateRenewPeriod() { await using var fx = await GreetingContract.CreateAsync(_network); var newRenewal = TimeSpan.FromDays(Generator.Integer(180, 365)); var pex = await Assert.ThrowsAsync <PrecheckException>(async() => { var record = await fx.Client.UpdateContractWithRecordAsync(new UpdateContractParams { Contract = fx.ContractRecord.Contract, RenewPeriod = newRenewal, }); }); Assert.Equal(ResponseCode.AutorenewDurationNotInRange, pex.Status); Assert.StartsWith("Transaction Failed Pre-Check: AutorenewDurationNotInRange", pex.Message); var info = await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract); Assert.NotNull(info); Assert.Equal(fx.ContractRecord.Contract, info.Contract); Assert.Equal(fx.ContractRecord.Contract, info.Address); Assert.Equal(fx.ContractParams.Administrator, info.Administrator); Assert.Equal(fx.ContractParams.RenewPeriod, info.RenewPeriod); Assert.Equal(fx.ContractParams.Memo, info.Memo); Assert.Equal((ulong)fx.ContractParams.InitialBalance, info.Balance); AssertHg.NotEmpty(info.Ledger); }
public async Task CanUpdateAdminKey() { await using var fx = await GreetingContract.CreateAsync(_network); var(newPublicKey, newPrivateKey) = Generator.KeyPair(); var newEndorsement = new Endorsement(newPublicKey); var updatedSignatory = new Signatory(_network.Signatory, fx.PrivateKey, newPrivateKey); fx.Client.Configure(ctx => ctx.Signatory = updatedSignatory); var record = await fx.Client.UpdateContractWithRecordAsync(new UpdateContractParams { Contract = fx.ContractRecord.Contract, Administrator = newEndorsement, }); var info = await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract); Assert.NotNull(info); Assert.Equal(fx.ContractRecord.Contract, info.Contract); Assert.Equal(fx.ContractRecord.Contract, info.Address); Assert.Equal(newEndorsement, info.Administrator); Assert.Equal(fx.ContractParams.RenewPeriod, info.RenewPeriod); Assert.Equal(fx.ContractParams.Memo, info.Memo); Assert.Equal((ulong)fx.ContractParams.InitialBalance, info.Balance); AssertHg.NotEmpty(info.Ledger); }
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 receipt = await fx.Client.SubmitMessageAsync(fx.Record.Topic, message); 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.NotEmpty(info.RunningHash.ToArray()); 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); AssertHg.NotEmpty(info.Ledger); }
public async Task CanCreateAccountAsync() { var initialBalance = (ulong)Generator.Integer(10, 200); var(publicKey1, privateKey1) = Generator.KeyPair(); var(publicKey2, privateKey2) = Generator.KeyPair(); var endorsement = new Endorsement(publicKey1, publicKey2); var signatory = new Signatory(privateKey1, privateKey2); var client = _network.NewClient(); var createResult = await client.CreateAccountAsync(new CreateAccountParams { InitialBalance = initialBalance, Endorsement = endorsement }); Assert.NotNull(createResult); Assert.NotNull(createResult.Address); Assert.Equal(_network.ServerRealm, createResult.Address.RealmNum); Assert.Equal(_network.ServerShard, createResult.Address.ShardNum); Assert.True(createResult.Address.AccountNum > 0); var info = await client.GetAccountInfoAsync(createResult.Address); Assert.Equal(initialBalance, info.Balance); Assert.Equal(createResult.Address.RealmNum, info.Address.RealmNum); Assert.Equal(createResult.Address.ShardNum, info.Address.ShardNum); Assert.Equal(createResult.Address.AccountNum, info.Address.AccountNum); Assert.Equal(endorsement, info.Endorsement); Assert.Equal(0, info.AutoAssociationLimit); Assert.Equal(Alias.None, info.Alias); AssertHg.NotEmpty(info.Ledger); Assert.Equal(new Address(0, 0, 0), info.Proxy); Assert.False(info.Deleted); // Move remaining funds back to primary account. var from = createResult.Address; await client.TransferAsync(from, _network.Payer, (long)initialBalance, signatory); var receipt = await client.DeleteAccountAsync(createResult.Address, _network.Payer, signatory); Assert.NotNull(receipt); Assert.Equal(ResponseCode.Success, receipt.Status); var exception = await Assert.ThrowsAsync <PrecheckException>(async() => { await client.GetAccountInfoAsync(createResult.Address); }); Assert.StartsWith("Transaction Failed Pre-Check: AccountDeleted", exception.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); }
public async Task CanGetFileInfo() { await using var test = await TestFile.CreateAsync(_network); var info = await test.Client.GetFileInfoAsync(test.Record.File); Assert.NotNull(info); Assert.Equal(test.Record.File, info.File); Assert.Equal(test.CreateParams.Memo, info.Memo); Assert.Equal(test.CreateParams.Contents.Length, info.Size); Assert.Equal(test.CreateParams.Expiration, info.Expiration); Assert.Equal(new Endorsement[] { test.PublicKey }, info.Endorsements); Assert.False(info.Deleted); AssertHg.NotEmpty(info.Ledger); }
public async Task CanGetStatefulContractInfo() { await using var fx = await StatefulContract.CreateAsync(_network); var info = await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract); Assert.NotNull(info); Assert.Equal(fx.ContractRecord.Contract, info.Contract); Assert.Equal(fx.ContractRecord.Contract, info.Address); // Assume for now they are equal Assert.NotNull(info.SmartContractId); Assert.Equal(fx.ContractParams.Administrator, info.Administrator); Assert.InRange(info.Expiration, DateTime.UtcNow, DateTime.MaxValue); Assert.Equal(fx.ContractParams.RenewPeriod, info.RenewPeriod); Assert.InRange(info.Size, 0, fx.FileParams.Contents.Length); Assert.Equal(fx.ContractParams.Memo, info.Memo); Assert.Equal((ulong)fx.ContractParams.InitialBalance, info.Balance); AssertHg.NotEmpty(info.Ledger); }
public async Task CanGetImutableFileInfo() { await using var test = await TestFile.CreateAsync(_network, fx => { fx.CreateParams.Endorsements = Array.Empty <Endorsement>(); }); var info = await test.Client.GetFileInfoAsync(test.Record.File); Assert.NotNull(info); Assert.Equal(test.Record.File, info.File); Assert.Equal(test.CreateParams.Memo, info.Memo); Assert.Equal(test.CreateParams.Contents.Length, info.Size); Assert.Equal(test.CreateParams.Expiration, info.Expiration); Assert.Empty(info.Endorsements); Assert.False(info.Deleted); AssertHg.NotEmpty(info.Ledger); }
public async Task CanUpdateMultiplePropertiesAtOnce() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxTempate = await TestAccount.CreateAsync(_network); var record = await fxAccount.Client.UpdateAccountWithRecordAsync(new UpdateAccountParams { Address = fxAccount, Signatory = new Signatory(fxAccount, fxTempate), Endorsement = fxTempate.CreateParams.Endorsement, RequireReceiveSignature = fxTempate.CreateParams.RequireReceiveSignature, Proxy = fxTempate, Memo = fxTempate.CreateParams.Memo }); Assert.Equal(ResponseCode.Success, record.Status); Assert.False(record.Hash.IsEmpty); Assert.NotNull(record.Concensus); Assert.NotNull(record.CurrentExchangeRate); Assert.NotNull(record.NextExchangeRate); Assert.NotEmpty(record.Hash.ToArray()); Assert.Empty(record.Memo); Assert.InRange(record.Fee, 0UL, ulong.MaxValue); Assert.Equal(_network.Payer, record.Id.Address); var info = await fxAccount.Client.GetAccountInfoAsync(fxAccount); Assert.Equal(fxAccount.Record.Address, info.Address); Assert.NotNull(info.SmartContractId); Assert.False(info.Deleted); Assert.Equal(fxTempate.Record.Address, info.Proxy); Assert.Equal(0, info.ProxiedToAccount); Assert.Equal(fxTempate.PublicKey, info.Endorsement); Assert.Equal(fxAccount.CreateParams.InitialBalance, info.Balance); Assert.Equal(fxTempate.CreateParams.RequireReceiveSignature, info.ReceiveSignatureRequired); Assert.True(info.AutoRenewPeriod.TotalSeconds > 0); Assert.True(info.Expiration > DateTime.MinValue); Assert.Equal(fxTempate.CreateParams.Memo, info.Memo); Assert.Equal(0, info.AssetCount); Assert.Equal(fxAccount.CreateParams.AutoAssociationLimit, info.AutoAssociationLimit); Assert.Equal(Alias.None, info.Alias); AssertHg.NotEmpty(info.Ledger); }
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.NotEmpty(info.RunningHash.ToArray()); 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); AssertHg.NotEmpty(info.Ledger); }
public async Task CanDeleteAFileWithRecordNoSignatoryAsync() { await using var test = await TestFile.CreateAsync(_network); var result = await test.Client.DeleteFileWithRecordAsync(test.Record.File, ctx => ctx.Signatory = new Signatory(_network.PrivateKey, test.CreateParams.Signatory)); Assert.NotNull(result); Assert.Equal(ResponseCode.Success, result.Status); var info = await test.Client.GetFileInfoAsync(test.Record.File); Assert.NotNull(info); Assert.Equal(test.Record.File, info.File); Assert.Equal(0, info.Size); Assert.Equal(test.CreateParams.Expiration, info.Expiration); Assert.Equal(new Endorsement[] { test.PublicKey }, info.Endorsements); Assert.True(info.Deleted); AssertHg.NotEmpty(info.Ledger); }
public async Task CanGetAssetInfo() { await using var fxAccount = await TestAccount.CreateAsync(_network); await using var fxAsset = await TestAsset.CreateAsync(_network, fx => fx.Params.GrantKycEndorsement = null, fxAccount); var asset = new Asset(fxAsset.Record.Token, 1); var receipt = await fxAsset.Client.TransferAssetAsync(asset, fxAsset.TreasuryAccount.Record.Address, fxAccount.Record.Address, fxAsset.TreasuryAccount.PrivateKey); Assert.Equal(ResponseCode.Success, receipt.Status); var info = await fxAsset.Client.GetAssetInfoAsync(asset); Assert.Equal(asset, info.Asset); Assert.Equal(fxAccount.Record.Address, info.Owner); Assert.Equal(fxAsset.MintRecord.Concensus, info.Created); Assert.Equal(fxAsset.Metadata[0].ToArray(), info.Metadata.ToArray()); AssertHg.NotEmpty(info.Ledger); }
public async Task CanCreateATopicWithEmptyMemoAsync() { await using var fx = await TestTopic.CreateAsync(_network, fx => { fx.Params.Memo = string.Empty; }); var info = await fx.Client.GetTopicInfoAsync(fx.Record.Topic); Assert.Empty(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); }
public async Task CanGetInfoForAliasFacet() { await using var fxAccount = await TestAliasAccount.CreateAsync(_network); var infoFromAddress = await fxAccount.Client.GetAccountInfoAsync(fxAccount.CreateRecord.Address); Assert.Equal(fxAccount.CreateRecord.Address, infoFromAddress.Address); Assert.NotNull(infoFromAddress.SmartContractId); Assert.False(infoFromAddress.Deleted); Assert.NotNull(infoFromAddress.Proxy); Assert.Equal(Address.None, infoFromAddress.Proxy); Assert.Equal(0, infoFromAddress.ProxiedToAccount); Assert.Equal(fxAccount.PublicKey, infoFromAddress.Endorsement); Assert.True(infoFromAddress.Balance > 0); Assert.False(infoFromAddress.ReceiveSignatureRequired); Assert.True(infoFromAddress.AutoRenewPeriod.TotalSeconds > 0); Assert.True(infoFromAddress.Expiration > DateTime.MinValue); Assert.Equal("auto-created account", infoFromAddress.Memo); Assert.Equal(0, infoFromAddress.AssetCount); Assert.Equal(0, infoFromAddress.AutoAssociationLimit); Assert.Equal(fxAccount.Alias, infoFromAddress.Alias); AssertHg.NotEmpty(infoFromAddress.Ledger); var infoFromAlias = await fxAccount.Client.GetAccountInfoAsync(fxAccount.Alias); Assert.Equal(fxAccount.CreateRecord.Address, infoFromAlias.Address); Assert.NotNull(infoFromAlias.SmartContractId); Assert.False(infoFromAlias.Deleted); Assert.NotNull(infoFromAlias.Proxy); Assert.Equal(Address.None, infoFromAlias.Proxy); Assert.Equal(0, infoFromAlias.ProxiedToAccount); Assert.Equal(fxAccount.PublicKey, infoFromAlias.Endorsement); Assert.True(infoFromAlias.Balance > 0); Assert.False(infoFromAlias.ReceiveSignatureRequired); Assert.True(infoFromAlias.AutoRenewPeriod.TotalSeconds > 0); Assert.True(infoFromAlias.Expiration > DateTime.MinValue); Assert.Equal("auto-created account", infoFromAlias.Memo); Assert.Equal(0, infoFromAlias.AssetCount); Assert.Equal(0, infoFromAlias.AutoAssociationLimit); Assert.Equal(fxAccount.Alias, infoFromAlias.Alias); AssertHg.Equal(infoFromAddress.Ledger, infoFromAlias.Ledger); }
public async Task CanUpdateMultiplePropertiesInOneCallButNotRenewalPeriod() { await using var fx = await GreetingContract.CreateAsync(_network); var originalInfo = await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract); var(newPublicKey, newPrivateKey) = Generator.KeyPair(); var newExpiration = Generator.TruncatedFutureDate(2400, 4800); var newEndorsement = new Endorsement(newPublicKey); var updatedSignatory = new Signatory(_network.Signatory, newPrivateKey); var newRenewPeriod = TimeSpan.FromDays(Generator.Integer(180, 365)); var newMemo = Generator.Code(50); fx.Client.Configure(ctx => ctx.Signatory = updatedSignatory); var pex = await Assert.ThrowsAsync <PrecheckException>(async() => { var record = await fx.Client.UpdateContractWithRecordAsync(new UpdateContractParams { Contract = fx.ContractRecord.Contract, Expiration = newExpiration, Administrator = newEndorsement, RenewPeriod = newRenewPeriod, Memo = newMemo }); }); Assert.Equal(ResponseCode.AutorenewDurationNotInRange, pex.Status); Assert.StartsWith("Transaction Failed Pre-Check: AutorenewDurationNotInRange", pex.Message); var info = await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract); Assert.NotNull(info); Assert.Equal(fx.ContractRecord.Contract, info.Contract); Assert.Equal(fx.ContractRecord.Contract, info.Address); Assert.Equal(originalInfo.Expiration, info.Expiration); Assert.Equal(originalInfo.Administrator, info.Administrator); Assert.Equal(originalInfo.RenewPeriod, info.RenewPeriod); Assert.Equal(originalInfo.Memo, info.Memo); Assert.Equal((ulong)fx.ContractParams.InitialBalance, info.Balance); AssertHg.NotEmpty(info.Ledger); }
public async Task CanGetInfoForAssetTreasuryAccount() { await using var fxAsset = await TestAsset.CreateAsync(_network); var info = await fxAsset.Client.GetAccountInfoAsync(fxAsset.TreasuryAccount.Record.Address); Assert.Equal(fxAsset.TreasuryAccount.Record.Address, info.Address); Assert.NotNull(info.SmartContractId); Assert.False(info.Deleted); Assert.NotNull(info.Proxy); Assert.Equal(new Address(0, 0, 0), info.Proxy); Assert.True(info.ProxiedToAccount > -1); Assert.True(info.Balance > 0); Assert.False(info.ReceiveSignatureRequired); Assert.True(info.AutoRenewPeriod.TotalSeconds > 0); Assert.True(info.Expiration > DateTime.MinValue); Assert.Equal(fxAsset.Metadata.Length, info.AssetCount); Assert.Equal(fxAsset.TreasuryAccount.CreateParams.AutoAssociationLimit, info.AutoAssociationLimit); Assert.Equal(Alias.None, info.Alias); AssertHg.NotEmpty(info.Ledger); }
public async Task CanGetTokenInfo() { await using var fx = await TestPendingTransfer.CreateAsync(_network); Assert.Equal(ResponseCode.Success, fx.Record.Status); var info = await fx.PayingAccount.Client.GetPendingTransactionInfoAsync(fx.Record.Pending.Id); Assert.Equal(fx.Record.Pending.Id, info.Id); Assert.Equal(fx.Record.Pending.TxId, info.TxId); Assert.Equal(_network.Payer, info.Creator); Assert.Equal(fx.PayingAccount, info.Payer); Assert.Single(info.Endorsements); Assert.Equal(new Endorsement(fx.PayingAccount.PublicKey), info.Endorsements[0]); Assert.Equal(new Endorsement(fx.PublicKey), info.Administrator); Assert.Equal(fx.Memo, info.Memo); Assert.True(info.Expiration > DateTime.MinValue); Assert.Null(info.Executed); Assert.Null(info.Deleted); Assert.False(info.PendingTransactionBody.IsEmpty); AssertHg.NotEmpty(info.Ledger); }
async Task CanGetImutableStatefulContractInfo() { await using var fx = await StatefulContract.CreateAsync(_network, f => { f.ContractParams.Administrator = null; }); var info = await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract); Assert.NotNull(info); Assert.Equal(fx.ContractRecord.Contract, info.Contract); Assert.Equal(fx.ContractRecord.Contract, info.Address); // Assume for now they are equal Assert.NotNull(info.SmartContractId); // Immutable Contracts list their "contract" key as the administrator Key. Assert.Equal(KeyType.Contract, info.Administrator.Type); Assert.Equal(fx.ContractRecord.Contract, info.Administrator.Contract); Assert.InRange(info.Expiration, DateTime.UtcNow, DateTime.MaxValue); Assert.Equal(fx.ContractParams.RenewPeriod, info.RenewPeriod); Assert.InRange(info.Size, 0, fx.FileParams.Contents.Length); Assert.StartsWith(fx.ContractParams.Memo, info.Memo); Assert.Equal((ulong)fx.ContractParams.InitialBalance, info.Balance); AssertHg.NotEmpty(info.Ledger); }
public async Task NetworkAllowsDuplicateSegments() { await using var fx = await TestTopic.CreateAsync(_network); var parentTx = fx.Client.CreateNewTxId(); var copies = Generator.Integer(10, 20); for (int i = 0; i < copies; i++) { var receipt = await fx.Client.SubmitMessageAsync(new SubmitMessageParams { Topic = fx.Record.Topic, Segment = Encoding.ASCII.GetBytes(Generator.String(120, 199)), ParentTxId = parentTx, Index = 2, TotalSegmentCount = 3, Signatory = fx.ParticipantPrivateKey }); Assert.Equal(ResponseCode.Success, receipt.Status); Assert.Equal((ulong)(i + 1), 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.NotEmpty(info.RunningHash.ToArray()); Assert.Equal((ulong)copies, 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); }
public async Task UpdateContractExpirationDate() { await using var fx = await GreetingContract.CreateAsync(_network); var oldExpiration = (await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract)).Expiration; var newExpiration = oldExpiration.AddMonths(12); var record = await fx.Client.UpdateContractWithRecordAsync(new UpdateContractParams { Contract = fx.ContractRecord.Contract, Expiration = newExpiration }); var info = await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract); Assert.NotNull(info); Assert.Equal(fx.ContractRecord.Contract, info.Contract); Assert.Equal(fx.ContractRecord.Contract, info.Address); Assert.Equal(newExpiration, info.Expiration); Assert.Equal(fx.PublicKey, info.Administrator); Assert.Equal(fx.ContractParams.RenewPeriod, info.RenewPeriod); Assert.Equal(fx.ContractParams.Memo, info.Memo); Assert.Equal((ulong)fx.ContractParams.InitialBalance, info.Balance); AssertHg.NotEmpty(info.Ledger); }
public async Task DeletingPendingTransactionDoesNotRemovePendingInfo() { await using var fx = await TestPendingTransfer.CreateAsync(_network); var receipt = await fx.Client.DeletePendingTransactionAsync(fx.Record.Pending.Id, ctx => ctx.Signatory = new Signatory(fx.PrivateKey, ctx.Signatory)); var record = await fx.Client.GetTransactionRecordAsync(receipt.Id); var info = await fx.PayingAccount.Client.GetPendingTransactionInfoAsync(fx.Record.Pending.Id); Assert.Equal(fx.Record.Pending.Id, info.Id); Assert.Equal(fx.Record.Pending.TxId, info.TxId); Assert.Equal(_network.Payer, info.Creator); Assert.Equal(fx.PayingAccount, info.Payer); Assert.Single(info.Endorsements); Assert.Equal(new Endorsement(fx.PayingAccount.PublicKey), info.Endorsements[0]); Assert.Equal(new Endorsement(fx.PublicKey), info.Administrator); Assert.Equal(fx.Memo, info.Memo); Assert.True(info.Expiration > DateTime.MinValue); Assert.Null(info.Executed); Assert.Equal(record.Concensus, info.Deleted); Assert.False(info.PendingTransactionBody.IsEmpty); AssertHg.NotEmpty(info.Ledger); }
public async Task CanUpdateFileKey() { await using var test = await TestFile.CreateAsync(_network); var(newPublicKey, newPrivateKey) = Generator.KeyPair(); var updateRecord = await test.Client.UpdateFileWithRecordAsync(new UpdateFileParams { File = test.Record.File, Endorsements = new Endorsement[] { newPublicKey }, Signatory = new Signatory(_network.PrivateKey, test.PrivateKey, newPrivateKey) }); Assert.Equal(ResponseCode.Success, updateRecord.Status); var info = await test.Client.GetFileInfoAsync(test.Record.File); Assert.NotNull(info); Assert.Equal(test.Record.File, info.File); Assert.Equal(test.CreateParams.Contents.Length, info.Size); Assert.Equal(test.CreateParams.Expiration, info.Expiration); Assert.Equal(new Endorsement[] { newPublicKey }, info.Endorsements); Assert.False(info.Deleted); AssertHg.NotEmpty(info.Ledger); }