Skip to content
Snippets Groups Projects
Commit 16de80fa authored by Ethan Buchman's avatar Ethan Buchman
Browse files

give dupeouttx signbytes (for txid)

parent 31a11627
No related branches found
No related tags found
No related merge requests found
......@@ -328,7 +328,8 @@ type DupeoutTx struct {
}
func (tx *DupeoutTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
PanicSanity("DupeoutTx has no sign bytes")
wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
wire.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","vote_a":%v,"vote_b":%v}]}`, TxTypeDupeout, tx.Address, tx.VoteA, tx.VoteB)), w, n, err)
}
func (tx *DupeoutTx) String() string {
......
......@@ -176,3 +176,34 @@ func TestPermissionsTxSignable(t *testing.T) {
t.Errorf("Got unexpected sign string for CallTx. Expected:\n%v\nGot:\n%v", expected, signStr)
}
}
func TestDupeoutTxSignable(t *testing.T) {
privAcc := acm.GenPrivAccount()
partSetHeader := PartSetHeader{Total: 10, Hash: []byte("partsethash")}
voteA := &Vote{
Height: 10,
Round: 2,
Type: VoteTypePrevote,
BlockHash: []byte("myblockhash"),
BlockPartsHeader: partSetHeader,
}
sig := privAcc.Sign(chainID, voteA)
voteA.Signature = sig.(acm.SignatureEd25519)
voteB := voteA.Copy()
voteB.BlockHash = []byte("myotherblockhash")
sig = privAcc.Sign(chainID, voteB)
voteB.Signature = sig.(acm.SignatureEd25519)
dupeoutTx := &DupeoutTx{
Address: []byte("address1"),
VoteA: *voteA,
VoteB: *voteB,
}
signBytes := acm.SignBytes(chainID, dupeoutTx)
signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%s","tx":[20,{"address":"6164647265737331","vote_a":%v,"vote_b":%v}]}`,
config.GetString("chain_id"), *voteA, *voteB)
if signStr != expected {
t.Errorf("Got unexpected sign string for DupeoutTx")
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment