CrossChainEnabled.test.js 2.9 KB

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