minor cleanup

This commit is contained in:
Ethan Buchman 2017-04-17 17:47:00 -04:00
parent f857f6218b
commit e6ec782f0c
2 changed files with 13 additions and 9 deletions

View File

@ -70,8 +70,8 @@ func (at *appTest) reset() {
// returns the final balance and expected balance for input and output accounts
func (at *appTest) exec(tx *types.SendTx, checkTx bool) (res abci.Result, inputGot, inputExp, outputGot, outputExpected types.Coins) {
initBalFoo := at.app.GetState().GetAccount(at.accIn.Account.PubKey.Address()).Balance
initBalBar := at.app.GetState().GetAccount(at.accOut.Account.PubKey.Address()).Balance
initBalIn := at.app.GetState().GetAccount(at.accIn.Account.PubKey.Address()).Balance
initBalOut := at.app.GetState().GetAccount(at.accOut.Account.PubKey.Address()).Balance
txBytes := []byte(wire.BinaryBytes(struct{ types.Tx }{tx}))
if checkTx {
@ -80,10 +80,10 @@ func (at *appTest) exec(tx *types.SendTx, checkTx bool) (res abci.Result, inputG
res = at.app.DeliverTx(txBytes)
}
endBalFoo := at.app.GetState().GetAccount(at.accIn.Account.PubKey.Address()).Balance
endBalBar := at.app.GetState().GetAccount(at.accOut.Account.PubKey.Address()).Balance
decrBalFooExp := tx.Outputs[0].Coins.Plus(types.Coins{tx.Fee})
return res, endBalFoo, initBalFoo.Minus(decrBalFooExp), endBalBar, initBalBar.Plus(tx.Outputs[0].Coins)
endBalIn := at.app.GetState().GetAccount(at.accIn.Account.PubKey.Address()).Balance
endBalOut := at.app.GetState().GetAccount(at.accOut.Account.PubKey.Address()).Balance
decrBalInExp := tx.Outputs[0].Coins.Plus(types.Coins{tx.Fee})
return res, endBalIn, initBalIn.Minus(decrBalInExp), endBalOut, initBalOut.Plus(tx.Outputs[0].Coins)
}
//--------------------------------------------------------

View File

@ -65,6 +65,10 @@ func (et *execTest) reset() {
et.store = types.NewMemKVStore()
et.state = NewState(et.store)
et.state.SetChainID(et.chainID)
// NOTE we dont run acc2State here
// so we can test non-existing accounts
}
//--------------------------------------------------------
@ -111,7 +115,7 @@ func TestGetOrMakeOutputs(t *testing.T) {
_, res = getOrMakeOutputs(et.state, nil, txs)
assert.True(res.IsErr(), "getOrMakeOutputs: expected error when sending duplicate accounts")
//test sending to existing/new account account
//test sending to existing/new account
et.reset()
txs1 := types.Accs2TxOutputs(et.accIn)
txs2 := types.Accs2TxOutputs(et.accOut)
@ -207,11 +211,11 @@ func TestValidateOutputsAdvanced(t *testing.T) {
//validateOutputsBasic
txs := types.Accs2TxOutputs(et.accIn)
res := validateOutputsBasic(txs)
assert.True(res.IsOK(), fmt.Sprintf("validateOutputsBasic: expected no error on good tx input. Error: %v", res.Error()))
assert.True(res.IsOK(), fmt.Sprintf("validateOutputsBasic: expected no error on good tx output. Error: %v", res.Error()))
txs[0].Coins[0].Amount = 0
res = validateOutputsBasic(txs)
assert.True(res.IsErr(), fmt.Sprintf("validateInputBasic: expected error on bad tx inputi. Error: %v", res.Error()))
assert.True(res.IsErr(), fmt.Sprintf("validateInputBasic: expected error on bad tx output. Error: %v", res.Error()))
}
func TestSumOutput(t *testing.T) {