forked from Dapp-Learning-DAO/Dapp-Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrolContract_test.js
61 lines (50 loc) · 1.81 KB
/
controlContract_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const { expect } = require('chai');
describe('Control contract', function () {
let dataContract;
let controlContract;
let alice;
beforeEach(async function () {
[alice] = await ethers.getSigners();
// Deploy DataContract
let dataContractFactory = await ethers.getContractFactory('DataContract');
dataContract = await dataContractFactory.deploy();
await dataContract.deployed();
// Deploy ControlContract
let controlContractFactory = await ethers.getContractFactory(
'ControlContract'
);
controlContract = await controlContractFactory.deploy(dataContract.address);
await controlContract.deployed();
});
it('Only deployer can set the balance', async function () {
const artifact = artifacts.readArtifactSync('DataContract');
const aliceDataContract = new ethers.Contract(
dataContract.address,
artifact.abi,
alice
);
await aliceDataContract.setBalance(alice.address, 100);
// Check balance
expect(await aliceDataContract.getBalance(alice.address)).to.equal(100);
});
it('Other account cannot set the balance', async function () {
await expect(
controlContract.setBalance(controlContract.address, 100)
).to.be.revertedWith('Not sufficient permission');
});
it('The control contract can send TX when it has permission', async function () {
const artifact = artifacts.readArtifactSync('DataContract');
const aliceDataContract = new ethers.Contract(
dataContract.address,
artifact.abi,
alice
);
await aliceDataContract.allowAccess(controlContract.address);
// Control Contract set balance
await controlContract.setBalance(controlContract.address, 100);
// Check balance
expect(await controlContract.getBalance(controlContract.address)).to.equal(
100
);
});
});