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

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

chris-4chain
Copy link
Contributor

Pull Request Checklist

  • πŸ“– I created my PR using provided : CODE_STANDARDS
  • πŸ“– I have read the short Code of Conduct: CODE_OF_CONDUCT
  • 🏠 I tested my changes locally.
  • βœ… I have provided tests for my changes.
  • πŸ“ I have used conventional commits.
  • πŸ“— I have updated any related documentation.
  • πŸ’Ύ PR was issued based on the Github or Jira issue.

Copy link

Manual Tests

ℹ️ Remember to ask team members to perform manual tests and to assign tested label after testing.

@codecov-commenter
Copy link

codecov-commenter commented Feb 14, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 34.70437% with 254 lines in your changes missing coverage. Please review.

Project coverage is 36.67%. Comparing base (34b60ef) to head (184885d).

Files with missing lines Patch % Lines
...ail/testabilities/assert_paymail_service_client.go 0.00% 42 Missing ⚠️
...ion/outlines/testabilities/mocked_utxo_selector.go 0.00% 31 Missing ⚠️
.../tester/paymailmock/mock_paymail_host_responses.go 0.00% 30 Missing ⚠️
...ternal/testabilities/assert_transaction_details.go 0.00% 24 Missing ⚠️
...rnal/testabilities/assert_transactions_endpoint.go 0.00% 18 Missing ⚠️
engine/v2/transaction/outlines/add_change.go 64.28% 10 Missing and 5 partials ⚠️
...al/sql/testabilities/assertions_inputs_selector.go 0.00% 11 Missing ⚠️
engine/tester/jsonrequire/funcs.go 0.00% 10 Missing ⚠️
...on/outlines/testabilities/assert_outline_output.go 0.00% 10 Missing ⚠️
...tlines/testabilities/assert_outline_transaction.go 0.00% 9 Missing ⚠️
... and 16 more
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main     #910    +/-   ##
========================================
  Coverage   36.67%   36.67%            
========================================
  Files         410      413     +3     
  Lines       19209    19425   +216     
========================================
+ Hits         7044     7125    +81     
- Misses      11587    11713   +126     
- Partials      578      587     +9     
Flag Coverage Ξ”
unittests 36.67% <34.70%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Ξ”
api/gen.models.go 0.00% <ΓΈ> (ΓΈ)
engine/client_internal.go 69.48% <100.00%> (ΓΈ)
engine/tester/paymailmock/mock_capability.go 0.00% <ΓΈ> (ΓΈ)
...ne/tester/paymailmock/mock_capability_factories.go 0.00% <ΓΈ> (ΓΈ)
...gine/v2/database/testabilities/fixture_database.go 0.00% <ΓΈ> (ΓΈ)
engine/v2/transaction/annotation.go 0.00% <ΓΈ> (ΓΈ)
...e/v2/transaction/outlines/output_specifications.go 76.00% <100.00%> (+3.27%) ⬆️
...ansaction/outlines/transaction_outlines_service.go 89.39% <100.00%> (+1.06%) ⬆️
...ction/outlines/utxo/internal/sql/calculate_size.go 100.00% <100.00%> (ΓΈ)
...utlines/utxo/internal/sql/inputs_query_composer.go 100.00% <100.00%> (ΓΈ)
... and 26 more

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update 34b60ef...184885d. Read the comment docs.

@chris-4chain chris-4chain marked this pull request as ready for review February 14, 2025 11:10
@chris-4chain chris-4chain requested a review from a team as a code owner February 14, 2025 11:10
.golangci-lint.yml Outdated Show resolved Hide resolved
)

type TransactionDetailsAssertions interface {
WithOutValues(values ...bsv.Satoshis) TransactionDetailsAssertions
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it without or with output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll rename it to WithOutputValues

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

}

func (a *transactionAssertions) WithOutValues(values ...bsv.Satoshis) TransactionDetailsAssertions {
if len(values) != len(a.tx.Outputs) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add t.Helper() - I recently add it in many places, it's possible that I overlooked something but still maybe it's better to use this approach in new methods, and add missing when we accidentally came across such a method

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

Comment on lines 26 to 28
if len(values) != len(a.tx.Outputs) {
a.t.Fatalf("expected %d outputs, got %d", len(values), len(a.tx.Outputs))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

To follow some convention that we are using require in many packages I would rather use it here like:

Suggested change
if len(values) != len(a.tx.Outputs) {
a.t.Fatalf("expected %d outputs, got %d", len(values), len(a.tx.Outputs))
}
a.require.Lenf(a.tx.Outputs, len(values), "Tx has less outputs then expected values")

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


// and:
client := given.HttpClient().ForUser()
for variationName, variation := range variations {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know that previously there was a duplication and this wasn't best solution,
But this isn't best either.

Maybe it's just a mistake in our thinking.
Maybe we should have all those different cases for default request.
And simply 2 additional tests for different format where we will check only the format of hex.

It should be clearer then, and easier to run particular thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just introduced new approach.
I tried not to repeat test-cases not testing code.
Take a look 🀞

for name, test := range successTestCases {
	t.Run(name, func(t *testing.T) {
		suite.Run(t, newTxOutlineSuite(test, initialSatoshis))
	})
}

basicTestCase := successTestCases["create transaction outline for op_return strings as default data"]

t.Run("explicit beef as requested format", func(t *testing.T) {
	suite.Run(t,
		newTxOutlineSuite(basicTestCase, initialSatoshis).withExplicitFormat("BEEF"),
	)
})

t.Run("explicit raw as requested format", func(t *testing.T) {
	suite.Run(t,
		newTxOutlineSuite(basicTestCase, initialSatoshis).withExplicitFormat("RAW"),
	)
})

@@ -24,6 +24,11 @@ func (t *TransactionSpec) evaluate(ctx *evaluationContext) (*sdk.Transaction, tr
return nil, transaction.Annotations{}, err
}

outputs, err = calculateChange(ctx, inputs, outputs, ctx.feeUnit)
if err != nil {
return nil, transaction.Annotations{}, spverrors.Wrapf(err, "failed to calculate change")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it would be better to have some defined error here?

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

engine/v2/transaction/outlines/calculate_fee_test.go Outdated Show resolved Hide resolved
engine/v2/transaction/outlines/calculate_change.go Outdated Show resolved Hide resolved
engine/v2/transaction/outlines/calculate_change.go Outdated Show resolved Hide resolved
# Conflicts:
#	actions/testabilities/assert_transactions_endpoint.go
#	engine/client_internal.go
#	engine/v2/transaction/outlines/interface.go
#	engine/v2/transaction/outlines/testabilities/fixture_outline_transaction.go
#	engine/v2/transaction/outlines/transaction_outlines_service.go
#	engine/v2/transaction/outlines/utxo/internal/sql/inputs_query_composer.go
#	engine/v2/transaction/outlines/utxo/internal/sql/selector_example_test.go
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.

4 participants