Skip to content

Commit

Permalink
udb: use new errors package
Browse files Browse the repository at this point in the history
  • Loading branch information
kLkA committed May 24, 2018
1 parent a8d4597 commit 3e900aa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dcrwallet
vendor
*~
.vscode
.idea
Binary file modified wallet/udb/testdata/v9.db.gz
Binary file not shown.
26 changes: 8 additions & 18 deletions wallet/udb/testdata/v9.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ import (
"github.com/decred/dcrwallet/walletdb"
_ "github.com/decred/dcrwallet/walletdb/bdb"
"github.com/decred/dcrwallet/walletseed"
"github.com/pkg/errors"
"golang.org/x/crypto/ripemd160"
"github.com/decred/dcrd/txscript"
"github.com/decred/dcrwallet/apperrors"
"github.com/decred/dcrwallet/errors"
"github.com/decred/dcrd/dcrec/secp256k1"
)

Expand Down Expand Up @@ -59,6 +58,8 @@ func main() {
}

func setup() error {
const op errors.Op = "udb.V9DatabaseSetup"

var chainParams = &chaincfg.TestNet2Params
os.Remove(dbname)
db, err := walletdb.Create("bdb", dbname)
Expand Down Expand Up @@ -120,18 +121,16 @@ func setup() error {

address1, err := dcrutil.NewAddressSecpPubKeyCompressed(pk, chainParams)

msScript, err := txscript.MultiSigScript(
[]*dcrutil.AddressSecpPubKey{address1},
1)
msScript, err := txscript.MultiSigScript([]*dcrutil.AddressSecpPubKey{address1}, 1)
if err != nil {
return err
}

_, err = amgr.ImportScript(amgrns, msScript)
if err != nil {
// We don't care if we've already used this address.
if err.(apperrors.E).ErrorCode != apperrors.ErrDuplicateAddress {
return err
if err != nil && !errors.Is(errors.Exist, err) {
return errors.E(op, err)
}
}
err = txmgr.InsertTxScript(txmgrns, msScript)
Expand Down Expand Up @@ -164,17 +163,8 @@ func setup() error {

var p2shScriptHash [ripemd160.Size]byte
key := keyMultisigOut(rec.Hash, 0)
val := valueMultisigOut(p2shScriptHash,
1,
1,
false,
0,
headerData.BlockHash,
1, // height
dcrutil.Amount(0),
chainhash.Hash{}, // Unspent
0xFFFFFFFF, // Unspent
rec.Hash)
val := valueMultisigOut(p2shScriptHash, 1, 1, false, 0, headerData.BlockHash,
1, dcrutil.Amount(0), chainhash.Hash{}, 0xFFFFFFFF, rec.Hash)

err = putMultisigOutRawValues(txmgrns, key, val)
if err != nil {
Expand Down
10 changes: 4 additions & 6 deletions wallet/udb/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/decred/dcrd/chaincfg"
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/wire"
"github.com/decred/dcrwallet/errors"
"github.com/decred/dcrwallet/walletdb"
_ "github.com/decred/dcrwallet/walletdb/bdb"
)
Expand Down Expand Up @@ -444,14 +445,11 @@ func verifyV10Upgrade(t *testing.T, db walletdb.DB) {

// should exist 2 multisigOuts with valid TX
if msoWithTX != 2 {
err = fmt.Errorf("should be 2 valid transactions for MSOs, got: %d", msoWithTX)

return err
return errors.New("expected to have 2 valid transactions for MSOs")
}
if len(multisigOutsMarkedForDelete) > 0 {
err = fmt.Errorf("expected to have 0 MSOs marked for delete, got: %d", len(multisigOutsMarkedForDelete))

return err
if len(multisigOutsMarkedForDelete) > 0 {
return errors.New("expected to have 0 MSOs marked for delete")
}

return err
Expand Down

0 comments on commit 3e900aa

Please sign in to comment.