code cleanup
This commit is contained in:
parent
a1c7722a80
commit
3afade80b2
|
@ -29,8 +29,9 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cdc = wire.NewCodec()
|
cdc = wire.NewCodec()
|
||||||
cdc.RegisterInterface((*rational.Rational)(nil), nil)
|
cdc.RegisterInterface((*rational.Rational)(nil), nil) // XXX make like crypto.RegisterWire()
|
||||||
cdc.RegisterConcrete(rational.Rat{}, "rat", nil)
|
cdc.RegisterConcrete(rational.Rat{}, "rat", nil)
|
||||||
|
crypto.RegisterWire(cdc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCandidateKey - get the key for the candidate with pubKey
|
// GetCandidateKey - get the key for the candidate with pubKey
|
||||||
|
|
|
@ -4,11 +4,11 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
crypto "github.com/tendermint/go-crypto"
|
||||||
"github.com/tendermint/tmlibs/rational"
|
"github.com/tendermint/tmlibs/rational"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
crypto "github.com/tendermint/go-crypto"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// XXX XXX XXX
|
// XXX XXX XXX
|
||||||
|
@ -105,29 +105,7 @@ import (
|
||||||
//// test validator added at the end
|
//// test validator added at the end
|
||||||
//vs2 = []Validator{v1, v2, v4, v5}
|
//vs2 = []Validator{v1, v2, v4, v5}
|
||||||
//changed = vs1.validatorsUpdated(vs2)
|
//changed = vs1.validatorsUpdated(vs2)
|
||||||
//require.Equal(1, len(changed))
|
//require.Equal(1, len(changed)) //testChange(t, vs2[3], changed[0]) //// test multiple validators added //vs2 = []Validator{v1, v2, v3, v4, v5} //changed = vs1.validatorsUpdated(vs2) //require.Equal(2, len(changed)) //testChange(t, vs2[2], changed[0]) //testChange(t, vs2[4], changed[1]) //// test validator removed at the beginning //vs2 = []Validator{v2, v4} //changed = vs1.validatorsUpdated(vs2) //require.Equal(1, len(changed)) //testRemove(t, vs1[0], changed[0]) //// test validator removed in the middle //vs2 = []Validator{v1, v4} //changed = vs1.validatorsUpdated(vs2) //require.Equal(1, len(changed)) //testRemove(t, vs1[1], changed[0]) //// test validator removed at the end
|
||||||
//testChange(t, vs2[3], changed[0])
|
|
||||||
|
|
||||||
//// test multiple validators added
|
|
||||||
//vs2 = []Validator{v1, v2, v3, v4, v5}
|
|
||||||
//changed = vs1.validatorsUpdated(vs2)
|
|
||||||
//require.Equal(2, len(changed))
|
|
||||||
//testChange(t, vs2[2], changed[0])
|
|
||||||
//testChange(t, vs2[4], changed[1])
|
|
||||||
|
|
||||||
//// test validator removed at the beginning
|
|
||||||
//vs2 = []Validator{v2, v4}
|
|
||||||
//changed = vs1.validatorsUpdated(vs2)
|
|
||||||
//require.Equal(1, len(changed))
|
|
||||||
//testRemove(t, vs1[0], changed[0])
|
|
||||||
|
|
||||||
//// test validator removed in the middle
|
|
||||||
//vs2 = []Validator{v1, v4}
|
|
||||||
//changed = vs1.validatorsUpdated(vs2)
|
|
||||||
//require.Equal(1, len(changed))
|
|
||||||
//testRemove(t, vs1[1], changed[0])
|
|
||||||
|
|
||||||
//// test validator removed at the end
|
|
||||||
//vs2 = []Validator{v1, v2}
|
//vs2 = []Validator{v1, v2}
|
||||||
//changed = vs1.validatorsUpdated(vs2)
|
//changed = vs1.validatorsUpdated(vs2)
|
||||||
//require.Equal(1, len(changed))
|
//require.Equal(1, len(changed))
|
||||||
|
@ -140,25 +118,7 @@ import (
|
||||||
//testRemove(t, vs1[1], changed[0])
|
//testRemove(t, vs1[1], changed[0])
|
||||||
//testRemove(t, vs1[2], changed[1])
|
//testRemove(t, vs1[2], changed[1])
|
||||||
|
|
||||||
//// test many types of changes
|
//// test many types of changes //vs2 = []Validator{v1, v3, v4, v5} //vs2[2].VotingPower = rational.New(11) //changed = vs1.validatorsUpdated(vs2) //require.Equal(4, len(changed), "%v", changed) // change 1, remove 1, add 2 //testRemove(t, vs1[1], changed[0]) //testChange(t, vs2[1], changed[1]) //testChange(t, vs2[2], changed[2]) //testChange(t, vs2[3], changed[3]) //} //func TestUpdateValidatorSet(t *testing.T) { //assert, require := assert.New(t), require.New(t) //store := initTestStore(t) //params := loadParams(store) //gs := loadGlobalState(store) //N := 5
|
||||||
//vs2 = []Validator{v1, v3, v4, v5}
|
|
||||||
//vs2[2].VotingPower = rational.New(11)
|
|
||||||
//changed = vs1.validatorsUpdated(vs2)
|
|
||||||
//require.Equal(4, len(changed), "%v", changed) // change 1, remove 1, add 2
|
|
||||||
//testRemove(t, vs1[1], changed[0])
|
|
||||||
//testChange(t, vs2[1], changed[1])
|
|
||||||
//testChange(t, vs2[2], changed[2])
|
|
||||||
//testChange(t, vs2[3], changed[3])
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
//func TestUpdateValidatorSet(t *testing.T) {
|
|
||||||
//assert, require := assert.New(t), require.New(t)
|
|
||||||
//store := initTestStore(t)
|
|
||||||
//params := loadParams(store)
|
|
||||||
//gs := loadGlobalState(store)
|
|
||||||
|
|
||||||
//N := 5
|
|
||||||
//actors := newAddrs(N)
|
//actors := newAddrs(N)
|
||||||
//candidates := candidatesFromActors(actors, []int64{400, 200, 100, 10, 1})
|
//candidates := candidatesFromActors(actors, []int64{400, 200, 100, 10, 1})
|
||||||
//for _, c := range candidates {
|
//for _, c := range candidates {
|
||||||
|
@ -204,15 +164,13 @@ func TestState(t *testing.T) {
|
||||||
assert, require := assert.New(t), require.New(t)
|
assert, require := assert.New(t), require.New(t)
|
||||||
|
|
||||||
store := initTestStore(t)
|
store := initTestStore(t)
|
||||||
cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
|
|
||||||
cdc.RegisterConcrete(crypto.PubKeyEd25519{}, "crypto/PubKeyEd25519", nil)
|
|
||||||
|
|
||||||
//delegator := crypto.Address{[]byte("addressdelegator")}
|
//delegator := crypto.Address{[]byte("addressdelegator")}
|
||||||
//validator := crypto.Address{[]byte("addressvalidator")}
|
//validator := crypto.Address{[]byte("addressvalidator")}
|
||||||
delegator := []byte("addressdelegator")
|
delegator := []byte("addressdelegator")
|
||||||
validator := []byte("addressvalidator")
|
validator := []byte("addressvalidator")
|
||||||
|
//pk := newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB57")
|
||||||
pk := newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB57")
|
pk := crypto.GenPrivKeyEd25519().PubKey()
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// Candidate checks
|
// Candidate checks
|
||||||
|
@ -230,9 +188,9 @@ func TestState(t *testing.T) {
|
||||||
return c1.Status == c2.Status &&
|
return c1.Status == c2.Status &&
|
||||||
c1.PubKey.Equals(c2.PubKey) &&
|
c1.PubKey.Equals(c2.PubKey) &&
|
||||||
bytes.Equal(c1.Owner, c2.Owner) &&
|
bytes.Equal(c1.Owner, c2.Owner) &&
|
||||||
c1.Assets == c2.Assets &&
|
c1.Assets.Equal(c2.Assets) &&
|
||||||
c1.Liabilities == c2.Liabilities &&
|
c1.Liabilities.Equal(c2.Liabilities) &&
|
||||||
c1.VotingPower == c2.VotingPower &&
|
c1.VotingPower.Equal(c2.VotingPower) &&
|
||||||
c1.Description == c2.Description
|
c1.Description == c2.Description
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +203,8 @@ func TestState(t *testing.T) {
|
||||||
// set and retrieve a record
|
// set and retrieve a record
|
||||||
saveCandidate(store, candidate)
|
saveCandidate(store, candidate)
|
||||||
resCand = loadCandidate(store, pk)
|
resCand = loadCandidate(store, pk)
|
||||||
assert.True(candidatesEqual(candidate, resCand))
|
assert.Equal(candidate, resCand)
|
||||||
|
assert.True(candidatesEqual(candidate, resCand), "%#v \n %#v", resCand, candidate)
|
||||||
|
|
||||||
// modify a records, save, and retrieve
|
// modify a records, save, and retrieve
|
||||||
candidate.Liabilities = rational.New(99)
|
candidate.Liabilities = rational.New(99)
|
||||||
|
|
|
@ -23,12 +23,13 @@ func subspace(prefix []byte) (start, end []byte) {
|
||||||
|
|
||||||
func initTestStore(t *testing.T) sdk.KVStore {
|
func initTestStore(t *testing.T) sdk.KVStore {
|
||||||
// Capabilities key to access the main KVStore.
|
// Capabilities key to access the main KVStore.
|
||||||
db, err := dbm.NewGoLevelDB("stake", "data")
|
//db, err := dbm.NewGoLevelDB("stake", "data")
|
||||||
require.Nil(t, err)
|
db := dbm.NewMemDB()
|
||||||
stakeStoreKey := sdk.NewKVStoreKey("stake")
|
stakeStoreKey := sdk.NewKVStoreKey("stake")
|
||||||
ms := store.NewCommitMultiStore(db)
|
ms := store.NewCommitMultiStore(db)
|
||||||
ms.MountStoreWithDB(stakeStoreKey, sdk.StoreTypeIAVL, db)
|
ms.MountStoreWithDB(stakeStoreKey, sdk.StoreTypeIAVL, db)
|
||||||
ms.LoadLatestVersion()
|
err := ms.LoadLatestVersion()
|
||||||
|
require.Nil(t, err)
|
||||||
return ms.GetKVStore(stakeStoreKey)
|
return ms.GetKVStore(stakeStoreKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue