From 0065dd8ccb2792c8f906ef6e2c3e6e353742b64a Mon Sep 17 00:00:00 2001 From: Alok Menghrajani Date: Wed, 17 Oct 2018 21:39:55 -0700 Subject: [PATCH 1/2] Increase utils.go test coverage --- utils/utils_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/utils/utils_test.go b/utils/utils_test.go index 42328a1..70a159a 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -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) @@ -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) { @@ -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) { From 190c98abc8b1408dfa08c42f25a271204398aa33 Mon Sep 17 00:00:00 2001 From: Alok Menghrajani Date: Wed, 17 Oct 2018 21:58:06 -0700 Subject: [PATCH 2/2] Increase address_deriver test coverage --- deriver/address_deriver_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/deriver/address_deriver_test.go b/deriver/address_deriver_test.go index 21375c6..033bb2c 100644 --- a/deriver/address_deriver_test.go +++ b/deriver/address_deriver_test.go @@ -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",