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

Fix Annotate SQL scan destination #87

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 42 additions & 2 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ func TestWalletAdd(t *testing.T) {
func TestWallet(t *testing.T) {
log := zaptest.NewLogger(t)

// create syncer
syncerListener, err := net.Listen("tcp", ":0")
if err != nil {
t.Fatal(err)
}
defer syncerListener.Close()

// create chain manager
n, genesisBlock := testNetwork()
giftPrivateKey := types.GeneratePrivateKey()
giftAddress := types.StandardUnlockHash(giftPrivateKey.PublicKey())
Expand All @@ -241,26 +249,37 @@ func TestWallet(t *testing.T) {
Address: giftAddress,
}

// create wallets
dbstore, tipState, err := chain.NewDBStore(chain.NewMemDB(), n, genesisBlock)
if err != nil {
t.Fatal(err)
}
cm := chain.NewManager(dbstore, tipState)

// create the sqlite store
ws, err := sqlite.OpenDatabase(filepath.Join(t.TempDir(), "wallets.db"), log.Named("sqlite3"))
if err != nil {
t.Fatal(err)
}
defer ws.Close()

// create the syncer
s := syncer.New(syncerListener, cm, ws, gateway.Header{
GenesisID: genesisBlock.ID(),
UniqueID: gateway.GenerateUniqueID(),
NetAddress: syncerListener.Addr().String(),
})

// create the wallet manager
wm, err := wallet.NewManager(cm, ws, log.Named("wallet"))
if err != nil {
t.Fatal(err)
}

// create seed address vault
sav := wallet.NewSeedAddressVault(wallet.NewSeed(), 0, 20)
c, shutdown := runServer(cm, nil, wm)

// run server
c, shutdown := runServer(cm, s, wm)
defer shutdown()
w, err := c.AddWallet(api.WalletUpdateRequest{Name: "primary"})
if err != nil {
Expand Down Expand Up @@ -331,13 +350,34 @@ func TestWallet(t *testing.T) {
sig := giftPrivateKey.SignHash(cm.TipState().WholeSigHash(txn, types.Hash256(giftSCOID), 0, 0, nil))
txn.Signatures[0].Signature = sig[:]

// broadcast the transaction to the transaction pool
if err := c.TxpoolBroadcast([]types.Transaction{txn}, nil); err != nil {
t.Fatal(err)
}

// shouldn't have any events yet
events, err = wc.Events(0, -1)
if err != nil {
t.Fatal(err)
} else if len(events) != 0 {
t.Fatal("event history should be empty")
}

tpool, err := wc.PoolTransactions()
if err != nil {
t.Fatal(err)
} else if len(tpool) != 1 {
t.Fatal("txpool should have one transaction")
}

cs := cm.TipState()
b := types.Block{
ParentID: cs.Index.ID,
Timestamp: types.CurrentTimestamp(),
MinerPayouts: []types.SiacoinOutput{{Address: types.VoidAddress, Value: cs.BlockReward()}},
Transactions: []types.Transaction{txn},
}

for b.ID().CmpWork(cs.ChildTarget) < 0 {
b.Nonce += cs.NonceFactor()
}
Expand Down
2 changes: 1 addition & 1 deletion persist/sqlite/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ WHERE wa.wallet_id=$1 AND sa.sia_address=$2 LIMIT 1`
// addresses into memory.
ownsAddress := func(address types.Address) bool {
var dbID int64
err := stmt.QueryRow(id, encode(address)).Scan(dbID)
err := stmt.QueryRow(id, encode(address)).Scan(&dbID)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
panic(err) // database error
}
Expand Down