-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix "transaction spends nonexisting siacoin output" when refreshing c…
…ontracts (#1111) `UnconfirmedParents` would only ever return direct parents for a txn but not grandparents and so on. Leading to hosts not knowing about certain parents yet and txns failing.
- Loading branch information
1 parent
82246d9
commit c3155f8
Showing
2 changed files
with
66 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} else if !reflect.DeepEqual(parents[0], grandparent) { | ||
t.Fatalf("expected grandparent") | ||
} else if !reflect.DeepEqual(parents[1], parent) { | ||
t.Fatalf("expected parent") | ||
} | ||
} |