github.com/MetalBlockchain/metalgo@v1.11.9/vms/secp256k1fx/input_test.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package secp256k1fx 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestInputVerifyNil(t *testing.T) { 13 tests := []struct { 14 name string 15 in *Input 16 expectedErr error 17 }{ 18 { 19 name: "nil input", 20 in: nil, 21 expectedErr: ErrNilInput, 22 }, 23 { 24 name: "not sorted", 25 in: &Input{SigIndices: []uint32{2, 1}}, 26 expectedErr: ErrInputIndicesNotSortedUnique, 27 }, 28 { 29 name: "not unique", 30 in: &Input{SigIndices: []uint32{2, 2}}, 31 expectedErr: ErrInputIndicesNotSortedUnique, 32 }, 33 { 34 name: "passes verification", 35 in: &Input{SigIndices: []uint32{1, 2}}, 36 expectedErr: nil, 37 }, 38 } 39 40 for _, tt := range tests { 41 t.Run(tt.name, func(t *testing.T) { 42 err := tt.in.Verify() 43 require.ErrorIs(t, err, tt.expectedErr) 44 }) 45 } 46 } 47 48 func TestInputCost(t *testing.T) { 49 tests := []struct { 50 name string 51 in *Input 52 expectedCost uint64 53 }{ 54 { 55 name: "2 sigs", 56 in: &Input{SigIndices: []uint32{1, 2}}, 57 expectedCost: 2 * CostPerSignature, 58 }, 59 { 60 name: "3 sigs", 61 in: &Input{SigIndices: []uint32{1, 2, 3}}, 62 expectedCost: 3 * CostPerSignature, 63 }, 64 } 65 66 for _, tt := range tests { 67 t.Run(tt.name, func(t *testing.T) { 68 require := require.New(t) 69 cost, err := tt.in.Cost() 70 require.NoError(err) 71 require.Equal(tt.expectedCost, cost) 72 }) 73 } 74 }