Skip to content

Commit

Permalink
tests now
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Oct 19, 2023
1 parent 62474fc commit 0b97642
Show file tree
Hide file tree
Showing 8 changed files with 604 additions and 394 deletions.
7 changes: 1 addition & 6 deletions client/asset/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2205,12 +2205,7 @@ func (btc *baseWallet) fundMultiSplitTx(
return sum >= req, sum - req
}

var avail uint64
for _, utxo := range utxos {
avail += utxo.Amount
}

fundSplitCoins, _, spents, _, inputsSize, _, err := btc.cm.FundWithUTXOs(utxos, avail, keep, false, enough)
fundSplitCoins, _, spents, _, inputsSize, _, err := btc.cm.FundWithUTXOs(utxos, keep, false, enough)
if err != nil {
return false, nil, nil
}
Expand Down
6 changes: 5 additions & 1 deletion client/asset/btc/coinmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ func NewCoinManager(

func (c *CoinManager) FundWithUTXOs(
utxos []*CompositeUTXO,
avail, keep uint64,
keep uint64,
lockUnspents bool,
enough EnoughFunc,
) (coins asset.Coins, fundingCoins map[OutPoint]*UTxO, spents []*Output, redeemScripts []dex.Bytes, size, sum uint64, err error) {
var avail uint64
for _, utxo := range utxos {
avail += utxo.Amount
}

c.mtx.Lock()
defer c.mtx.Unlock()
Expand Down
5 changes: 5 additions & 0 deletions client/asset/zec/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const (
errUTxORetrieval
errLockUnspent
errFunding
errNoTx
errGetChainInfo
errGetNetInfo
errBadInput
errMaxLock
)

// Error is an error code and a wrapped error.
Expand Down
22 changes: 11 additions & 11 deletions client/asset/zec/regnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ const (
testnetOverwinterActivationHeight = 207500
)

var (
tLotSize uint64 = 1e6
tZEC = &dex.Asset{
ID: BipID,
Symbol: "zec",
SwapSize: dexzec.InitTxSize,
SwapSizeBase: dexzec.InitTxSizeBase,
MaxFeeRate: 100,
SwapConf: 1,
}
)
// var (
// tLotSize uint64 = 1e6
// tZEC = &dex.Asset{
// ID: BipID,
// Symbol: "zec",
// SwapSize: dexzec.InitTxSize,
// SwapSizeBase: dexzec.InitTxSizeBase,
// MaxFeeRate: 100,
// SwapConf: 1,
// }
// )

func TestWallet(t *testing.T) {
livetest.Run(t, &livetest.Config{
Expand Down
33 changes: 11 additions & 22 deletions client/asset/zec/transparent_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,19 @@ func getWalletTransaction(c rpcCaller, txHash *chainhash.Hash) (*btc.GetTransact
return &tx, nil
}

func getBalance(c rpcCaller) (bal uint64, err error) {
return bal, c.CallRPC("getbalance", nil, &bal)
}

type networkInfo struct {
Connections uint32 `json:"connections"`
}

func peerCount(c rpcCaller) (uint32, error) {
var r struct {
Connections uint32 `json:"connections"`
}
var r networkInfo
err := c.CallRPC("getnetworkinfo", nil, &r)
if err != nil {
return 0, err
return 0, codedError(errGetNetInfo, err)
}
return r.Connections, nil
}
Expand Down Expand Up @@ -345,27 +351,10 @@ func getTxOutput(c rpcCaller, txHash *chainhash.Hash, index uint32) (*btcjson.Ge
return res, c.CallRPC("gettxout", []any{txHash.String(), index, true}, &res)
}

func swapConfirmations(c rpcCaller, txHash *chainhash.Hash, vout uint32) (confs uint32, spent bool, err error) {
// Check for an unspent output.
txOut, err := getTxOutput(c, txHash, vout)
if err == nil && txOut != nil {
return uint32(txOut.Confirmations), false, nil
}
// Check wallet transactions.
tx, err := getWalletTransaction(c, txHash)
if err != nil {
if btc.IsTxNotFoundErr(err) {
return 0, false, asset.CoinNotFoundError
}
return 0, false, err
}
return uint32(tx.Confirmations), true, nil
}

func syncStatus(c rpcCaller) (*btc.SyncStatus, error) {
chainInfo, err := getBlockchainInfo(c)
if err != nil {
return nil, fmt.Errorf("getblockchaininfo error: %w", err)
return nil, newError(errGetChainInfo, "getblockchaininfo error: %w", err)
}
return &btc.SyncStatus{
Target: int32(chainInfo.Headers),
Expand Down
Loading

0 comments on commit 0b97642

Please sign in to comment.