@@ -290,10 +290,73 @@ func TestDepositStake(t *testing.T) {
290290 }
291291 })
292292
293- t .Run ("insufficient stake amount" , func (t * testing.T ) {
293+ t .Run ("sufficient stake amount extra height " , func (t * testing.T ) {
294294 t .Parallel ()
295295
296- totalAmount := big .NewInt (0 )
296+ balance := big .NewInt (0 ).Mul (staking .MinimumStakeAmount , big .NewInt (2 ))
297+ prevStake := staking .MinimumStakeAmount
298+
299+ expectedCallData , err := stakingContractABI .Pack ("manageStake" , nonce , staking .MinimumStakeAmount , stakingHeight )
300+ if err != nil {
301+ t .Fatal (err )
302+ }
303+
304+ contract := staking .New (
305+ owner ,
306+ stakingContractAddress ,
307+ stakingContractABI ,
308+ bzzTokenAddress ,
309+ transactionMock .New (
310+ transactionMock .WithSendFunc (func (ctx context.Context , request * transaction.TxRequest , boost int ) (txHash common.Hash , err error ) {
311+ if * request .To == bzzTokenAddress {
312+ return txHashApprove , nil
313+ }
314+ if * request .To == stakingContractAddress {
315+ if ! bytes .Equal (expectedCallData [:80 ], request .Data [:80 ]) {
316+ return common.Hash {}, fmt .Errorf ("got wrong call data. wanted %x, got %x" , expectedCallData , request .Data )
317+ }
318+ return txHashDeposited , nil
319+ }
320+ return common.Hash {}, errors .New ("sent to wrong contract" )
321+ }),
322+ transactionMock .WithWaitForReceiptFunc (func (ctx context.Context , txHash common.Hash ) (receipt * types.Receipt , err error ) {
323+ if txHash == txHashDeposited {
324+ return & types.Receipt {
325+ Status : 1 ,
326+ }, nil
327+ }
328+ if txHash == txHashApprove {
329+ return & types.Receipt {
330+ Status : 1 ,
331+ }, nil
332+ }
333+ return nil , errors .New ("unknown tx hash" )
334+ }),
335+ transactionMock .WithCallFunc (func (ctx context.Context , request * transaction.TxRequest ) (result []byte , err error ) {
336+ if * request .To == bzzTokenAddress {
337+ return balance .FillBytes (make ([]byte , 32 )), nil
338+ }
339+ if * request .To == stakingContractAddress {
340+ return getPotentialStakeResponse (t , prevStake ), nil
341+ }
342+ return nil , errors .New ("unexpected call" )
343+ }),
344+ ),
345+ nonce ,
346+ false ,
347+ 1 ,
348+ )
349+
350+ _ , err = contract .DepositStake (ctx , stakedAmount )
351+ if err != nil {
352+ t .Fatal (err )
353+ }
354+ })
355+
356+ t .Run ("insufficient stake amount extra height" , func (t * testing.T ) {
357+ t .Parallel ()
358+
359+ totalAmount := big .NewInt (0 ).Mul (staking .MinimumStakeAmount , big .NewInt (10 ))
297360 prevStake := big .NewInt (0 )
298361
299362 contract := staking .New (
@@ -314,11 +377,11 @@ func TestDepositStake(t *testing.T) {
314377 ),
315378 nonce ,
316379 false ,
317- stakingHeight ,
380+ 1 ,
318381 )
319382
320- _ , err := contract .DepositStake (ctx , big . NewInt ( 100000000000000000 ) )
321- if ! errors .Is (err , staking .ErrInsufficientFunds ) {
383+ _ , err := contract .DepositStake (ctx , stakedAmount )
384+ if ! errors .Is (err , staking .ErrInsufficientStakeAmount ) {
322385 t .Fatal (fmt .Errorf ("wanted %w, got %w" , staking .ErrInsufficientStakeAmount , err ))
323386 }
324387 })
0 commit comments