public void FromDivisible_WithValidValue_ShouldSuccess(string s) { var value = decimal.Parse(s); var amount = TokenAmount.FromDivisible(value); Assert.Equal((long)(value * 100000000), amount.Value); }
public void GreaterThanOrEqual_WithGreater_ShouldReturnTrue(long left, long right) { var first = new TokenAmount(left); var second = new TokenAmount(right); Assert.True(first >= second); }
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); }
public void GreaterThan_WithLess_ShouldReturnFalse(long left, long right) { var first = new TokenAmount(left); var second = new TokenAmount(right); Assert.False(first > second); }
public void Inequality_WithGreater_ShouldReturnTrue(long left, long right) { var first = new TokenAmount(left); var second = new TokenAmount(right); Assert.True(first != second); }
public void Addition_SumIsOverflow_ShouldThrow(long left, long right) { var first = new TokenAmount(left); var second = new TokenAmount(right); Assert.Throws <OverflowException>(() => first + second); }
public void LessThanOrEqual_WithSame_ShouldReturnTrue(long value) { var first = new TokenAmount(value); var second = new TokenAmount(value); Assert.True(first <= second); }
public void LessThan_WithSame_ShouldReturnFalse(long value) { var first = new TokenAmount(value); var second = new TokenAmount(value); Assert.False(first < second); }
public void LessThanOrEqual_WithGreater_ShouldReturnFalse(long left, long right) { var first = new TokenAmount(left); var second = new TokenAmount(right); Assert.False(first <= second); }
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>()); }
public void ConvertTo_WithTargetIsLong_ShouldSuccess() { var amount = new TokenAmount(1); var converted = this.subject.ConvertTo(amount, typeof(long)); Assert.Equal(amount.Value, converted); }
public void Inequality_WithSame_ShouldReturnFalse(long value) { var first = new TokenAmount(value); var second = new TokenAmount(value); Assert.False(first != second); }
public void LessThan_WithLess_ShouldReturnTrue(long left, long right) { var first = new TokenAmount(left); var second = new TokenAmount(right); Assert.True(first < second); }
public void Constructor_WithInvalidAmount_ShouldThrow(long value) { var amount = new TokenAmount(value); Assert.Throws <ArgumentOutOfRangeException>( "amount", () => new SimpleSendV0(TestAddress.Regtest1, null, this.property, amount)); }
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); }
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); }
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); }
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; }
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)); } }
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); }
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))); }
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; }
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; }
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>()); }
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)); }
/// <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; }
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() } }); } }
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; }
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; }
public void Parse_WithValidDivisible_ShouldSuccess(string divisible, long expected) { var amount = TokenAmount.Parse(divisible); Assert.Equal(expected, amount.Value); }