github.com/hyperion-hyn/go-ethereum@v2.4.0+incompatible/consensus/istanbul/types_test.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package istanbul 18 19 import ( 20 "math/big" 21 "testing" 22 ) 23 24 func TestViewCompare(t *testing.T) { 25 // test equality 26 srvView := &View{ 27 Sequence: big.NewInt(2), 28 Round: big.NewInt(1), 29 } 30 tarView := &View{ 31 Sequence: big.NewInt(2), 32 Round: big.NewInt(1), 33 } 34 if r := srvView.Cmp(tarView); r != 0 { 35 t.Errorf("source(%v) should be equal to target(%v): have %v, want %v", srvView, tarView, r, 0) 36 } 37 38 // test larger Sequence 39 tarView = &View{ 40 Sequence: big.NewInt(1), 41 Round: big.NewInt(1), 42 } 43 if r := srvView.Cmp(tarView); r != 1 { 44 t.Errorf("source(%v) should be larger than target(%v): have %v, want %v", srvView, tarView, r, 1) 45 } 46 47 // test larger Round 48 tarView = &View{ 49 Sequence: big.NewInt(2), 50 Round: big.NewInt(0), 51 } 52 if r := srvView.Cmp(tarView); r != 1 { 53 t.Errorf("source(%v) should be larger than target(%v): have %v, want %v", srvView, tarView, r, 1) 54 } 55 56 // test smaller Sequence 57 tarView = &View{ 58 Sequence: big.NewInt(3), 59 Round: big.NewInt(1), 60 } 61 if r := srvView.Cmp(tarView); r != -1 { 62 t.Errorf("source(%v) should be smaller than target(%v): have %v, want %v", srvView, tarView, r, -1) 63 } 64 tarView = &View{ 65 Sequence: big.NewInt(2), 66 Round: big.NewInt(2), 67 } 68 if r := srvView.Cmp(tarView); r != -1 { 69 t.Errorf("source(%v) should be smaller than target(%v): have %v, want %v", srvView, tarView, r, -1) 70 } 71 }