Skip to content
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

Merged
merged 6 commits into from
Feb 12, 2025
Merged

Unit test keystore #3151

merged 6 commits into from
Feb 12, 2025

Conversation

benma
Copy link
Contributor

@benma benma commented Feb 3, 2025

No description provided.

@benma benma force-pushed the unit-test-keystore branch 2 times, most recently from 2a82e50 to 7a9bc0d Compare February 4, 2025 08:27
@benma benma requested a review from Beerosagos February 4, 2025 08:30
benma added 4 commits February 5, 2025 14:20
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.
@benma benma force-pushed the unit-test-keystore branch from 15c4b8f to 123953b Compare February 5, 2025 13:21
Copy link
Collaborator

@Beerosagos Beerosagos left a 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")
Copy link
Collaborator

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

Copy link
Contributor Author

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
Copy link
Collaborator

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

Copy link
Contributor Author

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this was renamed?

Copy link
Contributor Author

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.

@benma benma force-pushed the unit-test-keystore branch from 123953b to e2ef679 Compare February 12, 2025 10:11
@benma benma merged commit 319b006 into BitBoxSwiss:master Feb 12, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants