Skip to content

Commit

Permalink
node: add TestUnconfirmedParents
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Mar 27, 2024
1 parent 447b3d1 commit caeb895
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
23 changes: 13 additions & 10 deletions internal/node/transactionpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,18 @@ func (tp txpool) AcceptTransactionSet(txns []types.Transaction) error {
}

func (tp txpool) UnconfirmedParents(txn types.Transaction) ([]types.Transaction, error) {
pool := tp.Transactions()
return unconfirmedParents(txn, tp.Transactions()), nil
}

func (tp txpool) Subscribe(subscriber modules.TransactionPoolSubscriber) {
tp.tp.TransactionPoolSubscribe(subscriber)
}

func (tp txpool) Close() error {
return tp.tp.Close()
}

func unconfirmedParents(txn types.Transaction, pool []types.Transaction) []types.Transaction {
outputToParent := make(map[types.SiacoinOutputID]*types.Transaction)
for i, txn := range pool {
for j := range txn.SiacoinOutputs {
Expand All @@ -58,15 +69,7 @@ func (tp txpool) UnconfirmedParents(txn types.Transaction) ([]types.Transaction,
}
}
}
return parents, nil
}

func (tp txpool) Subscribe(subscriber modules.TransactionPoolSubscriber) {
tp.tp.TransactionPoolSubscribe(subscriber)
}

func (tp txpool) Close() error {
return tp.tp.Close()
return parents
}

func NewTransactionPool(tp modules.TransactionPool) bus.TransactionPool {
Expand Down
40 changes: 40 additions & 0 deletions internal/node/transactionpool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package node

import (
"reflect"
"testing"

"go.sia.tech/core/types"
)

func TestUnconfirmedParents(t *testing.T) {
grandparent := types.Transaction{
SiacoinOutputs: []types.SiacoinOutput{{}},
}
parent := types.Transaction{
SiacoinInputs: []types.SiacoinInput{
{
ParentID: grandparent.SiacoinOutputID(0),
},
},
SiacoinOutputs: []types.SiacoinOutput{{}},
}
txn := types.Transaction{
SiacoinInputs: []types.SiacoinInput{
{
ParentID: parent.SiacoinOutputID(0),
},
},
SiacoinOutputs: []types.SiacoinOutput{{}},
}
pool := []types.Transaction{grandparent, parent}

parents := unconfirmedParents(txn, pool)
if len(parents) != 2 {
t.Fatalf("expected 2 parents, got %v", len(parents))

Check failure on line 34 in internal/node/transactionpool_test.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21)

Test go.sia.tech/renterd/internal/node/TestUnconfirmedParents failed in 0s

transactionpool_test.go:34: expected 2 parents, got 1

Check failure on line 34 in internal/node/transactionpool_test.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.22)

Test go.sia.tech/renterd/internal/node/TestUnconfirmedParents failed in 0s

transactionpool_test.go:34: expected 2 parents, got 1
} else if !reflect.DeepEqual(parents[0], grandparent) {
t.Fatalf("expected grandparent")
} else if !reflect.DeepEqual(parents[1], parent) {
t.Fatalf("expected parent")
}
}

0 comments on commit caeb895

Please sign in to comment.