code.vegaprotocol.io/vega@v0.79.0/commands/key_rotate_submission_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 TestSubmittingNoKeyRotateSubmissionCommandFails(t *testing.T) { 29 err := checkKeyRotateSubmission(nil) 30 31 assert.Contains(t, err.Get("key_rotate_submission"), commands.ErrIsRequired) 32 } 33 34 func TestKeyRotateSubmissionSubmittingEmptyCommandFails(t *testing.T) { 35 err := checkKeyRotateSubmission(&commandspb.KeyRotateSubmission{}) 36 37 assert.Contains(t, err.Get("key_rotate_submission.new_pub_key"), commands.ErrIsRequired) 38 assert.Contains(t, err.Get("key_rotate_submission.new_pub_key_index"), commands.ErrIsRequired) 39 assert.Contains(t, err.Get("key_rotate_submission.current_pub_key_hash"), commands.ErrIsRequired) 40 assert.Contains(t, err.Get("key_rotate_submission.target_block"), commands.ErrIsRequired) 41 } 42 43 func TestKeyRotateSubmissionMissingNewPubKeyFails(t *testing.T) { 44 err := checkKeyRotateSubmission(&commandspb.KeyRotateSubmission{ 45 NewPubKeyIndex: 10, 46 TargetBlock: 100, 47 CurrentPubKeyHash: "w3werertdg", 48 }) 49 50 assert.Contains(t, err.Get("key_rotate_submission.new_pub_key"), commands.ErrIsRequired) 51 } 52 53 func TestKeyRotateSubmissionMissingNewPubKeyIndexFails(t *testing.T) { 54 err := checkKeyRotateSubmission(&commandspb.KeyRotateSubmission{ 55 NewPubKey: "123456789abcdef", 56 TargetBlock: 100, 57 CurrentPubKeyHash: "w3werertdg", 58 }) 59 60 assert.Contains(t, err.Get("key_rotate_submission.new_pub_key_index"), commands.ErrIsRequired) 61 } 62 63 func TestKeyRotateSubmissionMissingCurrentPubKeyHashFails(t *testing.T) { 64 err := checkKeyRotateSubmission(&commandspb.KeyRotateSubmission{ 65 NewPubKey: "123456789abcdef", 66 NewPubKeyIndex: 10, 67 TargetBlock: 100, 68 }) 69 70 assert.Contains(t, err.Get("key_rotate_submission.current_pub_key_hash"), commands.ErrIsRequired) 71 } 72 73 func TestKeyRotateSubmissionMissingTargetBlockFails(t *testing.T) { 74 err := checkKeyRotateSubmission(&commandspb.KeyRotateSubmission{ 75 NewPubKey: "123456789abcdef", 76 NewPubKeyIndex: 10, 77 CurrentPubKeyHash: "w3werertdg", 78 }) 79 80 assert.Contains(t, err.Get("key_rotate_submission.target_block"), commands.ErrIsRequired) 81 } 82 83 func TestSubmittingEmptyCommandSuccess(t *testing.T) { 84 err := checkKeyRotateSubmission(&commandspb.KeyRotateSubmission{ 85 NewPubKeyIndex: 10, 86 NewPubKey: "123456789abcdef", 87 TargetBlock: 100, 88 CurrentPubKeyHash: "w3werertdg", 89 }) 90 91 assert.True(t, err.Empty()) 92 } 93 94 func checkKeyRotateSubmission(cmd *commandspb.KeyRotateSubmission) commands.Errors { 95 err := commands.CheckKeyRotateSubmission(cmd) 96 97 var e commands.Errors 98 if ok := errors.As(err, &e); !ok { 99 return commands.NewErrors() 100 } 101 return e 102 }