Skip to content

Commit

Permalink
Removed two miners that were not performing well
Browse files Browse the repository at this point in the history
Referencing #95
  • Loading branch information
mrz1836 committed Jun 30, 2023
1 parent 73618b6 commit 1b3cac0
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 36 deletions.
2 changes: 1 addition & 1 deletion best_quote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestClient_BestQuote(t *testing.T) {
var fee uint64
fee, err = response.Quote.CalculateFee(mapi.FeeCategoryRelay, mapi.FeeTypeData, 1000)
require.NoError(t, err)
assert.Equal(t, uint64(100), fee)
assert.Equal(t, uint64(250), fee)

fee, err = response.Quote.CalculateFee(mapi.FeeCategoryMining, mapi.FeeTypeData, 1000)
require.NoError(t, err)
Expand Down
24 changes: 12 additions & 12 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestNewClient(t *testing.T) {
assert.NoError(t, err)

// Test default miners
assert.Equal(t, 4, len(client.Miners()))
assert.Equal(t, 2, len(client.Miners()))
})

t.Run("custom http client", func(t *testing.T) {
Expand All @@ -82,12 +82,12 @@ func TestNewClient(t *testing.T) {
assert.Equal(t, MinerTaal, miner.Name)

// Get Mempool
miner = client.MinerByName(MinerMempool)
assert.Equal(t, MinerMempool, miner.Name)
// miner = client.MinerByName(MinerMempool)
// assert.Equal(t, MinerMempool, miner.Name)

// Get Matterpool
miner = client.MinerByName(MinerMatterpool)
assert.Equal(t, MinerMatterpool, miner.Name)
// miner = client.MinerByName(MinerMatterpool)
// assert.Equal(t, MinerMatterpool, miner.Name)

// Get GorillaPool
miner = client.MinerByName(MinerGorillaPool)
Expand Down Expand Up @@ -123,7 +123,7 @@ func ExampleNewClient() {
}

fmt.Printf("created new client with %d default miners", len(client.Miners()))
// Output:created new client with 4 default miners
// Output:created new client with 2 default miners
}

// BenchmarkNewClient benchmarks the method NewClient()
Expand Down Expand Up @@ -619,7 +619,7 @@ func ExampleClient_RemoveMiner() {

// Show response
fmt.Printf("total miners: %d", len(client.Miners()))
// Output:total miners: 3
// Output:total miners: 1
}

// BenchmarkClient_RemoveMiner benchmarks the method RemoveMiner()
Expand All @@ -637,19 +637,19 @@ func TestDefaultMiners(t *testing.T) {
miners, err := DefaultMiners()
require.NoError(t, err)
require.NotNil(t, miners)
assert.Equal(t, 4, len(miners))
// assert.Equal(t, MinerMempool, miners[1].Name)
//assert.Equal(t, MinerMatterpool, miners[1].Name)
assert.Equal(t, 2, len(miners))
assert.Equal(t, MinerTaal, miners[0].Name)
assert.Equal(t, MinerMempool, miners[1].Name)
assert.Equal(t, MinerGorillaPool, miners[3].Name)
assert.Equal(t, MinerMatterpool, miners[2].Name)
assert.Equal(t, MinerGorillaPool, miners[1].Name)
})
}

// ExampleDefaultMiners example using DefaultMiners()
func ExampleDefaultMiners() {
miners, _ := DefaultMiners()
fmt.Printf("total miners: %d", len(miners))
// Output:total miners: 4
// Output:total miners: 2
}

// BenchmarkDefaultMiners benchmarks the method DefaultMiners()
Expand Down
80 changes: 77 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,33 @@ const (
// MinerTaal is the name of the known miner for "Taal"
MinerTaal = "Taal"

// MinerGorillaPool is the name of the known miner for "GorillaPool"
MinerGorillaPool = "GorillaPool"

// MinerMempool is the name of the known miner for "Mempool"
MinerMempool = "Mempool"

// MinerMatterpool is the name of the known miner for "Matterpool"
MinerMatterpool = "Matterpool"

// MinerGorillaPool is the name of the known miner for "GorillaPool"
MinerGorillaPool = "GorillaPool"
)

// KnownMiners is a pre-filled list of known miners
const KnownMiners = `
[
{
"name":"Taal",
"miner_id":"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270"
},
{
"name":"GorillaPool",
"miner_id":"03ad780153c47df915b3d2e23af727c68facaca4facd5f155bf5018b979b9aeb83"
}
]
`

// KnownMinersAll is a pre-filled list of known miners
// deprecated: use KnownMiners instead
const KnownMinersAll = `
[
{
"name":"Taal",
Expand Down Expand Up @@ -195,3 +210,62 @@ const KnownMinersAPIs = `
}
]
`

// KnownMinersAPIsAll is a pre-filled list of known miners with their APIs
// Any pre-filled tokens are for free use only
// update your custom token with client.MinerUpdateToken("name", "token")
// deprecated: use KnownMinersAPIsAll instead
const KnownMinersAPIsAll = `
[
{
"miner_id":"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270",
"apis":[
{
"token":"",
"url":"https://merchantapi.taal.com",
"type":"mAPI"
},
{
"token":"",
"url":"https://tapi.taal.com/arc",
"type":"Arc"
}
]
},
{
"miner_id":"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270",
"apis":[
{
"token":"561b756d12572020ea9a104c3441b71790acbbce95a6ddbf7e0630971af9424b",
"url":"https://www.ddpurse.com/openapi",
"type":"mAPI"
}
]
},
{
"miner_id":"0253a9b2d017254b91704ba52aad0df5ca32b4fb5cb6b267ada6aefa2bc5833a93",
"apis":[
{
"token":"",
"url":"https://merchantapi.matterpool.io",
"type":"mAPI"
}
]
},
{
"miner_id":"03ad780153c47df915b3d2e23af727c68facaca4facd5f155bf5018b979b9aeb83",
"apis":[
{
"token":"",
"url":"https://merchantapi.gorillapool.io",
"type":"mAPI"
},
{
"token":"",
"url":"https://arc.gorillapool.io",
"type":"Arc"
}
]
}
]
`
2 changes: 1 addition & 1 deletion fee_quote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ func ExampleFeePayload_CalculateFee() {

// Note: cannot show response since the miner might be different each time
fmt.Printf("got best quote and fee for 1000 byte tx is: %d", fee)
// Output:got best quote and fee for 1000 byte tx is: 430
// Output:got best quote and fee for 1000 byte tx is: 500
}

// BenchmarkFeePayload_CalculateFee benchmarks the method CalculateFee()
Expand Down
18 changes: 9 additions & 9 deletions query_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestClient_QueryTransaction(t *testing.T) {
client := newTestClient(&mockHTTPValidQuery{})

// Create a req
response, err := client.QueryTransaction(context.Background(), client.MinerByName(MinerMatterpool), testTx)
response, err := client.QueryTransaction(context.Background(), client.MinerByName(MinerGorillaPool), testTx)
assert.NoError(t, err)
assert.NotNil(t, response)

Expand All @@ -90,13 +90,13 @@ func TestClient_QueryTransaction(t *testing.T) {

t.Run("validate parsed values", func(t *testing.T) {
client := newTestClient(&mockHTTPValidQuery{})
response, err := client.QueryTransaction(context.Background(), client.MinerByName(MinerMatterpool), testTx)
response, err := client.QueryTransaction(context.Background(), client.MinerByName(MinerGorillaPool), testTx)
assert.NoError(t, err)
assert.NotNil(t, response)

// Test parsed values
assert.Equal(t, MinerMatterpool, response.Miner.Name)
assert.Equal(t, "0253a9b2d017254b91704ba52aad0df5ca32b4fb5cb6b267ada6aefa2bc5833a93", response.Miner.MinerID)
assert.Equal(t, MinerGorillaPool, response.Miner.Name)
assert.Equal(t, "03ad780153c47df915b3d2e23af727c68facaca4facd5f155bf5018b979b9aeb83", response.Miner.MinerID)
assert.Equal(t, "2020-10-10T13:07:26.014Z", response.Query.Timestamp)
assert.Equal(t, "0.1.0", response.Query.APIVersion)
assert.Equal(t, "0000000000000000050a09fe90b0e8542bba9e712edb8cc9349e61888fe45ac5", response.Query.BlockHash)
Expand All @@ -113,35 +113,35 @@ func TestClient_QueryTransaction(t *testing.T) {

t.Run("http error", func(t *testing.T) {
client := newTestClient(&mockHTTPError{})
response, err := client.QueryTransaction(context.Background(), client.MinerByName(MinerMatterpool), testTx)
response, err := client.QueryTransaction(context.Background(), client.MinerByName(MinerGorillaPool), testTx)
assert.Error(t, err)
assert.Nil(t, response)
})

t.Run("bad request", func(t *testing.T) {
client := newTestClient(&mockHTTPBadRequest{})
response, err := client.QueryTransaction(context.Background(), client.MinerByName(MinerMatterpool), testTx)
response, err := client.QueryTransaction(context.Background(), client.MinerByName(MinerGorillaPool), testTx)
assert.Error(t, err)
assert.Nil(t, response)
})

t.Run("invalid JSON", func(t *testing.T) {
client := newTestClient(&mockHTTPInvalidJSON{})
response, err := client.QueryTransaction(context.Background(), client.MinerByName(MinerMatterpool), testTx)
response, err := client.QueryTransaction(context.Background(), client.MinerByName(MinerGorillaPool), testTx)
assert.Error(t, err)
assert.Nil(t, response)
})

t.Run("invalid signature", func(t *testing.T) {
client := newTestClient(&mockHTTPInvalidSignature{})
response, err := client.QueryTransaction(context.Background(), client.MinerByName(MinerMatterpool), testTx)
response, err := client.QueryTransaction(context.Background(), client.MinerByName(MinerGorillaPool), testTx)
assert.Error(t, err)
assert.Nil(t, response)
})

t.Run("bad query", func(t *testing.T) {
client := newTestClient(&mockHTTPBadQuery{})
response, err := client.QueryTransaction(context.Background(), client.MinerByName(MinerMatterpool), testTx)
response, err := client.QueryTransaction(context.Background(), client.MinerByName(MinerGorillaPool), testTx)
assert.Error(t, err)
assert.Nil(t, response)
})
Expand Down
16 changes: 8 additions & 8 deletions submit_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestClient_SubmitTransaction(t *testing.T) {
client := newTestClient(&mockHTTPValidSubmission{})

// Create a req
response, err := client.SubmitTransaction(context.Background(), client.MinerByName(MinerMatterpool), tx)
response, err := client.SubmitTransaction(context.Background(), client.MinerByName(MinerGorillaPool), tx)
assert.NoError(t, err)
assert.NotNil(t, response)

Expand All @@ -99,12 +99,12 @@ func TestClient_SubmitTransaction(t *testing.T) {
defer goleak.VerifyNone(t)

client := newTestClient(&mockHTTPValidSubmission{})
response, err := client.SubmitTransaction(context.Background(), client.MinerByName(MinerMatterpool), tx)
response, err := client.SubmitTransaction(context.Background(), client.MinerByName(MinerGorillaPool), tx)
assert.NoError(t, err)
assert.NotNil(t, response)

// Test parsed values
assert.Equal(t, MinerMatterpool, response.Miner.Name)
assert.Equal(t, MinerGorillaPool, response.Miner.Name)
assert.Equal(t, submitTestPublicKey, response.Results.MinerID)
assert.Equal(t, "2020-01-15T11:40:29.826Z", response.Results.Timestamp)
assert.Equal(t, "0.1.0", response.Results.APIVersion)
Expand All @@ -123,39 +123,39 @@ func TestClient_SubmitTransaction(t *testing.T) {
t.Run("http error", func(t *testing.T) {
defer goleak.VerifyNone(t)
client := newTestClient(&mockHTTPError{})
response, err := client.SubmitTransaction(context.Background(), client.MinerByName(MinerMatterpool), tx)
response, err := client.SubmitTransaction(context.Background(), client.MinerByName(MinerGorillaPool), tx)
assert.Error(t, err)
assert.Nil(t, response)
})

t.Run("bad request", func(t *testing.T) {
defer goleak.VerifyNone(t)
client := newTestClient(&mockHTTPBadRequest{})
response, err := client.SubmitTransaction(context.Background(), client.MinerByName(MinerMatterpool), tx)
response, err := client.SubmitTransaction(context.Background(), client.MinerByName(MinerGorillaPool), tx)
assert.Error(t, err)
assert.Nil(t, response)
})

t.Run("invalid JSON", func(t *testing.T) {
defer goleak.VerifyNone(t)
client := newTestClient(&mockHTTPInvalidJSON{})
response, err := client.SubmitTransaction(context.Background(), client.MinerByName(MinerMatterpool), tx)
response, err := client.SubmitTransaction(context.Background(), client.MinerByName(MinerGorillaPool), tx)
assert.Error(t, err)
assert.Nil(t, response)
})

t.Run("invalid signature", func(t *testing.T) {
defer goleak.VerifyNone(t)
client := newTestClient(&mockHTTPInvalidSignature{})
response, err := client.SubmitTransaction(context.Background(), client.MinerByName(MinerMatterpool), tx)
response, err := client.SubmitTransaction(context.Background(), client.MinerByName(MinerGorillaPool), tx)
assert.Error(t, err)
assert.Nil(t, response)
})

t.Run("bad submission", func(t *testing.T) {
defer goleak.VerifyNone(t)
client := newTestClient(&mockHTTPBadSubmission{})
response, err := client.SubmitTransaction(context.Background(), client.MinerByName(MinerMatterpool), tx)
response, err := client.SubmitTransaction(context.Background(), client.MinerByName(MinerGorillaPool), tx)
assert.Error(t, err)
assert.Nil(t, response)
})
Expand Down
4 changes: 2 additions & 2 deletions submit_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ func TestClient_SubmitTransactions(t *testing.T) {
err: errors.New("miner was nil"),
},
"empty txs should return error": {
miner: MinerMatterpool,
miner: MinerGorillaPool,
err: errors.New("no transactions"),
txs: []Transaction{},
},
"one valid and one invalid tx should return specific response": {
miner: MinerMatterpool,
miner: MinerGorillaPool,
txs: []Transaction{{RawTx: rawTx}},
exp: &SubmitTransactionsResponse{
Payload: UnifiedTxsPayload{
Expand Down

0 comments on commit 1b3cac0

Please sign in to comment.