AccessControlCrossChain.test.js 1.9 KB

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