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

feat(SPV-1059) fee and change #910

Merged
merged 38 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ce87fb2
feat(SPV-1059): calculate estimated fee
chris-4chain Feb 13, 2025
1d8bad7
feat(SPV-1059): calculate change
chris-4chain Feb 13, 2025
0a96379
feat(SPV-1059): transaction with change output
chris-4chain Feb 13, 2025
8e5b7e6
feat(SPV-1059): test cases variations
chris-4chain Feb 13, 2025
dd2507c
feat(SPV-1059): custom instructions for change output
chris-4chain Feb 13, 2025
4d9f647
feat(SPV-1059): paymailmock destination responder
chris-4chain Feb 13, 2025
9d3826b
feat(SPV-1059): adjust failing tests
chris-4chain Feb 14, 2025
e4b1bf5
feat(SPV-1059): adjust failing tests
chris-4chain Feb 14, 2025
35d3f9c
feat(SPV-1059): lint
chris-4chain Feb 14, 2025
b4bed0e
Merge branch 'main' into feat/SPV-1059-fee-and-change
chris-4chain Feb 14, 2025
9d842d0
feat(SPV-1059): self review
chris-4chain Feb 14, 2025
1493cdf
feat(SPV-1059): unit tests regarding change outputs
chris-4chain Feb 14, 2025
232ee8e
feat(SPV-1059): lint
chris-4chain Feb 14, 2025
a45f6da
feat(SPV-1059): TestEstimateSizeAgainstRealTxSie
chris-4chain Feb 14, 2025
1221a05
feat(SPV-1059): TestEstimateSizeAgainstRealTxSie
chris-4chain Feb 14, 2025
1a598f7
Merge branch 'main' into feat/SPV-1059-fee-and-change
chris-4chain Feb 14, 2025
4535089
feat(SPV-1059): test name
chris-4chain Feb 14, 2025
a6cfaab
feat(SPV-1059): lint
chris-4chain Feb 14, 2025
71943c3
Merge branch 'main' into feat/SPV-1059-fee-and-change
chris-4chain Feb 17, 2025
7dd5608
Merge branch 'main' into feat/SPV-1059-fee-and-change
chris-4chain Feb 18, 2025
a44d0a4
feat(SPV-1059): adjust to new generated models
chris-4chain Feb 18, 2025
af0460c
feat: select tx change with utxo selector (#915)
dorzepowski Feb 19, 2025
9e5b8d5
feat(SPV-1059): address comments
chris-4chain Feb 19, 2025
3042d81
feat(SPV-1059): outlines test suite
chris-4chain Feb 19, 2025
ad93462
feat(SPV-1059): addressing comments
chris-4chain Feb 19, 2025
184885d
feat(SPV-1059): lint
chris-4chain Feb 19, 2025
9acdfcf
chore(SPV-1554): lint and more functions
chris-4chain Feb 19, 2025
f120682
Merge branch 'main' into feat/SPV-1059-fee-and-change
chris-4chain Feb 19, 2025
5905447
feat(SPV-1059): adjustments after merge
chris-4chain Feb 19, 2025
ffa558f
Revert "chore(SPV-1554): lint and more functions"
chris-4chain Feb 20, 2025
405a661
test: additional information in case of failure of tests
dorzepowski Feb 20, 2025
da9ded0
feat(SPV-1059): improved assertion for selected utxos
chris-4chain Feb 20, 2025
0cb108e
chore(SPV-1554): simplify implementation
chris-4chain Feb 20, 2025
5cb8dd4
Merge branch 'main' into feat/SPV-1059-fee-and-change
chris-4chain Feb 20, 2025
cef647f
Merge branch 'main' into feat/SPV-1059-fee-and-change
chris-4chain Feb 20, 2025
90fd2e7
feat(SPV-1059): address comments
chris-4chain Feb 21, 2025
b3bbf66
feat(SPV-1059): lint
chris-4chain Feb 21, 2025
8cb8a85
feat(SPV-1059): fix tx version
chris-4chain Feb 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,17 @@ issues:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- gocyclo
- errcheck
- gosec
- wrapcheck
- bodyclose

- path: /testabilities/
linters:
- gosec
- wrapcheck
- bodyclose

- path: tester/
linters:
- gocyclo
Expand Down
5 changes: 3 additions & 2 deletions actions/testabilities/assert_spvwallet_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/bitcoin-sv/spv-wallet/actions/testabilities/apierror"
testpaymail "github.com/bitcoin-sv/spv-wallet/engine/paymail/testabilities"
testengine "github.com/bitcoin-sv/spv-wallet/engine/testabilities"
"github.com/bitcoin-sv/spv-wallet/engine/tester/fixtures"
"github.com/bitcoin-sv/spv-wallet/engine/tester/jsonrequire"
Expand All @@ -19,7 +20,7 @@ import (
type SPVWalletApplicationAssertions interface {
Response(response *resty.Response) SPVWalletResponseAssertions
User(user fixtures.User) SPVWalletAppUserAssertions
ExternalPaymailHost() testengine.PaymailExternalAssertions
ExternalPaymailHost() testpaymail.PaymailExternalAssertions
}

type SPVWalletResponseAssertions interface {
Expand Down Expand Up @@ -73,7 +74,7 @@ func (a *appAssertions) User(user fixtures.User) SPVWalletAppUserAssertions {
}
}

func (a *appAssertions) ExternalPaymailHost() testengine.PaymailExternalAssertions {
func (a *appAssertions) ExternalPaymailHost() testpaymail.PaymailExternalAssertions {
return a.engineAssertions.ExternalPaymailHost()
}

Expand Down
8 changes: 8 additions & 0 deletions actions/v2/transactions/internal/mapping/outline_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ func outlineOutputEntryToResponse(index int, value *transaction.OutputAnnotation
func outlineOutputToResponse(from *transaction.OutputAnnotation) api.ModelsOutputAnnotation {
return api.ModelsOutputAnnotation{
Bucket: api.ModelsOutputAnnotationBucket(from.Bucket),
CustomInstructions: lo.IfF(
from.CustomInstructions != nil,
func() *api.ModelsSPVWalletCustomInstructions {
return lo.ToPtr(
lo.Map(*from.CustomInstructions, lox.MappingFn(customInstructionsToResponse)),
)
},
).Else(nil),
Paymail: lo.IfF(
from.Paymail != nil,
func() *api.ModelsPaymailAnnotationDetails {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package testabilities

import (
"testing"

sdk "github.com/bitcoin-sv/go-sdk/transaction"
"github.com/bitcoin-sv/spv-wallet/engine/tester/fixtures"
"github.com/bitcoin-sv/spv-wallet/engine/v2/transaction"
"github.com/bitcoin-sv/spv-wallet/models/bsv"
"github.com/stretchr/testify/require"
)

type TransactionDetailsAssertions interface {
WithOutputValues(values ...bsv.Satoshis) TransactionDetailsAssertions
OutputUnlockableBy(vout int, user fixtures.User) TransactionDetailsAssertions
}

type transactionAssertions struct {
t testing.TB
tx *sdk.Transaction
require *require.Assertions
annotations transaction.Annotations
}

func (a *transactionAssertions) WithOutputValues(values ...bsv.Satoshis) TransactionDetailsAssertions {
a.t.Helper()
a.require.Lenf(a.tx.Outputs, len(values), "Tx has less outputs then expected values")
for i, v := range values {
a.require.Equal(v, bsv.Satoshis(a.tx.Outputs[i].Satoshis), "output value mismatch")
}
return a
}

func (a *transactionAssertions) OutputUnlockableBy(vout int, user fixtures.User) TransactionDetailsAssertions {
a.t.Helper()
a.require.Less(vout, len(a.tx.Outputs), "output index out of range")

outputAnnotation, ok := a.annotations.Outputs[vout]
if !ok {
a.t.Fatalf("output %d has no required annotation", vout)
}
a.require.NotNil(outputAnnotation.CustomInstructions, "output %d has no custom instructions", vout)

fixtures.GivenTX(a.t).
WithSender(user).
WithInputFromUTXO(a.tx, uint32(vout), *outputAnnotation.CustomInstructions...).
WithOPReturn("dummy data").
TX() // during TX call, the transaction is signed. Should fail if the UTXO cannot be unlocked by the user.

return a
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ type TransactionsEndpointAssertions interface {

type TransactionsResponseAssertions interface {
testabilities.SPVWalletResponseAssertions
ContainsValidBEEFHexInField(field string) TransactionsResponseAssertions
ContainsValidRawTxHexInField(field string) TransactionsResponseAssertions
ContainsValidTransaction(format string) TransactionDetailsAssertions
}

func Then(t testing.TB, app testabilities.SPVWalletApplicationFixture) TransactionsEndpointAssertions {
Expand Down Expand Up @@ -50,16 +49,23 @@ type transactionResponseAssertions struct {
assert *assert.Assertions
}

func (a *transactionResponseAssertions) ContainsValidBEEFHexInField(field string) TransactionsResponseAssertions {
txHex := a.SPVWalletResponseAssertions.JSONValue().GetString(field)
_, err := sdk.NewTransactionFromBEEFHex(txHex)
a.require.NoError(err, "hex is not valid BEEF")
return a
}

func (a *transactionResponseAssertions) ContainsValidRawTxHexInField(field string) TransactionsResponseAssertions {
txHex := a.SPVWalletResponseAssertions.JSONValue().GetString(field)
_, err := sdk.NewTransactionFromHex(txHex)
a.require.NoError(err, "hex is not valid raw tx")
return a
func (a *transactionResponseAssertions) ContainsValidTransaction(format string) TransactionDetailsAssertions {
a.t.Helper()
txHex := a.SPVWalletResponseAssertions.JSONValue().GetString("hex")
var tx *sdk.Transaction
var err error
switch format {
case "BEEF":
tx, err = sdk.NewTransactionFromBEEFHex(txHex)
case "RAW":
tx, err = sdk.NewTransactionFromHex(txHex)
default:
a.t.Fatalf("unsupported format: %s", format)
}
a.require.NoError(err, "hex is not valid tx in format %s", format)
return &transactionAssertions{
t: a.t,
require: a.require,
tx: tx,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/bitcoin-sv/spv-wallet/actions/testabilities"
"github.com/bitcoin-sv/spv-wallet/engine/tester/fixtures"
"github.com/bitcoin-sv/spv-wallet/engine/tester/paymailmock"
)

// ExpectedCustomInstructions represents json array with custom instructions of UTXO created with Faucet().TopUp() method
Expand All @@ -18,7 +19,7 @@ const ExpectedCustomInstructions = `[

type TransactionsEndpointFixture interface {
testabilities.SPVWalletApplicationFixture
OutlineResponseContext(additionalParams map[string]any) map[string]any
OutlineResponseContext(format string, additionalParams map[string]any) map[string]any
}

func Given(t testing.TB) TransactionsEndpointFixture {
Expand All @@ -31,11 +32,14 @@ type fixture struct {
testabilities.SPVWalletApplicationFixture
}

func (f *fixture) OutlineResponseContext(paramsOverride map[string]any) map[string]any {
params := make(map[string]any)
params["ReceiverPaymail"] = fixtures.RecipientExternal.DefaultPaymail()
params["SenderPaymail"] = fixtures.Sender.DefaultPaymail()
params["CustomInstructions"] = ExpectedCustomInstructions
func (f *fixture) OutlineResponseContext(format string, paramsOverride map[string]any) map[string]any {
params := map[string]any{
"Format": format,
"ReceiverPaymail": fixtures.RecipientExternal.DefaultPaymail(),
"SenderPaymail": fixtures.Sender.DefaultPaymail(),
"CustomInstructions": ExpectedCustomInstructions,
"Reference": paymailmock.MockedReferenceID,
}

maps.Copy(params, paramsOverride)

Expand Down
Loading
Loading