Example #1
0
        public async Task DissociationRequiresSigningByTargetAccount()
        {
            await using var fxAccount = await TestAccount.CreateAsync(_network);

            await using var fxToken = await TestToken.CreateAsync(_network, null, fxAccount);

            var association = await AssertHg.TokenIsAssociatedAsync(fxToken, fxAccount);

            Assert.Equal(fxToken.Record.Token, association.Token);
            Assert.Equal(fxToken.Params.Symbol, association.Symbol);
            Assert.Equal(0UL, association.Balance);
            Assert.Equal(TokenKycStatus.Revoked, association.KycStatus);
            Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus);

            var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
            {
                await fxAccount.Client.DissociateTokenAsync(fxToken.Record.Token, fxAccount.Record.Address);
            });

            Assert.Equal(ResponseCode.InvalidSignature, tex.Status);
            Assert.StartsWith("Unable to Dissociate Token from Account, status: InvalidSignature", tex.Message);

            association = await AssertHg.TokenIsAssociatedAsync(fxToken, fxAccount);

            Assert.Equal(fxToken.Record.Token, association.Token);
            Assert.Equal(fxToken.Params.Symbol, association.Symbol);
            Assert.Equal(0UL, association.Balance);
            Assert.Equal(TokenKycStatus.Revoked, association.KycStatus);
            Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus);
        }
Example #2
0
        public async Task CanDissociateTokenFromAccountAndGetRecord()
        {
            await using var fxAccount = await TestAccount.CreateAsync(_network);

            await using var fxToken = await TestToken.CreateAsync(_network, null, fxAccount);

            var association = await AssertHg.TokenIsAssociatedAsync(fxToken, fxAccount);

            Assert.Equal(fxToken.Record.Token, association.Token);
            Assert.Equal(fxToken.Params.Symbol, association.Symbol);
            Assert.Equal(0UL, association.Balance);
            Assert.Equal(TokenKycStatus.Revoked, association.KycStatus);
            Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus);

            var record = await fxAccount.Client.DissociateTokenWithRecordAsync(fxToken.Record.Token, fxAccount.Record.Address, fxAccount.PrivateKey);

            Assert.Equal(ResponseCode.Success, record.Status);
            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);

            await AssertHg.TokenNotAssociatedAsync(fxToken, fxAccount);
        }
Example #3
0
        public async Task CanDissociateMultipleTokensWithAccountNoExtraSignatory()
        {
            await using var fxAccount = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 120_00_000_000);

            await using var fxToken1 = await TestToken.CreateAsync(_network, null, fxAccount);

            await using var fxToken2 = await TestToken.CreateAsync(_network, null, fxAccount);

            var tokens = new Address[] { fxToken1.Record.Token, fxToken2.Record.Token };

            await AssertHg.TokenIsAssociatedAsync(fxToken1, fxAccount);

            await AssertHg.TokenIsAssociatedAsync(fxToken2, fxAccount);

            var receipt = await fxAccount.Client.DissociateTokensAsync(tokens, fxAccount.Record.Address, ctx =>
            {
                ctx.Payer     = fxAccount.Record.Address;
                ctx.Signatory = fxAccount.PrivateKey;
            });

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

            await AssertHg.TokenNotAssociatedAsync(fxToken1, fxAccount);

            await AssertHg.TokenNotAssociatedAsync(fxToken2, fxAccount);
        }
Example #4
0
        public async Task CanDissociateMultipleTokensWithAccountAndGetRecordNoExtraSignatory()
        {
            await using var fxAccount = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 120_00_000_000);

            await using var fxToken1 = await TestToken.CreateAsync(_network, null, fxAccount);

            await using var fxToken2 = await TestToken.CreateAsync(_network, null, fxAccount);

            var tokens = new Address[] { fxToken1.Record.Token, fxToken2.Record.Token };

            await AssertHg.TokenIsAssociatedAsync(fxToken1, fxAccount);

            await AssertHg.TokenIsAssociatedAsync(fxToken2, fxAccount);

            var record = await fxAccount.Client.DissociateTokensWithRecordAsync(tokens, fxAccount.Record.Address, ctx =>
            {
                ctx.Payer     = fxAccount.Record.Address;
                ctx.Signatory = fxAccount.PrivateKey;
            });

            Assert.Equal(ResponseCode.Success, record.Status);
            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(fxAccount.Record.Address, record.Id.Address);

            await AssertHg.TokenNotAssociatedAsync(fxToken1, fxAccount);

            await AssertHg.TokenNotAssociatedAsync(fxToken2, fxAccount);
        }
Example #5
0
    public async Task CanAssociateTokenWithAliasAccountDefect()
    {
        // Associating a token with an account using its alias address has not yet been
        // implemented by the network, although it will accept the transaction.
        var testFailException = (await Assert.ThrowsAsync <TransactionException>(CanAssociateTokenWithAliasAccount));

        Assert.StartsWith("Unable to associate Token with Account, status: InvalidAccountId", testFailException.Message);
        //[Fact(DisplayName = "Associate Tokens: Can Associate token with Alias Account")]
        async Task CanAssociateTokenWithAliasAccount()
        {
            await using var fxAccount = await TestAliasAccount.CreateAsync(_network);

            await using var fxToken = await TestToken.CreateAsync(_network);

            await AssertHg.TokenNotAssociatedAsync(fxToken, fxAccount);

            var receipt = await fxAccount.Client.AssociateTokenAsync(fxToken.Record.Token, fxAccount.Alias, fxAccount.PrivateKey);

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

            var association = await AssertHg.TokenIsAssociatedAsync(fxToken, fxAccount);

            Assert.Equal(fxToken.Record.Token, association.Token);
            Assert.Equal(fxToken.Params.Symbol, association.Symbol);
            Assert.Equal(0UL, association.Balance);
            Assert.Equal(fxToken.Params.Decimals, association.Decimals);
            Assert.Equal(TokenKycStatus.Revoked, association.KycStatus);
            Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus);
            Assert.False(association.AutoAssociated);
        }
    }
Example #6
0
    public async Task CanLimitTokenAutoAssociation()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.AutoAssociationLimit = 1);

        await using var fxToken1 = await TestToken.CreateAsync(_network, fx => fx.Params.GrantKycEndorsement = null);

        await using var fxToken2 = await TestToken.CreateAsync(_network, fx => fx.Params.GrantKycEndorsement = null);

        await AssertHg.TokenNotAssociatedAsync(fxToken1, fxAccount);

        await AssertHg.TokenNotAssociatedAsync(fxToken2, fxAccount);

        var xferAmount1 = fxToken1.Params.Circulation / 2;
        var receipt     = await fxToken1.Client.TransferTokensAsync(fxToken1, fxToken1.TreasuryAccount, fxAccount, (long)xferAmount1, fxToken1.TreasuryAccount);

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

        var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
        {
            var xferAmount2 = fxToken2.Params.Circulation / 2;
            var receipt2    = await fxToken2.Client.TransferTokensAsync(fxToken2, fxToken2.TreasuryAccount, fxAccount, (long)xferAmount2, fxToken2.TreasuryAccount);
        });

        Assert.Equal(ResponseCode.NoRemainingAutomaticAssociations, tex.Status);
        Assert.StartsWith("Unable to execute transfers, status: NoRemainingAutomaticAssociations", tex.Message);

        await AssertHg.TokenIsAssociatedAsync(fxToken1, fxAccount);

        await AssertHg.TokenNotAssociatedAsync(fxToken2, fxAccount);

        await AssertHg.TokenBalanceAsync(fxToken1, fxAccount, xferAmount1);
    }
Example #7
0
    public async Task CanAssociateTokenWithAccountAndGetRecordNoExtraSignatory()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 120_00_000_000);

        await using var fxToken = await TestToken.CreateAsync(_network);

        await AssertHg.TokenNotAssociatedAsync(fxToken, fxAccount);

        var record = await fxAccount.Client.AssociateTokenWithRecordAsync(fxToken.Record.Token, fxAccount.Record.Address, ctx =>
        {
            ctx.Payer     = fxAccount.Record.Address;
            ctx.Signatory = fxAccount.PrivateKey;
        });

        Assert.Equal(ResponseCode.Success, record.Status);
        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(fxAccount.Record.Address, record.Id.Address);

        var association = await AssertHg.TokenIsAssociatedAsync(fxToken, fxAccount);

        Assert.Equal(fxToken.Record.Token, association.Token);
        Assert.Equal(fxToken.Params.Symbol, association.Symbol);
        Assert.Equal(0UL, association.Balance);
        Assert.Equal(fxToken.Params.Decimals, association.Decimals);
        Assert.Equal(TokenKycStatus.Revoked, association.KycStatus);
        Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus);
        Assert.False(association.AutoAssociated);
    }
Example #8
0
    public async Task CanAssociateTokenWithAccountNoExtraSignatory()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 120_00_000_000);

        await using var fxToken = await TestToken.CreateAsync(_network);

        await AssertHg.TokenNotAssociatedAsync(fxToken, fxAccount);

        var receipt = await fxAccount.Client.AssociateTokenAsync(fxToken.Record.Token, fxAccount.Record.Address, ctx =>
        {
            ctx.Payer     = fxAccount.Record.Address;
            ctx.Signatory = fxAccount.PrivateKey;
        });

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

        var association = await AssertHg.TokenIsAssociatedAsync(fxToken, fxAccount);

        Assert.Equal(fxToken.Record.Token, association.Token);
        Assert.Equal(fxToken.Params.Symbol, association.Symbol);
        Assert.Equal(0UL, association.Balance);
        Assert.Equal(fxToken.Params.Decimals, association.Decimals);
        Assert.Equal(TokenKycStatus.Revoked, association.KycStatus);
        Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus);
        Assert.False(association.AutoAssociated);
    }
Example #9
0
    public async Task CanAssociateMultipleAssetsWithAccount()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network);

        await using var fxAsset1 = await TestAsset.CreateAsync(_network);

        await using var fxAsset2 = await TestAsset.CreateAsync(_network);

        await using var fxToken3 = await TestToken.CreateAsync(_network);

        var assets = new Address[] { fxAsset1.Record.Token, fxAsset2.Record.Token, fxToken3.Record.Token };

        await AssertHg.AssetNotAssociatedAsync(fxAsset1, fxAccount);

        await AssertHg.AssetNotAssociatedAsync(fxAsset2, fxAccount);

        await AssertHg.TokenNotAssociatedAsync(fxToken3, fxAccount);

        var receipt = await fxAccount.Client.AssociateTokensAsync(assets, fxAccount.Record.Address, fxAccount.PrivateKey);

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

        var association = await AssertHg.AssetIsAssociatedAsync(fxAsset1, fxAccount);

        Assert.Equal(fxAsset1.Record.Token, association.Token);
        Assert.Equal(fxAsset1.Params.Symbol, association.Symbol);
        Assert.Equal(0UL, association.Balance);
        Assert.Equal(0U, association.Decimals);
        Assert.Equal(TokenKycStatus.Revoked, association.KycStatus);
        Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus);
        Assert.False(association.AutoAssociated);

        association = await AssertHg.AssetIsAssociatedAsync(fxAsset2, fxAccount);

        Assert.Equal(fxAsset2.Record.Token, association.Token);
        Assert.Equal(fxAsset2.Params.Symbol, association.Symbol);
        Assert.Equal(0UL, association.Balance);
        Assert.Equal(0U, association.Decimals);
        Assert.Equal(TokenKycStatus.Revoked, association.KycStatus);
        Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus);
        Assert.False(association.AutoAssociated);

        association = await AssertHg.TokenIsAssociatedAsync(fxToken3, fxAccount);

        Assert.Equal(fxToken3.Record.Token, association.Token);
        Assert.Equal(fxToken3.Params.Symbol, association.Symbol);
        Assert.Equal(0UL, association.Balance);
        Assert.Equal(fxToken3.Params.Decimals, association.Decimals);
        Assert.Equal(TokenKycStatus.Revoked, association.KycStatus);
        Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus);
        Assert.False(association.AutoAssociated);
    }
        public async Task NoTokenBalanceRecordExistsWhenNotAssociated()
        {
            await using var fxAccount = await TestAccount.CreateAsync(_network);

            await using var fxToken = await TestToken.CreateAsync(_network);

            await AssertHg.TokenNotAssociatedAsync(fxToken, fxAccount);

            var receipt = await fxAccount.Client.AssociateTokenAsync(fxToken.Record.Token, fxAccount.Record.Address, fxAccount.PrivateKey);

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

            var association = await AssertHg.TokenIsAssociatedAsync(fxToken, fxAccount);

            Assert.Equal(fxToken.Record.Token, association.Token);
            Assert.Equal(fxToken.Params.Symbol, association.Symbol);
            Assert.Equal(0UL, association.Balance);
            Assert.Equal(TokenKycStatus.Revoked, association.KycStatus);
            Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus);
        }
Example #11
0
    public async Task CanDissociateTokenFromAccount()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network);

        await using var fxToken = await TestToken.CreateAsync(_network, null, fxAccount);

        var association = await AssertHg.TokenIsAssociatedAsync(fxToken, fxAccount);

        Assert.Equal(fxToken.Record.Token, association.Token);
        Assert.Equal(fxToken.Params.Symbol, association.Symbol);
        Assert.Equal(0UL, association.Balance);
        Assert.Equal(fxToken.Params.Decimals, association.Decimals);
        Assert.Equal(TokenKycStatus.Revoked, association.KycStatus);
        Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus);
        Assert.False(association.AutoAssociated);

        var receipt = await fxAccount.Client.DissociateTokenAsync(fxToken.Record.Token, fxAccount.Record.Address, fxAccount.PrivateKey);

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

        await AssertHg.TokenNotAssociatedAsync(fxToken, fxAccount);
    }
Example #12
0
    public async Task CanDissociateMultipleTokensWithAccount()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network);

        await using var fxToken1 = await TestToken.CreateAsync(_network, null, fxAccount);

        await using var fxToken2 = await TestToken.CreateAsync(_network, null, fxAccount);

        var tokens = new Address[] { fxToken1.Record.Token, fxToken2.Record.Token };

        await AssertHg.TokenIsAssociatedAsync(fxToken1, fxAccount);

        await AssertHg.TokenIsAssociatedAsync(fxToken2, fxAccount);

        var receipt = await fxAccount.Client.DissociateTokensAsync(tokens, fxAccount.Record.Address, fxAccount.PrivateKey);

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

        await AssertHg.TokenNotAssociatedAsync(fxToken1, fxAccount);

        await AssertHg.TokenNotAssociatedAsync(fxToken2, fxAccount);
    }
Example #13
0
    public async Task CanRaiseLimitTokenAutoAssociation()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.AutoAssociationLimit = 1);

        await using var fxToken1 = await TestToken.CreateAsync(_network, fx => fx.Params.GrantKycEndorsement = null);

        await using var fxToken2 = await TestToken.CreateAsync(_network, fx => fx.Params.GrantKycEndorsement = null);

        await AssertHg.TokenNotAssociatedAsync(fxToken1, fxAccount);

        await AssertHg.TokenNotAssociatedAsync(fxToken2, fxAccount);

        var xferAmount1 = fxToken1.Params.Circulation / 2;
        var receipt     = await fxToken1.Client.TransferTokensAsync(fxToken1, fxToken1.TreasuryAccount, fxAccount, (long)xferAmount1, fxToken1.TreasuryAccount);

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

        await fxAccount.Client.UpdateAccountAsync(new UpdateAccountParams
        {
            Address = fxAccount,
            AutoAssociationLimit = 2,
            Signatory            = fxAccount
        });

        var xferAmount2 = fxToken2.Params.Circulation / 2;
        var receipt2    = await fxToken2.Client.TransferTokensAsync(fxToken2, fxToken2.TreasuryAccount, fxAccount, (long)xferAmount2, fxToken2.TreasuryAccount);

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

        await AssertHg.TokenIsAssociatedAsync(fxToken1, fxAccount);

        await AssertHg.TokenIsAssociatedAsync(fxToken2, fxAccount);

        await AssertHg.TokenBalanceAsync(fxToken1, fxAccount, xferAmount1);

        await AssertHg.TokenBalanceAsync(fxToken2, fxAccount, xferAmount2);
    }
Example #14
0
    public async Task CanAutoAssociateTokenWithAccount()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network);

        await using var fxToken = await TestToken.CreateAsync(_network, fx => fx.Params.GrantKycEndorsement = null);

        await AssertHg.TokenNotAssociatedAsync(fxToken, fxAccount);

        var xferAmount = fxToken.Params.Circulation / 2;
        var receipt    = await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount);

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

        var association = await AssertHg.TokenIsAssociatedAsync(fxToken, fxAccount);

        Assert.Equal(fxToken.Record.Token, association.Token);
        Assert.Equal(fxToken.Params.Symbol, association.Symbol);
        Assert.Equal(xferAmount, association.Balance);
        Assert.Equal(fxToken.Params.Decimals, association.Decimals);
        Assert.Equal(TokenKycStatus.NotApplicable, association.KycStatus);
        Assert.Equal(TokenTradableStatus.Tradable, association.TradableStatus);
        Assert.True(association.AutoAssociated);

        var info = await fxAccount.Client.GetAccountInfoAsync(fxAccount);

        Assert.Equal(fxAccount.CreateParams.AutoAssociationLimit, info.AutoAssociationLimit);
        Assert.Single(info.Tokens);

        var balance = info.Tokens[0];

        Assert.Equal(fxToken.Record.Token, balance.Token);
        Assert.Equal(fxToken.Params.Symbol, balance.Symbol);
        Assert.Equal(TokenKycStatus.NotApplicable, balance.KycStatus);
        Assert.Equal(TokenTradableStatus.Tradable, balance.TradableStatus);
        Assert.True(balance.AutoAssociated);
    }