Browse Source

.

pull/9/head
Jae Kwon 11 years ago
parent
commit
ad57d57cf6
4 changed files with 56 additions and 32 deletions
  1. +1
    -0
      blocks/adjustment.go
  2. +1
    -1
      blocks/block.go
  3. +50
    -24
      blocks/block_test.go
  4. +4
    -7
      blocks/vote.go

+ 1
- 0
blocks/adjustment.go View File

@ -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


+ 1
- 1
blocks/block.go View File

@ -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{


+ 50
- 24
blocks/block_test.go View File

@ -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{}
txs = append(txs, sendTx)
txs = append(txs, nameTx)
// Adjs
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,
Adjustments:nil,
Signatures: []Signature{randSig(),randSig()},
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(),
}
*/

+ 4
- 7
blocks/vote.go View File

@ -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 = self.Height.WriteTo(w)
n += n_; if err != nil { return n, err }
n_, err = self.BlockHash.WriteTo(w)
n += n_; if err != nil { return n, err }
n_, err = self.Signature.WriteTo(w)
n += n_; return
n, err = WriteOnto(self.Height, w, n, err)
n, err = WriteOnto(self.BlockHash, w, n, err)
n, err = WriteOnto(self.Signature, w, n, err)
return
} }

Loading…
Cancel
Save