github.com/Finschia/finschia-sdk@v0.49.1/x/fbridge/types/params_test.go (about) 1 package types_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 "github.com/Finschia/finschia-sdk/x/fbridge/types" 9 ) 10 11 func TestCheckTrustLevelThreshold(t *testing.T) { 12 tcs := map[string]struct { 13 total uint64 14 current uint64 15 trustLevel types.Fraction 16 isPanic bool 17 isValid bool 18 }{ 19 "meet the trust level": { 20 current: 3, 21 total: 4, 22 trustLevel: types.Fraction{Numerator: 2, Denominator: 3}, 23 isValid: true, 24 }, 25 "not meet the trust level": { 26 current: 1, 27 total: 2, 28 trustLevel: types.Fraction{Numerator: 2, Denominator: 3}, 29 isValid: false, 30 }, 31 "total is 0": { 32 total: 0, 33 current: 3, 34 trustLevel: types.Fraction{Numerator: 2, Denominator: 3}, 35 isValid: false, 36 }, 37 "invalid trust level - 1": { 38 total: 10, 39 current: 8, 40 trustLevel: types.Fraction{Numerator: 3, Denominator: 2}, 41 isPanic: true, 42 }, 43 "invalid trust level - 2": { 44 total: 10, 45 current: 8, 46 trustLevel: types.Fraction{Numerator: 3, Denominator: 0}, 47 isPanic: true, 48 }, 49 } 50 51 for name, tc := range tcs { 52 t.Run(name, func(t *testing.T) { 53 if tc.isPanic { 54 require.Panics(t, func() { types.CheckTrustLevelThreshold(tc.total, tc.current, tc.trustLevel) }) 55 } else if tc.isValid { 56 require.True(t, types.CheckTrustLevelThreshold(tc.total, tc.current, tc.trustLevel)) 57 } else { 58 require.False(t, types.CheckTrustLevelThreshold(tc.total, tc.current, tc.trustLevel)) 59 } 60 }) 61 } 62 }