AccessControlCrossChain.test.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const { expectRevert } = require('@openzeppelin/test-helpers');
  2. const { BridgeHelper } = require('../helpers/crosschain');
  3. const {
  4. shouldBehaveLikeAccessControl,
  5. } = require('./AccessControl.behavior.js');
  6. const crossChainRoleAlias = (role) => web3.utils.leftPad(
  7. web3.utils.toHex(web3.utils.toBN(role).xor(web3.utils.toBN(web3.utils.soliditySha3('CROSSCHAIN_ALIAS')))),
  8. 64,
  9. );
  10. const AccessControlCrossChainMock = artifacts.require('AccessControlCrossChainMock');
  11. const ROLE = web3.utils.soliditySha3('ROLE');
  12. contract('AccessControl', function (accounts) {
  13. before(async function () {
  14. this.bridge = await BridgeHelper.deploy();
  15. });
  16. beforeEach(async function () {
  17. this.accessControl = await AccessControlCrossChainMock.new({ from: 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(
  31. accounts[0],
  32. this.accessControl,
  33. 'senderProtected',
  34. [ ROLE ],
  35. ),
  36. `AccessControl: account ${accounts[0].toLowerCase()} is missing role ${crossChainRoleAlias(ROLE)}`,
  37. );
  38. });
  39. it('Crosschain calls not authorized to non-aliased addresses', async function () {
  40. await this.bridge.call(
  41. accounts[1],
  42. this.accessControl,
  43. 'senderProtected',
  44. [ ROLE ],
  45. );
  46. });
  47. });
  48. });