balances.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * This file is part of the storage node for the Joystream project.
  3. * Copyright (C) 2019 Joystream Contributors
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. 'use strict';
  19. const mocha = require('mocha');
  20. const expect = require('chai').expect;
  21. const sinon = require('sinon');
  22. const { RuntimeApi } = require('@joystream/storage-runtime-api');
  23. describe('Balances', () => {
  24. var api;
  25. var key;
  26. before(async () => {
  27. api = await RuntimeApi.create();
  28. key = await api.identities.loadUnlock('test/data/edwards_unlocked.json');
  29. });
  30. it('returns free balance for an account', async () => {
  31. const balance = await api.balances.freeBalance(key.address);
  32. // Should be exactly zero
  33. expect(balance.cmpn(0)).to.equal(0);
  34. });
  35. it('checks whether a minimum balance exists', async () => {
  36. // A minimum of 0 should exist, but no more.
  37. expect(await api.balances.hasMinimumBalanceOf(key.address, 0)).to.be.true;
  38. expect(await api.balances.hasMinimumBalanceOf(key.address, 1)).to.be.false;
  39. });
  40. it('returns the base transaction fee of the chain', async () => {
  41. const fee = await api.balances.baseTransactionFee();
  42. // >= 0 comparison works
  43. expect(fee.cmpn(0)).to.be.at.least(0);
  44. });
  45. });