handler tests compile

...

...
This commit is contained in:
rigelrozanski 2018-04-01 18:05:58 +02:00
parent 6b279bd8bd
commit 1db8764b9e
6 changed files with 134 additions and 128 deletions

View File

@ -95,7 +95,7 @@ func handleMsgDeclareCandidacy(ctx sdk.Context, msg MsgDeclareCandidacy, k Keepe
// move coins from the msg.Address account to a (self-bond) delegator account // move coins from the msg.Address account to a (self-bond) delegator account
// the candidate account and global shares are updated within here // the candidate account and global shares are updated within here
return delegateWithCandidate(ctx, k, msg.CandidateAddr, msg.Bond, candidate).Result() return delegate(ctx, k, msg.CandidateAddr, msg.Bond, candidate).Result()
} }
func handleMsgEditCandidacy(ctx sdk.Context, msg MsgEditCandidacy, k Keeper) sdk.Result { func handleMsgEditCandidacy(ctx sdk.Context, msg MsgEditCandidacy, k Keeper) sdk.Result {
@ -139,10 +139,10 @@ func handleMsgDelegate(ctx sdk.Context, msg MsgDelegate, k Keeper) sdk.Result {
GasUsed: GasDelegate, GasUsed: GasDelegate,
} }
} }
return delegateWithCandidate(ctx, k, msg.DelegatorAddr, msg.Bond, candidate).Result() return delegate(ctx, k, msg.DelegatorAddr, msg.Bond, candidate).Result()
} }
func delegateWithCandidate(ctx sdk.Context, k Keeper, delegatorAddr sdk.Address, func delegate(ctx sdk.Context, k Keeper, delegatorAddr sdk.Address,
bondAmt sdk.Coin, candidate Candidate) sdk.Error { bondAmt sdk.Coin, candidate Candidate) sdk.Error {
if candidate.Status == Revoked { //candidate has been withdrawn if candidate.Status == Revoked { //candidate has been withdrawn

View File

@ -32,72 +32,82 @@ func newTestMsgDelegate(amt int64, delegatorAddr, candidateAddr sdk.Address) Msg
} }
func TestDuplicatesMsgDeclareCandidacy(t *testing.T) { func TestDuplicatesMsgDeclareCandidacy(t *testing.T) {
ctx, _, keeper := createTestInput(t, addrs[0], false, 1000) ctx, _, keeper := createTestInput(t, false, 1000)
msgDeclareCandidacy := newTestMsgDeclareCandidacy(addrs[0], pks[0], 10) msgDeclareCandidacy := newTestMsgDeclareCandidacy(addrs[0], pks[0], 10)
got := handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper) got := handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper)
assert.True(t, got.IsOK(), "%v", got) assert.True(t, got.IsOK(), "%v", got)
// one sender cannot bond twice // one candidate cannot bond twice
msgDeclareCandidacy.PubKey = pks[1] msgDeclareCandidacy.PubKey = pks[1]
got = handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper) got = handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper)
assert.False(t, got.IsOK(), "%v", got) assert.False(t, got.IsOK(), "%v", got)
} }
func TestIncrementsMsgDelegate(t *testing.T) { func TestIncrementsMsgDelegate(t *testing.T) {
ctx, _, keeper := createTestInput(t, addrs[0], false, 1000) initBond := int64(1000)
ctx, accMapper, keeper := createTestInput(t, false, initBond)
params := keeper.GetParams(ctx)
bondAmount := int64(10)
candidateAddr, delegatorAddr := addrs[0], addrs[1]
// first declare candidacy // first declare candidacy
bondAmount := int64(10) msgDeclareCandidacy := newTestMsgDeclareCandidacy(candidateAddr, pks[0], bondAmount)
msgDeclareCandidacy := newTestMsgDeclareCandidacy(addrs[0], pks[0], bondAmount) got := handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper)
got := deliverer.declareCandidacy(msgDeclareCandidacy) assert.True(t, got.IsOK(), "expected declare candidacy msg to be ok, got %v", got)
assert.NoError(t, got, "expected declare candidacy msg to be ok, got %v", got) expectedBond := bondAmount
expectedBond := bondAmount // 1 since we send 1 at the start of loop,
// just send the same msgbond multiple times // just send the same msgbond multiple times
msgDelegate := newTestMsgDelegate(bondAmount, addrs[0]) msgDelegate := newTestMsgDelegate(bondAmount, delegatorAddr, candidateAddr)
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
got := deliverer.delegate(msgDelegate) got := handleMsgDelegate(ctx, msgDelegate, keeper)
assert.NoError(t, got, "expected msg %d to be ok, got %v", i, got) assert.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)
//Check that the accounts and the bond account have the appropriate values //Check that the accounts and the bond account have the appropriate values
candidates := mapper.GetCandidates() candidates := keeper.GetCandidates(ctx, 100)
expectedBond += bondAmount expectedBond += bondAmount
//expectedSender := initSender - expectedBond expectedDelegator := initBond - expectedBond
gotBonded := candidates[0].Liabilities.Evaluate() gotBonded := candidates[0].Liabilities.Evaluate()
//gotSender := accStore[string(deliverer.sender)] //XXX use StoreMapper gotDelegator := accMapper.GetAccount(ctx, delegatorAddr).GetCoins().AmountOf(params.BondDenom)
assert.Equal(t, expectedBond, gotBonded, "i: %v, %v, %v", i, expectedBond, gotBonded) assert.Equal(t, expectedBond, gotBonded, "i: %v, %v, %v", i, expectedBond, gotBonded)
//assert.Equal(t, expectedSender, gotSender, "i: %v, %v, %v", i, expectedSender, gotSender) // XXX fix assert.Equal(t, expectedDelegator, gotDelegator, "i: %v, %v, %v", i, expectedDelegator, gotDelegator) // XXX fix
} }
} }
func TestIncrementsMsgUnbond(t *testing.T) { func TestIncrementsMsgUnbond(t *testing.T) {
ctx, _, keeper := createTestInput(t, addrs[0], false, 0)
// set initial bond
initBond := int64(1000) initBond := int64(1000)
//accStore[string(deliverer.sender)] = initBond //XXX use StoreMapper ctx, accMapper, keeper := createTestInput(t, false, initBond)
got := deliverer.declareCandidacy(newTestMsgDeclareCandidacy(addrs[0], pks[0], initBond)) params := keeper.GetParams(ctx)
assert.NoError(t, got, "expected initial bond msg to be ok, got %v", got)
// just send the same msgunbond multiple times // declare candidacy, delegate
// XXX use decimals here candidateAddr, delegatorAddr := addrs[0], addrs[1]
msgDeclareCandidacy := newTestMsgDeclareCandidacy(candidateAddr, pks[0], initBond)
got := handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper)
assert.True(t, got.IsOK(), "expected declare-candidacy to be ok, got %v", got)
msgDelegate := newTestMsgDelegate(initBond, delegatorAddr, candidateAddr)
got = handleMsgDelegate(ctx, msgDelegate, keeper)
assert.True(t, got.IsOK(), "expected delegation to be ok, got %v", got)
// just send the same msgUnbond multiple times
// TODO use decimals here
unbondShares, unbondSharesStr := int64(10), "10" unbondShares, unbondSharesStr := int64(10), "10"
msgUndelegate := NewMsgUnbond(addrs[0], unbondSharesStr) msgUnbond := NewMsgUnbond(delegatorAddr, candidateAddr, unbondSharesStr)
nUnbonds := 5 numUnbonds := 5
for i := 0; i < nUnbonds; i++ { for i := 0; i < numUnbonds; i++ {
got := deliverer.unbond(msgUndelegate) got := handleMsgUnbond(ctx, msgUnbond, keeper)
assert.NoError(t, got, "expected msg %d to be ok, got %v", i, got) assert.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)
//Check that the accounts and the bond account have the appropriate values //Check that the accounts and the bond account have the appropriate values
candidates := mapper.GetCandidates() candidate, found := keeper.GetCandidate(ctx, candidateAddr)
expectedBond := initBond - int64(i+1)*unbondShares // +1 since we send 1 at the start of loop require.True(t, found)
//expectedSender := initSender + (initBond - expectedBond) expectedBond := initBond - int64(i+1)*unbondShares
gotBonded := candidates[0].Liabilities.Evaluate() expectedDelegator := initBond - expectedBond
//gotSender := accStore[string(deliverer.sender)] // XXX use storemapper gotBonded := candidate.Liabilities.Evaluate()
gotDelegator := accMapper.GetAccount(ctx, delegatorAddr).GetCoins().AmountOf(params.BondDenom)
assert.Equal(t, expectedBond, gotBonded, "%v, %v", expectedBond, gotBonded) assert.Equal(t, expectedBond, gotBonded, "%v, %v", expectedBond, gotBonded)
//assert.Equal(t, expectedSender, gotSender, "%v, %v", expectedSender, gotSender) //XXX fix assert.Equal(t, expectedDelegator, gotDelegator, "%v, %v", expectedDelegator, gotDelegator)
} }
// these are more than we have bonded now // these are more than we have bonded now
@ -110,134 +120,130 @@ func TestIncrementsMsgUnbond(t *testing.T) {
} }
for _, c := range errorCases { for _, c := range errorCases {
unbondShares := strconv.Itoa(int(c)) unbondShares := strconv.Itoa(int(c))
msgUndelegate := NewMsgUnbond(addrs[0], unbondShares) msgUnbond := NewMsgUnbond(delegatorAddr, candidateAddr, unbondShares)
got = deliverer.unbond(msgUndelegate) got = handleMsgUnbond(ctx, msgUnbond, keeper)
assert.Error(t, got, "expected unbond msg to fail") assert.False(t, got.IsOK(), "expected unbond msg to fail")
} }
leftBonded := initBond - unbondShares*int64(nUnbonds) leftBonded := initBond - unbondShares*int64(numUnbonds)
// should be unable to unbond one more than we have // should be unable to unbond one more than we have
msgUndelegate = NewMsgUnbond(addrs[0], strconv.Itoa(int(leftBonded)+1)) msgUnbond = NewMsgUnbond(delegatorAddr, candidateAddr, strconv.Itoa(int(leftBonded)+1))
got = deliverer.unbond(msgUndelegate) got = handleMsgUnbond(ctx, msgUnbond, keeper)
assert.Error(t, got, "expected unbond msg to fail") assert.False(t, got.IsOK(), "expected unbond msg to fail")
// should be able to unbond just what we have // should be able to unbond just what we have
msgUndelegate = NewMsgUnbond(addrs[0], strconv.Itoa(int(leftBonded))) msgUnbond = NewMsgUnbond(delegatorAddr, candidateAddr, strconv.Itoa(int(leftBonded)))
got = deliverer.unbond(msgUndelegate) got = handleMsgUnbond(ctx, msgUnbond, keeper)
assert.NoError(t, got, "expected unbond msg to pass") assert.True(t, got.IsOK(), "expected unbond msg to pass")
} }
func TestMultipleMsgDeclareCandidacy(t *testing.T) { func TestMultipleMsgDeclareCandidacy(t *testing.T) {
initSender := int64(1000) initBond := int64(1000)
//ctx, accStore, mapper, deliverer := createTestInput(t, addrs[0], false, initSender) ctx, accMapper, keeper := createTestInput(t, false, initBond)
ctx, mapper, keeper := createTestInput(t, addrs[0], false, initSender) params := keeper.GetParams(ctx)
addrs := []sdk.Address{addrs[0], addrs[1], addrs[2]} candidateAddrs := []sdk.Address{addrs[0], addrs[1], addrs[2]}
// bond them all // bond them all
for i, addr := range addrs { for i, candidateAddr := range candidateAddrs {
msgDeclareCandidacy := newTestMsgDeclareCandidacy(addrs[i], pks[i], 10) msgDeclareCandidacy := newTestMsgDeclareCandidacy(candidateAddr, pks[i], 10)
deliverer.sender = addr got := handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper)
got := deliverer.declareCandidacy(msgDeclareCandidacy) assert.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)
assert.NoError(t, got, "expected msg %d to be ok, got %v", i, got)
//Check that the account is bonded //Check that the account is bonded
candidates := mapper.GetCandidates() candidates := keeper.GetCandidates(ctx, 100)
require.Equal(t, i, len(candidates)) require.Equal(t, i, len(candidates))
val := candidates[i] val := candidates[i]
balanceExpd := initSender - 10 balanceExpd := initBond - 10
balanceGot := accStore.GetAccount(ctx, val.Address).GetCoins() balanceGot := accMapper.GetAccount(ctx, val.Address).GetCoins().AmountOf(params.BondDenom)
assert.Equal(t, i+1, len(candidates), "expected %d candidates got %d, candidates: %v", i+1, len(candidates), candidates) assert.Equal(t, i+1, len(candidates), "expected %d candidates got %d, candidates: %v", i+1, len(candidates), candidates)
assert.Equal(t, 10, int(val.Liabilities.Evaluate()), "expected %d shares, got %d", 10, val.Liabilities) assert.Equal(t, 10, int(val.Liabilities.Evaluate()), "expected %d shares, got %d", 10, val.Liabilities)
assert.Equal(t, balanceExpd, balanceGot, "expected account to have %d, got %d", balanceExpd, balanceGot) assert.Equal(t, balanceExpd, balanceGot, "expected account to have %d, got %d", balanceExpd, balanceGot)
} }
// unbond them all // unbond them all
for i, addr := range addrs { for i, candidateAddr := range candidateAddrs {
candidatePre := mapper.GetCandidate(addrs[i]) candidatePre, found := keeper.GetCandidate(ctx, candidateAddr)
msgUndelegate := NewMsgUnbond(addrs[i], "10") require.True(t, found)
deliverer.sender = addr msgUnbond := NewMsgUnbond(candidateAddr, candidateAddr, "10") // self-delegation
got := deliverer.unbond(msgUndelegate) got := handleMsgUnbond(ctx, msgUnbond, keeper)
assert.NoError(t, got, "expected msg %d to be ok, got %v", i, got) assert.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)
//Check that the account is unbonded //Check that the account is unbonded
candidates := mapper.GetCandidates() candidates := keeper.GetCandidates(ctx, 100)
assert.Equal(t, len(addrs)-(i+1), len(candidates), "expected %d candidates got %d", len(addrs)-(i+1), len(candidates)) assert.Equal(t, len(candidateAddrs)-(i+1), len(candidates),
"expected %d candidates got %d", len(candidateAddrs)-(i+1), len(candidates))
candidatePost := mapper.GetCandidate(addrs[i]) candidatePost, found := keeper.GetCandidate(ctx, candidateAddr)
balanceExpd := initSender require.True(t, found)
balanceGot := accStore.GetAccount(ctx, candidatePre.Address).GetCoins() balanceExpd := initBond
balanceGot := accMapper.GetAccount(ctx, candidatePre.Address).GetCoins().AmountOf(params.BondDenom)
assert.Nil(t, candidatePost, "expected nil candidate retrieve, got %d", 0, candidatePost) assert.Nil(t, candidatePost, "expected nil candidate retrieve, got %d", 0, candidatePost)
assert.Equal(t, balanceExpd, balanceGot, "expected account to have %d, got %d", balanceExpd, balanceGot) assert.Equal(t, balanceExpd, balanceGot, "expected account to have %d, got %d", balanceExpd, balanceGot)
} }
} }
func TestMultipleMsgDelegate(t *testing.T) { func TestMultipleMsgDelegate(t *testing.T) {
sender, delegators := addrs[0], addrs[1:] ctx, _, keeper := createTestInput(t, false, 0)
_, _, mapper, deliverer := createTestInput(t, addrs[0], false, 1000) candidateAddr, delegatorAddrs := addrs[0], addrs[1:]
ctx, _, keeper := createTestInput(t, addrs[0], false, 0)
//first make a candidate //first make a candidate
msgDeclareCandidacy := newTestMsgDeclareCandidacy(sender, pks[0], 10) msgDeclareCandidacy := newTestMsgDeclareCandidacy(candidateAddr, pks[0], 10)
got := deliverer.declareCandidacy(msgDeclareCandidacy) got := handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper)
require.NoError(t, got, "expected msg to be ok, got %v", got) require.True(t, got.IsOK(), "expected msg to be ok, got %v", got)
// delegate multiple parties // delegate multiple parties
for i, delegator := range delegators { for i, delegatorAddr := range delegatorAddrs {
msgDelegate := newTestMsgDelegate(10, sender) msgDelegate := newTestMsgDelegate(10, delegatorAddr, candidateAddr)
deliverer.sender = delegator got := handleMsgDelegate(ctx, msgDelegate, keeper)
got := deliverer.delegate(msgDelegate) require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)
require.NoError(t, got, "expected msg %d to be ok, got %v", i, got)
//Check that the account is bonded //Check that the account is bonded
bond := mapper.getDelegatorBond(delegator, sender) bond, found := keeper.getDelegatorBond(ctx, delegatorAddr, candidateAddr)
require.True(t, found)
assert.NotNil(t, bond, "expected delegatee bond %d to exist", bond) assert.NotNil(t, bond, "expected delegatee bond %d to exist", bond)
} }
// unbond them all // unbond them all
for i, delegator := range delegators { for i, delegatorAddr := range delegatorAddrs {
msgUndelegate := NewMsgUnbond(sender, "10") msgUnbond := NewMsgUnbond(delegatorAddr, candidateAddr, "10")
deliverer.sender = delegator got := handleMsgUnbond(ctx, msgUnbond, keeper)
got := deliverer.unbond(msgUndelegate) require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)
require.NoError(t, got, "expected msg %d to be ok, got %v", i, got)
//Check that the account is unbonded //Check that the account is unbonded
bond := mapper.getDelegatorBond(delegator, sender) _, found := keeper.getDelegatorBond(ctx, delegatorAddr, candidateAddr)
assert.Nil(t, bond, "expected delegatee bond %d to be nil", bond) require.False(t, found)
} }
} }
func TestVoidCandidacy(t *testing.T) { func TestVoidCandidacy(t *testing.T) {
sender, delegator := addrs[0], addrs[1] candidateAddr, delegatorAddr := addrs[0], addrs[1]
_, _, _, deliverer := createTestInput(t, addrs[0], false, 1000) ctx, _, keeper := createTestInput(t, false, 0)
// create the candidate // create the candidate
msgDeclareCandidacy := newTestMsgDeclareCandidacy(addrs[0], pks[0], 10) msgDeclareCandidacy := newTestMsgDeclareCandidacy(candidateAddr, pks[0], 10)
got := deliverer.declareCandidacy(msgDeclareCandidacy) got := handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper)
require.NoError(t, got, "expected no error on runMsgDeclareCandidacy") require.True(t, got.IsOK(), "expected no error on runMsgDeclareCandidacy")
// bond a delegator // bond a delegator
msgDelegate := newTestMsgDelegate(10, addrs[0]) msgDelegate := newTestMsgDelegate(10, delegatorAddr, candidateAddr)
deliverer.sender = delegator got = handleMsgDelegate(ctx, msgDelegate, keeper)
got = deliverer.delegate(msgDelegate) require.True(t, got.IsOK(), "expected ok, got %v", got)
require.NoError(t, got, "expected ok, got %v", got)
// unbond the candidates bond portion // unbond the candidates bond portion
msgUndelegate := NewMsgUnbond(addrs[0], "10") msgUnbond := NewMsgUnbond(delegatorAddr, candidateAddr, "10")
deliverer.sender = sender got = handleMsgUnbond(ctx, msgUnbond, keeper)
got = deliverer.unbond(msgUndelegate) require.True(t, got.IsOK(), "expected no error on runMsgDeclareCandidacy")
require.NoError(t, got, "expected no error on runMsgDeclareCandidacy")
// test that this pubkey cannot yet be bonded too // test that this pubkey cannot yet be bonded too
deliverer.sender = delegator got = handleMsgDelegate(ctx, msgDelegate, keeper)
got = deliverer.delegate(msgDelegate) assert.False(t, got.IsOK(), "expected error, got %v", got)
assert.Error(t, got, "expected error, got %v", got)
// test that the delegator can still withdraw their bonds // test that the delegator can still withdraw their bonds
got = deliverer.unbond(msgUndelegate) got = handleMsgUnbond(ctx, msgUnbond, keeper)
require.NoError(t, got, "expected no error on runMsgDeclareCandidacy") require.True(t, got.IsOK(), "expected no error on runMsgDeclareCandidacy")
// verify that the pubkey can now be reused // verify that the pubkey can now be reused
got = deliverer.declareCandidacy(msgDeclareCandidacy) got = handleMsgDeclareCandidacy(ctx, msgDeclareCandidacy, keeper)
assert.NoError(t, got, "expected ok, got %v", got) assert.True(t, got.IsOK(), "expected ok, got %v", got)
} }

View File

@ -27,7 +27,7 @@ var (
// This function tests GetCandidate, GetCandidates, setCandidate, removeCandidate // This function tests GetCandidate, GetCandidates, setCandidate, removeCandidate
func TestCandidate(t *testing.T) { func TestCandidate(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
//construct the candidates //construct the candidates
var candidates [3]Candidate var candidates [3]Candidate
@ -97,7 +97,7 @@ func TestCandidate(t *testing.T) {
// tests GetDelegatorBond, GetDelegatorBonds, SetDelegatorBond, removeDelegatorBond // tests GetDelegatorBond, GetDelegatorBonds, SetDelegatorBond, removeDelegatorBond
func TestBond(t *testing.T) { func TestBond(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
//construct the candidates //construct the candidates
amts := []int64{9, 8, 7} amts := []int64{9, 8, 7}
@ -196,7 +196,7 @@ func TestBond(t *testing.T) {
// TODO integrate in testing for equal validators, whichever one was a validator // TODO integrate in testing for equal validators, whichever one was a validator
// first remains the validator https://github.com/cosmos/cosmos-sdk/issues/582 // first remains the validator https://github.com/cosmos/cosmos-sdk/issues/582
func TestGetValidators(t *testing.T) { func TestGetValidators(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
// initialize some candidates into the state // initialize some candidates into the state
amts := []int64{0, 100, 1, 400, 200} amts := []int64{0, 100, 1, 400, 200}
@ -269,7 +269,7 @@ func TestGetValidators(t *testing.T) {
// clear the tracked changes to the validator set // clear the tracked changes to the validator set
func TestClearAccUpdateValidators(t *testing.T) { func TestClearAccUpdateValidators(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
amts := []int64{100, 400, 200} amts := []int64{100, 400, 200}
candidates := make([]Candidate, len(amts)) candidates := make([]Candidate, len(amts))
@ -294,7 +294,7 @@ func TestClearAccUpdateValidators(t *testing.T) {
// test the mechanism which keeps track of a validator set change // test the mechanism which keeps track of a validator set change
func TestGetAccUpdateValidators(t *testing.T) { func TestGetAccUpdateValidators(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
params := defaultParams() params := defaultParams()
params.MaxValidators = 4 params.MaxValidators = 4
keeper.setParams(ctx, params) keeper.setParams(ctx, params)
@ -506,7 +506,7 @@ func TestGetAccUpdateValidators(t *testing.T) {
// test if is a validator from the last update // test if is a validator from the last update
func TestIsRecentValidator(t *testing.T) { func TestIsRecentValidator(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
amts := []int64{9, 8, 7, 10, 6} amts := []int64{9, 8, 7, 10, 6}
var candidatesIn [5]Candidate var candidatesIn [5]Candidate
@ -546,7 +546,7 @@ func TestIsRecentValidator(t *testing.T) {
} }
func TestParams(t *testing.T) { func TestParams(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
expParams := defaultParams() expParams := defaultParams()
//check that the empty keeper loads the default //check that the empty keeper loads the default
@ -561,7 +561,7 @@ func TestParams(t *testing.T) {
} }
func TestPool(t *testing.T) { func TestPool(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
expPool := initialPool() expPool := initialPool()
//check that the empty keeper loads the default //check that the empty keeper loads the default

View File

@ -54,7 +54,7 @@ func TestUnbondedShareExRate(t *testing.T) {
} }
func TestBondedToUnbondedPool(t *testing.T) { func TestBondedToUnbondedPool(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
poolA := keeper.GetPool(ctx) poolA := keeper.GetPool(ctx)
assert.Equal(t, poolA.bondedShareExRate(), sdk.OneRat) assert.Equal(t, poolA.bondedShareExRate(), sdk.OneRat)
@ -81,7 +81,7 @@ func TestBondedToUnbondedPool(t *testing.T) {
} }
func TestUnbonbedtoBondedPool(t *testing.T) { func TestUnbonbedtoBondedPool(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
poolA := keeper.GetPool(ctx) poolA := keeper.GetPool(ctx)
assert.Equal(t, poolA.bondedShareExRate(), sdk.OneRat) assert.Equal(t, poolA.bondedShareExRate(), sdk.OneRat)
@ -109,7 +109,7 @@ func TestUnbonbedtoBondedPool(t *testing.T) {
} }
func TestAddTokensBonded(t *testing.T) { func TestAddTokensBonded(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
poolA := keeper.GetPool(ctx) poolA := keeper.GetPool(ctx)
assert.Equal(t, poolA.bondedShareExRate(), sdk.OneRat) assert.Equal(t, poolA.bondedShareExRate(), sdk.OneRat)
@ -125,7 +125,7 @@ func TestAddTokensBonded(t *testing.T) {
} }
func TestRemoveSharesBonded(t *testing.T) { func TestRemoveSharesBonded(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
poolA := keeper.GetPool(ctx) poolA := keeper.GetPool(ctx)
assert.Equal(t, poolA.bondedShareExRate(), sdk.OneRat) assert.Equal(t, poolA.bondedShareExRate(), sdk.OneRat)
@ -142,7 +142,7 @@ func TestRemoveSharesBonded(t *testing.T) {
} }
func TestAddTokensUnbonded(t *testing.T) { func TestAddTokensUnbonded(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
poolA := keeper.GetPool(ctx) poolA := keeper.GetPool(ctx)
assert.Equal(t, poolA.unbondedShareExRate(), sdk.OneRat) assert.Equal(t, poolA.unbondedShareExRate(), sdk.OneRat)
@ -158,7 +158,7 @@ func TestAddTokensUnbonded(t *testing.T) {
} }
func TestRemoveSharesUnbonded(t *testing.T) { func TestRemoveSharesUnbonded(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
poolA := keeper.GetPool(ctx) poolA := keeper.GetPool(ctx)
assert.Equal(t, poolA.unbondedShareExRate(), sdk.OneRat) assert.Equal(t, poolA.unbondedShareExRate(), sdk.OneRat)
@ -174,7 +174,7 @@ func TestRemoveSharesUnbonded(t *testing.T) {
} }
func TestCandidateAddTokens(t *testing.T) { func TestCandidateAddTokens(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
poolA := keeper.GetPool(ctx) poolA := keeper.GetPool(ctx)
candA := Candidate{ candA := Candidate{
@ -200,7 +200,7 @@ func TestCandidateAddTokens(t *testing.T) {
} }
func TestCandidateRemoveShares(t *testing.T) { func TestCandidateRemoveShares(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
poolA := keeper.GetPool(ctx) poolA := keeper.GetPool(ctx)
candA := Candidate{ candA := Candidate{

View File

@ -130,7 +130,7 @@ func paramsNoInflation() Params {
} }
// hogpodge of all sorts of input required for testing // hogpodge of all sorts of input required for testing
func createTestInput(t *testing.T, sender sdk.Address, isCheckTx bool, initCoins int64) (sdk.Context, sdk.AccountMapper, Keeper) { func createTestInput(t *testing.T, isCheckTx bool, initCoins int64) (sdk.Context, sdk.AccountMapper, Keeper) {
db := dbm.NewMemDB() db := dbm.NewMemDB()
keyStake := sdk.NewKVStoreKey("stake") keyStake := sdk.NewKVStoreKey("stake")
keyMain := keyStake //sdk.NewKVStoreKey("main") //TODO fix multistore keyMain := keyStake //sdk.NewKVStoreKey("main") //TODO fix multistore

View File

@ -9,7 +9,7 @@ import (
) )
func TestGetInflation(t *testing.T) { func TestGetInflation(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
pool := keeper.GetPool(ctx) pool := keeper.GetPool(ctx)
params := keeper.GetParams(ctx) params := keeper.GetParams(ctx)
hrsPerYrRat := sdk.NewRat(hrsPerYr) hrsPerYrRat := sdk.NewRat(hrsPerYr)
@ -60,7 +60,7 @@ func TestGetInflation(t *testing.T) {
} }
func TestProcessProvisions(t *testing.T) { func TestProcessProvisions(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0) ctx, _, keeper := createTestInput(t, false, 0)
params := defaultParams() params := defaultParams()
keeper.setParams(ctx, params) keeper.setParams(ctx, params)
pool := keeper.GetPool(ctx) pool := keeper.GetPool(ctx)