@@ -134,33 +134,33 @@ describe("Lease", function () {
134
134
} ) ;
135
135
136
136
it ( "buyToken" , async function ( ) {
137
- const [ author , , operator , buyer ] = await ethers . getSigners ( ) ;
137
+ const [ author , someoneElse , operator , buyer ] = await ethers . getSigners ( ) ;
138
138
139
- let authorBalance = await ethers . provider . getBalance ( author . address ) ;
140
- let operatorBalance = await ethers . provider . getBalance ( operator . address ) ;
141
- let buyerBalance = await ethers . provider . getBalance ( buyer . address ) ;
139
+ // let authorBalance = await ethers.provider.getBalance(author.address);
140
+ // let operatorBalance = await ethers.provider.getBalance(operator.address);
141
+ // let buyerBalance = await ethers.provider.getBalance(buyer.address);
142
142
143
- console . log ( {
144
- authorBalance : ethers . formatEther ( authorBalance ) ,
145
- operatorBalance : ethers . formatEther ( operatorBalance ) ,
146
- buyerBalance : ethers . formatEther ( buyerBalance ) ,
147
- } ) ;
143
+ // console.log({
144
+ // authorBalance: ethers.formatEther(authorBalance),
145
+ // operatorBalance: ethers.formatEther(operatorBalance),
146
+ // buyerBalance: ethers.formatEther(buyerBalance),
147
+ // });
148
148
149
149
const ERC721 = await createERC721Contract ( ) ;
150
150
151
151
await ERC721 . connect ( author ) . setApprovalForAll ( operator . address , true ) ;
152
152
153
153
await ERC721 . connect ( operator ) . setTokenForSale ( 0 , BigInt ( ethers . parseEther ( "1" ) ) ) ;
154
154
155
- authorBalance = await ethers . provider . getBalance ( author . address ) ;
156
- operatorBalance = await ethers . provider . getBalance ( operator . address ) ;
157
- buyerBalance = await ethers . provider . getBalance ( buyer . address ) ;
155
+ // authorBalance = await ethers.provider.getBalance(author.address);
156
+ // operatorBalance = await ethers.provider.getBalance(operator.address);
157
+ // buyerBalance = await ethers.provider.getBalance(buyer.address);
158
158
159
- console . log ( {
160
- authorBalance : ethers . formatEther ( authorBalance ) ,
161
- operatorBalance : ethers . formatEther ( operatorBalance ) ,
162
- buyerBalance : ethers . formatEther ( buyerBalance ) ,
163
- } ) ;
159
+ // console.log({
160
+ // authorBalance: ethers.formatEther(authorBalance),
161
+ // operatorBalance: ethers.formatEther(operatorBalance),
162
+ // buyerBalance: ethers.formatEther(buyerBalance),
163
+ // });
164
164
165
165
ERC721 . on ( "Transfer" , ( from , to , tokenId ) => {
166
166
// console.log({ from, to, tokenId });
@@ -187,14 +187,28 @@ describe("Lease", function () {
187
187
188
188
expect ( ownerOf0 ) . to . equal ( buyer . address ) ;
189
189
190
- authorBalance = await ethers . provider . getBalance ( author . address ) ;
191
- operatorBalance = await ethers . provider . getBalance ( operator . address ) ;
192
- buyerBalance = await ethers . provider . getBalance ( buyer . address ) ;
190
+ // authorBalance = await ethers.provider.getBalance(author.address);
191
+ // operatorBalance = await ethers.provider.getBalance(operator.address);
192
+ // buyerBalance = await ethers.provider.getBalance(buyer.address);
193
193
194
- console . log ( {
195
- authorBalance : ethers . formatEther ( authorBalance ) ,
196
- operatorBalance : ethers . formatEther ( operatorBalance ) ,
197
- buyerBalance : ethers . formatEther ( buyerBalance ) ,
198
- } ) ;
194
+ // console.log({
195
+ // authorBalance: ethers.formatEther(authorBalance),
196
+ // operatorBalance: ethers.formatEther(operatorBalance),
197
+ // buyerBalance: ethers.formatEther(buyerBalance),
198
+ // });
199
+
200
+ // only the buyer should set prices now
201
+ await expect ( ERC721 . connect ( author ) . setTokenForSale ( 0 , BigInt ( ethers . parseEther ( "2" ) ) ) ) . to . be . reverted ;
202
+ await expect ( ERC721 . connect ( operator ) . setTokenForSale ( 0 , BigInt ( ethers . parseEther ( "2" ) ) ) ) . to . be . reverted ;
203
+
204
+ await expect ( ERC721 . connect ( buyer ) . setTokenForSale ( 0 , BigInt ( ethers . parseEther ( "2" ) ) ) )
205
+ . to . emit ( ERC721 , "SetTokenForSale" )
206
+ . withArgs ( buyer . address , 0 , BigInt ( ethers . parseEther ( "2" ) ) ) ;
207
+
208
+ const newPrice = await ERC721 . getTokenPrice ( 0 ) ;
209
+ expect ( ethers . formatEther ( newPrice ) ) . to . equal ( "2.0" ) ;
210
+
211
+ // too poor to buy
212
+ await expect ( ERC721 . connect ( someoneElse ) . buyToken ( 0 , { value : BigInt ( ethers . parseEther ( "1" ) ) } ) ) . to . be . reverted ;
199
213
} ) ;
200
214
} ) ;
0 commit comments