|
| 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 | + |
| 29 | + it("withdraw burns tokens", async () => { |
| 30 | + const [bridge, user] = await hardhatEthers.getSigners() |
| 31 | + const DATAv2onPolygon = await hardhatEthers.getContractFactory("DATAv2onPolygon") |
| 32 | + const token = await DATAv2onPolygon.deploy(bridge.address) |
| 33 | + await token.deployed() |
| 34 | + |
| 35 | + expect((await token.balanceOf(user.address)).toString()).to.equal("0") |
| 36 | + const amountWei = parseEther("1") |
| 37 | + const amountBytes = hexZeroPad(amountWei, 32) |
| 38 | + await expect(token.connect(bridge).deposit(user.address, amountBytes)).to.emit(token, "Transfer(address,address,uint256,bytes)") |
| 39 | + expect((await token.balanceOf(user.address)).toString()).to.equal(amountWei.toString()) |
| 40 | + |
| 41 | + await expect(token.connect(user).withdraw(parseEther("1"))).to.emit(token, "Transfer(address,address,uint256)") |
| 42 | + .withArgs(user.address, "0x0000000000000000000000000000000000000000", amountWei.toHexString()) |
| 43 | + |
| 44 | + expect((await token.balanceOf(user.address)).toString()).to.equal("0") |
| 45 | + }) |
| 46 | +}) |
0 commit comments