From 6085e53078034f86ff70c02bde0bd243bd9ea7e4 Mon Sep 17 00:00:00 2001 From: mrz1836 Date: Sun, 11 Oct 2020 12:28:40 -0400 Subject: [PATCH] Added tests for submit transaction --- README.md | 12 +- client_test.go | 1 + fee_quote_test.go | 35 +++-- query_transaction_test.go | 31 +++- submit_transaction.go | 2 +- submit_transaction_test.go | 296 +++++++++++++++++++++++++++++++++++++ 6 files changed, 354 insertions(+), 23 deletions(-) create mode 100644 submit_transaction_test.go diff --git a/README.md b/README.md index 920742b..787d758 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # go-minercraft > Interact with Bitcoin Miner APIs (unofficial Go library of [Minercraft](https://github.com/interplanaria/minercraft)) -[![Release](https://img.shields.io/github/release-pre/tonicpow/go-minercraft.svg?logo=github&style=flat&v=3)](https://github.com/tonicpow/go-minercraft/releases) -[![Build Status](https://travis-ci.com/tonicpow/go-minercraft.svg?branch=master&v=3)](https://travis-ci.com/tonicpow/go-minercraft) -[![Report](https://goreportcard.com/badge/github.com/tonicpow/go-minercraft?style=flat&v=3)](https://goreportcard.com/report/github.com/tonicpow/go-minercraft) -[![codecov](https://codecov.io/gh/tonicpow/go-minercraft/branch/master/graph/badge.svg?v=3)](https://codecov.io/gh/tonicpow/go-minercraft) -[![Go](https://img.shields.io/github/go-mod/go-version/tonicpow/go-minercraft?v=3)](https://golang.org/) +[![Release](https://img.shields.io/github/release-pre/tonicpow/go-minercraft.svg?logo=github&style=flat&v=4)](https://github.com/tonicpow/go-minercraft/releases) +[![Build Status](https://travis-ci.com/tonicpow/go-minercraft.svg?branch=master&v=4)](https://travis-ci.com/tonicpow/go-minercraft) +[![Report](https://goreportcard.com/badge/github.com/tonicpow/go-minercraft?style=flat&v=4)](https://goreportcard.com/report/github.com/tonicpow/go-minercraft) +[![codecov](https://codecov.io/gh/tonicpow/go-minercraft/branch/master/graph/badge.svg?v=4)](https://codecov.io/gh/tonicpow/go-minercraft) +[![Go](https://img.shields.io/github/go-mod/go-version/tonicpow/go-minercraft?v=4)](https://golang.org/)
@@ -165,4 +165,4 @@ nChain & team for developing the [brfc-merchant-api](https://github.com/bitcoin- ## License -![License](https://img.shields.io/github/license/tonicpow/go-minercraft.svg?style=flat&v=3) \ No newline at end of file +![License](https://img.shields.io/github/license/tonicpow/go-minercraft.svg?style=flat&v=4) \ No newline at end of file diff --git a/client_test.go b/client_test.go index 2af37da..633885b 100644 --- a/client_test.go +++ b/client_test.go @@ -10,6 +10,7 @@ import ( ) const ( + testAPIVersion = "0.1.0" testEncoding = "UTF-8" testMimeType = "application/json" testMinerID = "1234567" diff --git a/fee_quote_test.go b/fee_quote_test.go index 35e61b1..200aa0d 100644 --- a/fee_quote_test.go +++ b/fee_quote_test.go @@ -26,7 +26,7 @@ func (m *mockHTTPValidFeeQuote) Do(req *http.Request) (*http.Response, error) { if strings.Contains(req.URL.String(), "/mapi/feeQuote") { resp.StatusCode = http.StatusOK resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ - "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-10-09T21:26:17.410Z\",\"expiryTime\":\"2020-10-09T21:36:17.410Z\",\"minerId\":\"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\"currentHighestBlockHash\":\"0000000000000000035c5f8c0294802a01e500fa7b95337963bb3640da3bd565\",\"currentHighestBlockHeight\":656169,\"minerReputation\":null,\"fees\":[{\"id\":1,\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}},{\"id\":2,\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}}]}", + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-09T21:26:17.410Z\",\"expiryTime\":\"2020-10-09T21:36:17.410Z\",\"minerId\":\"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\"currentHighestBlockHash\":\"0000000000000000035c5f8c0294802a01e500fa7b95337963bb3640da3bd565\",\"currentHighestBlockHeight\":656169,\"minerReputation\":null,\"fees\":[{\"id\":1,\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}},{\"id\":2,\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}}]}", "signature": "3045022100eed49f6bf75d8f975f581271e3df658fbe8ec67e6301ea8fc25a72d18c92e30e022056af253f0d24db6a8fde4e2c1ee95e7a5ecf2c7cdc93246f8328c9e0ca582fc4", "publicKey": "03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270","encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } @@ -117,7 +117,7 @@ func (m *mockHTTPMissingFees) Do(req *http.Request) (*http.Response, error) { if strings.Contains(req.URL.String(), "/mapi/feeQuote") { resp.StatusCode = http.StatusOK resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ - "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-10-09T21:26:17.410Z\",\"expiryTime\":\"2020-10-09T21:36:17.410Z\",\"minerId\":\"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\"currentHighestBlockHash\":\"0000000000000000035c5f8c0294802a01e500fa7b95337963bb3640da3bd565\",\"currentHighestBlockHeight\":656169,\"minerReputation\":null,\"fees\":[]}", + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-09T21:26:17.410Z\",\"expiryTime\":\"2020-10-09T21:36:17.410Z\",\"minerId\":\"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\"currentHighestBlockHash\":\"0000000000000000035c5f8c0294802a01e500fa7b95337963bb3640da3bd565\",\"currentHighestBlockHeight\":656169,\"minerReputation\":null,\"fees\":[]}", "signature": "3045022100eed49f6bf75d8f975f581271e3df658fbe8ec67e6301ea8fc25a72d18c92e30e022056af253f0d24db6a8fde4e2c1ee95e7a5ecf2c7cdc93246f8328c9e0ca582fc4", "publicKey": "03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270","encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } @@ -143,7 +143,7 @@ func (m *mockHTTPInvalidSignature) Do(req *http.Request) (*http.Response, error) if strings.Contains(req.URL.String(), "/mapi/feeQuote") { resp.StatusCode = http.StatusOK resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ - "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-10-09T21:26:17.410Z\",\"expiryTime\":\"2020-10-09T21:36:17.410Z\",\"minerId\":\"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\"currentHighestBlockHash\":\"0000000000000000035c5f8c0294802a01e500fa7b95337963bb3640da3bd565\",\"currentHighestBlockHeight\":656169,\"minerReputation\":null,\"fees\":[{\"id\":1,\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}},{\"id\":2,\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}}]}", + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-09T21:26:17.410Z\",\"expiryTime\":\"2020-10-09T21:36:17.410Z\",\"minerId\":\"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\"currentHighestBlockHash\":\"0000000000000000035c5f8c0294802a01e500fa7b95337963bb3640da3bd565\",\"currentHighestBlockHeight\":656169,\"minerReputation\":null,\"fees\":[{\"id\":1,\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}},{\"id\":2,\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}}]}", "signature": "03045022100eed49f6bf75d8f975f581271e3df658fbe8ec67e6301ea8fc25a72d18c92e30e022056af253f0d24db6a8fde4e2c1ee95e7a5ecf2c7cdc93246f8328c9e0ca582fc40", "publicKey": "03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270","encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } @@ -152,11 +152,20 @@ func (m *mockHTTPInvalidSignature) Do(req *http.Request) (*http.Response, error) if strings.Contains(req.URL.String(), "/mapi/tx/"+testTx) { resp.StatusCode = http.StatusOK resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ - "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-10-11T15:41:29.269Z\",\"returnResult\":\"success\",\"resultDescription\":\"\",\"blockHash\":\"0000000000000000050a09fe90b0e8542bba9e712edb8cc9349e61888fe45ac5\",\"blockHeight\":612530,\"confirmations\":43923,\"minerId\":\"0211ccfc29e3058b770f3cf3eb34b0b2fd2293057a994d4d275121be4151cdf087\",\"txSecondMempoolExpiry\":0}", + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-11T15:41:29.269Z\",\"returnResult\":\"success\",\"resultDescription\":\"\",\"blockHash\":\"0000000000000000050a09fe90b0e8542bba9e712edb8cc9349e61888fe45ac5\",\"blockHeight\":612530,\"confirmations\":43923,\"minerId\":\"0211ccfc29e3058b770f3cf3eb34b0b2fd2293057a994d4d275121be4151cdf087\",\"txSecondMempoolExpiry\":0}", "signature": "03045022100eed49f6bf75d8f975f581271e3df658fbe8ec67e6301ea8fc25a72d18c92e30e022056af253f0d24db6a8fde4e2c1ee95e7a5ecf2c7cdc93246f8328c9e0ca582fc40", "publicKey": "03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270","encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } + // Invalid sig response + if strings.Contains(req.URL.String(), "/mapi/tx") { + resp.StatusCode = http.StatusOK + resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-01-15T11:40:29.826Z\",\"txid\":\"6bdbcfab0526d30e8d68279f79dff61fb4026ace8b7b32789af016336e54f2f0\",\"returnResult\":\"success\",\"resultDescription\":\"\",\"minerId\":\"03fcfcfcd0841b0a6ed2057fa8ed404788de47ceb3390c53e79c4ecd1e05819031\",\"currentHighestBlockHash\":\"71a7374389afaec80fcabbbf08dcd82d392cf68c9a13fe29da1a0c853facef01\",\"currentHighestBlockHeight\":207,\"txSecondMempoolExpiry\":0}", + "signature": "03045022100f65ae83b20bc60e7a5f0e9c1bd9aceb2b26962ad0ee35472264e83e059f4b9be022010ca2334ff088d6e085eb3c2118306e61ec97781e8e1544e75224533dcc323790", + "publicKey": "03fcfcfcd0841b0a6ed2057fa8ed404788de47ceb3390c53e79c4ecd1e05819031","encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) + } + // Default is valid return resp, nil } @@ -178,7 +187,7 @@ func (m *mockHTTPValidBestQuote) Do(req *http.Request) (*http.Response, error) { if req.URL.String() == defaultProtocol+"merchantapi.taal.com/mapi/feeQuote" { resp.StatusCode = http.StatusOK resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ - "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-10-09T21:26:17.410Z\",\"expiryTime\":\"2020-10-09T21:36:17.410Z\",\"minerId\":\"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\"currentHighestBlockHash\":\"0000000000000000035c5f8c0294802a01e500fa7b95337963bb3640da3bd565\",\"currentHighestBlockHeight\":656169,\"minerReputation\":null,\"fees\":[{\"id\":1,\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":400,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}},{\"id\":2,\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":225,\"bytes\":1000}}]}", + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-09T21:26:17.410Z\",\"expiryTime\":\"2020-10-09T21:36:17.410Z\",\"minerId\":\"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\"currentHighestBlockHash\":\"0000000000000000035c5f8c0294802a01e500fa7b95337963bb3640da3bd565\",\"currentHighestBlockHeight\":656169,\"minerReputation\":null,\"fees\":[{\"id\":1,\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":400,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}},{\"id\":2,\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":225,\"bytes\":1000}}]}", "signature": "3045022100eed49f6bf75d8f975f581271e3df658fbe8ec67e6301ea8fc25a72d18c92e30e022056af253f0d24db6a8fde4e2c1ee95e7a5ecf2c7cdc93246f8328c9e0ca582fc4", "publicKey": "03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270","encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } @@ -186,7 +195,7 @@ func (m *mockHTTPValidBestQuote) Do(req *http.Request) (*http.Response, error) { if req.URL.String() == defaultProtocol+"merchantapi.matterpool.io/mapi/feeQuote" { resp.StatusCode = http.StatusOK resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ - "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-10-09T22:08:26.236Z\",\"expiryTime\":\"2020-10-09T22:18:26.236Z\",\"minerId\":\"0211ccfc29e3058b770f3cf3eb34b0b2fd2293057a994d4d275121be4151cdf087\",\"currentHighestBlockHash\":\"0000000000000000028285a9168c95457521a743765f499de389c094e883f42a\",\"currentHighestBlockHeight\":656171,\"minerReputation\":null,\"fees\":[{\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":400,\"bytes\":1000},\"relayFee\":{\"satoshis\":100,\"bytes\":1000}},{\"feeType\":\"data\",\"miningFee\":{\"satoshis\":430,\"bytes\":1000},\"relayFee\":{\"satoshis\":110,\"bytes\":1000}}]}", + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-09T22:08:26.236Z\",\"expiryTime\":\"2020-10-09T22:18:26.236Z\",\"minerId\":\"0211ccfc29e3058b770f3cf3eb34b0b2fd2293057a994d4d275121be4151cdf087\",\"currentHighestBlockHash\":\"0000000000000000028285a9168c95457521a743765f499de389c094e883f42a\",\"currentHighestBlockHeight\":656171,\"minerReputation\":null,\"fees\":[{\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":400,\"bytes\":1000},\"relayFee\":{\"satoshis\":100,\"bytes\":1000}},{\"feeType\":\"data\",\"miningFee\":{\"satoshis\":430,\"bytes\":1000},\"relayFee\":{\"satoshis\":110,\"bytes\":1000}}]}", "signature": "3044022011f90db2661726eb2659c3447ccaa9fd3368194f87d5d86a23e673c45d5d714502200c51eb600e3370b49d759aa4d441000286937b0803037a1d6de4c5a5c559d74c", "publicKey": "0211ccfc29e3058b770f3cf3eb34b0b2fd2293057a994d4d275121be4151cdf087","encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } @@ -194,7 +203,7 @@ func (m *mockHTTPValidBestQuote) Do(req *http.Request) (*http.Response, error) { if req.URL.String() == defaultProtocol+"www.ddpurse.com/openapi/mapi/feeQuote" { resp.StatusCode = http.StatusOK resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ - "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-10-09T22:09:04.433Z\",\"expiryTime\":\"2020-10-09T22:19:04.433Z\",\"minerId\":null,\"currentHighestBlockHash\":\"0000000000000000028285a9168c95457521a743765f499de389c094e883f42a\",\"currentHighestBlockHeight\":656171,\"minerReputation\":null,\"fees\":[{\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}},{\"feeType\":\"data\",\"miningFee\":{\"satoshis\":420,\"bytes\":1000},\"relayFee\":{\"satoshis\":150,\"bytes\":1000}}]}", + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-09T22:09:04.433Z\",\"expiryTime\":\"2020-10-09T22:19:04.433Z\",\"minerId\":null,\"currentHighestBlockHash\":\"0000000000000000028285a9168c95457521a743765f499de389c094e883f42a\",\"currentHighestBlockHeight\":656171,\"minerReputation\":null,\"fees\":[{\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}},{\"feeType\":\"data\",\"miningFee\":{\"satoshis\":420,\"bytes\":1000},\"relayFee\":{\"satoshis\":150,\"bytes\":1000}}]}", "signature": null,"publicKey": null,"encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } @@ -219,7 +228,7 @@ func (m *mockHTTPBetterRate) Do(req *http.Request) (*http.Response, error) { if req.URL.String() == defaultProtocol+"merchantapi.taal.com/mapi/feeQuote" { resp.StatusCode = http.StatusOK resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ - "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-10-09T21:26:17.410Z\",\"expiryTime\":\"2020-10-09T21:36:17.410Z\",\"minerId\":\"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\"currentHighestBlockHash\":\"0000000000000000035c5f8c0294802a01e500fa7b95337963bb3640da3bd565\",\"currentHighestBlockHeight\":656169,\"minerReputation\":null,\"fees\":[{\"id\":1,\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":475,\"bytes\":1000},\"relayFee\":{\"satoshis\":150,\"bytes\":1000}},{\"id\":2,\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}}]}", + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-09T21:26:17.410Z\",\"expiryTime\":\"2020-10-09T21:36:17.410Z\",\"minerId\":\"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\"currentHighestBlockHash\":\"0000000000000000035c5f8c0294802a01e500fa7b95337963bb3640da3bd565\",\"currentHighestBlockHeight\":656169,\"minerReputation\":null,\"fees\":[{\"id\":1,\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":475,\"bytes\":1000},\"relayFee\":{\"satoshis\":150,\"bytes\":1000}},{\"id\":2,\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}}]}", "signature": "3045022100eed49f6bf75d8f975f581271e3df658fbe8ec67e6301ea8fc25a72d18c92e30e022056af253f0d24db6a8fde4e2c1ee95e7a5ecf2c7cdc93246f8328c9e0ca582fc4", "publicKey": "03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270","encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } @@ -227,7 +236,7 @@ func (m *mockHTTPBetterRate) Do(req *http.Request) (*http.Response, error) { if req.URL.String() == defaultProtocol+"merchantapi.matterpool.io/mapi/feeQuote" { resp.StatusCode = http.StatusOK resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ - "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-10-09T22:08:26.236Z\",\"expiryTime\":\"2020-10-09T22:18:26.236Z\",\"minerId\":\"0211ccfc29e3058b770f3cf3eb34b0b2fd2293057a994d4d275121be4151cdf087\",\"currentHighestBlockHash\":\"0000000000000000028285a9168c95457521a743765f499de389c094e883f42a\",\"currentHighestBlockHeight\":656171,\"minerReputation\":null,\"fees\":[{\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":405,\"bytes\":1000},\"relayFee\":{\"satoshis\":100,\"bytes\":1000}},{\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":100,\"bytes\":1000}}]}", + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-09T22:08:26.236Z\",\"expiryTime\":\"2020-10-09T22:18:26.236Z\",\"minerId\":\"0211ccfc29e3058b770f3cf3eb34b0b2fd2293057a994d4d275121be4151cdf087\",\"currentHighestBlockHash\":\"0000000000000000028285a9168c95457521a743765f499de389c094e883f42a\",\"currentHighestBlockHeight\":656171,\"minerReputation\":null,\"fees\":[{\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":405,\"bytes\":1000},\"relayFee\":{\"satoshis\":100,\"bytes\":1000}},{\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":100,\"bytes\":1000}}]}", "signature": "3044022011f90db2661726eb2659c3447ccaa9fd3368194f87d5d86a23e673c45d5d714502200c51eb600e3370b49d759aa4d441000286937b0803037a1d6de4c5a5c559d74c", "publicKey": "0211ccfc29e3058b770f3cf3eb34b0b2fd2293057a994d4d275121be4151cdf087","encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } @@ -235,7 +244,7 @@ func (m *mockHTTPBetterRate) Do(req *http.Request) (*http.Response, error) { if req.URL.String() == defaultProtocol+"www.ddpurse.com/openapi/mapi/feeQuote" { resp.StatusCode = http.StatusOK resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ - "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-10-09T22:09:04.433Z\",\"expiryTime\":\"2020-10-09T22:19:04.433Z\",\"minerId\":null,\"currentHighestBlockHash\":\"0000000000000000028285a9168c95457521a743765f499de389c094e883f42a\",\"currentHighestBlockHeight\":656171,\"minerReputation\":null,\"fees\":[{\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":350,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}},{\"feeType\":\"data\",\"miningFee\":{\"satoshis\":430,\"bytes\":1000},\"relayFee\":{\"satoshis\":175,\"bytes\":1000}}]}", + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-09T22:09:04.433Z\",\"expiryTime\":\"2020-10-09T22:19:04.433Z\",\"minerId\":null,\"currentHighestBlockHash\":\"0000000000000000028285a9168c95457521a743765f499de389c094e883f42a\",\"currentHighestBlockHeight\":656171,\"minerReputation\":null,\"fees\":[{\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":350,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}},{\"feeType\":\"data\",\"miningFee\":{\"satoshis\":430,\"bytes\":1000},\"relayFee\":{\"satoshis\":175,\"bytes\":1000}}]}", "signature": null,"publicKey": null,"encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } @@ -260,7 +269,7 @@ func (m *mockHTTPMissingFeeType) Do(req *http.Request) (*http.Response, error) { if strings.Contains(req.URL.String(), "/mapi/feeQuote") { resp.StatusCode = http.StatusOK resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ - "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-10-09T21:26:17.410Z\",\"expiryTime\":\"2020-10-09T21:36:17.410Z\",\"minerId\":\"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\"currentHighestBlockHash\":\"0000000000000000035c5f8c0294802a01e500fa7b95337963bb3640da3bd565\",\"currentHighestBlockHeight\":656169,\"minerReputation\":null,\"fees\":[{\"id\":2,\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}}]}", + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-09T21:26:17.410Z\",\"expiryTime\":\"2020-10-09T21:36:17.410Z\",\"minerId\":\"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\"currentHighestBlockHash\":\"0000000000000000035c5f8c0294802a01e500fa7b95337963bb3640da3bd565\",\"currentHighestBlockHeight\":656169,\"minerReputation\":null,\"fees\":[{\"id\":2,\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}}]}", "signature": "3045022100eed49f6bf75d8f975f581271e3df658fbe8ec67e6301ea8fc25a72d18c92e30e022056af253f0d24db6a8fde4e2c1ee95e7a5ecf2c7cdc93246f8328c9e0ca582fc4", "publicKey": "03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270","encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } @@ -335,8 +344,8 @@ func TestClient_FeeQuoteParsedValues(t *testing.T) { if response.Quote.Timestamp != "2020-10-09T21:26:17.410Z" { t.Fatalf("expected response.Quote.Timestamp to be %s, got %s", "2020-10-09T21:26:17.410Z", response.Quote.Timestamp) } - if response.Quote.APIVersion != "0.1.0" { - t.Fatalf("expected response.Quote.APIVersion to be %s, got %s", "0.1.0", response.Quote.APIVersion) + if response.Quote.APIVersion != testAPIVersion { + t.Fatalf("expected response.Quote.APIVersion to be %s, got %s", testAPIVersion, response.Quote.APIVersion) } if response.Quote.CurrentHighestBlockHash != "0000000000000000035c5f8c0294802a01e500fa7b95337963bb3640da3bd565" { t.Fatalf("expected response.Quote.CurrentHighestBlockHash to be %s, got %s", "0000000000000000035c5f8c0294802a01e500fa7b95337963bb3640da3bd565", response.Quote.CurrentHighestBlockHash) diff --git a/query_transaction_test.go b/query_transaction_test.go index 7d85e5e..2c79576 100644 --- a/query_transaction_test.go +++ b/query_transaction_test.go @@ -26,7 +26,7 @@ func (m *mockHTTPValidQuery) Do(req *http.Request) (*http.Response, error) { if strings.Contains(req.URL.String(), "/mapi/tx/"+testTx) { resp.StatusCode = http.StatusOK resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ - "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-10-10T13:07:26.014Z\",\"returnResult\":\"success\",\"resultDescription\":\"\",\"blockHash\":\"0000000000000000050a09fe90b0e8542bba9e712edb8cc9349e61888fe45ac5\",\"blockHeight\":612530,\"confirmations\":43733,\"minerId\":\"0211ccfc29e3058b770f3cf3eb34b0b2fd2293057a994d4d275121be4151cdf087\",\"txSecondMempoolExpiry\":0}", + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-10T13:07:26.014Z\",\"returnResult\":\"success\",\"resultDescription\":\"\",\"blockHash\":\"0000000000000000050a09fe90b0e8542bba9e712edb8cc9349e61888fe45ac5\",\"blockHeight\":612530,\"confirmations\":43733,\"minerId\":\"0211ccfc29e3058b770f3cf3eb34b0b2fd2293057a994d4d275121be4151cdf087\",\"txSecondMempoolExpiry\":0}", "signature": "3044022066a8a39ff5f5eae818636aa03fdfc386ea4f33f41993cf41d4fb6d4745ae032102206a8895a6f742d809647ad1a1df12230e9b480275853ed28bc178f4b48afd802a", "publicKey": "0211ccfc29e3058b770f3cf3eb34b0b2fd2293057a994d4d275121be4151cdf087","encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } @@ -97,6 +97,31 @@ func TestClient_QueryTransaction(t *testing.T) { } } +// ExampleClient_QueryTransaction example using QueryTransaction() +func ExampleClient_QueryTransaction() { + // Create a client (using a test client vs NewClient()) + client := newTestClient(&mockHTTPValidQuery{}) + + // Create a req + response, err := client.QueryTransaction(client.MinerByName(MinerTaal), testTx) + if err != nil { + fmt.Printf("error occurred: %s", err.Error()) + return + } + + fmt.Printf("got tx status %s from: %s", response.Query.ReturnResult, response.Miner.Name) + // Output:got tx status success from: Taal +} + +// BenchmarkClient_QueryTransaction benchmarks the method QueryTransaction() +func BenchmarkClient_QueryTransaction(b *testing.B) { + client := newTestClient(&mockHTTPValidQuery{}) + miner := client.MinerByName(MinerTaal) + for i := 0; i < b.N; i++ { + _, _ = client.QueryTransaction(miner, testTx) + } +} + // TestClient_QueryTransactionParsedValues tests the method QueryTransaction() func TestClient_QueryTransactionParsedValues(t *testing.T) { t.Parallel() @@ -124,8 +149,8 @@ func TestClient_QueryTransactionParsedValues(t *testing.T) { if response.Query.Timestamp != "2020-10-10T13:07:26.014Z" { t.Fatalf("expected response.Query.Timestamp to be %s, got %s", "2020-10-10T13:07:26.014Z", response.Query.Timestamp) } - if response.Query.APIVersion != "0.1.0" { - t.Fatalf("expected response.Query.APIVersion to be %s, got %s", "0.1.0", response.Query.APIVersion) + if response.Query.APIVersion != testAPIVersion { + t.Fatalf("expected response.Query.APIVersion to be %s, got %s", testAPIVersion, response.Query.APIVersion) } if response.Query.BlockHash != "0000000000000000050a09fe90b0e8542bba9e712edb8cc9349e61888fe45ac5" { t.Fatalf("expected response.Query.BlockHash to be %s, got %s", "0000000000000000050a09fe90b0e8542bba9e712edb8cc9349e61888fe45ac5", response.Query.BlockHash) diff --git a/submit_transaction.go b/submit_transaction.go index e5bec1a..d495979 100644 --- a/submit_transaction.go +++ b/submit_transaction.go @@ -107,7 +107,7 @@ func (c *Client) SubmitTransaction(miner *Miner, tx *Transaction) (*SubmitTransa } // Valid query? - if response.Results == nil { + if response.Results == nil || len(response.Results.ReturnResult) == 0 { return nil, errors.New("failed getting submission response from: " + miner.Name) } diff --git a/submit_transaction_test.go b/submit_transaction_test.go new file mode 100644 index 0000000..81321a9 --- /dev/null +++ b/submit_transaction_test.go @@ -0,0 +1,296 @@ +package minercraft + +import ( + "bytes" + "fmt" + "io/ioutil" + "net/http" + "strings" + "testing" +) + +// mockHTTPValidSubmission for mocking requests +type mockHTTPValidSubmission struct{} + +// Do is a mock http request +func (m *mockHTTPValidSubmission) Do(req *http.Request) (*http.Response, error) { + resp := new(http.Response) + resp.StatusCode = http.StatusBadRequest + + // No req found + if req == nil { + return resp, fmt.Errorf("missing request") + } + + // Valid response + if strings.Contains(req.URL.String(), "/mapi/tx") { + resp.StatusCode = http.StatusOK + resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-01-15T11:40:29.826Z\",\"txid\":\"6bdbcfab0526d30e8d68279f79dff61fb4026ace8b7b32789af016336e54f2f0\",\"returnResult\":\"success\",\"resultDescription\":\"\",\"minerId\":\"03fcfcfcd0841b0a6ed2057fa8ed404788de47ceb3390c53e79c4ecd1e05819031\",\"currentHighestBlockHash\":\"71a7374389afaec80fcabbbf08dcd82d392cf68c9a13fe29da1a0c853facef01\",\"currentHighestBlockHeight\":207,\"txSecondMempoolExpiry\":0}", + "signature": "3045022100f65ae83b20bc60e7a5f0e9c1bd9aceb2b26962ad0ee35472264e83e059f4b9be022010ca2334ff088d6e085eb3c2118306e61ec97781e8e1544e75224533dcc32379", + "publicKey": "03fcfcfcd0841b0a6ed2057fa8ed404788de47ceb3390c53e79c4ecd1e05819031","encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) + } + + // Default is valid + return resp, nil +} + +// mockHTTPBadSubmission for mocking requests +type mockHTTPBadSubmission struct{} + +// Do is a mock http request +func (m *mockHTTPBadSubmission) Do(req *http.Request) (*http.Response, error) { + resp := new(http.Response) + resp.StatusCode = http.StatusBadRequest + + // No req found + if req == nil { + return resp, fmt.Errorf("missing request") + } + + // Valid response + if strings.Contains(req.URL.String(), "/mapi/tx") { + resp.StatusCode = http.StatusOK + resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ + "payload": "{}", + "signature": "3044022066a8a39ff5f5eae818636aa03fdfc386ea4f33f41993cf41d4fb6d4745ae032102206a8895a6f742d809647ad1a1df12230e9b480275853ed28bc178f4b48afd802a", + "publicKey": "0211ccfc29e3058b770f3cf3eb34b0b2fd2293057a994d4d275121be4151cdf087","encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) + } + + // Default is valid + return resp, nil +} + +// TestClient_SubmitTransaction tests the method SubmitTransaction() +func TestClient_SubmitTransaction(t *testing.T) { + t.Parallel() + + testSignature := "3045022100f65ae83b20bc60e7a5f0e9c1bd9aceb2b26962ad0ee35472264e83e059f4b9be022010ca2334ff088d6e085eb3c2118306e61ec97781e8e1544e75224533dcc32379" + testPublicKey := "03fcfcfcd0841b0a6ed2057fa8ed404788de47ceb3390c53e79c4ecd1e05819031" + + // Create a client + client := newTestClient(&mockHTTPValidSubmission{}) + + tx := &Transaction{ + RawTx: "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1c03d7c6082f7376706f6f6c2e636f6d2f3edff034600055b8467f0040ffffffff01247e814a000000001976a914492558fb8ca71a3591316d095afc0f20ef7d42f788ac00000000", + } + + // Create a req + response, err := client.SubmitTransaction(client.MinerByName(MinerMatterpool), tx) + if err != nil { + t.Fatalf("error occurred: %s", err.Error()) + } else if response == nil { + t.Fatalf("expected response to not be nil") + } + + // Check returned values + if !response.Validated { + t.Fatalf("expected response.Validated to be true, got false") + } + if response.Signature != testSignature { + t.Fatalf("expected response.Signature to be %s, got %s", testSignature, response.Signature) + } + if response.PublicKey != testPublicKey { + t.Fatalf("expected response.PublicKey to be %s, got %s", testPublicKey, response.PublicKey) + } + if response.Encoding != testEncoding { + t.Fatalf("expected response.Encoding to be %s, got %s", testEncoding, response.Encoding) + } + if response.MimeType != testMimeType { + t.Fatalf("expected response.MimeType to be %s, got %s", testMimeType, response.MimeType) + } +} + +// ExampleClient_SubmitTransaction example using SubmitTransaction() +func ExampleClient_SubmitTransaction() { + // Create a client (using a test client vs NewClient()) + client := newTestClient(&mockHTTPValidSubmission{}) + + tx := &Transaction{ + RawTx: "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1c03d7c6082f7376706f6f6c2e636f6d2f3edff034600055b8467f0040ffffffff01247e814a000000001976a914492558fb8ca71a3591316d095afc0f20ef7d42f788ac00000000", + } + + // Create a req + response, err := client.SubmitTransaction(client.MinerByName(MinerTaal), tx) + if err != nil { + fmt.Printf("error occurred: %s", err.Error()) + return + } + + fmt.Printf("submitted tx to: %s", response.Miner.Name) + // Output:submitted tx to: Taal +} + +// BenchmarkClient_SubmitTransaction benchmarks the method SubmitTransaction() +func BenchmarkClient_SubmitTransaction(b *testing.B) { + client := newTestClient(&mockHTTPValidSubmission{}) + miner := client.MinerByName(MinerTaal) + tx := &Transaction{ + RawTx: "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1c03d7c6082f7376706f6f6c2e636f6d2f3edff034600055b8467f0040ffffffff01247e814a000000001976a914492558fb8ca71a3591316d095afc0f20ef7d42f788ac00000000", + } + for i := 0; i < b.N; i++ { + _, _ = client.SubmitTransaction(miner, tx) + } +} + +// TestClient_SubmitTransactionParsedValues tests the method SubmitTransaction() +func TestClient_SubmitTransactionParsedValues(t *testing.T) { + t.Parallel() + + testID := "03fcfcfcd0841b0a6ed2057fa8ed404788de47ceb3390c53e79c4ecd1e05819031" + + tx := &Transaction{ + RawTx: "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1c03d7c6082f7376706f6f6c2e636f6d2f3edff034600055b8467f0040ffffffff01247e814a000000001976a914492558fb8ca71a3591316d095afc0f20ef7d42f788ac00000000", + } + + // Create a client + client := newTestClient(&mockHTTPValidSubmission{}) + + // Create a req + response, err := client.SubmitTransaction(client.MinerByName(MinerMatterpool), tx) + if err != nil { + t.Fatalf("error occurred: %s", err.Error()) + } else if response == nil { + t.Fatalf("expected response to not be nil") + } + + // Test parsed values + if response.Miner.Name != MinerMatterpool { + t.Fatalf("expected response.Miner.Name to be %s, got %s", MinerTaal, response.Miner.Name) + } + if response.Results.MinerID != testID { + t.Fatalf("expected response.Results.MinerID to be %s, got %s", testID, response.Results.MinerID) + } + if response.Results.Timestamp != "2020-01-15T11:40:29.826Z" { + t.Fatalf("expected response.Results.Timestamp to be %s, got %s", "2020-01-15T11:40:29.826Z", response.Results.Timestamp) + } + if response.Results.APIVersion != testAPIVersion { + t.Fatalf("expected response.Results.APIVersion to be %s, got %s", testAPIVersion, response.Results.APIVersion) + } + if response.Results.ReturnResult != "success" { + t.Fatalf("expected response.Results.ReturnResult to be %s, got %s", "success", response.Results.ReturnResult) + } + if response.Results.TxID != "6bdbcfab0526d30e8d68279f79dff61fb4026ace8b7b32789af016336e54f2f0" { + t.Fatalf("expected response.Results.TxID to be %s, got %s", "6bdbcfab0526d30e8d68279f79dff61fb4026ace8b7b32789af016336e54f2f0", response.Results.TxID) + } +} + +// TestClient_SubmitTransactionInvalidMiner tests the method SubmitTransaction() +func TestClient_SubmitTransactionInvalidMiner(t *testing.T) { + t.Parallel() + + // Create a client + client := newTestClient(&mockHTTPValidSubmission{}) + + tx := &Transaction{ + RawTx: "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1c03d7c6082f7376706f6f6c2e636f6d2f3edff034600055b8467f0040ffffffff01247e814a000000001976a914492558fb8ca71a3591316d095afc0f20ef7d42f788ac00000000", + } + + // Create a req + response, err := client.SubmitTransaction(nil, tx) + if err == nil { + t.Fatalf("error should have occurred") + } else if response != nil { + t.Fatalf("expected response to be nil") + } +} + +// TestClient_SubmitTransactionHTTPError tests the method SubmitTransaction() +func TestClient_SubmitTransactionHTTPError(t *testing.T) { + t.Parallel() + + // Create a client + client := newTestClient(&mockHTTPError{}) + + tx := &Transaction{ + RawTx: "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1c03d7c6082f7376706f6f6c2e636f6d2f3edff034600055b8467f0040ffffffff01247e814a000000001976a914492558fb8ca71a3591316d095afc0f20ef7d42f788ac00000000", + } + + // Create a req + response, err := client.SubmitTransaction(client.MinerByName(MinerMatterpool), tx) + if err == nil { + t.Fatalf("error should have occurred") + } else if response != nil { + t.Fatalf("expected response to be nil") + } +} + +// TestClient_SubmitTransactionBadRequest tests the method SubmitTransaction() +func TestClient_SubmitTransactionBadRequest(t *testing.T) { + t.Parallel() + + // Create a client + client := newTestClient(&mockHTTPBadRequest{}) + + tx := &Transaction{ + RawTx: "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1c03d7c6082f7376706f6f6c2e636f6d2f3edff034600055b8467f0040ffffffff01247e814a000000001976a914492558fb8ca71a3591316d095afc0f20ef7d42f788ac00000000", + } + + // Create a req + response, err := client.SubmitTransaction(client.MinerByName(MinerMatterpool), tx) + if err == nil { + t.Fatalf("error should have occurred") + } else if response != nil { + t.Fatalf("expected response to be nil") + } +} + +// TestClient_SubmitTransactionInvalidJSON tests the method SubmitTransaction() +func TestClient_SubmitTransactionInvalidJSON(t *testing.T) { + t.Parallel() + + // Create a client + client := newTestClient(&mockHTTPInvalidJSON{}) + + tx := &Transaction{ + RawTx: "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1c03d7c6082f7376706f6f6c2e636f6d2f3edff034600055b8467f0040ffffffff01247e814a000000001976a914492558fb8ca71a3591316d095afc0f20ef7d42f788ac00000000", + } + + // Create a req + response, err := client.SubmitTransaction(client.MinerByName(MinerMatterpool), tx) + if err == nil { + t.Fatalf("error should have occurred") + } else if response != nil { + t.Fatalf("expected response to be nil") + } +} + +// TestClient_SubmitTransactionInvalidSignature tests the method SubmitTransaction() +func TestClient_SubmitTransactionInvalidSignature(t *testing.T) { + t.Parallel() + + // Create a client + client := newTestClient(&mockHTTPInvalidSignature{}) + + tx := &Transaction{ + RawTx: "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1c03d7c6082f7376706f6f6c2e636f6d2f3edff034600055b8467f0040ffffffff01247e814a000000001976a914492558fb8ca71a3591316d095afc0f20ef7d42f788ac00000000", + } + + // Create a req + response, err := client.SubmitTransaction(client.MinerByName(MinerMatterpool), tx) + if err == nil { + t.Fatalf("error should have occurred") + } else if response != nil { + t.Fatalf("expected response to be nil") + } +} + +// TestClient_SubmitTransactionBadSubmit tests the method SubmitTransaction() +func TestClient_SubmitTransactionBadSubmission(t *testing.T) { + t.Parallel() + + // Create a client + client := newTestClient(&mockHTTPBadSubmission{}) + + tx := &Transaction{ + RawTx: "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1c03d7c6082f7376706f6f6c2e636f6d2f3edff034600055b8467f0040ffffffff01247e814a000000001976a914492558fb8ca71a3591316d095afc0f20ef7d42f788ac00000000", + } + + // Create a req + response, err := client.SubmitTransaction(client.MinerByName(MinerMatterpool), tx) + if err == nil { + t.Fatalf("error should have occurred") + } else if response != nil { + t.Fatalf("expected response to be nil") + } +}