Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into dependabot/github_actions/master/actions/c…
Browse files Browse the repository at this point in the history
…ache-4
  • Loading branch information
jakubmkowalski authored Feb 12, 2024
2 parents c161f04 + ab61bac commit 94b98a4
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .github/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@
- color: c2e0c6
description: "Old, unused, stale"
name: "stale"
- color: 50e061
description: "PR was tested by a team member"
name: "tested"
15 changes: 15 additions & 0 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "On pull request"

on:
pull_request_target:
types:
- labeled
- unlabeled
- opened

permissions:
pull-requests: write

jobs:
on-pr:
uses: bactions/workflows/.github/workflows/on-pull-request.yml@main
50 changes: 50 additions & 0 deletions action_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,56 @@ func Test_RevertTransaction(t *testing.T) {
})
}

func Test_RecordTransaction(t *testing.T) {
ctx, client, _ := initSimpleTestCase(t)
// given
draftTransaction := newDraftTransaction(
testXPub, &TransactionConfig{
Outputs: []*TransactionOutput{{
To: "1A1PjKqjWMNBzTVdcBru27EV1PHcXWc63W",
Satoshis: 1000,
}},
ChangeNumberOfDestinations: 1,
Sync: &SyncConfig{
Broadcast: true,
BroadcastInstant: false,
PaymailP2P: false,
SyncOnChain: false,
},
},
append(client.DefaultModelOptions(), New())...,
)
draftTransactionID := draftTransaction.ID

t.Run("hex validation -> invalid hex", func(t *testing.T) {
invalidHex := "test"
// when
_, err := client.RecordTransaction(ctx, testXPub, invalidHex, draftTransactionID, client.DefaultModelOptions()...)

//then
require.Error(t, err)
})

t.Run("hex validation -> empty hex", func(t *testing.T) {
emptyHex := ""
// when
_, err := client.RecordTransaction(ctx, testXPub, emptyHex, draftTransactionID, client.DefaultModelOptions()...)

//then
require.Error(t, err)
})

t.Run("hex validation -> valid hex", func(t *testing.T) {
validHex := "020000000165bb8d2733298b2d3b441a871868d6323c5392facf0d3eced3a6c6a17dc84c10000000006a473044022057b101e9a017cdcc333ef66a4a1e78720ae15adf7d1be9c33abec0fe56bc849d022013daa203095522039fadaba99e567ec3cf8615861d3b7258d5399c9f1f4ace8f412103b9c72aebee5636664b519e5f7264c78614f1e57fa4097ae83a3012a967b1c4b9ffffffff03e0930400000000001976a91413473d21dc9e1fb392f05a028b447b165a052d4d88acf9020000000000001976a91455decebedd9a6c2c2d32cf0ee77e2640c3955d3488ac00000000000000000c006a09446f7457616c6c657400000000"
// when
_, err := client.RecordTransaction(ctx, testXPub, validHex, "", client.DefaultModelOptions()...)

//then
require.NotContains(t, err.Error(), "invalid hex")
})

}

func initRevertTransactionData(t *testing.T) (context.Context, ClientInterface, *Transaction, *bip32.ExtendedKey, func()) {
// this creates an xpub, destination and utxo
ctx, client, deferMe := initSimpleTestCase(t)
Expand Down
4 changes: 2 additions & 2 deletions go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions paymail_service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ func (p *PaymailDefaultServiceProvider) RecordTransaction(ctx context.Context,
if err != nil {
return nil, err
}
if err := rts.Validate(); err != nil {
return nil, err
}

rts.ForceBroadcast(true)

Expand Down
1 change: 1 addition & 0 deletions record_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func getIncomingTxRecordStrategy(ctx context.Context, c ClientInterface, txHex s
}

return rts, nil

}

func waitForRecordTxWriteLock(ctx context.Context, c ClientInterface, key string) func() {
Expand Down
4 changes: 4 additions & 0 deletions record_tx_strategy_external_incoming_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func (strategy *externalIncomingTx) Validate() error {
return ErrMissingFieldHex
}

if _, err := bt.NewTxFromString(strategy.Hex); err != nil {
return fmt.Errorf("invalid hex: %w", err)
}

return nil // is valid
}

Expand Down
5 changes: 5 additions & 0 deletions record_tx_strategy_internal_incoming_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"

"github.com/libsv/go-bt/v2"
"github.com/rs/zerolog"
)

Expand Down Expand Up @@ -52,6 +53,10 @@ func (strategy *internalIncomingTx) Validate() error {
return errors.New("tx cannot be nil")
}

if _, err := bt.NewTxFromString(strategy.Tx.Hex); err != nil {
return fmt.Errorf("invalid hex: %w", err)
}

return nil // is valid
}

Expand Down
4 changes: 4 additions & 0 deletions record_tx_strategy_outgoing_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (strategy *outgoingTx) Validate() error {
return ErrMissingFieldHex
}

if _, err := bt.NewTxFromString(strategy.Hex); err != nil {
return fmt.Errorf("invalid hex: %w", err)
}

if strategy.RelatedDraftID == "" {
return errors.New("empty RelatedDraftID")
}
Expand Down

0 comments on commit 94b98a4

Please sign in to comment.