Skip to content

Commit

Permalink
[test] refs #279 - GetCoins implementations full covered
Browse files Browse the repository at this point in the history
  • Loading branch information
e1Ru1o committed Jan 26, 2020
1 parent 595a1c4 commit fd72907
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/coin/skycoin/models/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ func (in *SkycoinTransactionInput) GetCoins(ticker string) (uint64, error) {
} else if ticker == CalculatedHour {
return in.skyIn.CalculatedHours * accuracy, nil
}
// TODO: The program never reach here because util.AltcoinQuotient(ticker) throws an error when a invalid ticker is supplied
logCoin.Errorf("Invalid ticker %v\n", ticker)
return uint64(0), errors.ErrInvalidAltcoinTicker
}
Expand Down Expand Up @@ -720,7 +719,6 @@ func (out *SkycoinTransactionOutput) GetCoins(ticker string) (uint64, error) {
} else if ticker == CalculatedHour {
return out.calculatedHours * accuracy, nil
}
// TODO: The program never reach here because util.AltcoinQuotient(ticker) throws an error when a invalid ticker is supplied
logCoin.Errorf("Invalid ticker %v\n", ticker)
return uint64(0), errors.ErrInvalidAltcoinTicker
}
Expand Down
45 changes: 45 additions & 0 deletions src/coin/skycoin/models/coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/SkycoinProject/skycoin/src/api"
Expand All @@ -18,6 +19,7 @@ import (
"github.com/fibercrypto/fibercryptowallet/src/coin/skycoin/skytypes"
"github.com/fibercrypto/fibercryptowallet/src/core"
"github.com/fibercrypto/fibercryptowallet/src/errors"
"github.com/fibercrypto/fibercryptowallet/src/util"
"github.com/fibercrypto/fibercryptowallet/src/util/requirethat"
)

Expand Down Expand Up @@ -1458,6 +1460,25 @@ func TestGetCoins(t *testing.T) {
GetCoins(string) (uint64, error)
}

fakeTicker := "MOCKSCOIN"
fakeDesc := "Fake coin"
fakeExp := 3
fakeMeta := core.AltcoinMetadata{
Name: fakeDesc,
Ticker: fakeTicker,
Family: fakeTicker,
HasBip44: false,
Bip44CoinType: 0,
Accuracy: int32(fakeExp),
}
mockPlugin := new(mocks.AltcoinPlugin)
mockPlugin.On("RegisterTo", mock.Anything).Return().Run(func(args mock.Arguments) {
manager := args.Get(0).(core.AltcoinManager)
manager.RegisterAltcoin(fakeMeta, mockPlugin)
})
mockPlugin.On("GetName").Return(fakeDesc)
util.RegisterAltcoin(mockPlugin)

invalidTicker := "INVALIDTICKER"
tests := []struct {
name string
Expand All @@ -1473,6 +1494,12 @@ func TestGetCoins(t *testing.T) {
obj: new(SkycoinCreatedTransactionOutput),
err: true,
},
{
name: "SkycoinCreatedTransactionOutput",
ticker: fakeTicker,
obj: new(SkycoinCreatedTransactionOutput),
err: true,
},
{
name: "SkycoinCreatedTransactionOutput",
ticker: Sky,
Expand Down Expand Up @@ -1546,6 +1573,12 @@ func TestGetCoins(t *testing.T) {
obj: new(SkycoinCreatedTransactionInput),
err: true,
},
{
name: "SkycoinCreatedTransactionInput",
ticker: fakeTicker,
obj: new(SkycoinCreatedTransactionInput),
err: true,
},
{
name: "SkycoinCreatedTransactionInput",
ticker: Sky,
Expand Down Expand Up @@ -1623,6 +1656,12 @@ func TestGetCoins(t *testing.T) {
obj: new(SkycoinTransactionInput),
err: true,
},
{
name: "SkycoinTransactionInput",
ticker: fakeTicker,
obj: new(SkycoinTransactionInput),
err: true,
},
{
name: "SkycoinTransactionInput",
ticker: Sky,
Expand Down Expand Up @@ -1680,6 +1719,12 @@ func TestGetCoins(t *testing.T) {
obj: new(SkycoinTransactionOutput),
err: true,
},
{
name: "SkycoinTransactionOutput",
ticker: fakeTicker,
obj: new(SkycoinTransactionOutput),
err: true,
},
{
name: "SkycoinTransactionOutput",
ticker: Sky,
Expand Down

0 comments on commit fd72907

Please sign in to comment.