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:
parent
46d23919e7
commit
42b3b54e3c
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user