code.vegaprotocol.io/vega@v0.79.0/commands/proposal_submission_for_update_network_parameter_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  	"testing"
    20  
    21  	"code.vegaprotocol.io/vega/commands"
    22  	types "code.vegaprotocol.io/vega/protos/vega"
    23  	commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
    24  
    25  	"github.com/stretchr/testify/assert"
    26  )
    27  
    28  func TestCheckProposalSubmissionForNetworkParameterUpdate(t *testing.T) {
    29  	t.Run("Submitting a network parameter changes without network parameter fails", testNetworkParameterChangeSubmissionWithoutNetworkParameterFails)
    30  	t.Run("Submitting a network parameter changes without changes fails", testNetworkParameterChangeSubmissionWithoutChangesFails)
    31  	t.Run("Submitting a network parameter change without key fails", testNetworkParameterChangeSubmissionWithoutKeyFails)
    32  	t.Run("Submitting a network parameter change with key succeeds", testNetworkParameterChangeSubmissionWithKeySucceeds)
    33  	t.Run("Submitting a network parameter change without value fails", testNetworkParameterChangeSubmissionWithoutValueFails)
    34  	t.Run("Submitting a network parameter change with value succeeds", testNetworkParameterChangeSubmissionWithValueSucceeds)
    35  }
    36  
    37  func testNetworkParameterChangeSubmissionWithoutNetworkParameterFails(t *testing.T) {
    38  	err := checkProposalSubmission(&commandspb.ProposalSubmission{
    39  		Terms: &types.ProposalTerms{
    40  			Change: &types.ProposalTerms_UpdateNetworkParameter{},
    41  		},
    42  	})
    43  
    44  	assert.Contains(t, err.Get("proposal_submission.terms.change.update_network_parameter"), commands.ErrIsRequired)
    45  }
    46  
    47  func testNetworkParameterChangeSubmissionWithoutChangesFails(t *testing.T) {
    48  	err := checkProposalSubmission(&commandspb.ProposalSubmission{
    49  		Terms: &types.ProposalTerms{
    50  			Change: &types.ProposalTerms_UpdateNetworkParameter{
    51  				UpdateNetworkParameter: &types.UpdateNetworkParameter{},
    52  			},
    53  		},
    54  	})
    55  
    56  	assert.Contains(t, err.Get("proposal_submission.terms.change.update_network_parameter.changes"), commands.ErrIsRequired)
    57  }
    58  
    59  func testNetworkParameterChangeSubmissionWithoutKeyFails(t *testing.T) {
    60  	err := checkProposalSubmission(&commandspb.ProposalSubmission{
    61  		Terms: &types.ProposalTerms{
    62  			Change: &types.ProposalTerms_UpdateNetworkParameter{
    63  				UpdateNetworkParameter: &types.UpdateNetworkParameter{
    64  					Changes: &types.NetworkParameter{
    65  						Key: "",
    66  					},
    67  				},
    68  			},
    69  		},
    70  	})
    71  
    72  	assert.Contains(t, err.Get("proposal_submission.terms.change.update_network_parameter.changes.key"), commands.ErrIsRequired)
    73  }
    74  
    75  func testNetworkParameterChangeSubmissionWithKeySucceeds(t *testing.T) {
    76  	err := checkProposalSubmission(&commandspb.ProposalSubmission{
    77  		Terms: &types.ProposalTerms{
    78  			Change: &types.ProposalTerms_UpdateNetworkParameter{
    79  				UpdateNetworkParameter: &types.UpdateNetworkParameter{
    80  					Changes: &types.NetworkParameter{
    81  						Key: "My key",
    82  					},
    83  				},
    84  			},
    85  		},
    86  	})
    87  
    88  	assert.NotContains(t, err.Get("proposal_submission.terms.change.update_network_parameter.changes.key"), commands.ErrIsRequired)
    89  }
    90  
    91  func testNetworkParameterChangeSubmissionWithoutValueFails(t *testing.T) {
    92  	err := checkProposalSubmission(&commandspb.ProposalSubmission{
    93  		Terms: &types.ProposalTerms{
    94  			Change: &types.ProposalTerms_UpdateNetworkParameter{
    95  				UpdateNetworkParameter: &types.UpdateNetworkParameter{
    96  					Changes: &types.NetworkParameter{
    97  						Value: "",
    98  					},
    99  				},
   100  			},
   101  		},
   102  	})
   103  
   104  	assert.Contains(t, err.Get("proposal_submission.terms.change.update_network_parameter.changes.value"), commands.ErrIsRequired)
   105  }
   106  
   107  func testNetworkParameterChangeSubmissionWithValueSucceeds(t *testing.T) {
   108  	err := checkProposalSubmission(&commandspb.ProposalSubmission{
   109  		Terms: &types.ProposalTerms{
   110  			Change: &types.ProposalTerms_UpdateNetworkParameter{
   111  				UpdateNetworkParameter: &types.UpdateNetworkParameter{
   112  					Changes: &types.NetworkParameter{
   113  						Value: "My value",
   114  					},
   115  				},
   116  			},
   117  		},
   118  	})
   119  
   120  	assert.NotContains(t, err.Get("proposal_submission.terms.change.update_network_parameter.changes.value"), commands.ErrIsRequired)
   121  }