Skip to content

Commit f942aca

Browse files
authored
Merge pull request #5 from streamr-dev/add-polygon-test
fix: deposit minting
2 parents c5a3702 + aed125f commit f942aca

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Continuous Integration
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- release/*
8+
push:
9+
branches:
10+
- main
11+
- release/*
12+
13+
jobs:
14+
build:
15+
name: Build
16+
timeout-minutes: 20
17+
runs-on: ${{ matrix.os }}
18+
continue-on-error: ${{ matrix.experimental }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
node_version:
23+
- 16.13.0
24+
os:
25+
- ubuntu-20.04
26+
experimental: [false]
27+
steps:
28+
- uses: actions/[email protected]
29+
with:
30+
submodules: true
31+
- name: Node ${{ matrix.node_version }} - x64 on ${{ matrix.os }}
32+
uses: actions/[email protected]
33+
with:
34+
node-version: ${{ matrix.node_version }}
35+
- uses: actions/[email protected]
36+
with:
37+
path: ~/.npm
38+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
39+
restore-keys: |
40+
${{ runner.os }}-node-
41+
- name: Install dependencies
42+
run: npm ci
43+
- name: Run lint and unit tests
44+
run: |
45+
npm run lint
46+
npm run build
47+
npm run test
48+
npm run cov

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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)