github.com/klaytn/klaytn@v1.12.1/consensus/istanbul/validator/validator_test.go (about) 1 package validator 2 3 import ( 4 "testing" 5 6 "github.com/klaytn/klaytn/common" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestCalcSeed(t *testing.T) { 11 type testCase struct { 12 hash common.Hash 13 expected int64 14 expectedErr error 15 } 16 testCases := []testCase{ 17 { 18 hash: common.HexToHash("0x1111"), 19 expected: 0, 20 expectedErr: nil, 21 }, 22 { 23 hash: common.HexToHash("0x1234000000000000000000000000000000000000000000000000000000000000"), 24 expected: 81979586966978560, 25 expectedErr: nil, 26 }, 27 { 28 hash: common.HexToHash("0x1234123412341230000000000000000000000000000000000000000000000000"), 29 expected: 81980837895291171, 30 expectedErr: nil, 31 }, 32 { 33 hash: common.HexToHash("0x1234123412341234000000000000000000000000000000000000000000000000"), 34 expected: 81980837895291171, 35 expectedErr: nil, 36 }, 37 { 38 hash: common.HexToHash("0x1234123412341234123412341234123412341234123412341234123412341234"), 39 expected: 81980837895291171, 40 expectedErr: nil, 41 }, 42 { 43 hash: common.HexToHash("0x0034123412341234123412341234123412341234123412341234123412341234"), 44 expected: 916044602622243, 45 expectedErr: nil, 46 }, 47 { 48 hash: common.HexToHash("0xabcdef3412341234123412341234123412341234123412341234123412341234"), 49 expected: 773738372352131363, 50 expectedErr: nil, 51 }, 52 } 53 54 for _, tc := range testCases { 55 actual, err := ConvertHashToSeed(tc.hash) 56 assert.Equal(t, err, tc.expectedErr) 57 assert.Equal(t, actual, tc.expected) 58 } 59 }