예제 #1
0
        public async Task CanDeleteAFile()
        {
            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, 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);
        }
예제 #2
0
        public async Task CanDeleteContract()
        {
            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 fx = await GreetingContract.CreateAsync(_network);

            var receipt = await fx.Client.SystemDeleteContractAsync(fx.ContractRecord.Contract, ctx => ctx.Payer = systemAddress);

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

            // But you still can't get the info
            var pex = await Assert.ThrowsAsync <PrecheckException>(async() =>
            {
                await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract);
            });

            Assert.Equal(ResponseCode.ContractDeleted, pex.Status);
            Assert.StartsWith("Transaction Failed Pre-Check: ContractDeleted", pex.Message);
        }
        public async Task CanNotScheduleRestore()
        {
            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 fxContract = await GreetingContract.CreateAsync(_network);

            await fxContract.Client.DeleteContractAsync(fxContract, _network.Payer, fxContract.PrivateKey);

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

            var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
            {
                await fxContract.Client.SystemRestoreContractAsync(
                    fxContract.ContractRecord.Contract,
                    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);
        }
    public async Task CanRestoreAFile()
    {
        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 Undelete Administrator Account.");
            return;
        }

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

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

        var receipt = await fxFile.Client.SystemRestoreFileAsync(fxFile, ctx => ctx.Payer = restoreAddress);

        Assert.Equal(ResponseCode.Success, receipt.Status);
        Assert.Equal(restoreAddress, 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.False(info.Deleted);
        // NETWORK V0.21.0 UNSUPPORTED vvvv
        // NOT IMPLEMENTED YET
        Assert.Empty(info.Ledger.ToArray());
        // NETWORK V0.21.0 UNSUPPORTED ^^^^
    }