UNPKG

@yoroi/portfolio

Version:

The Portfolio package of Yoroi SDK

37 lines 1.65 kB
import { tokenBalanceMocks } from '../adapters/token-balance.mocks'; import { AmountsCalcultor } from './amounts-calculator'; describe('AmountsCalculator', () => { const records = Object.fromEntries(tokenBalanceMocks.storage.entries1); it('should negate the amounts', () => { const amounts = AmountsCalcultor(records).negate().build(); Object.entries(amounts).forEach(_ref => { let [_, amount] = _ref; expect(amount.quantity).toBeLessThanOrEqual(0n); }); }); it('should drop specified tokens', () => { const amounts = AmountsCalcultor().plus(records).build(); expect(Object.keys(amounts)).toHaveLength(4); const newAmounts = AmountsCalcultor(amounts).drop([ // primary does not exist in the storage tokenBalanceMocks.primaryETH.info.id, tokenBalanceMocks.nftCryptoKitty.info.id]).build(); expect(Object.keys(newAmounts)).toHaveLength(3); }); it('should add new amounts', () => { const amounts = AmountsCalcultor(records).plus(records).build(); expect(Object.keys(amounts)).toHaveLength(4); Object.entries(amounts).forEach(_ref2 => { let [_, amount] = _ref2; expect(amount.quantity).toBe((records[amount.info.id]?.quantity ?? 0n) * 2n); }); }); it('should calculate the difference between two amounts', () => { const amounts = AmountsCalcultor(records).minus(records).build(); expect(Object.keys(amounts)).toHaveLength(4); Object.entries(amounts).forEach(_ref3 => { let [_, amount] = _ref3; expect(amount.quantity).toBe((records[amount.info.id]?.quantity ?? 0n) * 0n); }); }); }); //# sourceMappingURL=amounts-calculator.test.js.map