CrossChainEnabled.test.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. const { BridgeHelper } = require('../helpers/crosschain');
  2. const { expectRevertCustomError } = require('../helpers/customError');
  3. function randomAddress () {
  4. return web3.utils.toChecksumAddress(web3.utils.randomHex(20));
  5. }
  6. const CrossChainEnabledAMBMock = artifacts.require('CrossChainEnabledAMBMock');
  7. const CrossChainEnabledArbitrumL1Mock = artifacts.require('CrossChainEnabledArbitrumL1Mock');
  8. const CrossChainEnabledArbitrumL2Mock = artifacts.require('CrossChainEnabledArbitrumL2Mock');
  9. const CrossChainEnabledOptimismMock = artifacts.require('CrossChainEnabledOptimismMock');
  10. const CrossChainEnabledPolygonChildMock = artifacts.require('CrossChainEnabledPolygonChildMock');
  11. function shouldBehaveLikeReceiver (sender = randomAddress()) {
  12. it('should reject same-chain calls', async function () {
  13. await expectRevertCustomError(
  14. this.receiver.crossChainRestricted(),
  15. 'NotCrossChainCall()',
  16. );
  17. });
  18. it('should restrict to cross-chain call from a invalid sender', async function () {
  19. await expectRevertCustomError(
  20. this.bridge.call(sender, this.receiver, 'crossChainOwnerRestricted()'),
  21. `InvalidCrossChainSender("${sender}", "${await this.receiver.owner()}")`,
  22. );
  23. });
  24. it('should grant access to cross-chain call from the owner', async function () {
  25. await this.bridge.call(
  26. await this.receiver.owner(),
  27. this.receiver,
  28. 'crossChainOwnerRestricted()',
  29. );
  30. });
  31. }
  32. contract('CrossChainEnabled', function () {
  33. describe('AMB', function () {
  34. beforeEach(async function () {
  35. this.bridge = await BridgeHelper.deploy('AMB');
  36. this.receiver = await CrossChainEnabledAMBMock.new(this.bridge.address);
  37. });
  38. shouldBehaveLikeReceiver();
  39. });
  40. describe('Arbitrum-L1', function () {
  41. beforeEach(async function () {
  42. this.bridge = await BridgeHelper.deploy('Arbitrum-L1');
  43. this.receiver = await CrossChainEnabledArbitrumL1Mock.new(this.bridge.address);
  44. });
  45. shouldBehaveLikeReceiver();
  46. });
  47. describe('Arbitrum-L2', function () {
  48. beforeEach(async function () {
  49. this.bridge = await BridgeHelper.deploy('Arbitrum-L2');
  50. this.receiver = await CrossChainEnabledArbitrumL2Mock.new();
  51. });
  52. shouldBehaveLikeReceiver();
  53. });
  54. describe('Optimism', function () {
  55. beforeEach(async function () {
  56. this.bridge = await BridgeHelper.deploy('Optimism');
  57. this.receiver = await CrossChainEnabledOptimismMock.new(this.bridge.address);
  58. });
  59. shouldBehaveLikeReceiver();
  60. });
  61. describe('Polygon-Child', function () {
  62. beforeEach(async function () {
  63. this.bridge = await BridgeHelper.deploy('Polygon-Child');
  64. this.receiver = await CrossChainEnabledPolygonChildMock.new(this.bridge.address);
  65. });
  66. shouldBehaveLikeReceiver();
  67. });
  68. });