AccessControlCrossChain.test.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const { expectRevert } = require('@openzeppelin/test-helpers');
  2. const { BridgeHelper } = require('../helpers/crosschain');
  3. const {
  4. DEFAULT_ADMIN_ROLE,
  5. shouldBehaveLikeAccessControl,
  6. } = require('./AccessControl.behavior.js');
  7. const crossChainRoleAlias = (role) => web3.utils.leftPad(
  8. web3.utils.toHex(web3.utils.toBN(role).xor(web3.utils.toBN(web3.utils.soliditySha3('CROSSCHAIN_ALIAS')))),
  9. 64,
  10. );
  11. const AccessControlCrossChainMock = artifacts.require('$AccessControlCrossChainMock');
  12. const ROLE = web3.utils.soliditySha3('ROLE');
  13. contract('AccessControl', function (accounts) {
  14. before(async function () {
  15. this.bridge = await BridgeHelper.deploy();
  16. });
  17. beforeEach(async function () {
  18. this.accessControl = await AccessControlCrossChainMock.new({ from: accounts[0] });
  19. await this.accessControl.$_grantRole(DEFAULT_ADMIN_ROLE, accounts[0]);
  20. });
  21. shouldBehaveLikeAccessControl('AccessControl', ...accounts);
  22. describe('CrossChain enabled', function () {
  23. beforeEach(async function () {
  24. await this.accessControl.grantRole(ROLE, accounts[0], { from: accounts[0] });
  25. await this.accessControl.grantRole(crossChainRoleAlias(ROLE), accounts[1], { from: accounts[0] });
  26. });
  27. it('check alliassing', async function () {
  28. expect(await this.accessControl.$_crossChainRoleAlias(ROLE)).to.be.bignumber.equal(crossChainRoleAlias(ROLE));
  29. });
  30. it('Crosschain calls not authorized to non-aliased addresses', async function () {
  31. await expectRevert(
  32. this.bridge.call(
  33. accounts[0],
  34. this.accessControl,
  35. '$_checkRole(bytes32)',
  36. [ ROLE ],
  37. ),
  38. `AccessControl: account ${accounts[0].toLowerCase()} is missing role ${crossChainRoleAlias(ROLE)}`,
  39. );
  40. });
  41. it('Crosschain calls not authorized to non-aliased addresses', async function () {
  42. await this.bridge.call(
  43. accounts[1],
  44. this.accessControl,
  45. '$_checkRole(bytes32)',
  46. [ ROLE ],
  47. );
  48. });
  49. });
  50. });