forked from OpenZeppelin/openzeppelin-contracts
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdraft-ERC20Bridgeable.test.js
More file actions
89 lines (72 loc) · 3.08 KB
/
Copy pathdraft-ERC20Bridgeable.test.js
File metadata and controls
89 lines (72 loc) · 3.08 KB
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
const { ethers } = require('hardhat');
const { expect } = require('chai');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
const { shouldBehaveLikeERC20 } = require('../ERC20.behavior.js');
const { shouldSupportInterfaces } = require('../../../utils/introspection/SupportsInterface.behavior');
const name = 'My Token';
const symbol = 'MTKN';
const initialSupply = 100n;
async function fixture() {
const [other, bridge, ...accounts] = await ethers.getSigners();
const token = await ethers.deployContract('$ERC20BridgeableMock', [name, symbol, bridge]);
await token.$_mint(accounts[0], initialSupply);
return { bridge, other, accounts, token };
}
describe('ERC20Bridgeable', function () {
beforeEach(async function () {
Object.assign(this, await loadFixture(fixture));
});
describe('onlyTokenBridgeFn', function () {
it('reverts when called by non-bridge', async function () {
await expect(this.token.onlyTokenBridgeFn()).to.be.revertedWithCustomError(this.token, 'OnlyTokenBridge');
});
it('does not revert when called by bridge', async function () {
await expect(this.token.connect(this.bridge).onlyTokenBridgeFn())
.to.emit(this.token, 'OnlyTokenBridgeFnCalled')
.withArgs(this.bridge);
});
});
describe('crosschainMint', function () {
it('reverts when called by non-bridge', async function () {
await expect(this.token.crosschainMint(this.other, 100n)).to.be.revertedWithCustomError(
this.token,
'OnlyTokenBridge',
);
});
it('mints amount provided by the bridge when calling crosschainMint', async function () {
const amount = 100n;
await expect(this.token.connect(this.bridge).crosschainMint(this.other, amount))
.to.emit(this.token, 'CrosschainMint')
.withArgs(this.other, amount, this.bridge)
.to.emit(this.token, 'Transfer')
.withArgs(ethers.ZeroAddress, this.other, amount);
await expect(this.token.balanceOf(this.other)).to.eventually.equal(amount);
});
});
describe('crosschainBurn', function () {
it('reverts when called by non-bridge', async function () {
await expect(this.token.crosschainBurn(this.other, 100n)).to.be.revertedWithCustomError(
this.token,
'OnlyTokenBridge',
);
});
it('burns amount provided by the bridge when calling crosschainBurn', async function () {
const amount = 100n;
await this.token.$_mint(this.other, amount);
await expect(this.token.connect(this.bridge).crosschainBurn(this.other, amount))
.to.emit(this.token, 'CrosschainBurn')
.withArgs(this.other, amount, this.bridge)
.to.emit(this.token, 'Transfer')
.withArgs(this.other, ethers.ZeroAddress, amount);
await expect(this.token.balanceOf(this.other)).to.eventually.equal(0);
});
});
describe('ERC165', function () {
shouldSupportInterfaces({
ERC7802: ['crosschainMint(address,uint256)', 'crosschainBurn(address,uint256)'],
});
});
describe('ERC20 behavior', function () {
shouldBehaveLikeERC20(initialSupply);
});
});