mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
.
This commit is contained in:
parent
08faa88d02
commit
ad57d57cf6
@ -134,6 +134,7 @@ func (self *Dupeout) Type() Byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *Dupeout) WriteTo(w io.Writer) (n int64, err error) {
|
func (self *Dupeout) WriteTo(w io.Writer) (n int64, err error) {
|
||||||
|
n, err = WriteOnto(self.Type(), w, n, err)
|
||||||
n, err = WriteOnto(self.VoteA, w, n, err)
|
n, err = WriteOnto(self.VoteA, w, n, err)
|
||||||
n, err = WriteOnto(self.VoteB, w, n, err)
|
n, err = WriteOnto(self.VoteB, w, n, err)
|
||||||
return
|
return
|
||||||
|
@ -87,7 +87,7 @@ func ReadValidation(r io.Reader) Validation {
|
|||||||
sigs = append(sigs, ReadSignature(r))
|
sigs = append(sigs, ReadSignature(r))
|
||||||
}
|
}
|
||||||
adjs := make([]Adjustment, 0, numAdjs)
|
adjs := make([]Adjustment, 0, numAdjs)
|
||||||
for i:=0; i<numSigs; i++ {
|
for i:=0; i<numAdjs; i++ {
|
||||||
adjs = append(adjs, ReadAdjustment(r))
|
adjs = append(adjs, ReadAdjustment(r))
|
||||||
}
|
}
|
||||||
return Validation{
|
return Validation{
|
||||||
|
@ -24,25 +24,62 @@ func randBytes(n int) ByteSlice {
|
|||||||
return bs
|
return bs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func randSig() Signature {
|
||||||
|
return Signature{AccountNumber(randVar()), randBytes(32)}
|
||||||
|
}
|
||||||
|
|
||||||
func TestBlock(t *testing.T) {
|
func TestBlock(t *testing.T) {
|
||||||
|
|
||||||
|
// Txs
|
||||||
|
|
||||||
sendTx := &SendTx{
|
sendTx := &SendTx{
|
||||||
Signature: Signature{AccountNumber(randVar()), randBytes(32)},
|
Signature: randSig(),
|
||||||
Fee: randVar(),
|
Fee: randVar(),
|
||||||
To: AccountNumber(randVar()),
|
To: AccountNumber(randVar()),
|
||||||
Amount: randVar(),
|
Amount: randVar(),
|
||||||
}
|
}
|
||||||
|
|
||||||
nameTx := &NameTx{
|
nameTx := &NameTx{
|
||||||
Signature: Signature{AccountNumber(randVar()), randBytes(32)},
|
Signature: randSig(),
|
||||||
Fee: randVar(),
|
Fee: randVar(),
|
||||||
Name: String(randBytes(12)),
|
Name: String(randBytes(12)),
|
||||||
PubKey: randBytes(32),
|
PubKey: randBytes(32),
|
||||||
}
|
}
|
||||||
|
|
||||||
txs := []Tx{}
|
// Adjs
|
||||||
txs = append(txs, sendTx)
|
|
||||||
txs = append(txs, nameTx)
|
bond := &Bond{
|
||||||
|
Signature: randSig(),
|
||||||
|
Fee: randVar(),
|
||||||
|
UnbondTo: AccountNumber(randVar()),
|
||||||
|
Amount: randVar(),
|
||||||
|
}
|
||||||
|
|
||||||
|
unbond := &Unbond{
|
||||||
|
Signature: randSig(),
|
||||||
|
Fee: randVar(),
|
||||||
|
Amount: randVar(),
|
||||||
|
}
|
||||||
|
|
||||||
|
timeout := &Timeout{
|
||||||
|
Account: AccountNumber(randVar()),
|
||||||
|
Penalty: randVar(),
|
||||||
|
}
|
||||||
|
|
||||||
|
dupeout := &Dupeout{
|
||||||
|
VoteA: Vote{
|
||||||
|
Height: randVar(),
|
||||||
|
BlockHash: randBytes(32),
|
||||||
|
Signature: randSig(),
|
||||||
|
},
|
||||||
|
VoteB: Vote{
|
||||||
|
Height: randVar(),
|
||||||
|
BlockHash: randBytes(32),
|
||||||
|
Signature: randSig(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Block
|
||||||
|
|
||||||
block := &Block{
|
block := &Block{
|
||||||
Header{
|
Header{
|
||||||
@ -55,12 +92,17 @@ func TestBlock(t *testing.T) {
|
|||||||
DataHash: randBytes(32),
|
DataHash: randBytes(32),
|
||||||
},
|
},
|
||||||
Validation{
|
Validation{
|
||||||
Signatures:nil,
|
Signatures: []Signature{randSig(),randSig()},
|
||||||
Adjustments:nil,
|
Adjustments:[]Adjustment{bond,unbond,timeout,dupeout},
|
||||||
|
},
|
||||||
|
Data{
|
||||||
|
Txs: []Tx{sendTx, nameTx},
|
||||||
},
|
},
|
||||||
Data{txs},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write the block, read it in again, write it again.
|
||||||
|
// Then, compare.
|
||||||
|
|
||||||
blockBytes := BinaryBytes(block)
|
blockBytes := BinaryBytes(block)
|
||||||
block2 := ReadBlock(bytes.NewReader(blockBytes))
|
block2 := ReadBlock(bytes.NewReader(blockBytes))
|
||||||
blockBytes2 := BinaryBytes(block2)
|
blockBytes2 := BinaryBytes(block2)
|
||||||
@ -69,19 +111,3 @@ func TestBlock(t *testing.T) {
|
|||||||
t.Fatal("Write->Read of block failed.")
|
t.Fatal("Write->Read of block failed.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
bondTx := &BondTx{
|
|
||||||
Signature: Signature{AccountNumber(randVar()), randBytes(32)},
|
|
||||||
Fee: randVar(),
|
|
||||||
UnbondTo: AccountNumber(randVar()),
|
|
||||||
Amount: randVar(),
|
|
||||||
}
|
|
||||||
|
|
||||||
unbondTx := &UnbondTx{
|
|
||||||
Signature: Signature{AccountNumber(randVar()), randBytes(32)},
|
|
||||||
Fee: randVar(),
|
|
||||||
Amount: randVar(),
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
@ -25,11 +25,8 @@ func ReadVote(r io.Reader) Vote {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self Vote) WriteTo(w io.Writer) (n int64, err error) {
|
func (self Vote) WriteTo(w io.Writer) (n int64, err error) {
|
||||||
var n_ int64
|
n, err = WriteOnto(self.Height, w, n, err)
|
||||||
n_, err = self.Height.WriteTo(w)
|
n, err = WriteOnto(self.BlockHash, w, n, err)
|
||||||
n += n_; if err != nil { return n, err }
|
n, err = WriteOnto(self.Signature, w, n, err)
|
||||||
n_, err = self.BlockHash.WriteTo(w)
|
return
|
||||||
n += n_; if err != nil { return n, err }
|
|
||||||
n_, err = self.Signature.WriteTo(w)
|
|
||||||
n += n_; return
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user