@@ -4,17 +4,27 @@ namespace Thirdweb.Tests.Extensions;
44
55public class MarketplaceExtensionsTests : BaseTests
66{
7- private readonly string _marketplaceContractAddress = "0xc9671F631E8313D53ec0b5358e1a499c574fCe6A" ;
7+ private readonly string _marketplaceContractAddress = "0xb80E83b73571e63b3581b68f20bFC9E97965F329" ;
8+ private readonly string _drop1155ContractAddress = "0x37116cAe5e152C1A7345AAB0EC286Ff6E97c0605" ;
89
910 private readonly BigInteger _chainId = 421614 ;
1011
1112 public MarketplaceExtensionsTests ( ITestOutputHelper output )
1213 : base ( output ) { }
1314
14- private async Task < IThirdwebWallet > GetSmartWallet ( )
15+ private async Task < IThirdwebWallet > GetSmartWallet ( int claimAmount )
1516 {
1617 var privateKeyWallet = await PrivateKeyWallet . Generate ( this . Client ) ;
17- return await SmartWallet . Create ( personalWallet : privateKeyWallet , chainId : 421614 ) ;
18+ var smartWallet = await SmartWallet . Create ( personalWallet : privateKeyWallet , chainId : 421614 ) ;
19+
20+ if ( claimAmount > 0 )
21+ {
22+ var drop1155Contract = await ThirdwebContract . Create ( this . Client , this . _drop1155ContractAddress , this . _chainId ) ;
23+ var tokenId = 0 ;
24+ _ = await drop1155Contract . DropERC1155_Claim ( smartWallet , await smartWallet . GetAddress ( ) , tokenId , claimAmount ) ;
25+ }
26+
27+ return smartWallet ;
1828 }
1929
2030 private async Task < ThirdwebContract > GetMarketplaceContract ( )
@@ -24,6 +34,155 @@ private async Task<ThirdwebContract> GetMarketplaceContract()
2434
2535 #region IDirectListings
2636
37+ [ Fact ( Timeout = 120000 ) ]
38+ public async Task Marketplace_DirectListings_CreateListing_Success ( )
39+ {
40+ var contract = await this . GetMarketplaceContract ( ) ;
41+ var wallet = await this . GetSmartWallet ( 1 ) ;
42+
43+ var listingParams = new ListingParameters ( )
44+ {
45+ AssetContract = this . _drop1155ContractAddress ,
46+ TokenId = 0 ,
47+ Quantity = 1 ,
48+ Currency = Constants . NATIVE_TOKEN_ADDRESS ,
49+ PricePerToken = 1 ,
50+ StartTimestamp = Utils . GetUnixTimeStampNow ( ) ,
51+ EndTimestamp = Utils . GetUnixTimeStampNow ( ) + 3600 ,
52+ Reserved = false
53+ } ;
54+
55+ var receipt = await contract . Marketplace_DirectListings_CreateListing ( wallet , listingParams , true ) ;
56+
57+ Assert . NotNull ( receipt ) ;
58+ Assert . True ( receipt . TransactionHash . Length == 66 ) ;
59+
60+ var listingId = await contract . Marketplace_DirectListings_TotalListings ( ) - 1 ;
61+ var listing = await contract . Marketplace_DirectListings_GetListing ( listingId ) ;
62+
63+ Assert . NotNull ( listing ) ;
64+ Assert . Equal ( listing . ListingId , listingId ) ;
65+ Assert . Equal ( listing . TokenId , listingParams . TokenId ) ;
66+ Assert . Equal ( listing . Quantity , listingParams . Quantity ) ;
67+ Assert . Equal ( listing . PricePerToken , listingParams . PricePerToken ) ;
68+ Assert . True ( listing . StartTimestamp >= listingParams . StartTimestamp ) ;
69+ Assert . True ( listing . EndTimestamp >= listingParams . EndTimestamp ) ;
70+ Assert . Equal ( listing . ListingCreator , await wallet . GetAddress ( ) ) ;
71+ Assert . Equal ( listing . AssetContract , listingParams . AssetContract ) ;
72+ Assert . Equal ( listing . Currency , listingParams . Currency ) ;
73+ Assert . Equal ( TokenType . ERC1155 , listing . TokenTypeEnum ) ;
74+ Assert . Equal ( Status . CREATED , listing . StatusEnum ) ;
75+ Assert . Equal ( listing . Reserved , listingParams . Reserved ) ;
76+
77+ var isCurrencyApproved = await contract . Marketplace_DirectListings_IsCurrencyApprovedForListing ( listingId , Constants . NATIVE_TOKEN_ADDRESS ) ;
78+ Assert . True ( isCurrencyApproved ) ;
79+
80+ var currencyPriceForListing = await contract . Marketplace_DirectListings_CurrencyPriceForListing ( listingId , Constants . NATIVE_TOKEN_ADDRESS ) ;
81+ Assert . Equal ( currencyPriceForListing , listingParams . PricePerToken ) ;
82+ }
83+
84+ [ Fact ( Timeout = 120000 ) ]
85+ public async Task Marketplace_DirectListings_UpdateListing_Success ( )
86+ {
87+ var contract = await this . GetMarketplaceContract ( ) ;
88+ var wallet = await this . GetSmartWallet ( 1 ) ;
89+
90+ var originalTotal = await contract . Marketplace_DirectListings_TotalListings ( ) ;
91+
92+ var originalListing = new ListingParameters ( )
93+ {
94+ AssetContract = this . _drop1155ContractAddress ,
95+ TokenId = 0 ,
96+ Quantity = 1 ,
97+ Currency = Constants . NATIVE_TOKEN_ADDRESS ,
98+ PricePerToken = 1 ,
99+ StartTimestamp = Utils . GetUnixTimeStampNow ( ) + 1800 ,
100+ EndTimestamp = Utils . GetUnixTimeStampNow ( ) + 3600 ,
101+ Reserved = false
102+ } ;
103+
104+ var receipt = await contract . Marketplace_DirectListings_CreateListing ( wallet , originalListing , true ) ;
105+ Assert . NotNull ( receipt ) ;
106+
107+ var listingId = await contract . Marketplace_DirectListings_TotalListings ( ) - 1 ;
108+ Assert . True ( listingId == originalTotal ) ;
109+
110+ var updatedListingParams = originalListing ;
111+ updatedListingParams . PricePerToken = 2 ;
112+
113+ var updatedReceipt = await contract . Marketplace_DirectListings_UpdateListing ( wallet , listingId , updatedListingParams ) ;
114+ Assert . NotNull ( updatedReceipt ) ;
115+ Assert . True ( updatedReceipt . TransactionHash . Length == 66 ) ;
116+
117+ var listing = await contract . Marketplace_DirectListings_GetListing ( listingId ) ;
118+ Assert . NotNull ( listing ) ;
119+ Assert . Equal ( listing . PricePerToken , 2 ) ;
120+ }
121+
122+ [ Fact ( Timeout = 120000 ) ]
123+ public async Task Marketplace_DirectListings_CancelListing_Success ( )
124+ {
125+ var contract = await this . GetMarketplaceContract ( ) ;
126+ var wallet = await this . GetSmartWallet ( 1 ) ;
127+
128+ var originalTotal = await contract . Marketplace_DirectListings_TotalListings ( ) ;
129+
130+ var originalListing = new ListingParameters ( )
131+ {
132+ AssetContract = this . _drop1155ContractAddress ,
133+ TokenId = 0 ,
134+ Quantity = 1 ,
135+ Currency = Constants . NATIVE_TOKEN_ADDRESS ,
136+ PricePerToken = 1 ,
137+ StartTimestamp = Utils . GetUnixTimeStampNow ( ) + 1800 ,
138+ EndTimestamp = Utils . GetUnixTimeStampNow ( ) + 3600 ,
139+ Reserved = false
140+ } ;
141+
142+ var receipt = await contract . Marketplace_DirectListings_CreateListing ( wallet , originalListing , true ) ;
143+ Assert . NotNull ( receipt ) ;
144+
145+ var listingId = await contract . Marketplace_DirectListings_TotalListings ( ) - 1 ;
146+ Assert . True ( listingId == originalTotal ) ;
147+
148+ var removeReceipt = await contract . Marketplace_DirectListings_CancelListing ( wallet , listingId ) ;
149+ Assert . NotNull ( removeReceipt ) ;
150+ Assert . True ( removeReceipt . TransactionHash . Length == 66 ) ;
151+ }
152+
153+ [ Fact ( Timeout = 120000 ) ]
154+ public async Task Marketplace_DirectListings_ApproveBuyerForListing ( )
155+ {
156+ var contract = await this . GetMarketplaceContract ( ) ;
157+ var wallet = await this . GetSmartWallet ( 1 ) ;
158+
159+ var reservedListing = new ListingParameters ( )
160+ {
161+ AssetContract = this . _drop1155ContractAddress ,
162+ TokenId = 0 ,
163+ Quantity = 1 ,
164+ Currency = Constants . NATIVE_TOKEN_ADDRESS ,
165+ PricePerToken = 1 ,
166+ StartTimestamp = Utils . GetUnixTimeStampNow ( ) ,
167+ EndTimestamp = Utils . GetUnixTimeStampNow ( ) + 3600 ,
168+ Reserved = true
169+ } ;
170+
171+ var receipt = await contract . Marketplace_DirectListings_CreateListing ( wallet , reservedListing , true ) ;
172+ Assert . NotNull ( receipt ) ;
173+ Assert . True ( receipt . TransactionHash . Length == 66 ) ;
174+
175+ var listingId = await contract . Marketplace_DirectListings_TotalListings ( ) - 1 ;
176+
177+ var buyer = await PrivateKeyWallet . Generate ( this . Client ) ;
178+ var approveReceipt = await contract . Marketplace_DirectListings_ApproveBuyerForListing ( wallet , listingId , await buyer . GetAddress ( ) , true ) ;
179+ Assert . NotNull ( approveReceipt ) ;
180+ Assert . True ( approveReceipt . TransactionHash . Length == 66 ) ;
181+
182+ var isApproved = await contract . Marketplace_DirectListings_IsBuyerApprovedForListing ( listingId , await buyer . GetAddress ( ) ) ;
183+ Assert . True ( isApproved ) ;
184+ }
185+
27186 [ Fact ( Timeout = 120000 ) ]
28187 public async Task Marketplace_DirectListings_TotalListings_Success ( )
29188 {
0 commit comments