public async Task CanNotScheduleDelete()
        {
            var systemAddress = await _network.GetSystemDeleteAdminAddress();

            if (systemAddress is null)
            {
                _network.Output?.WriteLine("TEST SKIPPED: No access to System Delete Administrator Account.");
                return;
            }

            await using var fxFile = await TestFile.CreateAsync(_network);

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

            var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
            {
                await fxFile.Client.SystemDeleteFileAsync(
                    fxFile.Record.File,
                    ctx =>
                {
                    ctx.Payer     = systemAddress;
                    ctx.Signatory = new Signatory(
                        _network.PrivateKey,
                        new PendingParams {
                        PendingPayer = fxPayer
                    }
                        );
                });
            });

            Assert.Equal(ResponseCode.ScheduledTransactionNotInWhitelist, tex.Status);
            Assert.StartsWith("Unable to schedule transaction, status: ScheduledTransactionNotInWhitelist", tex.Message);
        }
示例#2
0
        public async Task CanDeleteAFileUsingSignatory()
        {
            var systemAddress = await _network.GetSystemDeleteAdminAddress();

            if (systemAddress is null)
            {
                _network.Output?.WriteLine("TEST SKIPPED: No access to System Delete Administrator Account.");
                return;
            }

            await using var fxFile = await TestFile.CreateAsync(_network);

            var receipt = await fxFile.Client.SystemDeleteFileAsync(fxFile, _network.Signatory, ctx => ctx.Payer = systemAddress);

            Assert.Equal(ResponseCode.Success, receipt.Status);
            Assert.Equal(systemAddress, receipt.Id.Address);

            var info = await fxFile.Client.GetFileInfoAsync(fxFile.Record.File);

            Assert.NotNull(info);
            Assert.Equal(fxFile.Record.File, info.File);
            Assert.Equal(fxFile.CreateParams.Contents.Length, info.Size);
            Assert.Equal(fxFile.CreateParams.Expiration, info.Expiration);
            Assert.Equal(new Endorsement[] { fxFile.PublicKey }, info.Endorsements);
            Assert.True(info.Deleted);
        }
示例#3
0
    public async Task CanNotScheduleFileAppend()
    {
        await using var fxPayer = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 20_00_000_000);

        await using var fxFile = await TestFile.CreateAsync(_network);

        var appendedContent = Encoding.Unicode.GetBytes(Generator.Code(50));

        var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
        {
            await fxFile.Client.AppendFileAsync(new AppendFileParams
            {
                File      = fxFile.Record.File,
                Contents  = appendedContent,
                Signatory = new Signatory(
                    fxFile.CreateParams.Signatory,
                    new PendingParams {
                    PendingPayer = fxPayer
                }
                    )
            });
        });

        Assert.Equal(ResponseCode.ScheduledTransactionNotInWhitelist, tex.Status);
        Assert.StartsWith("Unable to schedule transaction, status: ScheduledTransactionNotInWhitelist", tex.Message);
    }
示例#4
0
    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);
    }
示例#5
0
        public async Task CanDeleteAFileWithRecord()
        {
            var systemAddress = await _network.GetSystemDeleteAdminAddress();

            if (systemAddress is null)
            {
                _network.Output?.WriteLine("TEST SKIPPED: No access to System Delete Administrator Account.");
                return;
            }

            await using var fxFile = await TestFile.CreateAsync(_network);

            var record = await fxFile.Client.SystemDeleteFileWithRecordAsync(fxFile, ctx => ctx.Payer = systemAddress);

            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(systemAddress, record.Id.Address);

            var info = await fxFile.Client.GetFileInfoAsync(fxFile.Record.File);

            Assert.NotNull(info);
            Assert.Equal(fxFile.Record.File, info.File);
            Assert.Equal(fxFile.CreateParams.Contents.Length, info.Size);
            Assert.Equal(fxFile.CreateParams.Expiration, info.Expiration);
            Assert.Equal(new Endorsement[] { fxFile.PublicKey }, info.Endorsements);
            Assert.True(info.Deleted);
        }
示例#6
0
        public async Task CanUpdateFileKey()
        {
            await using var test = await TestFile.CreateAsync(_network);

            var (newPublicKey, newPrivateKey) = Generator.KeyPair();
            test.Client.Configure(ctx =>
            {
                ctx.Payer = new Account(
                    _network.AccountRealm,
                    _network.AccountShard,
                    _network.AccountNumber,
                    _network.PrivateKey,
                    test.PrivateKey,
                    newPrivateKey);
            });

            var updateRecord = await test.Client.UpdateFileAsync(new UpdateFileParams
            {
                File = test.Record.File,
                Endorsements = new Endorsement[] { newPublicKey }
            });
            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.Contents.Length + 30, info.Size);
            Assert.Equal(test.Expiration, info.Expiration);
            Assert.Equal(new Endorsement[] { newPublicKey }, info.Endorsements);
            Assert.False(info.Deleted);
        }
示例#7
0
        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);
        }
示例#8
0
    public async Task CanAppendToFileHavingExtraSignature()
    {
        await using var test = await TestFile.CreateAsync(_network);

        var(publicKey, privateKey) = Generator.KeyPair();

        await test.Client.UpdateFileAsync(new UpdateFileParams
        {
            File         = test.Record.File,
            Endorsements = new[] { new Endorsement(publicKey) },
            Signatory    = new Signatory(privateKey, test.CreateParams.Signatory)
        });

        var appendedContent     = Encoding.Unicode.GetBytes(Generator.Code(50));
        var concatinatedContent = test.CreateParams.Contents.ToArray().Concat(appendedContent).ToArray();

        var appendRecord = await test.Client.AppendFileWithRecordAsync(new AppendFileParams
        {
            File      = test.Record.File,
            Contents  = appendedContent,
            Signatory = privateKey
        });

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

        var newContent = await test.Client.GetFileContentAsync(test.Record.File);

        Assert.Equal(concatinatedContent.ToArray(), newContent.ToArray());
    }
        public async Task CanGetFileContent()
        {
            await using var test = await TestFile.CreateAsync(_network);

            var retrievedContents = await test.Client.GetFileContentAsync(test.Record.File);

            Assert.Equal(test.CreateParams.Contents.ToArray(), retrievedContents.ToArray());
        }
示例#10
0
        public async Task CanCreateAFileAsync()
        {
            await using var test = await TestFile.CreateAsync(_network);

            Assert.NotNull(test.Record);
            Assert.NotNull(test.Record.File);
            Assert.Equal(ResponseCode.Success, test.Record.Status);
        }
        public async Task RequiresAFee()
        {
            await using var test = await TestFile.CreateAsync(_network);

            var txId     = test.Client.CreateNewTxId();
            var contents = await test.Client.GetFileContentAsync(test.Record.File, ctx => ctx.Transaction = txId);

            var record = await test.Client.GetTransactionRecordAsync(txId);

            Assert.True(record.Transfers[_network.Payer] < 0);
        }
示例#12
0
        public async Task FileAddressForTokenSymbolRaisesError()
        {
            await using var fx = await TestFile.CreateAsync(_network);

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

            Assert.Equal(ResponseCode.InvalidTokenId, pex.Status);
            Assert.StartsWith("Transaction Failed Pre-Check: InvalidTokenId", pex.Message);
        }
示例#13
0
        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.Contents.Length, info.Size);
            Assert.Equal(test.CreateParams.Expiration, info.Expiration);
            Assert.Equal(new Endorsement[] { test.PublicKey }, info.Endorsements);
            Assert.False(info.Deleted);
        }
示例#14
0
        public async Task CanGetCreateFileReceipt()
        {
            await using var fx = await TestFile.CreateAsync(_network);

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

            var fileReceipt = Assert.IsType <FileReceipt>(receipt);

            Assert.Equal(fx.Record.Id, fileReceipt.Id);
            Assert.Equal(fx.Record.Status, fileReceipt.Status);
            Assert.Equal(fx.Record.CurrentExchangeRate, fileReceipt.CurrentExchangeRate);
            Assert.Equal(fx.Record.NextExchangeRate, fileReceipt.NextExchangeRate);
            Assert.Equal(fx.Record.File, fileReceipt.File);
        }
示例#15
0
        public async Task CanDeleteAFileAsync()
        {
            await using var test = await TestFile.CreateAsync(_network);

            var result = await test.Client.DeleteFileAsync(test.Record.File);

            Assert.NotNull(result);
            Assert.Equal(ResponseCode.Success, result.Status);

            var exception = await Assert.ThrowsAnyAsync <PrecheckException>(async() =>
            {
                await test.Client.GetFileInfoAsync(test.Record.File);
            });
        }
示例#16
0
        public async Task CanGetEmptyFileInfo()
        {
            await using var test = await TestFile.CreateAsync(_network, fx => {
                fx.CreateParams.Contents = ReadOnlyMemory <byte> .Empty;
            });

            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.False(info.Deleted);
        }
示例#17
0
        public async Task FileAddressAsTreasuryRaisesError()
        {
            var fxFile = await TestFile.CreateAsync(_network);

            var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
            {
                await TestToken.CreateAsync(_network, fx =>
                {
                    fx.Params.Treasury = fxFile.Record.File;
                });
            });

            Assert.Equal(ResponseCode.InvalidTreasuryAccountForToken, tex.Status);
            Assert.StartsWith("Unable to create Token, status: InvalidTreasuryAccountForToken", tex.Message);
        }
示例#18
0
        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.Contents.Length, info.Size);
            Assert.Equal(test.CreateParams.Expiration, info.Expiration);
            Assert.Empty(info.Endorsements);
            Assert.False(info.Deleted);
        }
示例#19
0
        public async Task CanUpdateFileContents()
        {
            await using var test = await TestFile.CreateAsync(_network);

            var newContents = Encoding.Unicode.GetBytes("Hello Again Hashgraph " + Generator.Code(50));

            var updateRecord = await test.Client.UpdateFileAsync(new UpdateFileParams
            {
                File = test.Record.File,
                Contents = newContents
            });
            Assert.Equal(ResponseCode.Success, updateRecord.Status);

            var retrievedContents = await test.Client.GetFileContentAsync(test.Record.File);
            Assert.Equal(newContents, retrievedContents.ToArray());
        }
示例#20
0
        public async Task CanUpdateFileContentsOfDeletedFile()
        {
            await using var test = await TestFile.CreateAsync(_network);

            var deleteResult = await test.Client.DeleteFileAsync(test.Record.File);
            Assert.Equal(ResponseCode.Success, deleteResult.Status);

            var exception = await Assert.ThrowsAsync<TransactionException>(async () =>
            {
                await test.Client.UpdateFileAsync(new UpdateFileParams
                {
                    File = test.Record.File,
                    Contents = Encoding.Unicode.GetBytes("Hello Again Hashgraph " + Generator.Code(50))
                });
            });
            Assert.StartsWith("Unable to update file, status: FileDeleted", exception.Message);
        }
    public async Task CanRestoreAFileWithRecordUsingSignatory()
    {
        var deleteAddress = await _network.GetSystemDeleteAdminAddress();

        if (deleteAddress is null)
        {
            _network.Output?.WriteLine("TEST SKIPPED: No access to System Delete Administrator Account.");
            return;
        }
        var restoreAddress = await _network.GetSystemUndeleteAdminAddress();

        if (restoreAddress is null)
        {
            _network.Output?.WriteLine("TEST SKIPPED: No access to System Restore Administrator Account.");
            return;
        }

        await using var fxFile = await TestFile.CreateAsync(_network);

        await fxFile.Client.SystemDeleteFileAsync(fxFile, ctx => ctx.Payer = deleteAddress);

        var record = await fxFile.Client.SystemRestoreFileWithRecordAsync(fxFile, _network.PrivateKey, ctx => ctx.Payer = restoreAddress);

        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(restoreAddress, record.Id.Address);

        var info = await fxFile.Client.GetFileInfoAsync(fxFile.Record.File);

        Assert.NotNull(info);
        Assert.Equal(fxFile.Record.File, info.File);
        Assert.Equal(fxFile.CreateParams.Contents.Length, info.Size);
        Assert.Equal(fxFile.CreateParams.Expiration, info.Expiration);
        Assert.Equal(new Endorsement[] { fxFile.PublicKey }, info.Endorsements);
        Assert.False(info.Deleted);
        // NETWORK V0.21.0 UNSUPPORTED vvvv
        // NOT IMPLEMENTED YET
        Assert.Empty(info.Ledger.ToArray());
        // NETWORK V0.21.0 UNSUPPORTED ^^^^
    }
示例#22
0
        public async Task CanDeleteAFileAsync()
        {
            await using var test = await TestFile.CreateAsync(_network);

            var result = await test.Client.DeleteFileWithRecordAsync(test.Record.File, test.Signatory);

            Assert.NotNull(result);
            Assert.Equal(ResponseCode.Success, result.Status);

            var pex = await Assert.ThrowsAsync <PrecheckException>(async() =>
            {
                await test.Client.GetFileInfoAsync(test.Record.File);
            });

            Assert.Equal(ResponseCode.FileDeleted, pex.Status);
            Assert.StartsWith("Transaction Failed Pre-Check: FileDeleted", pex.Message);
        }
示例#23
0
        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);
        }
示例#24
0
        public async Task CanGetCreateFileRecord()
        {
            await using var fx = await TestFile.CreateAsync(_network);

            var record = await fx.Client.GetTransactionRecordAsync(fx.Record.Id);

            var FileRecord = Assert.IsType <FileRecord>(record);

            Assert.Equal(fx.Record.Id, FileRecord.Id);
            Assert.Equal(fx.Record.Status, FileRecord.Status);
            Assert.Equal(fx.Record.CurrentExchangeRate, FileRecord.CurrentExchangeRate);
            Assert.Equal(fx.Record.NextExchangeRate, FileRecord.NextExchangeRate);
            Assert.Equal(fx.Record.Hash.ToArray(), FileRecord.Hash.ToArray());
            Assert.Equal(fx.Record.Concensus, FileRecord.Concensus);
            Assert.Equal(fx.Record.Memo, FileRecord.Memo);
            Assert.Equal(fx.Record.Fee, FileRecord.Fee);
            Assert.Equal(fx.Record.File, FileRecord.File);
        }
示例#25
0
        public async Task CanAppendToFile()
        {
            await using var test = await TestFile.CreateAsync(_network);

            var appendedContent     = Encoding.Unicode.GetBytes(Generator.Code(50));
            var concatinatedContent = test.Contents.Concat(appendedContent).ToArray();

            var appendRecord = await test.Client.AppendFileAsync(new AppendFileParams
            {
                File     = test.Record.File,
                Contents = appendedContent
            });

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

            var newContent = await test.Client.GetFileContentAsync(test.Record.File);

            Assert.Equal(concatinatedContent.ToArray(), newContent.ToArray());
        }
示例#26
0
    public async Task CanGetImutableEmptyFileInfo()
    {
        await using var test = await TestFile.CreateAsync(_network, fx =>
        {
            fx.CreateParams.Endorsements = Array.Empty <Endorsement>();
            fx.CreateParams.Contents     = ReadOnlyMemory <byte> .Empty;
        });

        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(0, info.Size);
        Assert.Equal(test.CreateParams.Expiration, info.Expiration);
        Assert.Empty(info.Endorsements);
        Assert.False(info.Deleted);
        AssertHg.NotEmpty(info.Ledger);
    }
示例#27
0
        public async Task UpdateWithNonExistantContractRaisesError()
        {
            await using var fx = await TestFile.CreateAsync(_network);

            var invalidContractAddress = fx.Record.File;
            await fx.Client.DeleteFileAsync(invalidContractAddress, fx.Signatory);

            var newMemo = Generator.Code(50);
            var pex     = await Assert.ThrowsAsync <PrecheckException>(async() =>
            {
                await fx.Client.UpdateContractWithRecordAsync(new UpdateContractParams
                {
                    Contract = invalidContractAddress,
                    Memo     = newMemo
                });
            });

            Assert.Equal(ResponseCode.InvalidContractId, pex.Status);
            Assert.StartsWith("Transaction Failed Pre-Check: InvalidContractId", pex.Message);
        }
示例#28
0
        public async Task CanNotScheduleACreateFile()
        {
            await using var fxPayer = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 20_00_000_000);

            var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
            {
                await TestFile.CreateAsync(_network, fx =>
                {
                    fx.CreateParams.Signatory = new Signatory(
                        fx.CreateParams.Signatory,
                        new PendingParams
                    {
                        PendingPayer = fxPayer,
                    });
                });
            });

            Assert.Equal(ResponseCode.ScheduledTransactionNotInWhitelist, tex.Status);
            Assert.StartsWith("Unable to schedule transaction, status: ScheduledTransactionNotInWhitelist", tex.Message);
        }
示例#29
0
        public async Task AppendingToDeletedFileThrowsError()
        {
            await using var test = await TestFile.CreateAsync(_network);

            var appendedContent = Encoding.Unicode.GetBytes(Generator.Code(50));

            var deleteRecord = await test.Client.DeleteFileAsync(test.Record.File);

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

            var exception = await Assert.ThrowsAnyAsync <TransactionException>(async() =>
            {
                await test.Client.AppendFileAsync(new AppendFileParams
                {
                    File     = test.Record.File,
                    Contents = appendedContent
                });
            });

            Assert.StartsWith("Unable to append to file, status: FileDeleted", exception.Message);
        }
示例#30
0
        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.Contents.Length, info.Size);
            Assert.Equal(test.Expiration, info.Expiration);
            Assert.Equal(new Endorsement[] { newPublicKey }, info.Endorsements);
            Assert.False(info.Deleted);
        }