Skip to content

Commit

Permalink
[test] refs #279 - Improve coverage in blockchain.go
Browse files Browse the repository at this point in the history
All testable internal paths covered
  • Loading branch information
e1Ru1o committed Jan 22, 2020
1 parent 504b414 commit 6c08bd1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/coin/skycoin/models/blockchain_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package skycoin

import (
"errors"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -77,10 +78,20 @@ func TestSkycoinBlockchainStatusGetCoinValue(t *testing.T) {
},
nil,
)
global_mock.On("BlockchainProgress").Return(&readable.BlockchainProgress{}, errors.New("failure")).Once()
global_mock.On("BlockchainProgress").Return(&readable.BlockchainProgress{}, nil)

block := &SkycoinBlockchain{CacheTime: 20}

// api interaction error
val, err := block.GetCoinValue(core.CoinCurrentSupply, Sky)
require.Error(t, err)

// invalid coin
val, err = block.GetCoinValue(core.CoinCurrentSupply, "INVALIDCOIN")
require.Error(t, err)

val, err = block.GetCoinValue(core.CoinCurrentSupply, Sky)
require.NoError(t, err)
require.Equal(t, val, uint64(200111111))
val, err = block.GetCoinValue(core.CoinCurrentSupply, CoinHour)
Expand All @@ -104,6 +115,7 @@ func TestSkycoinBlockchainStatusGetNumberOfBlocks(t *testing.T) {
},
nil,
)
global_mock.On("BlockchainProgress").Return(&readable.BlockchainProgress{}, errors.New("failure")).Once()
global_mock.On("BlockchainProgress").Return(
&readable.BlockchainProgress{
Current: uint64(20),
Expand All @@ -113,8 +125,13 @@ func TestSkycoinBlockchainStatusGetNumberOfBlocks(t *testing.T) {
nil,
)

block := &SkycoinBlockchain{CacheTime: 20}
// api interaction error
block := new(SkycoinBlockchain)
val, err := block.GetNumberOfBlocks()
require.Error(t, err)

block = &SkycoinBlockchain{CacheTime: 20}
val, err = block.GetNumberOfBlocks()
require.NoError(t, err)
require.Equal(t, val, uint64(20))
}
Expand All @@ -131,10 +148,16 @@ func TestSkycoinBlockchainStatusGetLastBlock(t *testing.T) {
},
nil,
)
global_mock.On("BlockchainProgress").Return(&readable.BlockchainProgress{}, errors.New("failure")).Once()
global_mock.On("BlockchainProgress").Return(&readable.BlockchainProgress{}, nil)

status := &SkycoinBlockchain{CacheTime: 20}

// api interaction error
block, err := status.GetLastBlock()
require.Error(t, err)

block, err = status.GetLastBlock()
require.NoError(t, err)
val, err2 := block.GetVersion()
require.NoError(t, err2)
Expand Down

0 comments on commit 6c08bd1

Please sign in to comment.