github.com/annchain/OG@v0.0.9/poc/tendermint/client_test.go (about) 1 package tendermint 2 3 import ( 4 "github.com/sirupsen/logrus" 5 "net/http" 6 _ "net/http/pprof" 7 "testing" 8 "time" 9 ) 10 11 var BlockTime = time.Millisecond * 1 12 13 func init() { 14 Formatter := new(logrus.TextFormatter) 15 //Formatter.ForceColors = false 16 Formatter.DisableColors = true 17 Formatter.TimestampFormat = "15:04:05.000000" 18 Formatter.FullTimestamp = true 19 20 logrus.SetFormatter(Formatter) 21 logrus.SetLevel(logrus.TraceLevel) 22 23 go func() { 24 logrus.Fatal(http.ListenAndServe("localhost:6060", nil)) 25 }() 26 27 } 28 29 func start(peers []Partner) { 30 for _, peer := range peers { 31 time.Sleep(2 * time.Second) 32 peer.SetPeers(peers) 33 peer.StartNewEra(0, 0) 34 go peer.EventLoop() 35 } 36 for { 37 time.Sleep(time.Second * 10) 38 } 39 } 40 41 func TestAllNonByzantine(t *testing.T) { 42 total := 5 43 var peers []Partner 44 for i := 0; i < total; i++ { 45 peers = append(peers, NewPartner(total, i, BlockTime)) 46 } 47 start(peers) 48 } 49 50 func TestByzantineButOK(t *testing.T) { 51 total := 4 52 byzantines := 1 53 var peers []Partner 54 for i := 0; i < total-byzantines; i++ { 55 peers = append(peers, NewPartner(total, i, BlockTime)) 56 } 57 for i := total - byzantines; i < total; i++ { 58 peers = append(peers, NewByzantinePartner(total, i, BlockTime, 59 ByzantineFeatures{ 60 SilenceProposal: true, 61 SilencePreVote: true, 62 SilencePreCommit: true, 63 })) 64 } 65 start(peers) 66 } 67 68 func TestByzantineNotOK(t *testing.T) { 69 total := 4 70 byzantines := 2 71 var peers []Partner 72 for i := 0; i < total-byzantines; i++ { 73 peers = append(peers, NewPartner(total, i, BlockTime)) 74 } 75 for i := total - byzantines; i < total; i++ { 76 peers = append(peers, NewByzantinePartner(total, i, BlockTime, 77 ByzantineFeatures{ 78 //SilenceProposal: true, 79 SilencePreVote: true, 80 //SilencePreCommit: true, 81 })) 82 } 83 start(peers) 84 } 85 86 func TestBadByzantineOK(t *testing.T) { 87 total := 4 88 byzantines := 1 89 var peers []Partner 90 for i := 0; i < total-byzantines; i++ { 91 peers = append(peers, NewPartner(total, i, BlockTime)) 92 } 93 for i := total - byzantines; i < total; i++ { 94 peers = append(peers, NewByzantinePartner(total, i, BlockTime, 95 ByzantineFeatures{ 96 BadPreCommit: true, 97 BadPreVote: true, 98 BadProposal: true, 99 })) 100 } 101 start(peers) 102 } 103 104 func TestManyBadByzantineOK(t *testing.T) { 105 total := 22 106 byzantines := 7 107 var peers []Partner 108 for i := 0; i < total-byzantines; i++ { 109 peers = append(peers, NewPartner(total, i, BlockTime)) 110 } 111 for i := total - byzantines; i < total; i++ { 112 peers = append(peers, NewByzantinePartner(total, i, BlockTime, 113 ByzantineFeatures{ 114 BadPreCommit: true, 115 BadPreVote: true, 116 BadProposal: true, 117 })) 118 } 119 start(peers) 120 }