Exemplo n.º 1
0
    public async Task CanReumeTokenCoinTradingAndGetRecordNoExtraSignatory()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network);

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

        await fxToken.Client.PauseTokenAsync(fxToken.Record.Token, fxToken.PausePrivateKey);

        var circulation = fxToken.Params.Circulation;
        var xferAmount  = circulation / 3;

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Suspended);

        var record = await fxToken.Client.ContinueTokenWithRecordAsync(fxToken.Record.Token, fxAccount, ctx => ctx.Signatory = new Signatory(_network.Signatory, fxToken.PausePrivateKey));

        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.TokenPausedAsync(fxToken, TokenTradableStatus.Tradable);

        await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount);

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Tradable);
    }
Exemplo n.º 2
0
    public async Task CanNotContinueTokenWhenPauseNotEnabled()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network);

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

        var circulation = fxToken.Params.Circulation;
        var xferAmount  = circulation / 3;

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.NotApplicable);

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

        Assert.Equal(ResponseCode.TokenHasNoPauseKey, tex.Status);
        Assert.StartsWith("Unable to Continue Token, status: TokenHasNoPauseKey", tex.Message);

        await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount);

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.NotApplicable);
    }
Exemplo n.º 3
0
    public async Task CanNotScheduleReumeTokenCoinTrading()
    {
        await using var fxPayer = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 20_00_000_000);

        await using var fxAccount = await TestAccount.CreateAsync(_network);

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

        await fxToken.Client.PauseTokenAsync(fxToken.Record.Token, fxToken.PausePrivateKey);

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Suspended);

        var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
        {
            await fxToken.Client.ContinueTokenAsync(
                fxToken.Record.Token,
                new Signatory(
                    fxToken.PausePrivateKey,
                    new PendingParams
            {
                PendingPayer = fxPayer
            }));
        });

        Assert.Equal(ResponseCode.ScheduledTransactionNotInWhitelist, tex.Status);
        Assert.StartsWith("Unable to schedule transaction, status: ScheduledTransactionNotInWhitelist", tex.Message);
    }
Exemplo n.º 4
0
    public async Task CanContinueAPausedAccount()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network);

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

        var circulation = fxToken.Params.Circulation;
        var xferAmount  = circulation / 3;

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Tradable);

        await fxToken.Client.PauseTokenAsync(fxToken.Record.Token, fxToken.PausePrivateKey);

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Suspended);

        await fxToken.Client.ContinueTokenAsync(fxToken.Record.Token, fxToken.PausePrivateKey);

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Tradable);

        await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount);

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Tradable);
    }
Exemplo n.º 5
0
    public async Task ContinueTokenRequiresSuspendKeyToSignTransaction()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network);

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

        await fxToken.Client.PauseTokenAsync(fxToken.Record.Token, fxToken.PausePrivateKey);

        var circulation = fxToken.Params.Circulation;
        var xferAmount  = circulation / 3;

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Suspended);

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

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

        tex = await Assert.ThrowsAsync <TransactionException>(async() =>
        {
            await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount);
        });

        Assert.Equal(ResponseCode.TokenIsPaused, tex.Status);
        Assert.StartsWith("Unable to execute transfers, status: TokenIsPaused", tex.Message);
    }
Exemplo n.º 6
0
    public async Task ResumingAnUnfrozenAccountIsNoop()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network);

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

        var circulation = fxToken.Params.Circulation;
        var xferAmount  = circulation / 3;

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Tradable);

        await fxToken.Client.ContinueTokenAsync(fxToken.Record.Token, fxToken.PausePrivateKey);

        var info = (await fxAccount.Client.GetAccountInfoAsync(fxAccount)).Tokens.FirstOrDefault(t => t.Token == fxToken.Record.Token);

        Assert.Equal(0Ul, info.Balance);
        Assert.Equal(fxToken.Params.Decimals, info.Decimals);
        Assert.Equal(TokenTradableStatus.Tradable, info.TradableStatus);
        Assert.False(info.AutoAssociated);

        await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount);

        info = (await fxAccount.Client.GetAccountInfoAsync(fxAccount)).Tokens.FirstOrDefault(t => t.Token == fxToken.Record.Token);
        Assert.Equal(xferAmount, info.Balance);
        Assert.Equal(fxToken.Params.Decimals, info.Decimals);
        Assert.Equal(TokenTradableStatus.Tradable, info.TradableStatus);
        Assert.False(info.AutoAssociated);
    }
Exemplo n.º 7
0
    public async Task CanReumeTokenCoinTradingFromAnyAccountWithSuspendKey()
    {
        await using var fxOther = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 100_00_000_000);

        await using var fxAccount = await TestAccount.CreateAsync(_network);

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

        await fxToken.Client.PauseTokenAsync(fxToken.Record.Token, fxToken.PausePrivateKey);

        var circulation = fxToken.Params.Circulation;
        var xferAmount  = circulation / 3;

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Suspended);

        await fxToken.Client.ContinueTokenAsync(fxToken.Record.Token, fxToken.PausePrivateKey, ctx =>
        {
            ctx.Payer     = fxOther.Record.Address;
            ctx.Signatory = fxOther.PrivateKey;
        });

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Tradable);

        await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount);

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Tradable);
    }
Exemplo n.º 8
0
    public async Task CanPauseTokenCoinTradingFromAnyAccountWithPauseKey()
    {
        await using var fxOther = await TestAccount.CreateAsync(_network, fx => fx.CreateParams.InitialBalance = 120_00_000_000);

        await using var fxAccount = await TestAccount.CreateAsync(_network);

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

        var circulation = fxToken.Params.Circulation;
        var xferAmount  = circulation / 3;

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Tradable);

        await fxToken.Client.PauseTokenAsync(fxToken.Record.Token, fxToken.PausePrivateKey, ctx =>
        {
            ctx.Payer     = fxOther.Record.Address;
            ctx.Signatory = fxOther.PrivateKey;
        });

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Suspended);

        var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
        {
            await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount);
        });

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

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Suspended);
    }
Exemplo n.º 9
0
    public async Task CanPauseTokenCoinTradingAndGetRecord()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network);

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

        var circulation = fxToken.Params.Circulation;
        var xferAmount  = circulation / 3;

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Tradable);

        var record = await fxToken.Client.PauseTokenWithRecordAsync(fxToken.Record.Token, fxToken.PausePrivateKey);

        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.TokenPausedAsync(fxToken, TokenTradableStatus.Suspended);

        var tex = await Assert.ThrowsAsync <TransactionException>(async() =>
        {
            await fxToken.Client.TransferTokensAsync(fxToken, fxToken.TreasuryAccount, fxAccount, (long)xferAmount, fxToken.TreasuryAccount);
        });

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

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Suspended);
    }
Exemplo n.º 10
0
    public async Task PauseTokenRequiresPauseKeyToSignTransaciton()
    {
        await using var fxAccount = await TestAccount.CreateAsync(_network);

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

        var circulation = fxToken.Params.Circulation;
        var xferAmount  = circulation / 3;

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Tradable);

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

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

        await AssertHg.TokenPausedAsync(fxToken, TokenTradableStatus.Tradable);
    }