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

Commit

Permalink
Merge pull request #33 from square/alok/more_tests
Browse files Browse the repository at this point in the history
add some tests
  • Loading branch information
alokmenghrajani authored Oct 18, 2018
2 parents 60e9eac + 190c98a commit 72a9479
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions deriver/address_deriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ import (
"github.com/stretchr/testify/assert"
)

func TestAddress(t *testing.T) {
deriver := NewAddressDeriver(Mainnet, []string{"xpub6CjzRxucHWJbmtuNTg6EjPax3V75AhsBRnFKn8MEkc8UFFEhrCoWcQN6oUBhfZWoFKqTyQ21iNVK8KMbC44ifW25uyXaMPWkRtpwcbAWXJx"}, 1, "")
addr := deriver.Derive(0, 5)
assert.Equal(t, addr.Path(), "m/.../0/5")
assert.Equal(t, addr.String(), "1N4VBTZqwLkHEKX79kjJ1WaYvX4c3txioz")
assert.Equal(t, addr.Change(), uint32(0))
assert.Equal(t, addr.Index(), uint32(5))
assert.Equal(t, addr.Network(), Mainnet)
assert.Equal(t, addr.Script(), "76a914e70369bfda4ba9bdcbb96cfd269a768573d0624c88ac")
}

func TestDeriveMultiSigSegwit(t *testing.T) {
xpubs := []string{
"tpubDAiPiLZeUdwo9oJiE9GZnteXj2E2MEMUb4knc4yCD87bL9siDgYcvrZSHZQZcYTyraL3fxVBRCcMiyfr3oQfH1wNo8J5i8aRAN56dDXaZxC",
Expand Down
10 changes: 10 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package utils

import (
"fmt"
"testing"

"github.com/btcsuite/btcd/chaincfg"
"github.com/stretchr/testify/assert"
)

func TestPanicOnError(t *testing.T) {
assert.Panics(t, func() { PanicOnError(fmt.Errorf("some error")) })
assert.NotPanics(t, func() { PanicOnError(nil) })
}

func TestMax(t *testing.T) {
v1 := uint32(0)
v2 := uint32(3418911847)
Expand Down Expand Up @@ -34,6 +40,8 @@ func TestXpubToNetwork(t *testing.T) {
assert.Equal(t, XpubToNetwork("xpub6C774QqLVXvX3WBMACHRVdWTyPphFh45cXFvawg9eFuNAK2DNPsWDf1zJcSyZWY59FNspYUCAUJJXhmVzCPcWzLWDm6yEQSN9982pBAsj1k"), Mainnet)

assert.Equal(t, XpubToNetwork("tpubDC5s7LsM3QFZz8CKNz8ePa2wpvQiq5LsGXrkoaaGsLhNx44wTr13XqoKEMCFPWMK4yen2DsLN7ArrZuqRqQE24Y9kNN51bpcjNdbWpJngdG"), Testnet)

assert.Panics(t, func() { XpubToNetwork("foobar") })
}

func TestAddressToNetwork(t *testing.T) {
Expand All @@ -43,6 +51,8 @@ func TestAddressToNetwork(t *testing.T) {
assert.Equal(t, AddressToNetwork("mm8xEm6YS8B7ErLYYqcdF6URWkS1BWnqtY"), Testnet)
assert.Equal(t, AddressToNetwork("2MvmkK3F4vT2h3gLjxz66SwQ5zW5XbsdZLu"), Testnet)
assert.Equal(t, AddressToNetwork("n3s7pVRvCEuXfF5fyh74JXmYg45q4Wev86"), Testnet)

assert.Panics(t, func() { AddressToNetwork("foobar") })
}

func TestChainConfig(t *testing.T) {
Expand Down

0 comments on commit 72a9479

Please sign in to comment.