-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransparentVault.test.js
166 lines (132 loc) · 8.05 KB
/
TransparentVault.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
const {expect} = require("chai");
const {deployContractUpgradeable, deployContract, amount, assertThrowsMessage} = require("./helpers");
describe("TransparentVault", function () {
let everdragons2Protector, everdragons2TransparentVault;
// mocks
let bulls, particle, fatBelly, stupidMonk, uselessWeapons;
// wallets
let e2Owner, bob, alice, fred, john, jane, mark;
before(async function () {
[e2Owner, bob, alice, fred, john, jane, mark] = await ethers.getSigners();
});
function transferNft(nft, user) {
return nft.connect(user)["safeTransferFrom(address,address,uint256)"];
}
beforeEach(async function () {
everdragons2Protector = await deployContractUpgradeable("Everdragons2ProtectorMintable", []);
everdragons2TransparentVault = await deployContractUpgradeable("Everdragons2TransparentVault", [
everdragons2Protector.address,
]);
await everdragons2Protector.addSubordinate(everdragons2TransparentVault.address);
expect(await everdragons2Protector.isProtector()).to.equal(true);
expect(await everdragons2Protector.supportsInterface("0x855f1e29")).to.be.true;
await expect(everdragons2Protector.connect(e2Owner).safeMint(bob.address, 1))
.emit(everdragons2Protector, "Transfer")
.withArgs(ethers.constants.AddressZero, bob.address, 1)
.emit(everdragons2TransparentVault, "Transfer")
.withArgs(ethers.constants.AddressZero, bob.address, 1);
await everdragons2Protector.connect(e2Owner).safeMint(bob.address, 2);
await everdragons2Protector.connect(e2Owner).safeMint(bob.address, 3);
await everdragons2Protector.connect(e2Owner).safeMint(bob.address, 4);
await everdragons2Protector.connect(e2Owner).safeMint(alice.address, 5);
await everdragons2Protector.connect(e2Owner).safeMint(alice.address, 6);
// erc20
bulls = await deployContract("Bulls");
await bulls.mint(bob.address, amount("90000"));
await bulls.mint(john.address, amount("60000"));
await bulls.mint(jane.address, amount("100000"));
await bulls.mint(alice.address, amount("100000"));
await bulls.mint(fred.address, amount("100000"));
fatBelly = await deployContract("FatBelly");
await fatBelly.mint(alice.address, amount("10000000"));
await fatBelly.mint(john.address, amount("2000000"));
await fatBelly.mint(fred.address, amount("30000000"));
// erc721
particle = await deployContract("Particle", "https://api.particle.com/");
await particle.safeMint(alice.address, 1);
await particle.safeMint(bob.address, 2);
await particle.safeMint(john.address, 3);
stupidMonk = await deployContract("StupidMonk", "https://api.stupidmonk.com/");
await stupidMonk.safeMint(bob.address, 1);
await stupidMonk.safeMint(alice.address, 2);
await stupidMonk.safeMint(john.address, 3);
// erc1155
uselessWeapons = await deployContract("UselessWeapons", "https://api.uselessweapons.com/");
await uselessWeapons.mintBatch(bob.address, [1, 2], [5, 2], "0x00");
await uselessWeapons.mintBatch(alice.address, [2], [2], "0x00");
await uselessWeapons.mintBatch(john.address, [3, 4], [10, 1], "0x00");
});
async function configure(protectorId, allowAll_, allowWithConfirmation_, allowList_, allowListStatus_) {
await everdragons2TransparentVault.configure(protectorId, allowAll_, allowWithConfirmation_, allowList_, allowListStatus_);
expect(await everdragons2TransparentVault.name()).equal("Everdragons2 - Cruna Transparent Vault");
expect(await everdragons2TransparentVault.symbol()).equal("tvNFTa");
}
it("should create a vault and add more assets to it", async function () {
// bob creates a vault depositing a particle token
await particle.connect(bob).setApprovalForAll(everdragons2TransparentVault.address, true);
await everdragons2TransparentVault.connect(bob).depositERC721(1, particle.address, 2);
expect((await everdragons2TransparentVault.amountOf(1, [particle.address], [2]))[0]).equal(1);
// bob adds a stupidMonk token to his vault
await stupidMonk.connect(bob).setApprovalForAll(everdragons2TransparentVault.address, true);
await everdragons2TransparentVault.connect(bob).depositERC721(1, stupidMonk.address, 1);
expect((await everdragons2TransparentVault.amountOf(1, [stupidMonk.address], [1]))[0]).equal(1);
// bob adds some bulls tokens to his vault
await bulls.connect(bob).approve(everdragons2TransparentVault.address, amount("10000"));
await everdragons2TransparentVault.connect(bob).depositERC20(1, bulls.address, amount("5000"));
expect((await everdragons2TransparentVault.amountOf(1, [bulls.address], [0]))[0]).equal(amount("5000"));
// the protected cannot be transferred
await expect(transferNft(everdragons2TransparentVault, bob)(bob.address, alice.address, 1)).revertedWith(
"TransferNotAllowed()"
);
// bob transfers the protector to alice
await expect(transferNft(everdragons2Protector, bob)(bob.address, alice.address, 1))
.emit(everdragons2Protector, "Transfer")
.withArgs(bob.address, alice.address, 1);
});
it("should allow a transfer if a transfer initializer is pending", async function () {
// bob creates a vault depositing a particle token
await particle.connect(bob).setApprovalForAll(everdragons2TransparentVault.address, true);
await everdragons2TransparentVault.connect(bob).depositERC721(1, particle.address, 2);
expect((await everdragons2TransparentVault.amountOf(1, [particle.address], [2]))[0]).equal(1);
await expect(everdragons2Protector.connect(bob).setInitiator(mark.address))
.emit(everdragons2Protector, "InitiatorStarted")
.withArgs(bob.address, mark.address, true);
// bob transfers the protector to alice
await expect(transferNft(everdragons2Protector, bob)(bob.address, alice.address, 1))
.emit(everdragons2Protector, "Transfer")
.withArgs(bob.address, alice.address, 1);
});
it("should not allow a transfer if a transfer initializer is active", async function () {
// bob creates a vault depositing a particle token
await particle.connect(bob).setApprovalForAll(everdragons2TransparentVault.address, true);
await everdragons2TransparentVault.connect(bob).depositERC721(1, particle.address, 2);
expect((await everdragons2TransparentVault.amountOf(1, [particle.address], [2]))[0]).equal(1);
await expect(everdragons2Protector.connect(bob).setInitiator(mark.address))
.emit(everdragons2Protector, "InitiatorStarted")
.withArgs(bob.address, mark.address, true);
await expect(everdragons2Protector.connect(mark).confirmInitiator(bob.address))
.emit(everdragons2Protector, "InitiatorUpdated")
.withArgs(bob.address, mark.address, true);
await expect(transferNft(everdragons2Protector, bob)(bob.address, alice.address, 1)).revertedWith("TransferNotPermitted()");
});
it("should allow a transfer if the transfer initializer starts it", async function () {
// bob creates a vault depositing a particle token
await particle.connect(bob).setApprovalForAll(everdragons2TransparentVault.address, true);
await everdragons2TransparentVault.connect(bob).depositERC721(1, particle.address, 2);
expect((await everdragons2TransparentVault.amountOf(1, [particle.address], [2]))[0]).equal(1);
await expect(everdragons2Protector.connect(bob).setInitiator(mark.address))
.emit(everdragons2Protector, "InitiatorStarted")
.withArgs(bob.address, mark.address, true);
await expect(everdragons2Protector.connect(mark).confirmInitiator(bob.address))
.emit(everdragons2Protector, "InitiatorUpdated")
.withArgs(bob.address, mark.address, true);
await expect(everdragons2Protector.connect(mark).startTransfer(1, alice.address, 1000))
.emit(everdragons2Protector, "TransferStarted")
.withArgs(mark.address, 1, alice.address);
await expect(everdragons2Protector.connect(bob).completeTransfer(1))
.emit(everdragons2Protector, "Transfer")
.withArgs(bob.address, alice.address, 1);
expect(await everdragons2Protector.ownerOf(1)).equal(alice.address);
expect(await everdragons2TransparentVault.ownerOf(1)).equal(alice.address);
});
});