diff --git a/chainstate/client_test.go b/chainstate/client_test.go index cf9efe4a..fff6e1ed 100644 --- a/chainstate/client_test.go +++ b/chainstate/client_test.go @@ -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) { diff --git a/chainstate/definitions.go b/chainstate/definitions.go index 970dff97..25d180eb 100644 --- a/chainstate/definitions.go +++ b/chainstate/definitions.go @@ -2,8 +2,6 @@ package chainstate import ( "time" - - "github.com/BuxOrg/bux/utils" ) // Chainstate configuration defaults @@ -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"` diff --git a/model_draft_transactions.go b/model_draft_transactions.go index b4f5ff21..ada89589 100644 --- a/model_draft_transactions.go +++ b/model_draft_transactions.go @@ -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" @@ -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 } diff --git a/model_draft_transactions_test.go b/model_draft_transactions_test.go index 19e526a6..e4e1e802 100644 --- a/model_draft_transactions_test.go +++ b/model_draft_transactions_test.go @@ -45,7 +45,9 @@ 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) @@ -53,7 +55,7 @@ func TestDraftTransaction_newDraftTransaction(t *testing.T) { 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) }) } @@ -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()) }) @@ -76,6 +80,7 @@ func TestDraftTransaction_getOutputSatoshis(t *testing.T) { ChangeDestinations: []*Destination{{ LockingScript: testLockingScript, }}, + FeeUnit: chainstate.MockDefaultFee, }, ) changSatoshis, err := draftTx.getChangeSatoshis(1000000) @@ -91,6 +96,7 @@ func TestDraftTransaction_getOutputSatoshis(t *testing.T) { ChangeDestinations: []*Destination{{ LockingScript: testLockingScript, }}, + FeeUnit: chainstate.MockDefaultFee, }, ) changSatoshis, err := draftTx.getChangeSatoshis(1000000) @@ -107,6 +113,7 @@ func TestDraftTransaction_getOutputSatoshis(t *testing.T) { }, { LockingScript: testTxInScriptPubKey, }}, + FeeUnit: chainstate.MockDefaultFee, }, ) changSatoshis, err := draftTx.getChangeSatoshis(1000001) @@ -127,6 +134,7 @@ func TestDraftTransaction_getOutputSatoshis(t *testing.T) { }, { LockingScript: testTxScriptPubKey1, }}, + FeeUnit: chainstate.MockDefaultFee, }, ) satoshis := uint64(1000001)