github.com/annchain/OG@v0.0.9/og/protocol/ogmessage/archive/sequencer_test.go (about) 1 // Copyright © 2019 Annchain Authors <EMAIL ADDRESS> 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package archive 15 16 import ( 17 "fmt" 18 types2 "github.com/annchain/OG/arefactor/og/types" 19 "github.com/annchain/OG/common" 20 "github.com/annchain/OG/common/math" 21 "github.com/annchain/OG/og/types" 22 23 "encoding/hex" 24 25 "testing" 26 ) 27 28 func TestSequencer(t *testing.T) { 29 addr := types2.RandomAddress() 30 from := common.HexToAddress("0x1") 31 seq1 := Sequencer{TxBase: TxBase{ParentsHash: types2.Hashes{types2.HexToHash("0x0")}}, Issuer: &addr} 32 seq2 := Tx{types.TxBase: TxBase{ParentsHash: types2.Hashes{types2.HexToHash("0x0")}}, 33 To: common.HexToAddress("0x1"), 34 From: &from, 35 Value: math.NewBigInt(0), 36 } 37 38 seq3 := Sequencer{TxBase: TxBase{ParentsHash: types2.Hashes{seq1.CalcMinedHash(), seq2.CalcMinedHash()}}} 39 40 fmt.Println(seq1.CalcMinedHash().String()) 41 fmt.Println(seq2.CalcMinedHash().String()) 42 fmt.Println(seq3.CalcMinedHash().String()) 43 44 } 45 46 func TestSequencerSize(t *testing.T) { 47 addr := types2.RandomAddress() 48 seq := Sequencer{Issuer: &addr} 49 n := 100 50 51 // make 1000 hashes 52 fmt.Println("Length", seq.Msgsize(), seq.Msgsize()/n) 53 bts, err := seq.MarshalMsg(nil) 54 if err != nil { 55 t.Fatal(err) 56 } 57 58 fmt.Println(hex.Dump(bts)) 59 } 60 61 func TestSequencerRawSize(t *testing.T) { 62 addr := types2.RandomAddress() 63 seq := Sequencer{Issuer: &addr} 64 n := 100 65 66 // make 1000 hashes 67 for i := 0; i < n; i++ { 68 //seq.Hashes = append(seq.Hashes, common.HexToHash("0xAABB000000000000000000000000CCDDCCDD000000000000000000000000EEFF").KeyBytes) 69 } 70 71 fmt.Println("Length", seq.Msgsize(), seq.Msgsize()/n) 72 bts, err := seq.MarshalMsg(nil) 73 fmt.Println("ActualLength", len(bts), len(bts)/n) 74 75 if err != nil { 76 t.Fatal(err) 77 } 78 79 fmt.Println(hex.Dump(bts)) 80 } 81 82 func TestSequencerSecpSign(t *testing.T) { 83 t.Parallel() 84 85 seq := Sequencer{} 86 addr := common.HexToAddress("7349f7a6f622378d5fb0e2c16b9d4a3e5237c187") 87 seq.Issuer = &addr 88 seq.Height = 221 89 90 // signer := ogcrypto.SignerSecp256k1{} 91 92 } 93 94 func TestSequencer_Number(t *testing.T) { 95 seq := RandomSequencer() 96 data, _ := seq.MarshalMsg(nil) 97 var newSeq Sequencer 98 o, err := newSeq.UnmarshalMsg(data) 99 fmt.Println(o, err) 100 }