remove cosmos sdk dependency

pull/1651/head
Rongjian Lan 5 years ago
parent f89b758b13
commit 38eaf3dbb5
  1. 1
      go.mod
  2. 5
      staking/types/decimal.go
  3. 51
      staking/types/decimal_test.go
  4. 3
      staking/types/validator.go

@ -9,7 +9,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d
github.com/cespare/cp v1.1.1
github.com/cosmos/cosmos-sdk v0.37.1
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set v1.7.1
github.com/edsrzf/mmap-go v1.0.0 // indirect

@ -161,8 +161,7 @@ func NewDecFromStr(str string) (d Dec, err error) {
}
if lenDecs > Precision {
return d, errors.New(
fmt.Sprintf("too much precision, maximum %v, len decimal %v", Precision, lenDecs))
return d, fmt.Errorf("too much precision, maximum %v, len decimal %v", Precision, lenDecs)
}
// add some extra zero's to correct to the Precision factor
@ -172,7 +171,7 @@ func NewDecFromStr(str string) (d Dec, err error) {
combined, ok := new(big.Int).SetString(combinedStr, 10) // base 10
if !ok {
return d, errors.New(fmt.Sprintf("bad string to integer conversion, combinedStr: %v", combinedStr))
return d, fmt.Errorf("bad string to integer conversion, combinedStr: %v", combinedStr)
}
if neg {
combined = new(big.Int).Neg(combined)

@ -7,8 +7,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
)
// create a decimal from a decimal string (ex. "1234.5678")
@ -267,8 +265,6 @@ func TestTruncate(t *testing.T) {
}
}
var cdc = codec.New()
func TestDecMarshalJSON(t *testing.T) {
decimal := func(i int64) Dec {
d := NewDec(0)
@ -307,14 +303,6 @@ func TestDecMarshalJSON(t *testing.T) {
}
}
func TestZeroDeserializationJSON(t *testing.T) {
d := Dec{new(big.Int)}
err := cdc.UnmarshalJSON([]byte(`"0"`), &d)
require.Nil(t, err)
err = cdc.UnmarshalJSON([]byte(`"{}"`), &d)
require.NotNil(t, err)
}
func TestSerializationText(t *testing.T) {
d := mustNewDecFromStr(t, "0.333")
@ -327,51 +315,12 @@ func TestSerializationText(t *testing.T) {
require.True(t, d.Equal(d2), "original: %v, unmarshalled: %v", d, d2)
}
func TestSerializationGocodecJSON(t *testing.T) {
d := mustNewDecFromStr(t, "0.333")
bz, err := cdc.MarshalJSON(d)
require.NoError(t, err)
d2 := Dec{new(big.Int)}
err = cdc.UnmarshalJSON(bz, &d2)
require.NoError(t, err)
require.True(t, d.Equal(d2), "original: %v, unmarshalled: %v", d, d2)
}
func TestSerializationGocodecBinary(t *testing.T) {
d := mustNewDecFromStr(t, "0.333")
bz, err := cdc.MarshalBinaryLengthPrefixed(d)
require.NoError(t, err)
var d2 Dec
err = cdc.UnmarshalBinaryLengthPrefixed(bz, &d2)
require.NoError(t, err)
require.True(t, d.Equal(d2), "original: %v, unmarshalled: %v", d, d2)
}
type testDEmbedStruct struct {
Field1 string `json:"f1"`
Field2 int `json:"f2"`
Field3 Dec `json:"f3"`
}
// TODO make work for UnmarshalJSON
func TestEmbeddedStructSerializationGocodec(t *testing.T) {
obj := testDEmbedStruct{"foo", 10, NewDecWithPrec(1, 3)}
bz, err := cdc.MarshalBinaryLengthPrefixed(obj)
require.Nil(t, err)
var obj2 testDEmbedStruct
err = cdc.UnmarshalBinaryLengthPrefixed(bz, &obj2)
require.Nil(t, err)
require.Equal(t, obj.Field1, obj2.Field1)
require.Equal(t, obj.Field2, obj2.Field2)
require.True(t, obj.Field3.Equal(obj2.Field3), "original: %v, unmarshalled: %v", obj, obj2)
}
func TestStringOverflow(t *testing.T) {
// two random 64 bit primes
dec1, err := NewDecFromStr("51643150036226787134389711697696177267")

@ -1,9 +1,10 @@
package types
import (
"math/big"
"github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/internal/common"
"math/big"
)
// Validator - data fields for a validator

Loading…
Cancel
Save