Skip to content

Commit aa7406a

Browse files
authored
Merge pull request #1 from rsksmart/DAO-384
DAO-384 Added RIF-Token contract
2 parents c655c7e + 1b66de2 commit aa7406a

File tree

9 files changed

+144
-2
lines changed

9 files changed

+144
-2
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ jobs:
1717
- name: Install dependencies
1818
run: yarn
1919

20+
- name: Compile contracts
21+
run: yarn compile
22+
2023
- name: Test and Lint
2124
run: |
2225
yarn test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ node_modules
1515

1616
# Hardhat Ignition default folder for deployments against a local node
1717
ignition/deployments/chain-31337
18+
19+
# PHPStorm
20+
.idea

.solhintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
contracts/RIFTokenTest.sol

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,28 @@ REPORT_GAS=true npx hardhat test
1111
npx hardhat node
1212
npx hardhat ignition deploy ./ignition/modules/Lock.ts
1313
```
14+
## RIF Token
15+
16+
The first contract that has been brought to the project is the RIF Token contract [RIFLabs RIF-Token](https://github.com/riflabs/RIF-Token)
17+
18+
A few simple tests have been created to make sure that the token works.
19+
20+
Refer to ```test/RIFToken.ts```
21+
22+
What is tested:
23+
24+
- That the contract has the initial balance defined in the RIFToken.sol
25+
- That the function ```.validAddress(address)``` works
26+
- That the ```transferAll()``` function works by using ```.setAuthorizedManagerContract```
27+
- That we can transfer token between accounts
28+
- That it emits a Transfer event
29+
30+
## Note
31+
32+
We will be using RIF-Token from the repository [RIFLabs RIF-Token](https://github.com/riflabs/RIF-Token)
33+
34+
The repository does not contain a package.json, causing hardhat to error when running ```yarn compile```
35+
36+
We decided (in the meantime) to fork the repository and add it there [Forked Repository](https://github.com/Freshenext/RIF-Token)
37+
38+
**In the future we must add a package.json to the main repository, and remove the forked repository.**

contracts/RIFTokenTest.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.4.24;
3+
4+
import "rif-token-contracts/contracts/RIF/RIFToken.sol";
5+
// File must exist, else test/RIFTokenTest.ts will fail
6+
contract RIFTokenTest is RIFToken {
7+
constructor () RIFToken () {
8+
9+
}
10+
}

hardhat.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { HardhatUserConfig } from "hardhat/config";
22
import "@nomicfoundation/hardhat-toolbox";
33

44
const config: HardhatUserConfig = {
5-
solidity: "0.8.24",
5+
solidity: {
6+
compilers: [
7+
{ version: '0.8.24' },
8+
{ version: '0.4.24' }
9+
]
10+
},
611
};
712

813
export default config;

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@
4343
"typechain": "^8.3.0",
4444
"typescript": "^5.4.5",
4545
"typescript-eslint": "^7.11.0"
46+
},
47+
"dependencies": {
48+
"rif-token-contracts": "https://github.com/Freshenext/RIF-Token"
4649
}
4750
}

test/RIFToken.test.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { expect } from 'chai';
2+
import { ethers } from 'hardhat';
3+
import { loadFixture } from '@nomicfoundation/hardhat-toolbox/network-helpers';
4+
5+
describe("RIFToken Contract", function () {
6+
7+
async function deployRif() {
8+
const [owner, addr1, addr2, ...addrs] = await ethers.getSigners();
9+
10+
// Deploy AddressHelper library
11+
const addressHelper = await ethers.deployContract("AddressHelper");
12+
// Deploy AddressLinker library
13+
const addressLinker = await ethers.deployContract("AddressLinker", { libraries: { AddressHelper: addressHelper }});
14+
15+
// Link libraries
16+
const rifToken = await ethers.deployContract("RIFToken", {
17+
libraries: {
18+
AddressLinker: addressLinker,
19+
AddressHelper: addressHelper,
20+
},
21+
});
22+
23+
return {
24+
rifToken,
25+
owner,
26+
addr1,
27+
addr2,
28+
addrs
29+
}
30+
}
31+
32+
it("Should assign the initial balance to the contract itself", async function () {
33+
const { rifToken } = await loadFixture(deployRif)
34+
const contractBalance = await rifToken.balanceOf(rifToken);
35+
expect(contractBalance).to.equal(ethers.parseUnits("1000000000", 18));
36+
});
37+
38+
it("Should use validAddress", async function () {
39+
const { rifToken, addr1 } = await loadFixture(deployRif)
40+
const addressOne = await addr1.getAddress();
41+
const isAddressOneValid = await rifToken.validAddress(addressOne)
42+
expect(isAddressOneValid).to.be.true;
43+
44+
});
45+
46+
// Single block to test the entire Transfer flow
47+
48+
let rifFixture: Awaited<ReturnType<typeof deployRif>>
49+
50+
it("Should transfer all the tokens to deployer/owner using setAuthorizedManagerContract", async function() {
51+
rifFixture = await loadFixture(deployRif)
52+
const { rifToken, owner } = rifFixture
53+
await rifToken.setAuthorizedManagerContract(owner)
54+
55+
expect(await rifToken.balanceOf(owner)).to.be.equal(ethers.parseUnits('1000000000', 'ether'))
56+
})
57+
58+
it("Should transfer tokens between accounts", async function () {
59+
const { rifToken, addr1, addr2 } = rifFixture
60+
// Close distribution
61+
const latestBlock = await ethers.provider.getBlock('latest')
62+
63+
if (latestBlock) {
64+
// We must close tokenDistribution to send transactions
65+
await rifToken.closeTokenDistribution(latestBlock.timestamp)
66+
67+
// Transfer 50 RIF Tokens to address 1
68+
await rifToken.transfer(addr1, ethers.parseUnits("50", 'ether'));
69+
const addr1Balance = await rifToken.balanceOf(addr1);
70+
expect(addr1Balance).to.equal(ethers.parseUnits("50", 'ether'));
71+
72+
// Transfer 10 RIF Tokens from address 1 to address 2
73+
await rifToken.connect(addr1).transfer(addr2, ethers.parseUnits("10", 'ether'));
74+
const addr2Balance = await rifToken.balanceOf(addr2);
75+
expect(addr2Balance).to.equal(ethers.parseUnits("10", 'ether'));
76+
}
77+
});
78+
79+
it('Should make sure that the "Transfer" event is emitted', async () => {
80+
// Also check that the event "Transfer" is emitted
81+
const { rifToken, addr1, owner } = rifFixture
82+
83+
await expect(
84+
rifToken.transfer(addr1, 1)
85+
).to.emit(rifToken, 'Transfer(address,address,uint256)')
86+
.withArgs(owner, addr1, 1)
87+
})
88+
});

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3967,6 +3967,10 @@ reusify@^1.0.4:
39673967
resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76"
39683968
integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==
39693969

3970+
"rif-token-contracts@https://github.com/Freshenext/RIF-Token":
3971+
version "1.0.0"
3972+
resolved "https://github.com/Freshenext/RIF-Token#c45fac79ec19c02d832e098140d17820d0c99192"
3973+
39703974
rimraf@^2.2.8:
39713975
version "2.7.1"
39723976
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec"

0 commit comments

Comments
 (0)