code.vegaprotocol.io/vega@v0.79.0/commands/cancel_amm_test.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package commands_test
    17  
    18  import (
    19  	"errors"
    20  	"testing"
    21  
    22  	"code.vegaprotocol.io/vega/commands"
    23  	commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
    24  
    25  	"github.com/stretchr/testify/assert"
    26  )
    27  
    28  func TestCheckCancelAMM(t *testing.T) {
    29  	cases := []struct {
    30  		submission commandspb.CancelAMM
    31  		errStr     string
    32  	}{
    33  		{
    34  			submission: commandspb.CancelAMM{},
    35  			errStr:     "cancel_amm.market_id (is required)",
    36  		},
    37  		{
    38  			submission: commandspb.CancelAMM{
    39  				MarketId: "notavalidmarketid",
    40  				Method:   commandspb.CancelAMM_METHOD_IMMEDIATE,
    41  			},
    42  			errStr: "cancel_amm.market_id (should be a valid Vega ID)",
    43  		},
    44  		{
    45  			submission: commandspb.CancelAMM{
    46  				MarketId: "e9982447fb4128f9968f9981612c5ea85d19b62058ec2636efc812dcbbc745ca",
    47  				Method:   commandspb.CancelAMM_METHOD_IMMEDIATE,
    48  			},
    49  		},
    50  		{
    51  			submission: commandspb.CancelAMM{
    52  				MarketId: "e9982447fb4128f9968f9981612c5ea85d19b62058ec2636efc812dcbbc745ca",
    53  				Method:   commandspb.CancelAMM_METHOD_UNSPECIFIED,
    54  			},
    55  			errStr: "cancel_amm.method (is required)",
    56  		},
    57  		{
    58  			submission: commandspb.CancelAMM{
    59  				MarketId: "e9982447fb4128f9968f9981612c5ea85d19b62058ec2636efc812dcbbc745ca",
    60  				Method:   commandspb.CancelAMM_Method(999),
    61  			},
    62  			errStr: "cancel_amm.method (is not a valid value)",
    63  		},
    64  	}
    65  
    66  	for n, c := range cases {
    67  		if len(c.errStr) <= 0 {
    68  			assert.NoError(t, commands.CheckCancelAMM(&c.submission), n)
    69  			continue
    70  		}
    71  
    72  		assert.Contains(t, checkCancelAMM(&c.submission).Error(), c.errStr, n)
    73  	}
    74  }
    75  
    76  func checkCancelAMM(cmd *commandspb.CancelAMM) commands.Errors {
    77  	err := commands.CheckCancelAMM(cmd)
    78  
    79  	var e commands.Errors
    80  	if ok := errors.As(err, &e); !ok {
    81  		return commands.NewErrors()
    82  	}
    83  
    84  	return e
    85  }