lnwallet: allow maximum state size to be used + tests

Add tests to assert maximum state can be used. Also test
that more than one input in the commitment transaction
will fail and that having state number larger than
maxStateHint will fail.
This commit is contained in:
Christopher Jämthagen 2017-01-09 14:58:58 +01:00 committed by Olaoluwa Osuntokun
parent 46d23919e7
commit 42b3b54e3c
2 changed files with 23 additions and 1 deletions

@ -784,7 +784,7 @@ func SetStateNumHint(commitTx *wire.MsgTx, stateNum uint64,
// With the current schema we are only able able to encode state num
// hints up to 2^48. Therefore if the passed height is greater than our
// state hint ceiling, then exit early.
if stateNum >= maxStateHint {
if stateNum > maxStateHint {
return fmt.Errorf("unable to encode state, %v is greater "+
"state num that max of %v", stateNum, maxStateHint)
}

@ -583,5 +583,27 @@ func TestCommitTxStateHint(t *testing.T) {
t.Fatalf("state number mismatched, expected %v, got %v",
stateNum, extractedStateNum)
}
//Test from maximum allowed state
stateNum = uint64(maxStateHint - i)
err = SetStateNumHint(commitTx, stateNum, obsfucator)
if err != nil {
t.Fatalf("unable to set state num %v: %v", i, err)
}
extractedStateNum = GetStateNumHint(commitTx, obsfucator)
if extractedStateNum != stateNum {
t.Fatalf("state number mismatched, expected %v, got %v",
stateNum, extractedStateNum)
}
}
if err := SetStateNumHint(commitTx, maxStateHint+1, obsfucator); err == nil {
t.Fatalf("state number should not exceed %X", maxStateHint)
}
commitTx.AddTxIn(&wire.TxIn{})
if err := SetStateNumHint(commitTx, 0, obsfucator); err == nil {
t.Fatalf("more than one input in commit transaction should not be valid")
}
}