-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit test keystore #3151
Unit test keystore #3151
Conversation
2a82e50
to
7a9bc0d
Compare
keystore.go, especially the BTC sign function, is untested and quite long/complicated. bitbox02-api-go has simulator tests, for reference: https://github.com/BitBoxSwiss/bitbox02-api-go/blob/0e6a62c1fcf54ebaace25f90f1ab67530fedf171/api/firmware/device_test.go#L165. If the keystore signing code lived in the bitbox02-api-go repo, we could more easily test it, and potential third parties would also have an easier time integrating the BitBox. As a first step, we add simulator tests to the bitbox-wallet-app repo for bitbox02/keystore.go, which would enable us to safely refactor the code so we can eventually move it to bitbox02-api-go. The code to download and run simulators was copied from bitbox02-api-go: https://github.com/BitBoxSwiss/bitbox02-api-go/blob/0e6a62c1fcf54ebaace25f90f1ab67530fedf171/api/firmware/device_test.go#L48
Reduces the need for the costly GetAccountAddress(), which was used to gather input address infos three times per input during signing instead of only once: 1. when creating the spendable UTXO set in sign.go 2. when needing the info to feed the keypath info to the keystore (bitbox02/keystore.go) 3. when needing to create the sigscript/witness after signing (bitbox02/keystore.go) identify output addresses. This makes TxProposal a little bit more similar to a PSBT It also helps to move us closer to a tx structure resembling PSBTs.
"Finalize" is a term used in PSBTs to complete the transaction after signing by inserting the relevant witnesses.
15c4b8f
to
123953b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK! left a couple of comments
) | ||
|
||
var ( | ||
log = logging.Get().WithGroup("simulator tx sign test") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nit: I'd suggest simulator tx signing test
. At first read I intended sign as +/- and thought it was a mistake :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 😄
@@ -36,7 +35,7 @@ import ( | |||
) | |||
|
|||
// PreviousOutputs represents a UTXO set. It also implements `txscript.PrevOutputFetcher`. | |||
type PreviousOutputs map[wire.OutPoint]*transactions.SpendableOutput | |||
type PreviousOutputs map[wire.OutPoint]UTXO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be possible to "merge" the UTXO and the SpendableOutput structs to simplify the code? Probably OT for this PR, anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think so, as the transactions package with SpendableOutput does not have access to the Address instance, which is part of UTXO.
@@ -16,18 +16,18 @@ | |||
package bitbox02 | |||
|
|||
import ( | |||
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/coin" | |||
coinpkg "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/coin" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this was renamed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because in keystore_simulator_test there is a global var coin
now which clashes. Could also rename the var, doesn't matter much I think.
Including a check if the BitBox02 identified it as a send-to-self.
123953b
to
e2ef679
Compare
No description provided.