@@ -21,7 +21,14 @@ import (
21
21
"crypto/elliptic"
22
22
crand "crypto/rand"
23
23
"crypto/rsa"
24
+ "reflect"
24
25
"testing"
26
+
27
+ "github.com/golang/protobuf/proto"
28
+ "github.com/hyperledger/fabric/orderer/common/bootstrap/static"
29
+ "github.com/hyperledger/fabric/orderer/rawledger/ramledger"
30
+ "github.com/hyperledger/fabric/orderer/sbft/simplebft"
31
+ cb "github.com/hyperledger/fabric/protos/common"
25
32
)
26
33
27
34
func TestSignAndVerifyRsa (t * testing.T ) {
@@ -59,3 +66,64 @@ func TestSignAndVerifyEcdsa(t *testing.T) {
59
66
t .Errorf ("Signature check failed: %s" , err )
60
67
}
61
68
}
69
+
70
+ func TestLedgerReadWrite (t * testing.T ) {
71
+ genesis , err := static .New ().GenesisBlock ()
72
+ if err != nil {
73
+ panic ("Failed to generate genesis block." )
74
+ }
75
+ _ , rl := ramledger .New (10 , genesis )
76
+ b := Backend {ledger : rl }
77
+
78
+ header := []byte ("header" )
79
+ e1 := & cb.Envelope {Payload : []byte ("data1" )}
80
+ e2 := & cb.Envelope {Payload : []byte ("data2" )}
81
+ ebytes1 , _ := proto .Marshal (e1 )
82
+ ebytes2 , _ := proto .Marshal (e2 )
83
+ data := [][]byte {ebytes1 , ebytes2 }
84
+ sgns := make (map [uint64 ][]byte )
85
+ sgns [uint64 (1 )] = []byte ("sgn1" )
86
+ sgns [uint64 (22 )] = []byte ("sgn22" )
87
+ batch := simplebft.Batch {Header : header , Payloads : data , Signatures : sgns }
88
+
89
+ b .Deliver (& batch )
90
+ batch2 := b .LastBatch ()
91
+
92
+ if ! reflect .DeepEqual (batch , * batch2 ) {
93
+ t .Errorf ("The wrong batch was returned by LastBatch after Deliver: %v (original was: %v)" , batch2 , & batch )
94
+ }
95
+ }
96
+
97
+ func TestEncoderEncodesDecodesSgnsWithoutPanic (t * testing.T ) {
98
+ defer func () {
99
+ if r := recover (); r != nil {
100
+ t .Errorf ("Encoding/decoding failed for valid signatures, code panicked." )
101
+ }
102
+ }()
103
+ sgns1 := make (map [uint64 ][]byte )
104
+ e1 := encodeSignatures (sgns1 )
105
+
106
+ sgns2 := make (map [uint64 ][]byte )
107
+ sgns2 [uint64 (1 )] = []byte ("sgn1" )
108
+ e2 := encodeSignatures (sgns2 )
109
+
110
+ sgns3 := make (map [uint64 ][]byte )
111
+ sgns3 [uint64 (22 )] = []byte ("sgn22" )
112
+ sgns3 [uint64 (143 )] = []byte ("sgn22" )
113
+ sgns3 [uint64 (200 )] = []byte ("sgn200" )
114
+ e3 := encodeSignatures (sgns3 )
115
+
116
+ rsgns1 := decodeSignatures (e1 )
117
+ rsgns2 := decodeSignatures (e2 )
118
+ rsgns3 := decodeSignatures (e3 )
119
+
120
+ if ! reflect .DeepEqual (sgns1 , rsgns1 ) {
121
+ t .Errorf ("Decoding error: %v (original: %v). (1)" , rsgns1 , sgns1 )
122
+ }
123
+ if ! reflect .DeepEqual (sgns2 , rsgns2 ) {
124
+ t .Errorf ("Decoding error: %v (original: %v). (2)" , rsgns2 , sgns2 )
125
+ }
126
+ if ! reflect .DeepEqual (sgns3 , rsgns3 ) {
127
+ t .Errorf ("Decoding error: %v (original: %v). (3)" , rsgns3 , sgns3 )
128
+ }
129
+ }
0 commit comments