Skip to content

Commit 187df30

Browse files
committed
feat(test): testing the pausable feature
1 parent f5a98c6 commit 187df30

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

test/16-pausable.js

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
const { SigningKey } = require("@ethersproject/signing-key");
2+
const truffleAssert = require("truffle-assertions");
3+
4+
var EUR = artifacts.require("./EUR.sol");
5+
var StandardController = artifacts.require("./StandardController.sol");
6+
var ERC20Lib = artifacts.require("./ERC20Lib.sol");
7+
var ERC677Lib = artifacts.require("./ERC677Lib.sol");
8+
var MintableTokenLib = artifacts.require("./MintableTokenLib.sol");
9+
var TokenStorageLib = artifacts.require("./TokenStorageLib.sol");
10+
var SmartController = artifacts.require("./SmartController.sol");
11+
var StandardController = artifacts.require("./StandardController.sol");
12+
var ConstantSmartController = artifacts.require(
13+
"./ConstantSmartController.sol"
14+
);
15+
var BlacklistValidator = artifacts.require("./BlacklistValidator.sol");
16+
17+
var SmartTokenLib = artifacts.require("./SmartTokenLib.sol");
18+
const AddressZero = "0x0000000000000000000000000000000000000000";
19+
20+
const wallet = {
21+
address: `0x77a3373AdCBe91E589D54F3a92Bb3F73F56686F4`,
22+
privateKey: `0x1a2a4798d8b0e070ceee86d09e0942ad489919450cda74d9ed4d9b90d0a3173a`,
23+
};
24+
25+
contract("PausableController", (accounts) => {
26+
if (web3.version.network <= 100) {
27+
console.log("Skipping test on local network");
28+
return;
29+
}
30+
const ADMIN_ROLE =
31+
"0xa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775"; // SHA3("ADMIN_ROLE")
32+
33+
const owner = accounts[0];
34+
const system = accounts[1];
35+
const admin = accounts[2];
36+
let controller;
37+
let eur;
38+
let mintableTokenLib;
39+
let smartTokenLib;
40+
let tokenStorageLib;
41+
let erc20Lib;
42+
let erc677Lib;
43+
let validator;
44+
45+
before("setup system role eure", async () => {
46+
// Link
47+
mintableTokenLib = await MintableTokenLib.new();
48+
smartTokenLib = await SmartTokenLib.new();
49+
tokenStorageLib = await TokenStorageLib.new();
50+
erc20Lib = await ERC20Lib.new();
51+
erc677Lib = await ERC677Lib.new();
52+
await SmartController.link("MintableTokenLib", mintableTokenLib.address);
53+
await SmartController.link("SmartTokenLib", smartTokenLib.address);
54+
await SmartController.link("TokenStorageLib", tokenStorageLib.address);
55+
await SmartController.link("ERC20Lib", erc20Lib.address);
56+
await SmartController.link("ERC677Lib", erc677Lib.address);
57+
58+
await StandardController.link("TokenStorageLib", tokenStorageLib.address);
59+
await StandardController.link("ERC20Lib", erc20Lib.address);
60+
await StandardController.link("ERC677Lib", erc677Lib.address);
61+
62+
await ConstantSmartController.link(
63+
"MintableTokenLib",
64+
mintableTokenLib.address
65+
);
66+
await ConstantSmartController.link("SmartTokenLib", smartTokenLib.address);
67+
await ConstantSmartController.link(
68+
"TokenStorageLib",
69+
tokenStorageLib.address
70+
);
71+
await ConstantSmartController.link("ERC20Lib", erc20Lib.address);
72+
await ConstantSmartController.link("ERC677Lib", erc677Lib.address);
73+
// Deploy
74+
eur = await EUR.new();
75+
validator = await BlacklistValidator.new();
76+
controller = await SmartController.new(
77+
AddressZero,
78+
validator.address,
79+
web3.utils.asciiToHex("EUR"),
80+
eur.address
81+
);
82+
await eur.setController(controller.address);
83+
await controller.addAdminAccount(admin);
84+
await controller.addSystemAccount(system);
85+
await controller.setMaxMintAllowance(1000000000000);
86+
await controller.setMintAllowance(system, 1000000000000, {
87+
from: admin,
88+
});
89+
});
90+
91+
it("should mint 74000 new tokens", async () => {
92+
await eur.mintTo(system, 74000, { from: system });
93+
const balance = await eur.balanceOf(system);
94+
assert.equal(balance.valueOf(), 74000, "did not mint 74000 tokens");
95+
});
96+
97+
it("should transfer 7200 tokens to second account", async () => {
98+
await eur.transfer(accounts[0], 7200, { from: system });
99+
const balance = await eur.balanceOf(accounts[0]);
100+
assert.equal(balance.valueOf(), 7200, "did not transfer 7200 tokens");
101+
});
102+
103+
it("should allow the third account to spend 9600 from the first account", async () => {
104+
await eur.transfer(accounts[0], 9600, { from: system });
105+
await eur.approve(accounts[2], 10600, { from: accounts[0] });
106+
const allowance = await eur.allowance(accounts[0], accounts[2]);
107+
assert.equal(allowance.valueOf(), 10600, "the allowance wasn't 9600");
108+
});
109+
110+
it("should transfer 9300 from the first account to the fourth using the third account", async () => {
111+
await eur.transferFrom(accounts[0], accounts[3], 9600, {
112+
from: accounts[2],
113+
});
114+
const balance = await eur.balanceOf(accounts[3]);
115+
assert.equal(
116+
balance.valueOf(),
117+
9600,
118+
"The forth account does not have 9600"
119+
);
120+
});
121+
122+
it("should pause the contract", async () => {
123+
await controller.pause({ from: owner });
124+
const paused = await controller.paused();
125+
assert.equal(paused, true, "The contract was not paused");
126+
});
127+
128+
it("should not allow the contract to mint new tokens", async () => {
129+
await truffleAssert.reverts(
130+
eur.mintTo(accounts[0], 1000, { from: system })
131+
);
132+
});
133+
134+
it("should not allow the contract to transfer tokens", async () => {
135+
await truffleAssert.reverts(
136+
eur.transfer(accounts[0], 1000, { from: system })
137+
);
138+
});
139+
140+
it("should not allow the contract to transfer tokens from another account", async () => {
141+
await truffleAssert.reverts(
142+
eur.transferFrom(accounts[0], accounts[3], 1000, { from: accounts[2] })
143+
);
144+
});
145+
});

0 commit comments

Comments
 (0)