Skip to content

Commit a72699c

Browse files
committed
fix: deposit minting
1 parent c5a3702 commit a72699c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

contracts/DATAv2onPolygon.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ contract DATAv2onPolygon is DATAv2 {
2626
function deposit(address user, bytes calldata depositData) external {
2727
require(_msgSender() == bridgeAddress, "error_onlyBridge");
2828
uint256 amount = abi.decode(depositData, (uint256));
29-
_mint(address(this), amount);
29+
30+
// emits two Transfer events: 0x0 -> bridgeAddress -> user
31+
_mint(bridgeAddress, amount);
3032
transferAndCall(user, amount, depositData);
3133
}
3234

test/DATAv2onPolygon-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { utils: { hexZeroPad, parseEther } } = require("ethers")
2+
const { expect } = require("chai")
3+
const { ethers: hardhatEthers } = require("hardhat")
4+
5+
describe("DATAv2onPolygon", () => {
6+
it("deposit mints tokens as expected", async () => {
7+
const [bridge] = await hardhatEthers.getSigners()
8+
const targetUser = "0x1234567890123456789012345678901234567890"
9+
const DATAv2onPolygon = await hardhatEthers.getContractFactory("DATAv2onPolygon")
10+
const token = await DATAv2onPolygon.deploy(bridge.address)
11+
await token.deployed()
12+
13+
expect((await token.balanceOf(targetUser)).toString()).to.equal("0")
14+
15+
const amountBytes = hexZeroPad(parseEther("1"), 32)
16+
await expect(token.connect(bridge).deposit(targetUser, amountBytes)).to.emit(token, "Transfer(address,address,uint256)")
17+
18+
expect((await token.balanceOf(targetUser)).toString()).to.equal(parseEther("1").toString())
19+
})
20+
21+
it("only bridge is allowed to deposit", async () => {
22+
const [bridge, another] = await hardhatEthers.getSigners()
23+
const DATAv2onPolygon = await hardhatEthers.getContractFactory("DATAv2onPolygon")
24+
const token = await DATAv2onPolygon.deploy(bridge.address)
25+
await token.deployed()
26+
await expect(token.connect(another).deposit(another.address, parseEther("1").toHexString())).to.be.revertedWith("error_onlyBridge")
27+
})
28+
})

0 commit comments

Comments
 (0)