github.com/deso-protocol/core@v1.2.9/lib/bitcoin_burner_test.go (about)

     1  package lib
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/btcsuite/btcd/chaincfg/chainhash"
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  var (
    12  	BlockCypherTestAPIKey = "3aaa4e1c99164e8ba9ade1a605a150c0"
    13  )
    14  
    15  func TestCheckDoubleSpend(t *testing.T) {
    16  	// Set up a blockchain
    17  	assert := assert.New(t)
    18  	require := require.New(t)
    19  	_, _ = assert, require
    20  
    21  	// Mainnet checks
    22  	{
    23  		params := &DeSoMainnetParams
    24  
    25  		// This txn is not a double-spend
    26  		{
    27  			hash, err := chainhash.NewHashFromStr("4d02fa8bed28405dd0f8eabbcd5a1ead6018ee7d260d026bb9ba99eb90f7389b")
    28  			require.NoError(err)
    29  			isDoubleSpend, err := BlockCypherCheckBitcoinDoubleSpend(hash, BlockCypherTestAPIKey, params)
    30  			require.NoError(err)
    31  			require.False(isDoubleSpend)
    32  		}
    33  		{
    34  			hash, err := chainhash.NewHashFromStr("60bbed01b7d6adfe1482161092894943e4ddff9cc9c9ed398df295cfcfde2d9e")
    35  			require.NoError(err)
    36  			isDoubleSpend, err := BlockCypherCheckBitcoinDoubleSpend(hash, BlockCypherTestAPIKey, params)
    37  			require.NoError(err)
    38  			require.True(isDoubleSpend)
    39  		}
    40  	}
    41  
    42  	{
    43  		// Testnet checks
    44  		params := &DeSoTestnetParams
    45  
    46  		// This txn is not a double-spend
    47  		{
    48  			hash, err := chainhash.NewHashFromStr("141efaf43d716166792dec365b5b598a0ad9920baf52446675840c4b3ea2e4e1")
    49  			require.NoError(err)
    50  			isDoubleSpend, err := BlockCypherCheckBitcoinDoubleSpend(hash, BlockCypherTestAPIKey, params)
    51  			require.NoError(err)
    52  			require.False(isDoubleSpend)
    53  		}
    54  		{
    55  			hash, err := chainhash.NewHashFromStr("60bbed01b7d6adfe1482161092894943e4ddff9cc9c9ed398df295cfcfde2d9e")
    56  			require.NoError(err)
    57  			isDoubleSpend, err := BlockCypherCheckBitcoinDoubleSpend(hash, BlockCypherTestAPIKey, params)
    58  			require.NoError(err)
    59  			require.True(isDoubleSpend)
    60  		}
    61  	}
    62  }
    63  
    64  // Comment this in to test the RBF checker. We comment it out for now since the transactions
    65  // used within it go stale and return different values after being mined.
    66  //
    67  //func TestCheckRBF(t *testing.T) {
    68  //
    69  //	// Set up a blockchain
    70  //	assert := assert.New(t)
    71  //	require := require.New(t)
    72  //	_, _ = assert, require
    73  //
    74  //	{
    75  //		isRBF, err := BlockonomicsCheckRBF("625ae824aaa832731fbd124d10e54e7e976083ef91da81f51f80838f0e442df6")
    76  //		require.NoError(err)
    77  //		require.True(isRBF)
    78  //	}
    79  //
    80  //	{
    81  //		isRBF, err := BlockonomicsCheckRBF("42239441b091f78185ee398cdbdc4f9710ccf2c309175b5f47cd189429f7552b")
    82  //		require.NoError(err)
    83  //		require.False(isRBF)
    84  //	}
    85  //}