forked from OpenZeppelin/openzeppelin-contracts
/
CrossChainEnabled.test.js
101 lines (80 loc) · 2.9 KB
/
CrossChainEnabled.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const { expect } = require('chai');
const CrossChainHelper = require('../helpers/crosschain');
/** Revert handler that supports custom errors. */
async function expectRevert (promise, reason) {
try {
await promise;
expect.fail('Expected promise to throw but it didn\'t');
} catch (error) {
if (reason) {
expect(error.message).to.include(reason);
}
}
}
function randomAddress () {
return web3.utils.toChecksumAddress(web3.utils.randomHex(20));
}
const CrossChainEnabledAMBMock = artifacts.require('CrossChainEnabledAMBMock');
const CrossChainEnabledArbitrumL1Mock = artifacts.require('CrossChainEnabledArbitrumL1Mock');
const CrossChainEnabledArbitrumL2Mock = artifacts.require('CrossChainEnabledArbitrumL2Mock');
const CrossChainEnabledOptimismMock = artifacts.require('CrossChainEnabledOptimismMock');
const CrossChainEnabledPolygonChildMock = artifacts.require('CrossChainEnabledPolygonChildMock');
function shouldBehaveLikeReceiver (sender = randomAddress()) {
it('should reject same-chain calls', async function () {
await expectRevert(
this.receiver.crossChainRestricted(),
'NotCrossChainCall()',
);
});
it('should restrict to cross-chain call from a invalid sender', async function () {
await expectRevert(CrossChainHelper.call(
sender,
this.receiver,
'crossChainOwnerRestricted()',
));
});
it('should grant access to cross-chain call from the owner', async function () {
await CrossChainHelper.call(
await this.receiver.owner(),
this.receiver,
'crossChainOwnerRestricted()',
);
});
}
contract('CrossChainEnabled', function () {
describe('AMB', function () {
CrossChainHelper.before('AMB');
beforeEach(async function () {
this.receiver = await CrossChainEnabledAMBMock.new(CrossChainHelper.bridge.address);
});
shouldBehaveLikeReceiver();
});
describe('Arbitrum-L1', function () {
CrossChainHelper.before('Arbitrum-L1');
beforeEach(async function () {
this.receiver = await CrossChainEnabledArbitrumL1Mock.new(await CrossChainHelper.bridge.inbox());
});
shouldBehaveLikeReceiver();
});
describe('Arbitrum-L2', function () {
CrossChainHelper.before('Arbitrum-L2');
beforeEach(async function () {
this.receiver = await CrossChainEnabledArbitrumL2Mock.new(CrossChainHelper.bridge.address);
});
shouldBehaveLikeReceiver();
});
describe('Optimism', function () {
CrossChainHelper.before('Optimism');
beforeEach(async function () {
this.receiver = await CrossChainEnabledOptimismMock.new(CrossChainHelper.bridge.address);
});
shouldBehaveLikeReceiver();
});
describe('Polygon-Child', function () {
CrossChainHelper.before('Polygon-Child');
beforeEach(async function () {
this.receiver = await CrossChainEnabledPolygonChildMock.new(CrossChainHelper.bridge.address);
});
shouldBehaveLikeReceiver();
});
});