roles.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/runtime-api');
  23. describe('Roles', () => {
  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 the required balance for role staking', async () => {
  31. const amount = await api.roles.requiredBalanceForRoleStaking(api.roles.ROLE_STORAGE);
  32. // Effectively checks that the role is at least defined.
  33. expect(amount.cmpn(0)).to.be.above(0);
  34. });
  35. it('returns whether an account has funds for role staking', async () => {
  36. expect(await api.roles.hasBalanceForRoleStaking(key.address, api.roles.ROLE_STORAGE)).to.be.false;
  37. });
  38. it('returns accounts for a role', async () => {
  39. const accounts = await api.roles.accountIdsByRole(api.roles.ROLE_STORAGE);
  40. // The chain may have accounts configured, so go for the bare minimum in
  41. // expectations.
  42. expect(accounts).to.have.lengthOf.above(-1);
  43. });
  44. it('can check whether an account fulfils requirements for role staking', async () => {
  45. expect(async _ => {
  46. await api.roles.checkAccountForRoleStaking(key.address, api.roles.ROLE_STORAGE);
  47. }).to.throw;
  48. });
  49. it('can check for an account to have a role', async () => {
  50. expect(await api.roles.checkForRole(key.address, api.roles.ROLE_STORAGE)).to.be.false;
  51. });
  52. // TODO requires complex setup, and may change in the near future.
  53. it('transfers funds for staking');
  54. it('can apply for a role');
  55. it('can wait for an account to have a role');
  56. });