Ejemplo n.º 1
0
        public void FromDivisible_WithValidValue_ShouldSuccess(string s)
        {
            var value  = decimal.Parse(s);
            var amount = TokenAmount.FromDivisible(value);

            Assert.Equal((long)(value * 100000000), amount.Value);
        }
Ejemplo n.º 2
0
        public void GreaterThanOrEqual_WithGreater_ShouldReturnTrue(long left, long right)
        {
            var first  = new TokenAmount(left);
            var second = new TokenAmount(right);

            Assert.True(first >= second);
        }
Ejemplo n.º 3
0
        public void Division_WithValidDivisor_ResultShouldBeDividedByThatAmount(long value, int divisor, long expect)
        {
            var amount = new TokenAmount(value);
            var result = amount / divisor;

            Assert.Equal(expect, result.Value);
        }
Ejemplo n.º 4
0
        public void GreaterThan_WithLess_ShouldReturnFalse(long left, long right)
        {
            var first  = new TokenAmount(left);
            var second = new TokenAmount(right);

            Assert.False(first > second);
        }
Ejemplo n.º 5
0
        public void Inequality_WithGreater_ShouldReturnTrue(long left, long right)
        {
            var first  = new TokenAmount(left);
            var second = new TokenAmount(right);

            Assert.True(first != second);
        }
Ejemplo n.º 6
0
        public void Addition_SumIsOverflow_ShouldThrow(long left, long right)
        {
            var first  = new TokenAmount(left);
            var second = new TokenAmount(right);

            Assert.Throws <OverflowException>(() => first + second);
        }
Ejemplo n.º 7
0
        public void LessThanOrEqual_WithSame_ShouldReturnTrue(long value)
        {
            var first  = new TokenAmount(value);
            var second = new TokenAmount(value);

            Assert.True(first <= second);
        }
Ejemplo n.º 8
0
        public void LessThan_WithSame_ShouldReturnFalse(long value)
        {
            var first  = new TokenAmount(value);
            var second = new TokenAmount(value);

            Assert.False(first < second);
        }
Ejemplo n.º 9
0
        public void LessThanOrEqual_WithGreater_ShouldReturnFalse(long left, long right)
        {
            var first  = new TokenAmount(left);
            var second = new TokenAmount(right);

            Assert.False(first <= second);
        }
Ejemplo n.º 10
0
        public async Task <string> GrantTokensAsync(
            Property property,
            BitcoinAddress from,
            BitcoinAddress?to,
            TokenAmount amount,
            string?note,
            CancellationToken cancellationToken = default)
        {
            if (amount <= TokenAmount.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(amount), amount, "The value is not valid.");
            }

            // Setup arguments.
            var args = new Collection <object>()
            {
                from.ToString(),
                ReferenceEquals(to, null) ? string.Empty : to.ToString(),
                property.Id.Value,
                amount.ToString(property.TokenType),
            };

            if (note != null)
            {
                args.Add(note);
            }

            // Invoke RPC.
            var resp = await this.Client.SendCommandAsync("elysium_sendgrant", args.ToArray());

            return(resp.Result.Value <string>());
        }
Ejemplo n.º 11
0
        public void ConvertTo_WithTargetIsLong_ShouldSuccess()
        {
            var amount    = new TokenAmount(1);
            var converted = this.subject.ConvertTo(amount, typeof(long));

            Assert.Equal(amount.Value, converted);
        }
Ejemplo n.º 12
0
        public void Inequality_WithSame_ShouldReturnFalse(long value)
        {
            var first  = new TokenAmount(value);
            var second = new TokenAmount(value);

            Assert.False(first != second);
        }
Ejemplo n.º 13
0
        public void LessThan_WithLess_ShouldReturnTrue(long left, long right)
        {
            var first  = new TokenAmount(left);
            var second = new TokenAmount(right);

            Assert.True(first < second);
        }
Ejemplo n.º 14
0
        public void Constructor_WithInvalidAmount_ShouldThrow(long value)
        {
            var amount = new TokenAmount(value);

            Assert.Throws <ArgumentOutOfRangeException>(
                "amount",
                () => new SimpleSendV0(TestAddress.Regtest1, null, this.property, amount));
        }
Ejemplo n.º 15
0
        public void Equals_WithSameValue_ShouldReturnTrue(long value)
        {
            var first  = new TokenAmount(value);
            var second = new TokenAmount(value);

            Assert.True(first.Equals(second));
            Assert.True(first.Equals((object)second));
            Assert.True(first == second);
        }
Ejemplo n.º 16
0
        public void Equals_WithValueGreaterThan_ShouldReturnFalse(long left, long right)
        {
            var first  = new TokenAmount(left);
            var second = new TokenAmount(right);

            Assert.False(first.Equals(second));
            Assert.False(first.Equals((object)second));
            Assert.False(first == second);
        }
Ejemplo n.º 17
0
        public void Addition_SumIsNotOverflow_ShouldReturnThatValue(long left, long right, long expect)
        {
            var first  = new TokenAmount(left);
            var second = new TokenAmount(right);

            var result = first + second;

            Assert.Equal(new TokenAmount(expect), result);
        }
Ejemplo n.º 18
0
        public TokenGrantHistory(TokenGrantType type, uint256 transaction, TokenAmount amount)
        {
            if (amount <= TokenAmount.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(amount));
            }

            this.Type        = type;
            this.Transaction = transaction;
            this.Amount      = amount;
        }
Ejemplo n.º 19
0
 protected async Task <string> SendTokensAsync(
     Property property,
     BitcoinAddress from,
     BitcoinAddress to,
     TokenAmount amount)
 {
     await using (var client = await this.Factory.CreatePropertyManagementClientAsync())
     {
         return(await client.SendTokensAsync(property, from, to, amount, null));
     }
 }
Ejemplo n.º 20
0
        public void Negate_WithNagatableAmount_ShouldReturnNagatedValue(long value, long expected)
        {
            // Arrange.
            var amount = new TokenAmount(value);

            // Act.
            var negated = TokenAmount.Negate(amount);

            // Assert.
            Assert.Equal(new TokenAmount(expected), negated);
        }
Ejemplo n.º 21
0
        public async Task <ElysiumBalance> GetBalanceAsync(
            BitcoinAddress address,
            Property property,
            CancellationToken cancellationToken = default)
        {
            var resp = await this.Client.SendCommandAsync("elysium_getbalance", address.ToString(), property.Id.Value);

            var balance  = resp.Result.Value <string>("balance");
            var reserved = resp.Result.Value <string>("reserved");

            return(new ElysiumBalance(TokenAmount.Parse(balance), TokenAmount.Parse(reserved)));
        }
Ejemplo n.º 22
0
        public ElysiumBalance(TokenAmount balance, TokenAmount reserved)
        {
            if (balance < TokenAmount.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(balance));
            }

            if (reserved < TokenAmount.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(reserved));
            }

            this.Balance  = balance;
            this.Reserved = reserved;
        }
Ejemplo n.º 23
0
        public TokenGrants(
            PropertyId propertyId,
            string propertyName,
            BitcoinAddress propertyIssuer,
            uint256 propertyCreationTransaction,
            TokenAmount totalTokens,
            IEnumerable <TokenGrantHistory> grantHistories)
        {
            if (totalTokens < TokenAmount.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(totalTokens));
            }

            this.PropertyId     = propertyId;
            this.PropertyName   = propertyName;
            this.PropertyIssuer = propertyIssuer;
            this.PropertyCreationTransaction = propertyCreationTransaction;
            this.TotalTokens    = totalTokens;
            this.GrantHistories = grantHistories;
        }
Ejemplo n.º 24
0
        public async Task <string> SendTokensAsync(
            Property property,
            BitcoinAddress from,
            BitcoinAddress to,
            TokenAmount amount,
            Money?referenceAmount,
            CancellationToken cancellationToken = default)
        {
            if (amount <= TokenAmount.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(amount), amount, "The value is not valid.");
            }

            // Setup arguments.
            var args = new Collection <object>()
            {
                from.ToString(),
                to.ToString(),
                property.Id.Value,
                amount.ToString(property.TokenType),
            };

            if (referenceAmount != null)
            {
                if (referenceAmount <= Money.Zero)
                {
                    throw new ArgumentOutOfRangeException(
                              nameof(referenceAmount),
                              referenceAmount,
                              "The value is not valid.");
                }

                args.Add(string.Empty); // redeemaddress, which Zcoin did not use.
                args.Add(referenceAmount.ToDecimal(MoneyUnit.BTC).ToString());
            }

            // Invoke RPC.
            var resp = await this.Client.SendCommandAsync("elysium_send", args.ToArray());

            return(resp.Result.Value <string>());
        }
Ejemplo n.º 25
0
        public async Task <TokenGrants> GetGrantsAsync(Property property, CancellationToken cancellationToken = default)
        {
            var resp = await this.Client.SendCommandAsync("elysium_getgrants", property.Id.Value);

            var histories = ((JArray)resp.Result["issuances"]).Select(i =>
            {
                var grant  = i.Value <string?>("grant");
                var revoke = i.Value <string>("revoke");
                var type   = (grant != null) ? TokenGrantType.Grant : TokenGrantType.Revoke;
                var tx     = uint256.Parse(i.Value <string>("txid"));
                var amount = TokenAmount.Parse(grant ?? revoke);

                return(new TokenGrantHistory(type, tx, amount));
            }).ToList();

            return(new TokenGrants(
                       new PropertyId(resp.Result.Value <long>("propertyid")),
                       resp.Result.Value <string>("name"),
                       BitcoinAddress.Create(resp.Result.Value <string>("issuer"), this.Client.Network),
                       uint256.Parse(resp.Result.Value <string>("creationtxid")),
                       TokenAmount.Parse(resp.Result.Value <string>("totaltokens")),
                       histories));
        }
Ejemplo n.º 26
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="minimumAllowedXdaiBalance">Minimum XDAI balance.</param>
 /// <param name="minimumAllowedTokenBalance">Minimum TOKEN balance.</param>
 public FaucetBalanceConfiguration(EthereumAmount minimumAllowedXdaiBalance, TokenAmount minimumAllowedTokenBalance)
 {
     this.MinimumAllowedXdaiBalance  = minimumAllowedXdaiBalance;
     this.MinimumAllowedTokenBalance = minimumAllowedTokenBalance;
 }
Ejemplo n.º 27
0
 private async Task NotifyForAllTokenBalanceChangesAsync(INetworkAccount contractAccount, TokenAmount minimumTokenAmount, TokenBalanceChangeEventArgs args)
 {
     if (args.NewBalance.TokenAmount < minimumTokenAmount)
     {
         string message = $"{contractAccount.Network.Name}: Faucet contract at address {contractAccount.Address} is low on {args.Token.Symbol}";
         this._logger.LogCritical(message);
         await this._alertDispatcher.TriggerAsync(GetContractTokenBalanceAlertKey(args.Account),
                                                  summary : message,
                                                  severity : EventSeverity.CRITICAL,
                                                  new Dictionary <string, string> {
             { "Current balance", args.NewBalance.ToFormattedUnit() }
         });
     }
 }
Ejemplo n.º 28
0
        public SimpleSendV0(BitcoinAddress sender, BitcoinAddress?receiver, PropertyId property, TokenAmount amount)
            : base(sender, receiver)
        {
            if (amount <= TokenAmount.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(amount), amount, "The value is less than one.");
            }

            this.Property = property;
            this.Amount   = amount;
        }
Ejemplo n.º 29
0
        public GrantTokensV0(BitcoinAddress sender, BitcoinAddress?receiver, PropertyId property, TokenAmount amount)
            : base(sender, receiver)
        {
            if (amount <= TokenAmount.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(amount));
            }

            this.Property = property;
            this.Amount   = amount;
        }
Ejemplo n.º 30
0
        public void Parse_WithValidDivisible_ShouldSuccess(string divisible, long expected)
        {
            var amount = TokenAmount.Parse(divisible);

            Assert.Equal(expected, amount.Value);
        }