@@ -36,7 +36,7 @@ async function createERC721Contract() {
36
36
37
37
describe ( "Lease" , function ( ) {
38
38
it ( "Initialize: call constructor" , async function ( ) {
39
- const [ owner , , signer ] = await ethers . getSigners ( ) ;
39
+ const [ author , , operator ] = await ethers . getSigners ( ) ;
40
40
41
41
// console.log({ owner: owner.address, signer: signer.address });
42
42
@@ -55,15 +55,15 @@ describe("Lease", function () {
55
55
56
56
// console.log({ ownerOf0, ownerOf1, ownerOf2, ownerOf3 });
57
57
58
- expect ( ownerOf0 ) . to . equal ( owner . address ) ;
59
- expect ( ownerOf1 ) . to . equal ( owner . address ) ;
60
- expect ( ownerOf2 ) . to . equal ( owner . address ) ;
61
- expect ( ownerOf3 ) . to . equal ( owner . address ) ;
58
+ expect ( ownerOf0 ) . to . equal ( author . address ) ;
59
+ expect ( ownerOf1 ) . to . equal ( author . address ) ;
60
+ expect ( ownerOf2 ) . to . equal ( author . address ) ;
61
+ expect ( ownerOf3 ) . to . equal ( author . address ) ;
62
62
63
- const token0 = await ERC721 . tokenURI ( 0 ) ;
64
- const token1 = await ERC721 . tokenURI ( 1 ) ;
65
- const token2 = await ERC721 . tokenURI ( 2 ) ;
66
- const token3 = await ERC721 . tokenURI ( 3 ) ;
63
+ // const token0 = await ERC721.tokenURI(0);
64
+ // const token1 = await ERC721.tokenURI(1);
65
+ // const token2 = await ERC721.tokenURI(2);
66
+ // const token3 = await ERC721.tokenURI(3);
67
67
68
68
// console.log({ token0, token1, token2, token3 });
69
69
@@ -72,11 +72,11 @@ describe("Lease", function () {
72
72
expect ( ethers . formatEther ( price ) ) . to . equal ( "0.5" ) ;
73
73
74
74
// check approval for all
75
- await expect ( ERC721 . connect ( owner ) . setApprovalForAll ( signer . address , true ) )
75
+ await expect ( ERC721 . connect ( author ) . setApprovalForAll ( operator . address , true ) )
76
76
. to . emit ( ERC721 , "ApprovalForAll" )
77
- . withArgs ( owner . address , signer . address , true ) ;
77
+ . withArgs ( author . address , operator . address , true ) ;
78
78
79
- const isApprovedForAll = await ERC721 . isApprovedForAll ( owner . address , signer . address ) ;
79
+ const isApprovedForAll = await ERC721 . isApprovedForAll ( author . address , operator . address ) ;
80
80
expect ( isApprovedForAll ) . to . be . true ;
81
81
} ) ;
82
82
@@ -90,30 +90,111 @@ describe("Lease", function () {
90
90
expect ( ethers . formatEther ( price ) ) . to . equal ( "0.5" ) ;
91
91
} ) ;
92
92
93
+ it ( "royaltyInfo" , async function ( ) {
94
+ const [ author ] = await ethers . getSigners ( ) ;
95
+
96
+ const ERC721 = await createERC721Contract ( ) ;
97
+
98
+ const price = await ERC721 . getTokenPrice ( 0 ) ;
99
+
100
+ const royaltyInfo = await ERC721 . royaltyInfo ( 0 , price ) ;
101
+
102
+ // console.log({ price: ethers.formatEther(price), royaltyInfo });
103
+
104
+ const [ receiver , royaltyAmount ] = royaltyInfo ;
105
+
106
+ expect ( ethers . formatEther ( royaltyAmount ) ) . to . equal ( "0.0005" ) ;
107
+ expect ( receiver ) . to . equal ( author . address ) ;
108
+ } ) ;
109
+
93
110
it ( "setTokenForSale" , async function ( ) {
94
- const [ owner , , signer , someoneElse ] = await ethers . getSigners ( ) ;
111
+ const [ author , , operator , someoneElse ] = await ethers . getSigners ( ) ;
95
112
96
113
const ERC721 = await createERC721Contract ( ) ;
97
114
98
- await ERC721 . connect ( owner ) . setApprovalForAll ( signer . address , true ) ;
115
+ await ERC721 . connect ( author ) . setApprovalForAll ( operator . address , true ) ;
99
116
100
- await ERC721 . connect ( signer ) . setTokenForSale ( owner . address , 0 , BigInt ( ethers . parseEther ( "0.6" ) ) ) ;
117
+ await ERC721 . connect ( operator ) . setTokenForSale ( 0 , BigInt ( ethers . parseEther ( "0.6" ) ) ) ;
101
118
102
119
const price1 = await ERC721 . getTokenPrice ( 0 ) ;
103
120
104
- console . log ( { price1 : ethers . formatEther ( price1 ) } ) ;
121
+ // console.log({ price1: ethers.formatEther(price1) });
105
122
106
123
expect ( ethers . formatEther ( price1 ) ) . to . equal ( "0.6" ) ;
107
124
108
- await ERC721 . connect ( owner ) . setTokenForSale ( owner . address , 1 , BigInt ( ethers . parseEther ( "0.6" ) ) ) ;
125
+ await ERC721 . connect ( author ) . setTokenForSale ( 1 , BigInt ( ethers . parseEther ( "0.6" ) ) ) ;
109
126
110
127
const price2 = await ERC721 . getTokenPrice ( 0 ) ;
111
128
112
- console . log ( { price2 : ethers . formatEther ( price2 ) } ) ;
129
+ // console.log({ price2: ethers.formatEther(price2) });
113
130
114
131
expect ( ethers . formatEther ( price2 ) ) . to . equal ( "0.6" ) ;
115
132
116
- await expect ( ERC721 . connect ( someoneElse ) . setTokenForSale ( owner . address , 2 , BigInt ( ethers . parseEther ( "0.6" ) ) ) ) . to . be
117
- . reverted ;
133
+ await expect ( ERC721 . connect ( someoneElse ) . setTokenForSale ( 2 , BigInt ( ethers . parseEther ( "0.6" ) ) ) ) . to . be . reverted ;
134
+ } ) ;
135
+
136
+ it ( "buyToken" , async function ( ) {
137
+ const [ author , , operator , buyer ] = await ethers . getSigners ( ) ;
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 ) ;
142
+
143
+ console . log ( {
144
+ authorBalance : ethers . formatEther ( authorBalance ) ,
145
+ operatorBalance : ethers . formatEther ( operatorBalance ) ,
146
+ buyerBalance : ethers . formatEther ( buyerBalance ) ,
147
+ } ) ;
148
+
149
+ const ERC721 = await createERC721Contract ( ) ;
150
+
151
+ await ERC721 . connect ( author ) . setApprovalForAll ( operator . address , true ) ;
152
+
153
+ await ERC721 . connect ( operator ) . setTokenForSale ( 0 , BigInt ( ethers . parseEther ( "1" ) ) ) ;
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 ) ;
158
+
159
+ console . log ( {
160
+ authorBalance : ethers . formatEther ( authorBalance ) ,
161
+ operatorBalance : ethers . formatEther ( operatorBalance ) ,
162
+ buyerBalance : ethers . formatEther ( buyerBalance ) ,
163
+ } ) ;
164
+
165
+ ERC721 . on ( "Transfer" , ( from , to , tokenId ) => {
166
+ // console.log({ from, to, tokenId });
167
+ expect ( from ) . to . equal ( author . address ) ;
168
+ expect ( to ) . to . equal ( buyer . address ) ;
169
+ expect ( tokenId ) . to . equal ( 0 ) ;
170
+ } ) ;
171
+
172
+ await expect ( ERC721 . connect ( buyer ) . buyToken ( 0 , { value : ethers . parseEther ( "1" ) } ) )
173
+ . to . emit ( ERC721 , "Purchase" )
174
+ . withArgs (
175
+ author . address ,
176
+ buyer . address ,
177
+ BigInt ( 0 ) ,
178
+ ethers . parseEther ( "1" ) ,
179
+ ethers . parseEther ( "0.001" ) ,
180
+ ethers . parseEther ( "0.0003" ) ,
181
+ ethers . parseEther ( "0.9987" ) ,
182
+ ) ;
183
+
184
+ const ownerOf0 = await ERC721 . ownerOf ( 0 ) ;
185
+
186
+ // console.log({ ownerOf0 });
187
+
188
+ expect ( ownerOf0 ) . to . equal ( buyer . address ) ;
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 ) ;
193
+
194
+ console . log ( {
195
+ authorBalance : ethers . formatEther ( authorBalance ) ,
196
+ operatorBalance : ethers . formatEther ( operatorBalance ) ,
197
+ buyerBalance : ethers . formatEther ( buyerBalance ) ,
198
+ } ) ;
118
199
} ) ;
119
200
} ) ;
0 commit comments