Skip to content

Commit

Permalink
fix blockcypher fetch from mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
glossd committed Jan 1, 2022
1 parent 0744355 commit bf2f01b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
16 changes: 16 additions & 0 deletions addressinfo/blockchain_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package addressinfo

import (
"github.com/glossd/btc/netchain"
"github.com/stretchr/testify/assert"
"testing"
)

func TestFetchFromBlockchain(t *testing.T) {
t.Run(netchain.MainNet.String(), func(t *testing.T) {
got, err := FetchFromBlockchain("3LQUu4v9z6KNch71j7kbj8GPeAGUo1FW6a", netchain.MainNet)
assert.Nil(t, err)
assert.Positive(t, got.Balance)
assert.Positive(t, len(got.UTXOs))
})
}
17 changes: 13 additions & 4 deletions addressinfo/blockcypher_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package addressinfo

import (
"fmt"
"github.com/glossd/btc/netchain"
"github.com/stretchr/testify/assert"
"testing"
)

func TestFetchBlockcypher(t *testing.T) {
got, err := FetchFromBlockcypher("mgFv6afUVhrdd3D6mY2iyWzHVk5b64qTok", netchain.TestNet)
assert.Nil(t, err)
fmt.Printf("UTXOs: %+v", got)
t.Run(netchain.TestNet.String(), func(t *testing.T) {
got, err := FetchFromBlockcypher("mop76RFpxCMpNBx2M2NtAJsZEmo6qu5PSa", netchain.TestNet)
assert.Nil(t, err)
assert.Positive(t, got.Balance)
assert.Positive(t, len(got.UTXOs))
})

t.Run(netchain.MainNet.String(), func(t *testing.T) {
got, err := FetchFromBlockcypher("3LQUu4v9z6KNch71j7kbj8GPeAGUo1FW6a", netchain.MainNet)
assert.Nil(t, err)
assert.Positive(t, got.Balance)
assert.Positive(t, len(got.UTXOs))
})
}
6 changes: 5 additions & 1 deletion netchain/netchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ func (n Net) GetBtcdNetParams() *chaincfg.Params {

func (n Net) GetBlockcypherChain() string {
switch n {
case MainNet: return "btc"
case MainNet: return "main"
case TestNet: return "test3"
default: panic(fmt.Sprintf("net chain '%s' is not supported", n))
}
}

func (n Net) String() string {
return string(n)
}

0 comments on commit bf2f01b

Please sign in to comment.