This commit is contained in:
Jae Kwon 2014-06-05 21:20:55 -07:00
parent 08faa88d02
commit ad57d57cf6
4 changed files with 56 additions and 32 deletions

View File

@ -134,6 +134,7 @@ func (self *Dupeout) Type() Byte {
}
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.VoteB, w, n, err)
return

View File

@ -87,7 +87,7 @@ func ReadValidation(r io.Reader) Validation {
sigs = append(sigs, ReadSignature(r))
}
adjs := make([]Adjustment, 0, numAdjs)
for i:=0; i<numSigs; i++ {
for i:=0; i<numAdjs; i++ {
adjs = append(adjs, ReadAdjustment(r))
}
return Validation{

View File

@ -24,25 +24,62 @@ func randBytes(n int) ByteSlice {
return bs
}
func randSig() Signature {
return Signature{AccountNumber(randVar()), randBytes(32)}
}
func TestBlock(t *testing.T) {
// Txs
sendTx := &SendTx{
Signature: Signature{AccountNumber(randVar()), randBytes(32)},
Signature: randSig(),
Fee: randVar(),
To: AccountNumber(randVar()),
Amount: randVar(),
}
nameTx := &NameTx{
Signature: Signature{AccountNumber(randVar()), randBytes(32)},
Signature: randSig(),
Fee: randVar(),
Name: String(randBytes(12)),
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{
Header{
@ -55,12 +92,17 @@ func TestBlock(t *testing.T) {
DataHash: randBytes(32),
},
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)
block2 := ReadBlock(bytes.NewReader(blockBytes))
blockBytes2 := BinaryBytes(block2)
@ -69,19 +111,3 @@ func TestBlock(t *testing.T) {
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(),
}
*/

View File

@ -25,11 +25,8 @@ func ReadVote(r io.Reader) Vote {
}
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
}