forked from compound-finance/comet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallow-test.ts
70 lines (57 loc) · 2.42 KB
/
allow-test.ts
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
62
63
64
65
66
67
68
69
70
import { ethers, event, expect, makeProtocol, wait } from './helpers';
describe('allow', function () {
it('isAllowed defaults to false', async () => {
const { comet } = await makeProtocol();
const [_admin, user, manager] = await ethers.getSigners();
const userAddress = user.address;
const managerAddress = manager.address;
expect(await comet.isAllowed(userAddress, managerAddress)).to.be.false;
});
it('allows a user to authorize a manager', async () => {
const { comet } = await makeProtocol();
const [_admin, user, manager] = await ethers.getSigners();
const userAddress = user.address;
const managerAddress = manager.address;
const tx = await wait(comet.connect(user).allow(managerAddress, true));
expect(await comet.isAllowed(userAddress, managerAddress)).to.be.true;
expect(event(tx, 0)).to.be.deep.equal({
Approval: {
owner: userAddress,
spender: managerAddress,
amount: ethers.constants.MaxUint256.toBigInt(),
}
});
});
it('allows a user to rescind authorization', async () => {
const { comet } = await makeProtocol();
const [_admin, user, manager] = await ethers.getSigners();
const userAddress = user.address;
const managerAddress = manager.address;
const _authorizeTx = await wait(comet.connect(user).allow(managerAddress, true));
expect(await comet.isAllowed(userAddress, managerAddress)).to.be.true;
const rescindTx = await wait(comet.connect(user).allow(managerAddress, false));
expect(await comet.isAllowed(userAddress, managerAddress)).to.be.false;
expect(event(rescindTx, 0)).to.be.deep.equal({
Approval: {
owner: userAddress,
spender: managerAddress,
amount: 0n,
}
});
});
});
describe('hasPermission', function () {
it('is true for self', async () => {
const { comet, users: [alice] } = await makeProtocol();
expect(await comet.hasPermission(alice.address, alice.address)).to.be.true;
});
it('is false by default for others', async () => {
const { comet, users: [alice, bob] } = await makeProtocol();
expect(await comet.hasPermission(alice.address, bob.address)).to.be.false;
});
it('is true when user is allowed', async () => {
const { comet, users: [alice, bob] } = await makeProtocol();
await comet.connect(alice).allow(bob.address, true);
expect(await comet.hasPermission(alice.address, bob.address)).to.be.true;
});
});