github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/chain/consensus/neatcon/epoch/epoch_test.go (about) 1 package epoch 2 3 import ( 4 "fmt" 5 "math/big" 6 "sort" 7 "testing" 8 "time" 9 10 "github.com/neatlab/neatio/utilities/common" 11 ) 12 13 func TestEstimateEpoch(t *testing.T) { 14 timeA := time.Now() 15 timeB := timeA.Unix() 16 timeStr := timeA.String() 17 t.Logf("now: %v, %v", timeB, timeStr) 18 19 formatTimeStr := "2021-12-20 09:51:38.397502 +0800 CST m=+10323.270024761" 20 parse, e := time.Parse("", formatTimeStr) 21 if e == nil { 22 t.Logf("time: %v", parse) 23 } else { 24 t.Errorf("parse error: %v", e) 25 } 26 27 timeC := time.Now().UnixNano() 28 t.Logf("time c %v", timeC) 29 t.Logf("time c %v", timeC) 30 } 31 32 func TestVoteSetCompare(t *testing.T) { 33 var voteArr []*EpochValidatorVote 34 voteArr = []*EpochValidatorVote{ 35 { 36 Address: common.HexToAddress("0e0ffd4c684b325be82f120a7938c7d938ff3dca"), 37 Amount: big.NewInt(1), 38 }, 39 { 40 Address: common.HexToAddress("0e0ffd4c684b325be82f120a7938c7d938ff3dca"), 41 Amount: big.NewInt(1), 42 }, 43 { 44 Address: common.HexToAddress("0e0ffd4c684b325be82f120a7938c7d938ff3dca"), 45 Amount: big.NewInt(1), 46 }, 47 { 48 Address: common.HexToAddress("0e0ffd4c684b325be82f120a7938c7d938ff3dca"), 49 Amount: big.NewInt(1), 50 }, 51 { 52 Address: common.HexToAddress("0e0ffd4c684b325be82f120a7938c7d938ff3dca"), 53 Amount: big.NewInt(1), 54 }, 55 { 56 Address: common.HexToAddress("0e0ffd4c684b325be82f120a7938c7d938ff3dca"), 57 Amount: big.NewInt(1), 58 }, 59 } 60 61 sort.Slice(voteArr, func(i, j int) bool { 62 if voteArr[i].Amount.Cmp(voteArr[j].Amount) == 0 { 63 return compareAddress(voteArr[i].Address[:], voteArr[j].Address[:]) 64 } 65 66 return voteArr[i].Amount.Cmp(voteArr[j].Amount) == 1 67 }) 68 for i := range voteArr { 69 fmt.Printf("address:%v, amount: %v\n", voteArr[i].Address, voteArr[i].Amount) 70 } 71 }