diff --git a/persist/sqlite/consensus_test.go b/persist/sqlite/consensus_test.go index 85cde59..1d064ba 100644 --- a/persist/sqlite/consensus_test.go +++ b/persist/sqlite/consensus_test.go @@ -318,8 +318,10 @@ func TestEphemeralBalance(t *testing.T) { expectedPayout := cm.TipState().BlockReward() maturityHeight := cm.TipState().MaturityHeight() + 1 + block := mineBlock(cm.TipState(), nil, addr) + minerPayoutID := block.ID().MinerOutputID(0) // mine a block sending the payout to the wallet - if err := cm.AddBlocks([]types.Block{mineBlock(cm.TipState(), nil, addr)}); err != nil { + if err := cm.AddBlocks([]types.Block{block}); err != nil { t.Fatal(err) } @@ -339,6 +341,8 @@ func TestEphemeralBalance(t *testing.T) { t.Fatalf("expected 1 event, got %v", len(events)) } else if events[0].Data.EventType() != wallet.EventTypeMinerPayout { t.Fatalf("expected payout event, got %v", events[0].Data.EventType()) + } else if events[0].ID != types.Hash256(minerPayoutID) { + t.Fatalf("expected %v, got %v", minerPayoutID, events[0].ID) } // mine until the payout matures @@ -419,6 +423,24 @@ func TestEphemeralBalance(t *testing.T) { t.Fatalf("expected 0, got %v", balance.Siacoins) } + // check that both transactions were added + events, err = db.WalletEvents("test", 0, 100) + if err != nil { + t.Fatal(err) + } else if len(events) != 3 { // 1 payout, 2 transactions + t.Fatalf("expected 3 events, got %v", len(events)) + } else if events[2].Data.EventType() != wallet.EventTypeMinerPayout { + t.Fatalf("expected miner payout event, got %v", events[2].Data.EventType()) + } else if events[1].Data.EventType() != wallet.EventTypeTransaction { + t.Fatalf("expected transaction event, got %v", events[1].Data.EventType()) + } else if events[0].Data.EventType() != wallet.EventTypeTransaction { + t.Fatalf("expected transaction event, got %v", events[0].Data.EventType()) + } else if events[1].ID != types.Hash256(parentTxn.ID()) { // parent txn first + t.Fatalf("expected %v, got %v", parentTxn.ID(), events[1].ID) + } else if events[0].ID != types.Hash256(txn.ID()) { // child txn second + t.Fatalf("expected %v, got %v", txn.ID(), events[0].ID) + } + // trigger a reorg var blocks []types.Block state := revertState diff --git a/persist/sqlite/wallet.go b/persist/sqlite/wallet.go index ace68de..b2136e9 100644 --- a/persist/sqlite/wallet.go +++ b/persist/sqlite/wallet.go @@ -24,7 +24,7 @@ func getWalletEvents(tx *txn, walletID string, offset, limit int) (events []wall FROM events ev INNER JOIN chain_indices ci ON (ev.index_id = ci.id) WHERE ev.id IN (SELECT event_id FROM event_addresses WHERE address_id IN (SELECT address_id FROM wallet_addresses WHERE wallet_id=$1)) - ORDER BY ev.maturity_height DESC + ORDER BY ev.maturity_height DESC, ev.id DESC LIMIT $2 OFFSET $3` rows, err := tx.Query(query, walletID, limit, offset)