Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
chore(BUX-461): get rid of hardcoded DefaultFee
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-4chain authored and dorzepowski committed Jan 12, 2024
1 parent eea46e5 commit 6c672a3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
10 changes: 4 additions & 6 deletions chainstate/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,14 @@ func TestNewClient(t *testing.T) {
assert.Equal(t, TestNet, c.Network())
})

t.Run("custom network - stn", func(t *testing.T) {
c, err := NewClient(
t.Run("no provider when using minercraft with customNet", func(t *testing.T) {
_, err := NewClient(
context.Background(),
WithNetwork(StressTestNet),
WithMinercraft(&MinerCraftBase{}),
WithFeeUnit(DefaultFee()),
WithFeeUnit(MockDefaultFee),
)
require.NoError(t, err)
require.NotNil(t, c)
assert.Equal(t, StressTestNet, c.Network())
require.Error(t, err)
})

t.Run("unreacheble miners", func(t *testing.T) {
Expand Down
12 changes: 0 additions & 12 deletions chainstate/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package chainstate

import (
"time"

"github.com/BuxOrg/bux/utils"
)

// Chainstate configuration defaults
Expand Down Expand Up @@ -50,16 +48,6 @@ const (
ProviderNone = "none" // No providers (used to indicate no providers)
)

// DefaultFee is used when a fee has not been set by the user
// This default is currently accepted by all BitcoinSV miners (50/1000) (7.27.23)
// Actual TAAL FeeUnit - 1/1000, GorillaPool - 50/1000 (7.27.23)
func DefaultFee() *utils.FeeUnit {
return &utils.FeeUnit{
Satoshis: 1,
Bytes: 1000,
}
}

// BlockInfo is the response info about a returned block
type BlockInfo struct {
Bits string `json:"bits"`
Expand Down
7 changes: 1 addition & 6 deletions model_draft_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"math/big"
"time"

"github.com/BuxOrg/bux/chainstate"
"github.com/BuxOrg/bux/utils"
"github.com/bitcoinschema/go-bitcoin/v2"
"github.com/libsv/go-bk/bec"
Expand Down Expand Up @@ -63,11 +62,7 @@ func newDraftTransaction(rawXpubKey string, config *TransactionConfig, opts ...M
}

if config.FeeUnit == nil {
if c := draft.Client(); c != nil {
draft.Configuration.FeeUnit = c.Chainstate().FeeUnit()
} else {
draft.Configuration.FeeUnit = chainstate.DefaultFee()
}
draft.Configuration.FeeUnit = draft.Client().Chainstate().FeeUnit()
}
return draft
}
Expand Down
14 changes: 11 additions & 3 deletions model_draft_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ func TestDraftTransaction_newDraftTransaction(t *testing.T) {
t.Run("valid config", func(t *testing.T) {
expires := time.Now().UTC().Add(defaultDraftTxExpiresIn)
draftTx := newDraftTransaction(
testXPub, &TransactionConfig{}, New(),
testXPub, &TransactionConfig{
FeeUnit: chainstate.MockDefaultFee,
}, New(),
)
require.NotNil(t, draftTx)
assert.NotEqual(t, "", draftTx.ID)
assert.Equal(t, 64, len(draftTx.ID))
assert.WithinDurationf(t, expires, draftTx.ExpiresAt, 1*time.Second, "within 1 second")
assert.Equal(t, DraftStatusDraft, draftTx.Status)
assert.Equal(t, testXPubID, draftTx.XpubID)
assert.Equal(t, *chainstate.DefaultFee(), *draftTx.Configuration.FeeUnit)
assert.Equal(t, *chainstate.MockDefaultFee, *draftTx.Configuration.FeeUnit)
})
}

Expand All @@ -62,7 +64,9 @@ func TestDraftTransaction_GetModelName(t *testing.T) {
t.Parallel()

t.Run("model name", func(t *testing.T) {
draftTx := newDraftTransaction(testXPub, &TransactionConfig{}, New())
draftTx := newDraftTransaction(testXPub, &TransactionConfig{
FeeUnit: chainstate.MockDefaultFee,
}, New())
require.NotNil(t, draftTx)
assert.Equal(t, ModelDraftTransaction.String(), draftTx.GetModelName())
})
Expand All @@ -76,6 +80,7 @@ func TestDraftTransaction_getOutputSatoshis(t *testing.T) {
ChangeDestinations: []*Destination{{
LockingScript: testLockingScript,
}},
FeeUnit: chainstate.MockDefaultFee,
},
)
changSatoshis, err := draftTx.getChangeSatoshis(1000000)
Expand All @@ -91,6 +96,7 @@ func TestDraftTransaction_getOutputSatoshis(t *testing.T) {
ChangeDestinations: []*Destination{{
LockingScript: testLockingScript,
}},
FeeUnit: chainstate.MockDefaultFee,
},
)
changSatoshis, err := draftTx.getChangeSatoshis(1000000)
Expand All @@ -107,6 +113,7 @@ func TestDraftTransaction_getOutputSatoshis(t *testing.T) {
}, {
LockingScript: testTxInScriptPubKey,
}},
FeeUnit: chainstate.MockDefaultFee,
},
)
changSatoshis, err := draftTx.getChangeSatoshis(1000001)
Expand All @@ -127,6 +134,7 @@ func TestDraftTransaction_getOutputSatoshis(t *testing.T) {
}, {
LockingScript: testTxScriptPubKey1,
}},
FeeUnit: chainstate.MockDefaultFee,
},
)
satoshis := uint64(1000001)
Expand Down

0 comments on commit 6c672a3

Please sign in to comment.