github.com/MetalBlockchain/metalgo@v1.11.9/genesis/config_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 genesis 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/require" 10 11 "github.com/MetalBlockchain/metalgo/ids" 12 ) 13 14 func TestAllocationCompare(t *testing.T) { 15 type test struct { 16 name string 17 alloc1 Allocation 18 alloc2 Allocation 19 expected int 20 } 21 tests := []test{ 22 { 23 name: "equal", 24 alloc1: Allocation{}, 25 alloc2: Allocation{}, 26 expected: 0, 27 }, 28 { 29 name: "initial amount smaller", 30 alloc1: Allocation{}, 31 alloc2: Allocation{ 32 InitialAmount: 1, 33 }, 34 expected: -1, 35 }, 36 { 37 name: "bytes smaller", 38 alloc1: Allocation{}, 39 alloc2: Allocation{ 40 AVAXAddr: ids.ShortID{1}, 41 }, 42 expected: -1, 43 }, 44 } 45 for _, tt := range tests { 46 t.Run(tt.name, func(t *testing.T) { 47 require := require.New(t) 48 49 require.Equal(tt.expected, tt.alloc1.Compare(tt.alloc2)) 50 require.Equal(-tt.expected, tt.alloc2.Compare(tt.alloc1)) 51 }) 52 } 53 }