@@ -139,89 +139,89 @@ func TestCreateAndLockEscrow_Success(t *testing.T) {
139139 t .Log ("✓ Escrow created and funds locked successfully" )
140140}
141141
142- // func TestCreateAndLockEscrow_InsufficientBalance(t *testing.T) {
143- // wrapper, mockStub := testutils.NewMockStubWrapper()
144- // fixtures := testutils.NewTestFixtures()
145- //
146- // // Setup: Create digital asset
147- // err := fixtures.CreateMockDigitalAsset(
148- // mockStub,
149- // fixtures.AssetID,
150- // fixtures.AssetSymbol,
151- // fixtures.AssetName,
152- // fixtures.IssuerCertHash,
153- // 1000.0,
154- // )
155- // if err != nil {
156- // t.Fatalf("Failed to create mock digital asset: %v", err)
157- // }
158- //
159- // // Setup: Create buyer wallet with insufficient balance
160- // err = fixtures.CreateMockWallet(
161- // mockStub,
162- // fixtures.BuyerPubKey,
163- // fixtures.BuyerCertHash,
164- // fixtures.BuyerWalletID,
165- // fixtures.BuyerWalletUUID,
166- // fixtures.AssetID,
167- // 50.0, // only 50 available
168- // 0.0,
169- // )
170- // if err != nil {
171- // t.Fatalf("Failed to create buyer wallet: %v", err)
172- // }
173- //
174- // err = fixtures.CreateMockUserDir(
175- // mockStub,
176- // fixtures.BuyerPubKeyHash,
177- // fixtures.BuyerWalletUUID,
178- // fixtures.BuyerCertHash,
179- // )
180- // if err != nil {
181- // t.Fatalf("Failed to create buyer user directory: %v", err)
182- // }
183- //
184- // // Setup: Create seller wallet and directory
185- // err = fixtures.CreateMockWallet(
186- // mockStub,
187- // fixtures.SellerPubKey,
188- // fixtures.SellerCertHash,
189- // fixtures.SellerWalletID,
190- // fixtures.SellerWalletUUID,
191- // fixtures.AssetID,
192- // 0.0,
193- // 0.0,
194- // )
195- // if err != nil {
196- // t.Fatalf("Failed to create seller wallet: %v", err)
197- // }
198- //
199- // err = fixtures.CreateMockUserDir(
200- // mockStub,
201- // fixtures.SellerPubKeyHash,
202- // fixtures.SellerWalletUUID,
203- // fixtures.SellerCertHash,
204- // )
205- // if err != nil {
206- // t.Fatalf("Failed to create seller user directory: %v", err)
207- // }
208- //
209- // // Try to lock more than available
210- // args := map[string]any{
211- // "escrowId": fixtures.EscrowID,
212- // "buyerPubKey": fixtures.BuyerPubKey,
213- // "sellerPubKey": fixtures.SellerPubKey,
214- // "amount": 100.0, // trying to lock 100 but only have 50
215- // "assetType": assets.Key{"@key": "digitalAsset:" + fixtures.AssetID},
216- // "parcelId": fixtures.ParcelID,
217- // "secret": fixtures.Secret,
218- // "buyerCertHash": fixtures.BuyerCertHash,
219- // }
220- //
221- // _, txErr := CreateAndLockEscrow.Routine(wrapper.StubWrapper, args)
222- // testutils.AssertError(t, txErr, "should fail with insufficient balance")
223- // testutils.AssertErrorStatus(t, txErr, 400, "should return 400 status")
224- // }
142+ func TestCreateAndLockEscrow_InsufficientBalance (t * testing.T ) {
143+ wrapper , mockStub := testutils .NewMockStubWrapper ()
144+ fixtures := testutils .NewTestFixtures ()
145+
146+ // Setup: Create digital asset
147+ err := fixtures .CreateMockDigitalAsset (
148+ mockStub ,
149+ fixtures .AssetID ,
150+ fixtures .AssetSymbol ,
151+ fixtures .AssetName ,
152+ fixtures .IssuerCertHash ,
153+ 1000.0 ,
154+ )
155+ if err != nil {
156+ t .Fatalf ("Failed to create mock digital asset: %v" , err )
157+ }
158+
159+ // Setup: Create buyer wallet with insufficient balance
160+ err = fixtures .CreateMockWallet (
161+ mockStub ,
162+ fixtures .BuyerPubKey ,
163+ fixtures .BuyerCertHash ,
164+ fixtures .BuyerWalletID ,
165+ fixtures .BuyerWalletUUID ,
166+ fixtures .AssetID ,
167+ 50.0 , // only 50 available
168+ 0.0 ,
169+ )
170+ if err != nil {
171+ t .Fatalf ("Failed to create buyer wallet: %v" , err )
172+ }
173+
174+ err = fixtures .CreateMockUserDir (
175+ mockStub ,
176+ fixtures .BuyerPubKeyHash ,
177+ fixtures .BuyerWalletUUID ,
178+ fixtures .BuyerCertHash ,
179+ )
180+ if err != nil {
181+ t .Fatalf ("Failed to create buyer user directory: %v" , err )
182+ }
183+
184+ // Setup: Create seller wallet and directory
185+ err = fixtures .CreateMockWallet (
186+ mockStub ,
187+ fixtures .SellerPubKey ,
188+ fixtures .SellerCertHash ,
189+ fixtures .SellerWalletID ,
190+ fixtures .SellerWalletUUID ,
191+ fixtures .AssetID ,
192+ 0.0 ,
193+ 0.0 ,
194+ )
195+ if err != nil {
196+ t .Fatalf ("Failed to create seller wallet: %v" , err )
197+ }
198+
199+ err = fixtures .CreateMockUserDir (
200+ mockStub ,
201+ fixtures .SellerPubKeyHash ,
202+ fixtures .SellerWalletUUID ,
203+ fixtures .SellerCertHash ,
204+ )
205+ if err != nil {
206+ t .Fatalf ("Failed to create seller user directory: %v" , err )
207+ }
208+
209+ // Try to lock more than available
210+ args := map [string ]any {
211+ "escrowId" : fixtures .EscrowID ,
212+ "buyerPubKey" : fixtures .BuyerPubKey ,
213+ "sellerPubKey" : fixtures .SellerPubKey ,
214+ "amount" : 100.0 , // trying to lock 100 but only have 50
215+ "assetType" : assets.Key {"@key" : "digitalAsset:" + fixtures .AssetID },
216+ "parcelId" : fixtures .ParcelID ,
217+ "secret" : fixtures .Secret ,
218+ "buyerCertHash" : fixtures .BuyerCertHash ,
219+ }
220+
221+ _ , txErr := CreateAndLockEscrow .Routine (wrapper .StubWrapper , args )
222+ testutils .AssertError (t , txErr , "should fail with insufficient balance" )
223+ testutils .AssertErrorStatus (t , txErr , 400 , "should return 400 status" )
224+ }
225225
226226func TestCreateAndLockEscrow_BuyerWalletNotFound (t * testing.T ) {
227227 wrapper , _ := testutils .NewMockStubWrapper ()
0 commit comments