pr comments

This commit is contained in:
rigelrozanski 2018-06-08 10:03:37 -07:00
parent 61a510ed08
commit 42def02ae9
3 changed files with 2 additions and 20 deletions

View File

@ -6,10 +6,10 @@ FEATURES
IMPROVEMENTS IMPROVEMENTS
* export command now writes current validator set for Tendermint * export command now writes current validator set for Tendermint
* [tests] Application module tests now use a mock application
FIXES FIXES
* [lcd] Switch to bech32 for addresses on all human readable inputs and outputs * [lcd] Switch to bech32 for addresses on all human readable inputs and outputs
* [lcd] Switch to bech32 for addresses on all human readable inputs and outputs
## 0.18.0 ## 0.18.0

View File

@ -19,12 +19,10 @@ import (
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tmlibs/log"
) )
var accName = "foobart"
func setGenesis(bapp *BasecoinApp, accs ...auth.BaseAccount) error { func setGenesis(bapp *BasecoinApp, accs ...auth.BaseAccount) error {
genaccs := make([]*types.GenesisAccount, len(accs)) genaccs := make([]*types.GenesisAccount, len(accs))
for i, acc := range accs { for i, acc := range accs {
genaccs[i] = types.NewGenesisAccount(&types.AppAccount{acc, accName}) genaccs[i] = types.NewGenesisAccount(&types.AppAccount{acc, "foobart"})
} }
genesisState := types.GenesisState{ genesisState := types.GenesisState{

View File

@ -1,7 +1,6 @@
package mock package mock
import ( import (
"fmt"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -42,70 +41,55 @@ func getMockApp(t *testing.T) *App {
} }
func TestMsgChangePubKey(t *testing.T) { func TestMsgChangePubKey(t *testing.T) {
fmt.Println("wackydebugoutput TestMsgChangePubKey 0")
mapp := getMockApp(t) mapp := getMockApp(t)
// Construct some genesis bytes to reflect basecoin/types/AppAccount // Construct some genesis bytes to reflect basecoin/types/AppAccount
// Give 77 foocoin to the first key // Give 77 foocoin to the first key
coins := sdk.Coins{{"foocoin", 77}} coins := sdk.Coins{{"foocoin", 77}}
fmt.Println("wackydebugoutput TestMsgChangePubKey 1")
acc1 := &auth.BaseAccount{ acc1 := &auth.BaseAccount{
Address: addr1, Address: addr1,
Coins: coins, Coins: coins,
} }
fmt.Println("wackydebugoutput TestMsgChangePubKey 3")
accs := []auth.Account{acc1} accs := []auth.Account{acc1}
fmt.Println("wackydebugoutput TestMsgChangePubKey 4")
// Construct genesis state // Construct genesis state
SetGenesis(mapp, accs) SetGenesis(mapp, accs)
// A checkTx context (true) // A checkTx context (true)
ctxCheck := mapp.BaseApp.NewContext(true, abci.Header{}) ctxCheck := mapp.BaseApp.NewContext(true, abci.Header{})
fmt.Println("wackydebugoutput TestMsgChangePubKey 5")
res1 := mapp.AccountMapper.GetAccount(ctxCheck, addr1) res1 := mapp.AccountMapper.GetAccount(ctxCheck, addr1)
assert.Equal(t, acc1, res1.(*auth.BaseAccount)) assert.Equal(t, acc1, res1.(*auth.BaseAccount))
// Run a CheckDeliver // Run a CheckDeliver
SignCheckDeliver(t, mapp.BaseApp, sendMsg1, []int64{0}, true, priv1) SignCheckDeliver(t, mapp.BaseApp, sendMsg1, []int64{0}, true, priv1)
fmt.Println("wackydebugoutput TestMsgChangePubKey 6")
// Check balances // Check balances
CheckBalance(t, mapp, addr1, sdk.Coins{{"foocoin", 67}}) CheckBalance(t, mapp, addr1, sdk.Coins{{"foocoin", 67}})
fmt.Println("wackydebugoutput TestMsgChangePubKey 7")
CheckBalance(t, mapp, addr2, sdk.Coins{{"foocoin", 10}}) CheckBalance(t, mapp, addr2, sdk.Coins{{"foocoin", 10}})
fmt.Println("wackydebugoutput TestMsgChangePubKey 8")
changePubKeyMsg := auth.MsgChangeKey{ changePubKeyMsg := auth.MsgChangeKey{
Address: addr1, Address: addr1,
NewPubKey: priv2.PubKey(), NewPubKey: priv2.PubKey(),
} }
fmt.Println("wackydebugoutput TestMsgChangePubKey 10")
ctxDeliver := mapp.BaseApp.NewContext(false, abci.Header{}) ctxDeliver := mapp.BaseApp.NewContext(false, abci.Header{})
fmt.Println("wackydebugoutput TestMsgChangePubKey 11")
acc2 := mapp.AccountMapper.GetAccount(ctxDeliver, addr1) acc2 := mapp.AccountMapper.GetAccount(ctxDeliver, addr1)
// send a MsgChangePubKey // send a MsgChangePubKey
SignCheckDeliver(t, mapp.BaseApp, changePubKeyMsg, []int64{1}, true, priv1) SignCheckDeliver(t, mapp.BaseApp, changePubKeyMsg, []int64{1}, true, priv1)
fmt.Println("wackydebugoutput TestMsgChangePubKey 12")
acc2 = mapp.AccountMapper.GetAccount(ctxDeliver, addr1) acc2 = mapp.AccountMapper.GetAccount(ctxDeliver, addr1)
assert.True(t, priv2.PubKey().Equals(acc2.GetPubKey())) assert.True(t, priv2.PubKey().Equals(acc2.GetPubKey()))
// signing a SendMsg with the old privKey should be an auth error // signing a SendMsg with the old privKey should be an auth error
tx := GenTx(sendMsg1, []int64{2}, priv1) tx := GenTx(sendMsg1, []int64{2}, priv1)
fmt.Println("wackydebugoutput TestMsgChangePubKey 13")
res := mapp.Deliver(tx) res := mapp.Deliver(tx)
assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnauthorized), res.Code, res.Log) assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnauthorized), res.Code, res.Log)
// resigning the tx with the new correct priv key should work // resigning the tx with the new correct priv key should work
SignCheckDeliver(t, mapp.BaseApp, sendMsg1, []int64{2}, true, priv2) SignCheckDeliver(t, mapp.BaseApp, sendMsg1, []int64{2}, true, priv2)
fmt.Println("wackydebugoutput TestMsgChangePubKey 14")
// Check balances // Check balances
CheckBalance(t, mapp, addr1, sdk.Coins{{"foocoin", 57}}) CheckBalance(t, mapp, addr1, sdk.Coins{{"foocoin", 57}})
fmt.Println("wackydebugoutput TestMsgChangePubKey 15")
CheckBalance(t, mapp, addr2, sdk.Coins{{"foocoin", 20}}) CheckBalance(t, mapp, addr2, sdk.Coins{{"foocoin", 20}})
fmt.Println("wackydebugoutput TestMsgChangePubKey 16")
} }