CrossChainEnabled.test.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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(this.receiver.crossChainRestricted(), 'NotCrossChainCall()');
  14. await expectRevertCustomError(this.receiver.crossChainOwnerRestricted(), 'NotCrossChainCall()');
  15. });
  16. it('should restrict to cross-chain call from a invalid sender', async function () {
  17. await expectRevertCustomError(
  18. this.bridge.call(sender, this.receiver, 'crossChainOwnerRestricted()'),
  19. `InvalidCrossChainSender("${sender}", "${await this.receiver.owner()}")`,
  20. );
  21. });
  22. it('should grant access to cross-chain call from the owner', async function () {
  23. await this.bridge.call(await this.receiver.owner(), this.receiver, 'crossChainOwnerRestricted()');
  24. });
  25. }
  26. contract('CrossChainEnabled', function () {
  27. describe('AMB', function () {
  28. beforeEach(async function () {
  29. this.bridge = await BridgeHelper.deploy('AMB');
  30. this.receiver = await CrossChainEnabledAMBMock.new(this.bridge.address);
  31. });
  32. shouldBehaveLikeReceiver();
  33. });
  34. describe('Arbitrum-L1', function () {
  35. beforeEach(async function () {
  36. this.bridge = await BridgeHelper.deploy('Arbitrum-L1');
  37. this.receiver = await CrossChainEnabledArbitrumL1Mock.new(this.bridge.address);
  38. });
  39. shouldBehaveLikeReceiver();
  40. });
  41. describe('Arbitrum-L2', function () {
  42. beforeEach(async function () {
  43. this.bridge = await BridgeHelper.deploy('Arbitrum-L2');
  44. this.receiver = await CrossChainEnabledArbitrumL2Mock.new();
  45. });
  46. shouldBehaveLikeReceiver();
  47. });
  48. describe('Optimism', function () {
  49. beforeEach(async function () {
  50. this.bridge = await BridgeHelper.deploy('Optimism');
  51. this.receiver = await CrossChainEnabledOptimismMock.new(this.bridge.address);
  52. });
  53. shouldBehaveLikeReceiver();
  54. });
  55. describe('Polygon-Child', function () {
  56. beforeEach(async function () {
  57. this.bridge = await BridgeHelper.deploy('Polygon-Child');
  58. this.receiver = await CrossChainEnabledPolygonChildMock.new(this.bridge.address);
  59. });
  60. shouldBehaveLikeReceiver();
  61. });
  62. });