it('should clone for parse_json on itself', function() {
      var cur = currency.from_json('USD');
      var cur2 = currency.from_json(cur);
      assert.strictEqual(cur.to_json(), cur2.to_json());

      cur = currency.from_hex('015841551A748AD2C1F76FF6ECB0CCCD00000000');
      cur2 = currency.from_json(cur);
      assert.strictEqual(cur.to_json(), cur2.to_json());
    });
Example #2
0
    it('should return demurred value for demurrage currency', function() {
      var cur = currency.from_json('015841551A748AD2C1F76FF6ECB0CCCD00000000');

      // At start, no demurrage should occur
      assert.equal(1, cur.get_interest_at(443845330));
      assert.equal(1, precision(cur.get_interest_at(new Date(timeUtil.fromRipple(443845330))), 14));

      // After one year, 0.5% should have occurred
      assert.equal(0.995, precision(cur.get_interest_at(443845330 + 31536000), 14));
      assert.equal(0.995, precision(cur.get_interest_at(new Date(timeUtil.fromRipple(443845330 + 31536000))), 14));

      // After one demurrage period, 1/e should have occurred
      assert.equal(1/Math.E, cur.get_interest_at(443845330 + 6291418827.05));

      // One year before start, it should be (roughly) 0.5% higher.
      assert.equal(1.005, precision(cur.get_interest_at(443845330 - 31536000), 4));

      // One demurrage period before start, rate should be e
      assert.equal(Math.E, cur.get_interest_at(443845330 - 6291418827.05));
    });
 it('should clone currency object', function() {
   var c = currency.from_json('XRP');
   assert.strictEqual('XRP', c.clone().to_json());
 });
 it('should generate human string', function() {
   assert.strictEqual('XRP', currency.from_json('XRP').to_human());
 });
 it('from_json("XAU (0.5%pa").to_json() hex', function() {
   var r = currency.from_json("XAU (0.5%pa)");
   assert.strictEqual('015841550000000041F78E0A28CBF19200000000', r.to_json({force_hex: true}));
 });
 it('"USD".to_human() == "USD"', function() {
   assert.strictEqual('USD', currency.from_json('USD').to_human());
 });
 it('should get "XRP" iso_code', function() {
   assert.strictEqual('XRP', currency.from_json('XRP').get_iso());
 });
 it('"015841551A748AD2C1F76FF6ECB0CCCD00000000") == "015841551A748AD2C1F76FF6ECB0CCCD00000000"', function() {
   assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({full_name:'Gold'}), 'XAU - Gold (-0.5%pa)');
 });
 it('to_human "TIM" with null full_name', function() {
   var cur = currency.from_json("TIM");
   assert.strictEqual(cur.to_human({full_name: null}), "TIM");
 });
Example #10
0
 it('should be false for type 0 currency codes', function() {
   assert(!currency.from_hex('0000000000000000000000005553440000000000').has_interest());
   assert(!currency.from_json('USD').has_interest());
 });
Example #11
0
 it('to_human with full_name "USD - US Dollar"', function() {
   assert.strictEqual('USD - US Dollar', currency.from_json('USD').to_human({full_name:'US Dollar'}));
 });
Example #12
0
 it('to_human with full_name "XRP - Ripples"', function() {
   assert.strictEqual('XRP - Ripples', currency.from_json('XRP').to_human({full_name:'Ripples'}));
 });
Example #13
0
 it('to_human with full_name "USD - US Dollar do not show interest"', function() {
   assert.strictEqual(currency.from_json('USD').to_human({full_name:'US Dollar', show_interest:false}), 'USD - US Dollar');
 });
Example #14
0
 it('to_human interest XAU, do not show interest', function() {
   assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({show_interest:false}), 'XAU');
 });
Example #15
0
 it('to_human interest XAU with full name, show interest', function() {
   assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({full_name:'Gold', show_interest:true}), 'XAU - Gold (-0.5%pa)');
 });
Example #16
0
 it('should be true for type 1 currency codes', function() {
   assert(currency.from_hex('015841551A748AD2C1F76FF6ECB0CCCD00000000').has_interest());
   assert(currency.from_json('015841551A748AD2C1F76FF6ECB0CCCD00000000').has_interest());
 });
Example #17
0
 it('should parse a currency object', function() {
   assert.strictEqual('USD', new currency().parse_json(currency.from_json('USD')).to_json());
   assert.strictEqual('USD (0.5%pa)', new currency().parse_json(currency.from_json('USD (0.5%pa)')).to_json());
 });
Example #18
0
 it('from_json(NaN).to_json() == "XRP"', function() {
   var r = currency.from_json(NaN);
   assert(!r.is_valid());
   assert.strictEqual('XRP', r.to_json());
 });
Example #19
0
 it('from_json("0000000000000000000000000000000000000000").to_json() == "XRP"', function() {
   var r = currency.from_json('0000000000000000000000000000000000000000');
   assert(r.is_valid());
   assert(r.is_native());
   assert.strictEqual('XRP', r.to_json());
 });
Example #20
0
 it('should return 0 for currency without interest', function() {
   var cur = currency.from_json('USD - US Dollar');
   assert.equal(0, cur.get_interest_at(443845330));
   assert.equal(0, cur.get_interest_at(443845330  + 31536000));
 });
Example #21
0
 it('from_json("#$%").to_human()', function() {
   var r = currency.from_json('#$%');
   assert(r.is_valid());
   assert.strictEqual('0000000000000000000000002324250000000000', r.to_json());
 });
Example #22
0
 it('should get iso_code', function() {
   assert.strictEqual('USD', currency.from_json('USD (0.5%pa)').get_iso());
 });
Example #23
0
 it('"NaN".to_human() == "XRP"', function() {
   assert.strictEqual('XRP', currency.from_json(NaN).to_human());
 });
Example #24
0
 it('from_json("1").to_human()', function() {
   var r = currency.from_json('1');
   assert(r.is_valid());
   assert.strictEqual(1, r.to_json());
 });
Example #25
0
 it('should parse json 0', function() {
   var cur = currency.from_json('0');
   assert.strictEqual(cur.to_json(), 'XRP');
   assert.strictEqual(cur.get_iso(), 'XRP');
 });
Example #26
0
 it('from_json("XAU").to_json() hex', function() {
   var r = currency.from_json("XAU");
   assert.strictEqual('0000000000000000000000005841550000000000', r.to_json({force_hex: true}));
 });
Example #27
0
 it('from_json("XRP").is_valid()', function() {
   assert(currency.from_json('XRP').is_valid());
 });
 /**
  * apply interest to interest/demmurage currencies
  * @param {Object} rows
  */
 function handleInterest (rows) {
   var base    = ripple.Currency.from_json(params.base.currency);
   var counter = ripple.Currency.from_json(params.counter.currency);
   
   
   if (base.has_interest()) {
     if (options.view.reduce === false) {
       rows.forEach(function(row, i){
         if (!i) return;
       
         //apply interest to the base amount
         amount = ripple.Amount.from_human(row[2] + " " + params.base.currency).applyInterest(new Date(row[0])).to_human(); 
         pct   = row[2]/amount; 
         
         rows[i][2]  = amount;
         rows[i][1] *= pct;         
       });
       
     } else {
       rows.forEach(function(row, i){
         if (!i) return;
         
         //apply interest to the base volume
         value = ripple.Amount.from_human(row[1] + " " + params.base.currency).applyInterest(new Date(row[0])).to_human(); 
         pct   = row[1]/value;
         
         //adjust the prices
         rows[i][1] = value;
         rows[i][4] *= pct;
         rows[i][5] *= pct;
         rows[i][6] *= pct;
         rows[i][7] *= pct;
         rows[i][8] *= pct;
       });
     }
   } else if (counter.has_interest()) {
     if (options.view.reduce === false) {
       rows.forEach(function(row, i){
         if (!i) return;
         
         //apply interest to the counter amount
         amount = ripple.Amount.from_human(row[3] + " " + params.counter.currency).applyInterest(new Date(row[0])).to_human(); 
         pct   = amount/row[3]; 
         
         rows[i][3]  = amount;
         rows[i][1] *= pct;         
       });
       
     } else {         
       rows.forEach(function(row, i){
         if (!i) return;
         
         //apply interest to the counter volume
         value = ripple.Amount.from_human(row[2] + " " + params.counter.currency).applyInterest(new Date(row[0])).to_human(); 
         pct   = value/row[2];
         
         //adjust the prices
         rows[i][2] = value;
         rows[i][4] *= pct;
         rows[i][5] *= pct;
         rows[i][6] *= pct;
         rows[i][7] *= pct;
         rows[i][8] *= pct;
       });
     }      
   }
   
   return rows;
 }
Example #29
0
 it('!from_json(NaN).is_valid()', function() {
   assert(!currency.from_json(NaN).is_valid());
 });