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

Commit

Permalink
feat: remove the option to use whatsonchain for tx querying
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalibalashka committed Sep 19, 2023
1 parent 987f698 commit f14c11d
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 480 deletions.
10 changes: 4 additions & 6 deletions chainstate/chainstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@ func NewTestClient(ctx context.Context, t *testing.T, opts ...ClientOps) ClientI
func TestQueryTransactionFastest(t *testing.T) {
t.Run("no tx ID", func(t *testing.T) {
ctx := context.Background()
c, err := NewClient(ctx, WithMinercraft(&MinerCraftBase{}))
require.NoError(t, err)
c := NewTestClient(ctx, t, WithMinercraft(&minerCraftTxOnChain{}))

_, err = c.QueryTransactionFastest(ctx, "", RequiredInMempool, 5*time.Second)
_, err := c.QueryTransactionFastest(ctx, "", RequiredInMempool, 5*time.Second)
require.Error(t, err)
})

t.Run("fastest query", func(t *testing.T) {
ctx := context.Background()
c, err := NewClient(ctx, WithMinercraft(&MinerCraftBase{}))
require.NoError(t, err)
c := NewTestClient(ctx, t, WithMinercraft(&minerCraftTxOnChain{}))

var txInfo *TransactionInfo
txInfo, err = c.QueryTransactionFastest(ctx, testTransactionID, RequiredInMempool, 5*time.Second)
txInfo, err := c.QueryTransactionFastest(ctx, onChainExample1TxID, RequiredInMempool, 5*time.Second)
require.NoError(t, err)
assert.NotNil(t, txInfo)
})
Expand Down
9 changes: 0 additions & 9 deletions chainstate/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,6 @@ func WithWhatsOnChain(client whatsonchain.ClientInterface) ClientOps {
}
}

// WithWhatsOnChainAPIKey will set a custom WhatsOnChain API key
func WithWhatsOnChainAPIKey(apiKey string) ClientOps {
return func(c *clientOptions) {
if len(apiKey) > 0 {
c.config.whatsOnChainAPIKey = apiKey
}
}
}

// WithBroadcastMiners will set a list of miners for broadcasting
func WithBroadcastMiners(miners []*Miner) ClientOps {
return func(c *clientOptions) {
Expand Down
42 changes: 2 additions & 40 deletions chainstate/client_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,56 +116,18 @@ func TestWithWhatsOnChain(t *testing.T) {
t.Parallel()

t.Run("check type", func(t *testing.T) {
opt := WithWhatsOnChain(nil)
opt := WithMinercraft(nil)
assert.IsType(t, *new(ClientOps), opt)
})

t.Run("test applying nil", func(t *testing.T) {
options := &clientOptions{
config: &syncConfig{},
}
opt := WithWhatsOnChain(nil)
opt := WithMinercraft(nil)
opt(options)
assert.Nil(t, options.config.whatsOnChain)
})

t.Run("test applying option", func(t *testing.T) {
options := &clientOptions{
config: &syncConfig{},
}
customClient := &whatsOnChainTxOnChain{}
opt := WithWhatsOnChain(customClient)
opt(options)
assert.Equal(t, customClient, options.config.whatsOnChain)
})
}

// TestWithWhatsOnChainAPIKey will test the method WithWhatsOnChainAPIKey()
func TestWithWhatsOnChainAPIKey(t *testing.T) {
t.Parallel()

t.Run("check type", func(t *testing.T) {
opt := WithWhatsOnChainAPIKey("")
assert.IsType(t, *new(ClientOps), opt)
})

t.Run("test applying empty string", func(t *testing.T) {
options := &clientOptions{
config: &syncConfig{},
}
opt := WithWhatsOnChainAPIKey("")
opt(options)
assert.Equal(t, "", options.config.whatsOnChainAPIKey)
})

t.Run("test applying option", func(t *testing.T) {
options := &clientOptions{
config: &syncConfig{},
}
opt := WithWhatsOnChainAPIKey(testDummyKey)
opt(options)
assert.Equal(t, testDummyKey, options.config.whatsOnChainAPIKey)
})
}

// TestWithBroadcastMiners will test the method WithBroadcastMiners()
Expand Down
11 changes: 0 additions & 11 deletions chainstate/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ func TestNewClient(t *testing.T) {
assert.Equal(t, customClient, c.WhatsOnChain())
})

t.Run("custom whats on chain api key", func(t *testing.T) {
c, err := NewClient(
context.Background(),
WithWhatsOnChainAPIKey(testDummyKey),
WithMinercraft(&MinerCraftBase{}),
)
require.NoError(t, err)
require.NotNil(t, c)
assert.NotNil(t, c.WhatsOnChain())
})

t.Run("custom minercraft client", func(t *testing.T) {
customClient, err := minercraft.NewClient(
minercraft.DefaultClientOptions(), nil, "", nil, nil,
Expand Down
270 changes: 0 additions & 270 deletions chainstate/mock_whatsonchain_test.go

This file was deleted.

Loading

0 comments on commit f14c11d

Please sign in to comment.