From f35587c00d0f4806271dc6609d17c622cfb58a81 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Fri, 29 Jun 2018 18:10:15 -0700 Subject: [PATCH] Switch asserts to require (#1483) * meta: Switch the majority of asserts to require Switch most assert statements to require, to ease debugging. Closes #1418 * Fix imports --- baseapp/baseapp_test.go | 132 ++++++------- client/lcd/lcd_test.go | 136 ++++++------- cmd/gaia/app/genesis_test.go | 4 +- cmd/gaia/cli_test/cli_test.go | 43 +++-- crypto/encode_test.go | 31 ++- crypto/keys/bip39/wordcodec_test.go | 6 +- crypto/keys/hd/fundraiser_test.go | 14 +- crypto/keys/keybase_test.go | 98 +++++----- crypto/ledger_test.go | 7 +- examples/basecoin/app/app_test.go | 5 +- examples/democoin/app/app_test.go | 5 +- .../democoin/x/assoc/validator_set_test.go | 34 ++-- examples/democoin/x/cool/app_test.go | 3 +- examples/democoin/x/cool/keeper_test.go | 12 +- examples/democoin/x/oracle/oracle_test.go | 59 +++--- examples/democoin/x/pow/app_test.go | 3 +- examples/democoin/x/pow/handler_test.go | 16 +- examples/democoin/x/pow/keeper_test.go | 16 +- examples/democoin/x/pow/types_test.go | 20 +- .../democoin/x/simplestake/keeper_test.go | 19 +- examples/democoin/x/simplestake/msgs_test.go | 6 +- server/mock/app_test.go | 5 +- server/mock/store_test.go | 14 +- server/util_test.go | 3 +- store/cachekvstore_test.go | 51 +++-- store/iavlstore_test.go | 124 ++++++------ store/prefixstore_test.go | 7 +- store/rootmultistore_test.go | 62 +++--- types/coin_test.go | 47 ++--- types/context_test.go | 15 +- types/errors_test.go | 10 +- types/int_test.go | 104 +++++----- types/lib/linear_test.go | 42 ++--- types/rational_test.go | 73 ++++--- types/store_test.go | 6 +- x/auth/account_test.go | 44 ++--- x/auth/ante_test.go | 23 ++- x/auth/context_test.go | 12 +- x/auth/feekeeper_test.go | 16 +- x/auth/mapper_test.go | 18 +- x/auth/mock/auth_app_test.go | 7 +- x/auth/mock/simulate_block.go | 3 +- x/auth/stdtx_test.go | 8 +- x/bank/app_test.go | 5 +- x/bank/keeper_test.go | 93 ++++----- x/bank/msgs_test.go | 28 +-- x/fee_distribution/keeper_test.go | 6 +- x/gov/endblocker_test.go | 114 +++++------ x/gov/keeper_test.go | 178 +++++++++--------- x/gov/msgs_test.go | 14 +- x/gov/tally_test.go | 100 +++++----- x/ibc/app_test.go | 3 +- x/ibc/ibc_test.go | 30 +-- x/ibc/types_test.go | 18 +- x/slashing/app_test.go | 5 +- x/slashing/msg_test.go | 4 +- x/stake/app_test.go | 6 +- x/stake/handler_test.go | 55 +++--- x/stake/keeper/delegation_test.go | 79 ++++---- x/stake/keeper/inflation_test.go | 39 ++-- x/stake/keeper/keeper_test.go | 10 +- x/stake/keeper/validator_test.go | 72 +++---- x/stake/types/msg_test.go | 17 +- x/stake/types/pool_test.go | 41 ++-- x/stake/types/validator_test.go | 72 +++---- 65 files changed, 1156 insertions(+), 1196 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 9d567c6bff20..0d0b2262652c 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -37,26 +37,26 @@ func newBaseApp(name string) *BaseApp { func TestMountStores(t *testing.T) { name := t.Name() app := newBaseApp(name) - assert.Equal(t, name, app.Name()) + require.Equal(t, name, app.Name()) // make some cap keys capKey1 := sdk.NewKVStoreKey("key1") capKey2 := sdk.NewKVStoreKey("key2") // no stores are mounted - assert.Panics(t, func() { app.LoadLatestVersion(capKey1) }) + require.Panics(t, func() { app.LoadLatestVersion(capKey1) }) app.MountStoresIAVL(capKey1, capKey2) // stores are mounted err := app.LoadLatestVersion(capKey1) - assert.Nil(t, err) + require.Nil(t, err) // check both stores store1 := app.cms.GetCommitKVStore(capKey1) - assert.NotNil(t, store1) + require.NotNil(t, store1) store2 := app.cms.GetCommitKVStore(capKey2) - assert.NotNil(t, store2) + require.NotNil(t, store2) } // Test that we can make commits and then reload old versions. @@ -71,14 +71,14 @@ func TestLoadVersion(t *testing.T) { capKey := sdk.NewKVStoreKey("main") app.MountStoresIAVL(capKey) err := app.LoadLatestVersion(capKey) // needed to make stores non-nil - assert.Nil(t, err) + require.Nil(t, err) emptyCommitID := sdk.CommitID{} lastHeight := app.LastBlockHeight() lastID := app.LastCommitID() - assert.Equal(t, int64(0), lastHeight) - assert.Equal(t, emptyCommitID, lastID) + require.Equal(t, int64(0), lastHeight) + require.Equal(t, emptyCommitID, lastID) // execute some blocks header := abci.Header{Height: 1} @@ -94,7 +94,7 @@ func TestLoadVersion(t *testing.T) { app = NewBaseApp(name, nil, logger, db) app.MountStoresIAVL(capKey) err = app.LoadLatestVersion(capKey) - assert.Nil(t, err) + require.Nil(t, err) testLoadVersionHelper(t, app, int64(2), commitID2) // reload with LoadVersion, see if you can commit the same block and get @@ -102,7 +102,7 @@ func TestLoadVersion(t *testing.T) { app = NewBaseApp(name, nil, logger, db) app.MountStoresIAVL(capKey) err = app.LoadVersion(1, capKey) - assert.Nil(t, err) + require.Nil(t, err) testLoadVersionHelper(t, app, int64(1), commitID1) app.BeginBlock(abci.RequestBeginBlock{Header: header}) app.Commit() @@ -112,8 +112,8 @@ func TestLoadVersion(t *testing.T) { func testLoadVersionHelper(t *testing.T, app *BaseApp, expectedHeight int64, expectedID sdk.CommitID) { lastHeight := app.LastBlockHeight() lastID := app.LastCommitID() - assert.Equal(t, expectedHeight, lastHeight) - assert.Equal(t, expectedID, lastID) + require.Equal(t, expectedHeight, lastHeight) + require.Equal(t, expectedID, lastID) } // Test that the app hash is static @@ -125,7 +125,7 @@ func testLoadVersionHelper(t *testing.T, app *BaseApp, expectedHeight int64, exp capKey := sdk.NewKVStoreKey("main") app.MountStoresIAVL(capKey) err := app.LoadLatestVersion(capKey) // needed to make stores non-nil - assert.Nil(t, err) + require.Nil(t, err) // execute some blocks header := abci.Header{Height: 1} @@ -138,7 +138,7 @@ func testLoadVersionHelper(t *testing.T, app *BaseApp, expectedHeight int64, exp res = app.Commit() commitID2 := sdk.CommitID{2, res.Data} - assert.Equal(t, commitID1.Hash, commitID2.Hash) + require.Equal(t, commitID1.Hash, commitID2.Hash) } */ @@ -160,7 +160,7 @@ func TestInfo(t *testing.T) { assert.Equal(t, "", res.Version) assert.Equal(t, t.Name(), res.GetData()) assert.Equal(t, int64(0), res.LastBlockHeight) - assert.Equal(t, []uint8(nil), res.LastBlockAppHash) + require.Equal(t, []uint8(nil), res.LastBlockAppHash) // ----- test a proper response ------- // TODO @@ -179,7 +179,7 @@ func TestInitChainer(t *testing.T) { capKey2 := sdk.NewKVStoreKey("key2") app.MountStoresIAVL(capKey, capKey2) err := app.LoadLatestVersion(capKey) // needed to make stores non-nil - assert.Nil(t, err) + require.Nil(t, err) key, value := []byte("hello"), []byte("goodbye") @@ -198,7 +198,7 @@ func TestInitChainer(t *testing.T) { // initChainer is nil - nothing happens app.InitChain(abci.RequestInitChain{}) res := app.Query(query) - assert.Equal(t, 0, len(res.Value)) + require.Equal(t, 0, len(res.Value)) // set initChainer and try again - should see the value app.SetInitChainer(initChainer) @@ -206,31 +206,31 @@ func TestInitChainer(t *testing.T) { // assert that chainID is set correctly in InitChain chainID := app.deliverState.ctx.ChainID() - assert.Equal(t, "test-chain-id", chainID, "ChainID in deliverState not set correctly in InitChain") + require.Equal(t, "test-chain-id", chainID, "ChainID in deliverState not set correctly in InitChain") chainID = app.checkState.ctx.ChainID() - assert.Equal(t, "test-chain-id", chainID, "ChainID in checkState not set correctly in InitChain") + require.Equal(t, "test-chain-id", chainID, "ChainID in checkState not set correctly in InitChain") app.Commit() res = app.Query(query) - assert.Equal(t, value, res.Value) + require.Equal(t, value, res.Value) // reload app app = NewBaseApp(name, nil, logger, db) app.MountStoresIAVL(capKey, capKey2) err = app.LoadLatestVersion(capKey) // needed to make stores non-nil - assert.Nil(t, err) + require.Nil(t, err) app.SetInitChainer(initChainer) // ensure we can still query after reloading res = app.Query(query) - assert.Equal(t, value, res.Value) + require.Equal(t, value, res.Value) // commit and ensure we can still query app.BeginBlock(abci.RequestBeginBlock{}) app.Commit() res = app.Query(query) - assert.Equal(t, value, res.Value) + require.Equal(t, value, res.Value) } func getStateCheckingHandler(t *testing.T, capKey *sdk.KVStoreKey, txPerHeight int, checkHeader bool) func(ctx sdk.Context, msg sdk.Msg) sdk.Result { @@ -243,7 +243,7 @@ func getStateCheckingHandler(t *testing.T, capKey *sdk.KVStoreKey, txPerHeight i // check previous value in store counterBytes := []byte{byte(counter - 1)} prevBytes := store.Get(counterBytes) - assert.Equal(t, counterBytes, prevBytes) + require.Equal(t, counterBytes, prevBytes) } // set the current counter in the store @@ -255,7 +255,7 @@ func getStateCheckingHandler(t *testing.T, capKey *sdk.KVStoreKey, txPerHeight i if checkHeader { thisHeader := ctx.BlockHeader() height := int64((counter / txPerHeight) + 1) - assert.Equal(t, height, thisHeader.Height) + require.Equal(t, height, thisHeader.Height) } counter++ @@ -293,7 +293,7 @@ func TestCheckTx(t *testing.T) { capKey := sdk.NewKVStoreKey("main") app.MountStoresIAVL(capKey) err := app.LoadLatestVersion(capKey) // needed to make stores non-nil - assert.Nil(t, err) + require.Nil(t, err) app.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx) (newCtx sdk.Context, res sdk.Result, abort bool) { return }) txPerHeight := 3 @@ -317,7 +317,7 @@ func TestCheckTx(t *testing.T) { checkStateStore := app.checkState.ctx.KVStore(capKey) for i := 0; i < txPerHeight; i++ { storedValue := checkStateStore.Get([]byte{byte(i)}) - assert.Nil(t, storedValue) + require.Nil(t, storedValue) } } @@ -330,7 +330,7 @@ func TestDeliverTx(t *testing.T) { capKey := sdk.NewKVStoreKey("main") app.MountStoresIAVL(capKey) err := app.LoadLatestVersion(capKey) // needed to make stores non-nil - assert.Nil(t, err) + require.Nil(t, err) txPerHeight := 2 app.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx) (newCtx sdk.Context, res sdk.Result, abort bool) { return }) @@ -359,7 +359,7 @@ func TestSimulateTx(t *testing.T) { capKey := sdk.NewKVStoreKey("main") app.MountStoresIAVL(capKey) err := app.LoadLatestVersion(capKey) // needed to make stores non-nil - assert.Nil(t, err) + require.Nil(t, err) counter := 0 app.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx) (newCtx sdk.Context, res sdk.Result, abort bool) { return }) @@ -372,7 +372,7 @@ func TestSimulateTx(t *testing.T) { // check we can see the current header thisHeader := ctx.BlockHeader() height := int64(counter) - assert.Equal(t, height, thisHeader.Height) + require.Equal(t, height, thisHeader.Height) counter++ return sdk.Result{} }) @@ -421,18 +421,18 @@ func TestRunInvalidTransaction(t *testing.T) { capKey := sdk.NewKVStoreKey("main") app.MountStoresIAVL(capKey) err := app.LoadLatestVersion(capKey) // needed to make stores non-nil - assert.Nil(t, err) + require.Nil(t, err) app.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx) (newCtx sdk.Context, res sdk.Result, abort bool) { return }) app.Router().AddRoute(msgType2, func(ctx sdk.Context, msg sdk.Msg) (res sdk.Result) { return }) app.BeginBlock(abci.RequestBeginBlock{}) // Transaction where validate fails invalidTx := testTx{-1} err1 := app.Deliver(invalidTx) - assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeTxDecode), err1.Code) + require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeTxDecode), err1.Code) // Transaction with no known route unknownRouteTx := testUpdatePowerTx{} err2 := app.Deliver(unknownRouteTx) - assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnknownRequest), err2.Code) + require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnknownRequest), err2.Code) } // Test that transactions exceeding gas limits fail @@ -445,7 +445,7 @@ func TestTxGasLimits(t *testing.T) { capKey := sdk.NewKVStoreKey("main") app.MountStoresIAVL(capKey) err := app.LoadLatestVersion(capKey) // needed to make stores non-nil - assert.Nil(t, err) + require.Nil(t, err) app.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx) (newCtx sdk.Context, res sdk.Result, abort bool) { newCtx = ctx.WithGasMeter(sdk.NewGasMeter(0)) @@ -461,7 +461,7 @@ func TestTxGasLimits(t *testing.T) { app.BeginBlock(abci.RequestBeginBlock{Header: header}) res := app.Deliver(tx) - assert.Equal(t, res.Code, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOutOfGas), "Expected transaction to run out of gas") + require.Equal(t, res.Code, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOutOfGas), "Expected transaction to run out of gas") app.EndBlock(abci.RequestEndBlock{}) app.Commit() } @@ -474,7 +474,7 @@ func TestQuery(t *testing.T) { capKey := sdk.NewKVStoreKey("main") app.MountStoresIAVL(capKey) err := app.LoadLatestVersion(capKey) // needed to make stores non-nil - assert.Nil(t, err) + require.Nil(t, err) key, value := []byte("hello"), []byte("goodbye") @@ -492,25 +492,25 @@ func TestQuery(t *testing.T) { // query is empty before we do anything res := app.Query(query) - assert.Equal(t, 0, len(res.Value)) + require.Equal(t, 0, len(res.Value)) tx := testUpdatePowerTx{} // doesn't matter // query is still empty after a CheckTx app.Check(tx) res = app.Query(query) - assert.Equal(t, 0, len(res.Value)) + require.Equal(t, 0, len(res.Value)) // query is still empty after a DeliverTx before we commit app.BeginBlock(abci.RequestBeginBlock{}) app.Deliver(tx) res = app.Query(query) - assert.Equal(t, 0, len(res.Value)) + require.Equal(t, 0, len(res.Value)) // query returns correct value after Commit app.Commit() res = app.Query(query) - assert.Equal(t, value, res.Value) + require.Equal(t, value, res.Value) } // Test p2p filter queries @@ -521,7 +521,7 @@ func TestP2PQuery(t *testing.T) { capKey := sdk.NewKVStoreKey("main") app.MountStoresIAVL(capKey) err := app.LoadLatestVersion(capKey) // needed to make stores non-nil - assert.Nil(t, err) + require.Nil(t, err) app.SetAddrPeerFilter(func(addrport string) abci.ResponseQuery { require.Equal(t, "1.1.1.1:8000", addrport) @@ -585,8 +585,8 @@ func TestValidatorChange(t *testing.T) { // Load latest state, which should be empty. err := app.LoadLatestVersion(capKey) - assert.Nil(t, err) - assert.Equal(t, app.LastBlockHeight(), int64(0)) + require.Nil(t, err) + require.Equal(t, app.LastBlockHeight(), int64(0)) // Create the validators var numVals = 3 @@ -611,7 +611,7 @@ func TestValidatorChange(t *testing.T) { } txBytes := toJSON(tx) res := app.DeliverTx(txBytes) - assert.True(t, res.IsOK(), "%#v\nABCI log: %s", res, res.Log) + require.True(t, res.IsOK(), "%#v\nABCI log: %s", res, res.Log) } // Simulate the end of a block. @@ -624,18 +624,18 @@ func TestValidatorChange(t *testing.T) { pubkey, err := tmtypes.PB2TM.PubKey(val.PubKey) // Sanity - assert.Nil(t, err) + require.Nil(t, err) // Find matching update and splice it out. for j := 0; j < len(valUpdates); j++ { valUpdate := valUpdates[j] updatePubkey, err := tmtypes.PB2TM.PubKey(valUpdate.PubKey) - assert.Nil(t, err) + require.Nil(t, err) // Matched. if updatePubkey.Equals(pubkey) { - assert.Equal(t, valUpdate.Power, val.Power+1) + require.Equal(t, valUpdate.Power, val.Power+1) if j < len(valUpdates)-1 { // Splice it out. valUpdates = append(valUpdates[:j], valUpdates[j+1:]...) @@ -646,7 +646,7 @@ func TestValidatorChange(t *testing.T) { // Not matched. } } - assert.Equal(t, len(valUpdates), 0, "Some validator updates were unexpected") + require.Equal(t, len(valUpdates), 0, "Some validator updates were unexpected") } //---------------------------------------- @@ -808,15 +808,15 @@ func TestMultipleBurn(t *testing.T) { addr := priv.PubKey().Address() app.accountKeeper.AddCoins(app.deliverState.ctx, addr, sdk.Coins{{"foocoin", sdk.NewInt(100)}}) - assert.Equal(t, sdk.Coins{{"foocoin", sdk.NewInt(100)}}, app.accountKeeper.GetCoins(app.deliverState.ctx, addr), "Balance did not update") + require.Equal(t, sdk.Coins{{"foocoin", sdk.NewInt(100)}}, app.accountKeeper.GetCoins(app.deliverState.ctx, addr), "Balance did not update") msg := testBurnMsg{addr, sdk.Coins{{"foocoin", sdk.NewInt(50)}}} tx := GenTx(t.Name(), []sdk.Msg{msg, msg}, []int64{0}, []int64{0}, priv) res := app.Deliver(tx) - assert.Equal(t, true, res.IsOK(), res.Log) - assert.Equal(t, sdk.Coins(nil), app.accountKeeper.GetCoins(app.deliverState.ctx, addr), "Double burn did not work") + require.Equal(t, true, res.IsOK(), res.Log) + require.Equal(t, sdk.Coins(nil), app.accountKeeper.GetCoins(app.deliverState.ctx, addr), "Double burn did not work") } // tests multiples msgs of same type from different addresses in single tx @@ -861,8 +861,8 @@ func TestBurnMultipleOwners(t *testing.T) { app.accountKeeper.AddCoins(app.deliverState.ctx, addr1, sdk.Coins{{"foocoin", sdk.NewInt(100)}}) app.accountKeeper.AddCoins(app.deliverState.ctx, addr2, sdk.Coins{{"foocoin", sdk.NewInt(100)}}) - assert.Equal(t, sdk.Coins{{"foocoin", sdk.NewInt(100)}}, app.accountKeeper.GetCoins(app.deliverState.ctx, addr1), "Balance1 did not update") - assert.Equal(t, sdk.Coins{{"foocoin", sdk.NewInt(100)}}, app.accountKeeper.GetCoins(app.deliverState.ctx, addr2), "Balance2 did not update") + require.Equal(t, sdk.Coins{{"foocoin", sdk.NewInt(100)}}, app.accountKeeper.GetCoins(app.deliverState.ctx, addr1), "Balance1 did not update") + require.Equal(t, sdk.Coins{{"foocoin", sdk.NewInt(100)}}, app.accountKeeper.GetCoins(app.deliverState.ctx, addr2), "Balance2 did not update") msg1 := testBurnMsg{addr1, sdk.Coins{{"foocoin", sdk.NewInt(100)}}} msg2 := testBurnMsg{addr2, sdk.Coins{{"foocoin", sdk.NewInt(100)}}} @@ -871,19 +871,19 @@ func TestBurnMultipleOwners(t *testing.T) { tx := GenTx(t.Name(), []sdk.Msg{msg1, msg2}, []int64{0, 0}, []int64{0, 0}, priv1, priv1) res := app.Deliver(tx) - assert.Equal(t, sdk.ABCICodeType(0x10003), res.Code, "Wrong signatures passed") + require.Equal(t, sdk.ABCICodeType(0x10003), res.Code, "Wrong signatures passed") - assert.Equal(t, sdk.Coins{{"foocoin", sdk.NewInt(100)}}, app.accountKeeper.GetCoins(app.deliverState.ctx, addr1), "Balance1 changed after invalid sig") - assert.Equal(t, sdk.Coins{{"foocoin", sdk.NewInt(100)}}, app.accountKeeper.GetCoins(app.deliverState.ctx, addr2), "Balance2 changed after invalid sig") + require.Equal(t, sdk.Coins{{"foocoin", sdk.NewInt(100)}}, app.accountKeeper.GetCoins(app.deliverState.ctx, addr1), "Balance1 changed after invalid sig") + require.Equal(t, sdk.Coins{{"foocoin", sdk.NewInt(100)}}, app.accountKeeper.GetCoins(app.deliverState.ctx, addr2), "Balance2 changed after invalid sig") // test valid tx tx = GenTx(t.Name(), []sdk.Msg{msg1, msg2}, []int64{0, 1}, []int64{1, 0}, priv1, priv2) res = app.Deliver(tx) - assert.Equal(t, true, res.IsOK(), res.Log) + require.Equal(t, true, res.IsOK(), res.Log) - assert.Equal(t, sdk.Coins(nil), app.accountKeeper.GetCoins(app.deliverState.ctx, addr1), "Balance1 did not change after valid tx") - assert.Equal(t, sdk.Coins(nil), app.accountKeeper.GetCoins(app.deliverState.ctx, addr2), "Balance2 did not change after valid tx") + require.Equal(t, sdk.Coins(nil), app.accountKeeper.GetCoins(app.deliverState.ctx, addr1), "Balance1 did not change after valid tx") + require.Equal(t, sdk.Coins(nil), app.accountKeeper.GetCoins(app.deliverState.ctx, addr2), "Balance2 did not change after valid tx") } // tests different msg types in single tx with different addresses @@ -929,7 +929,7 @@ func TestSendBurn(t *testing.T) { acc := app.accountMapper.NewAccountWithAddress(app.deliverState.ctx, addr2) app.accountMapper.SetAccount(app.deliverState.ctx, acc) - assert.Equal(t, sdk.Coins{{"foocoin", sdk.NewInt(100)}}, app.accountKeeper.GetCoins(app.deliverState.ctx, addr1), "Balance1 did not update") + require.Equal(t, sdk.Coins{{"foocoin", sdk.NewInt(100)}}, app.accountKeeper.GetCoins(app.deliverState.ctx, addr1), "Balance1 did not update") sendMsg := testSendMsg{addr1, addr2, sdk.Coins{{"foocoin", sdk.NewInt(50)}}} @@ -940,10 +940,10 @@ func TestSendBurn(t *testing.T) { tx := GenTx(t.Name(), []sdk.Msg{sendMsg, msg2, msg1}, []int64{0, 1}, []int64{0, 0}, priv1, priv2) res := app.Deliver(tx) - assert.Equal(t, true, res.IsOK(), res.Log) + require.Equal(t, true, res.IsOK(), res.Log) - assert.Equal(t, sdk.Coins(nil), app.accountKeeper.GetCoins(app.deliverState.ctx, addr1), "Balance1 did not change after valid tx") - assert.Equal(t, sdk.Coins(nil), app.accountKeeper.GetCoins(app.deliverState.ctx, addr2), "Balance2 did not change after valid tx") + require.Equal(t, sdk.Coins(nil), app.accountKeeper.GetCoins(app.deliverState.ctx, addr1), "Balance1 did not change after valid tx") + require.Equal(t, sdk.Coins(nil), app.accountKeeper.GetCoins(app.deliverState.ctx, addr2), "Balance2 did not change after valid tx") // Check that state is only updated if all msgs in tx pass. app.accountKeeper.AddCoins(app.deliverState.ctx, addr1, sdk.Coins{{"foocoin", sdk.NewInt(50)}}) @@ -960,10 +960,10 @@ func TestSendBurn(t *testing.T) { app.BeginBlock(abci.RequestBeginBlock{}) app.deliverState.ctx = app.deliverState.ctx.WithChainID(t.Name()) - assert.Equal(t, sdk.ABCICodeType(0x1000a), res.Code, "Allowed tx to pass with insufficient funds") + require.Equal(t, sdk.ABCICodeType(0x1000a), res.Code, "Allowed tx to pass with insufficient funds") - assert.Equal(t, sdk.Coins{{"foocoin", sdk.NewInt(50)}}, app.accountKeeper.GetCoins(app.deliverState.ctx, addr1), "Allowed valid msg to pass in invalid tx") - assert.Equal(t, sdk.Coins(nil), app.accountKeeper.GetCoins(app.deliverState.ctx, addr2), "Balance2 changed after invalid tx") + require.Equal(t, sdk.Coins{{"foocoin", sdk.NewInt(50)}}, app.accountKeeper.GetCoins(app.deliverState.ctx, addr1), "Allowed valid msg to pass in invalid tx") + require.Equal(t, sdk.Coins(nil), app.accountKeeper.GetCoins(app.deliverState.ctx, addr2), "Balance2 changed after invalid tx") } //---------------------------------------- diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index e3b19c999d32..37d7e919166a 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -46,7 +46,7 @@ func TestKeys(t *testing.T) { reg, err := regexp.Compile(`([a-z]+ ){12}`) require.Nil(t, err) match := reg.MatchString(seed) - assert.True(t, match, "Returned seed has wrong format", seed) + require.True(t, match, "Returned seed has wrong format", seed) newName := "test_newname" newPassword := "0987654321" @@ -74,10 +74,10 @@ func TestKeys(t *testing.T) { addr2Bech32 := sdk.MustBech32ifyAcc(addr2Acc) addrBech32 := sdk.MustBech32ifyAcc(addr) - assert.Equal(t, name, m[0].Name, "Did not serve keys name correctly") - assert.Equal(t, addrBech32, m[0].Address, "Did not serve keys Address correctly") - assert.Equal(t, newName, m[1].Name, "Did not serve keys name correctly") - assert.Equal(t, addr2Bech32, m[1].Address, "Did not serve keys Address correctly") + require.Equal(t, name, m[0].Name, "Did not serve keys name correctly") + require.Equal(t, addrBech32, m[0].Address, "Did not serve keys Address correctly") + require.Equal(t, newName, m[1].Name, "Did not serve keys name correctly") + require.Equal(t, addr2Bech32, m[1].Address, "Did not serve keys Address correctly") // select key keyEndpoint := fmt.Sprintf("/keys/%s", newName) @@ -87,8 +87,8 @@ func TestKeys(t *testing.T) { err = cdc.UnmarshalJSON([]byte(body), &m2) require.Nil(t, err) - assert.Equal(t, newName, m2.Name, "Did not serve keys name correctly") - assert.Equal(t, addr2Bech32, m2.Address, "Did not serve keys Address correctly") + require.Equal(t, newName, m2.Name, "Did not serve keys name correctly") + require.Equal(t, addr2Bech32, m2.Address, "Did not serve keys Address correctly") // update key jsonStr = []byte(fmt.Sprintf(`{ @@ -120,7 +120,7 @@ func TestVersion(t *testing.T) { reg, err := regexp.Compile(`\d+\.\d+\.\d+(-dev)?`) require.Nil(t, err) match := reg.MatchString(body) - assert.True(t, match, body) + require.True(t, match, body) // node info res, body = Request(t, port, "GET", "/node_version", nil) @@ -129,7 +129,7 @@ func TestVersion(t *testing.T) { reg, err = regexp.Compile(`\d+\.\d+\.\d+(-dev)?`) require.Nil(t, err) match = reg.MatchString(body) - assert.True(t, match, body) + require.True(t, match, body) } func TestNodeStatus(t *testing.T) { @@ -144,14 +144,14 @@ func TestNodeStatus(t *testing.T) { err := cdc.UnmarshalJSON([]byte(body), &nodeInfo) require.Nil(t, err, "Couldn't parse node info") - assert.NotEqual(t, p2p.NodeInfo{}, nodeInfo, "res: %v", res) + require.NotEqual(t, p2p.NodeInfo{}, nodeInfo, "res: %v", res) // syncing res, body = Request(t, port, "GET", "/syncing", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) // we expect that there is no other node running so the syncing state is "false" - assert.Equal(t, "false", body) + require.Equal(t, "false", body) } func TestBlock(t *testing.T) { @@ -166,7 +166,7 @@ func TestBlock(t *testing.T) { err := cdc.UnmarshalJSON([]byte(body), &resultBlock) require.Nil(t, err, "Couldn't parse block") - assert.NotEqual(t, ctypes.ResultBlock{}, resultBlock) + require.NotEqual(t, ctypes.ResultBlock{}, resultBlock) // -- @@ -176,7 +176,7 @@ func TestBlock(t *testing.T) { err = wire.Cdc.UnmarshalJSON([]byte(body), &resultBlock) require.Nil(t, err, "Couldn't parse block") - assert.NotEqual(t, ctypes.ResultBlock{}, resultBlock) + require.NotEqual(t, ctypes.ResultBlock{}, resultBlock) // -- @@ -196,10 +196,10 @@ func TestValidators(t *testing.T) { err := cdc.UnmarshalJSON([]byte(body), &resultVals) require.Nil(t, err, "Couldn't parse validatorset") - assert.NotEqual(t, rpc.ResultValidatorsOutput{}, resultVals) + require.NotEqual(t, rpc.ResultValidatorsOutput{}, resultVals) - assert.Contains(t, resultVals.Validators[0].Address, "cosmosvaladdr") - assert.Contains(t, resultVals.Validators[0].PubKey, "cosmosvalpub") + require.Contains(t, resultVals.Validators[0].Address, "cosmosvaladdr") + require.Contains(t, resultVals.Validators[0].PubKey, "cosmosvalpub") // -- @@ -209,7 +209,7 @@ func TestValidators(t *testing.T) { err = cdc.UnmarshalJSON([]byte(body), &resultVals) require.Nil(t, err, "Couldn't parse validatorset") - assert.NotEqual(t, rpc.ResultValidatorsOutput{}, resultVals) + require.NotEqual(t, rpc.ResultValidatorsOutput{}, resultVals) // -- @@ -239,24 +239,24 @@ func TestCoinSend(t *testing.T) { tests.WaitForHeight(resultTx.Height+1, port) // check if tx was committed - assert.Equal(t, uint32(0), resultTx.CheckTx.Code) - assert.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.CheckTx.Code) + require.Equal(t, uint32(0), resultTx.DeliverTx.Code) // query sender acc = getAccount(t, port, addr) coins := acc.GetCoins() mycoins := coins[0] - assert.Equal(t, "steak", mycoins.Denom) - assert.Equal(t, initialBalance[0].Amount.SubRaw(1), mycoins.Amount) + require.Equal(t, "steak", mycoins.Denom) + require.Equal(t, initialBalance[0].Amount.SubRaw(1), mycoins.Amount) // query receiver acc = getAccount(t, port, receiveAddr) coins = acc.GetCoins() mycoins = coins[0] - assert.Equal(t, "steak", mycoins.Denom) - assert.Equal(t, int64(1), mycoins.Amount.Int64()) + require.Equal(t, "steak", mycoins.Denom) + require.Equal(t, int64(1), mycoins.Amount.Int64()) } func TestIBCTransfer(t *testing.T) { @@ -274,16 +274,16 @@ func TestIBCTransfer(t *testing.T) { tests.WaitForHeight(resultTx.Height+1, port) // check if tx was committed - assert.Equal(t, uint32(0), resultTx.CheckTx.Code) - assert.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.CheckTx.Code) + require.Equal(t, uint32(0), resultTx.DeliverTx.Code) // query sender acc = getAccount(t, port, addr) coins := acc.GetCoins() mycoins := coins[0] - assert.Equal(t, "steak", mycoins.Denom) - assert.Equal(t, initialBalance[0].Amount.SubRaw(1), mycoins.Amount) + require.Equal(t, "steak", mycoins.Denom) + require.Equal(t, initialBalance[0].Amount.SubRaw(1), mycoins.Amount) // TODO: query ibc egress packet state } @@ -301,7 +301,7 @@ func TestTxs(t *testing.T) { // query empty res, body = Request(t, port, "GET", fmt.Sprintf("/txs?tag=sender_bech32='%s'", "cosmosaccaddr1jawd35d9aq4u76sr3fjalmcqc8hqygs9gtnmv3"), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) - assert.Equal(t, "[]", body) + require.Equal(t, "[]", body) // create TX receiveAddr, resultTx := doSend(t, port, seed, name, password, addr) @@ -323,15 +323,15 @@ func TestTxs(t *testing.T) { // check if tx is queryable res, body = Request(t, port, "GET", fmt.Sprintf("/txs?tag=tx.hash='%s'", resultTx.Hash), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) - assert.NotEqual(t, "[]", body) + require.NotEqual(t, "[]", body) err := cdc.UnmarshalJSON([]byte(body), &indexedTxs) require.NoError(t, err) - assert.Equal(t, 1, len(indexedTxs)) + require.Equal(t, 1, len(indexedTxs)) // XXX should this move into some other testfile for txs in general? // test if created TX hash is the correct hash - assert.Equal(t, resultTx.Hash, indexedTxs[0].Hash) + require.Equal(t, resultTx.Hash, indexedTxs[0].Hash) // query sender // also tests url decoding @@ -342,7 +342,7 @@ func TestTxs(t *testing.T) { err = cdc.UnmarshalJSON([]byte(body), &indexedTxs) require.NoError(t, err) require.Equal(t, 1, len(indexedTxs), "%v", indexedTxs) // there are 2 txs created with doSend - assert.Equal(t, resultTx.Height, indexedTxs[0].Height) + require.Equal(t, resultTx.Height, indexedTxs[0].Height) // query recipient receiveAddrBech := sdk.MustBech32ifyAcc(receiveAddr) @@ -352,7 +352,7 @@ func TestTxs(t *testing.T) { err = cdc.UnmarshalJSON([]byte(body), &indexedTxs) require.NoError(t, err) require.Equal(t, 1, len(indexedTxs)) - assert.Equal(t, resultTx.Height, indexedTxs[0].Height) + require.Equal(t, resultTx.Height, indexedTxs[0].Height) } func TestValidatorsQuery(t *testing.T) { @@ -361,7 +361,7 @@ func TestValidatorsQuery(t *testing.T) { require.Equal(t, 2, len(pks)) validators := getValidators(t, port) - assert.Equal(t, len(validators), 2) + require.Equal(t, len(validators), 2) // make sure all the validators were found (order unknown because sorted by owner addr) foundVal1, foundVal2 := false, false @@ -373,8 +373,8 @@ func TestValidatorsQuery(t *testing.T) { if validators[0].PubKey == pk2Bech || validators[1].PubKey == pk2Bech { foundVal2 = true } - assert.True(t, foundVal1, "pk1Bech %v, owner1 %v, owner2 %v", pk1Bech, validators[0].Owner, validators[1].Owner) - assert.True(t, foundVal2, "pk2Bech %v, owner1 %v, owner2 %v", pk2Bech, validators[0].Owner, validators[1].Owner) + require.True(t, foundVal1, "pk1Bech %v, owner1 %v, owner2 %v", pk1Bech, validators[0].Owner, validators[1].Owner) + require.True(t, foundVal2, "pk2Bech %v, owner1 %v, owner2 %v", pk2Bech, validators[0].Owner, validators[1].Owner) } func TestBonding(t *testing.T) { @@ -390,18 +390,18 @@ func TestBonding(t *testing.T) { tests.WaitForHeight(resultTx.Height+1, port) // check if tx was committed - assert.Equal(t, uint32(0), resultTx.CheckTx.Code) - assert.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.CheckTx.Code) + require.Equal(t, uint32(0), resultTx.DeliverTx.Code) // query sender acc := getAccount(t, port, addr) coins := acc.GetCoins() - assert.Equal(t, int64(40), coins.AmountOf(denom).Int64()) + require.Equal(t, int64(40), coins.AmountOf(denom).Int64()) // query validator bond := getDelegation(t, port, addr, validator1Owner) - assert.Equal(t, "60/1", bond.Shares.String()) + require.Equal(t, "60/1", bond.Shares.String()) ////////////////////// // testing unbonding @@ -412,17 +412,17 @@ func TestBonding(t *testing.T) { // query validator bond = getDelegation(t, port, addr, validator1Owner) - assert.Equal(t, "30/1", bond.Shares.String()) + require.Equal(t, "30/1", bond.Shares.String()) // check if tx was committed - assert.Equal(t, uint32(0), resultTx.CheckTx.Code) - assert.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.CheckTx.Code) + require.Equal(t, uint32(0), resultTx.DeliverTx.Code) // should the sender should have not received any coins as the unbonding has only just begun // query sender acc = getAccount(t, port, addr) coins = acc.GetCoins() - assert.Equal(t, int64(40), coins.AmountOf("steak").Int64()) + require.Equal(t, int64(40), coins.AmountOf("steak").Int64()) // TODO add redelegation, need more complex capabilities such to mock context and } @@ -438,15 +438,15 @@ func TestSubmitProposal(t *testing.T) { tests.WaitForHeight(resultTx.Height+1, port) // check if tx was committed - assert.Equal(t, uint32(0), resultTx.CheckTx.Code) - assert.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.CheckTx.Code) + require.Equal(t, uint32(0), resultTx.DeliverTx.Code) var proposalID int64 cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID) // query proposal proposal := getProposal(t, port, proposalID) - assert.Equal(t, "Test", proposal.Title) + require.Equal(t, "Test", proposal.Title) } func TestDeposit(t *testing.T) { @@ -460,15 +460,15 @@ func TestDeposit(t *testing.T) { tests.WaitForHeight(resultTx.Height+1, port) // check if tx was committed - assert.Equal(t, uint32(0), resultTx.CheckTx.Code) - assert.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.CheckTx.Code) + require.Equal(t, uint32(0), resultTx.DeliverTx.Code) var proposalID int64 cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID) // query proposal proposal := getProposal(t, port, proposalID) - assert.Equal(t, "Test", proposal.Title) + require.Equal(t, "Test", proposal.Title) // create SubmitProposal TX resultTx = doDeposit(t, port, seed, name, password, addr, proposalID) @@ -476,11 +476,11 @@ func TestDeposit(t *testing.T) { // query proposal proposal = getProposal(t, port, proposalID) - assert.True(t, proposal.TotalDeposit.IsEqual(sdk.Coins{sdk.NewCoin("steak", 10)})) + require.True(t, proposal.TotalDeposit.IsEqual(sdk.Coins{sdk.NewCoin("steak", 10)})) // query deposit deposit := getDeposit(t, port, proposalID, addr) - assert.True(t, deposit.Amount.IsEqual(sdk.Coins{sdk.NewCoin("steak", 10)})) + require.True(t, deposit.Amount.IsEqual(sdk.Coins{sdk.NewCoin("steak", 10)})) } func TestVote(t *testing.T) { @@ -494,15 +494,15 @@ func TestVote(t *testing.T) { tests.WaitForHeight(resultTx.Height+1, port) // check if tx was committed - assert.Equal(t, uint32(0), resultTx.CheckTx.Code) - assert.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.CheckTx.Code) + require.Equal(t, uint32(0), resultTx.DeliverTx.Code) var proposalID int64 cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID) // query proposal proposal := getProposal(t, port, proposalID) - assert.Equal(t, "Test", proposal.Title) + require.Equal(t, "Test", proposal.Title) // create SubmitProposal TX resultTx = doDeposit(t, port, seed, name, password, addr, proposalID) @@ -510,15 +510,15 @@ func TestVote(t *testing.T) { // query proposal proposal = getProposal(t, port, proposalID) - assert.Equal(t, gov.StatusToString(gov.StatusVotingPeriod), proposal.Status) + require.Equal(t, gov.StatusToString(gov.StatusVotingPeriod), proposal.Status) // create SubmitProposal TX resultTx = doVote(t, port, seed, name, password, addr, proposalID) tests.WaitForHeight(resultTx.Height+1, port) vote := getVote(t, port, proposalID, addr) - assert.Equal(t, proposalID, vote.ProposalID) - assert.Equal(t, gov.VoteOptionToString(gov.OptionYes), vote.Option) + require.Equal(t, proposalID, vote.ProposalID) + require.Equal(t, gov.VoteOptionToString(gov.OptionYes), vote.Option) } func TestProposalsQuery(t *testing.T) { @@ -563,31 +563,31 @@ func TestProposalsQuery(t *testing.T) { // Test query all proposals proposals := getProposalsAll(t, port) - assert.Equal(t, proposalID1, (proposals[0]).ProposalID) - assert.Equal(t, proposalID2, (proposals[1]).ProposalID) - assert.Equal(t, proposalID3, (proposals[2]).ProposalID) + require.Equal(t, proposalID1, (proposals[0]).ProposalID) + require.Equal(t, proposalID2, (proposals[1]).ProposalID) + require.Equal(t, proposalID3, (proposals[2]).ProposalID) // Test query deposited by addr1 proposals = getProposalsFilterDepositer(t, port, addr) - assert.Equal(t, proposalID1, (proposals[0]).ProposalID) + require.Equal(t, proposalID1, (proposals[0]).ProposalID) // Test query deposited by addr2 proposals = getProposalsFilterDepositer(t, port, addr2) - assert.Equal(t, proposalID2, (proposals[0]).ProposalID) - assert.Equal(t, proposalID3, (proposals[1]).ProposalID) + require.Equal(t, proposalID2, (proposals[0]).ProposalID) + require.Equal(t, proposalID3, (proposals[1]).ProposalID) // Test query voted by addr1 proposals = getProposalsFilterVoter(t, port, addr) - assert.Equal(t, proposalID2, (proposals[0]).ProposalID) - assert.Equal(t, proposalID3, (proposals[1]).ProposalID) + require.Equal(t, proposalID2, (proposals[0]).ProposalID) + require.Equal(t, proposalID3, (proposals[1]).ProposalID) // Test query voted by addr2 proposals = getProposalsFilterVoter(t, port, addr2) - assert.Equal(t, proposalID3, (proposals[0]).ProposalID) + require.Equal(t, proposalID3, (proposals[0]).ProposalID) // Test query voted and deposited by addr1 proposals = getProposalsFilterVoterDepositer(t, port, addr, addr) - assert.Equal(t, proposalID2, (proposals[0]).ProposalID) + require.Equal(t, proposalID2, (proposals[0]).ProposalID) } //_____________________________________________________________________________ diff --git a/cmd/gaia/app/genesis_test.go b/cmd/gaia/app/genesis_test.go index 90677e8ff114..7f0da29901a6 100644 --- a/cmd/gaia/app/genesis_test.go +++ b/cmd/gaia/app/genesis_test.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" ) @@ -14,7 +14,7 @@ func TestToAccount(t *testing.T) { addr := sdk.Address(priv.PubKey().Address()) authAcc := auth.NewBaseAccountWithAddress(addr) genAcc := NewGenesisAccount(&authAcc) - assert.Equal(t, authAcc, *genAcc.ToAccount()) + require.Equal(t, authAcc, *genAcc.ToAccount()) } func TestGaiaAppGenTx(t *testing.T) { diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index f8937c42dc4f..62fe0631a396 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -5,7 +5,6 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client/keys" @@ -47,33 +46,33 @@ func TestGaiaCLISend(t *testing.T) { require.NoError(t, err) fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags)) - assert.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64()) + require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64()) executeWrite(t, fmt.Sprintf("gaiacli send %v --amount=10steak --to=%v --name=foo", flags, barCech), pass) tests.WaitForNextHeightTM(port) barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barCech, flags)) - assert.Equal(t, int64(10), barAcc.GetCoins().AmountOf("steak").Int64()) + require.Equal(t, int64(10), barAcc.GetCoins().AmountOf("steak").Int64()) fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags)) - assert.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64()) + require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64()) // test autosequencing executeWrite(t, fmt.Sprintf("gaiacli send %v --amount=10steak --to=%v --name=foo", flags, barCech), pass) tests.WaitForNextHeightTM(port) barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barCech, flags)) - assert.Equal(t, int64(20), barAcc.GetCoins().AmountOf("steak").Int64()) + require.Equal(t, int64(20), barAcc.GetCoins().AmountOf("steak").Int64()) fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags)) - assert.Equal(t, int64(30), fooAcc.GetCoins().AmountOf("steak").Int64()) + require.Equal(t, int64(30), fooAcc.GetCoins().AmountOf("steak").Int64()) // test memo executeWrite(t, fmt.Sprintf("gaiacli send %v --amount=10steak --to=%v --name=foo --memo 'testmemo'", flags, barCech), pass) tests.WaitForNextHeightTM(port) barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barCech, flags)) - assert.Equal(t, int64(30), barAcc.GetCoins().AmountOf("steak").Int64()) + require.Equal(t, int64(30), barAcc.GetCoins().AmountOf("steak").Int64()) fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags)) - assert.Equal(t, int64(20), fooAcc.GetCoins().AmountOf("steak").Int64()) + require.Equal(t, int64(20), fooAcc.GetCoins().AmountOf("steak").Int64()) } func TestGaiaCLICreateValidator(t *testing.T) { @@ -108,9 +107,9 @@ func TestGaiaCLICreateValidator(t *testing.T) { tests.WaitForNextHeightTM(port) barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barCech, flags)) - assert.Equal(t, int64(10), barAcc.GetCoins().AmountOf("steak").Int64()) + require.Equal(t, int64(10), barAcc.GetCoins().AmountOf("steak").Int64()) fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags)) - assert.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64()) + require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64()) // create validator cvStr := fmt.Sprintf("gaiacli stake create-validator %v", flags) @@ -127,8 +126,8 @@ func TestGaiaCLICreateValidator(t *testing.T) { require.Equal(t, int64(8), barAcc.GetCoins().AmountOf("steak").Int64(), "%v", barAcc) validator := executeGetValidator(t, fmt.Sprintf("gaiacli stake validator %v --output=json %v", barCech, flags)) - assert.Equal(t, validator.Owner, barAddr) - assert.Equal(t, "2/1", validator.PoolShares.Amount.String()) + require.Equal(t, validator.Owner, barAddr) + require.Equal(t, "2/1", validator.PoolShares.Amount.String()) // unbond a single share unbondStr := fmt.Sprintf("gaiacli stake unbond %v", flags) @@ -145,7 +144,7 @@ func TestGaiaCLICreateValidator(t *testing.T) { barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barCech, flags)) require.Equal(t, int64(9), barAcc.GetCoins().AmountOf("steak").Int64(), "%v", barAcc) validator = executeGetValidator(t, fmt.Sprintf("gaiacli stake validator %v --output=json %v", barCech, flags)) - assert.Equal(t, "1/1", validator.PoolShares.Amount.String()) + require.Equal(t, "1/1", validator.PoolShares.Amount.String()) } func TestGaiaCLISubmitProposal(t *testing.T) { @@ -172,33 +171,33 @@ func TestGaiaCLISubmitProposal(t *testing.T) { require.NoError(t, err) fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags)) - assert.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64()) + require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64()) executeWrite(t, fmt.Sprintf("gaiacli gov submitproposal %v --proposer=%v --deposit=5steak --type=Text --title=Test --description=test --name=foo", flags, fooCech), pass) tests.WaitForNextHeightTM(port) fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags)) - assert.Equal(t, int64(45), fooAcc.GetCoins().AmountOf("steak").Int64()) + require.Equal(t, int64(45), fooAcc.GetCoins().AmountOf("steak").Int64()) proposal1 := executeGetProposal(t, fmt.Sprintf("gaiacli gov query-proposal --proposalID=1 --output=json %v", flags)) - assert.Equal(t, int64(1), proposal1.ProposalID) - assert.Equal(t, gov.StatusToString(gov.StatusDepositPeriod), proposal1.Status) + require.Equal(t, int64(1), proposal1.ProposalID) + require.Equal(t, gov.StatusToString(gov.StatusDepositPeriod), proposal1.Status) executeWrite(t, fmt.Sprintf("gaiacli gov deposit %v --depositer=%v --deposit=10steak --proposalID=1 --name=foo", flags, fooCech), pass) tests.WaitForNextHeightTM(port) fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags)) - assert.Equal(t, int64(35), fooAcc.GetCoins().AmountOf("steak").Int64()) + require.Equal(t, int64(35), fooAcc.GetCoins().AmountOf("steak").Int64()) proposal1 = executeGetProposal(t, fmt.Sprintf("gaiacli gov query-proposal --proposalID=1 --output=json %v", flags)) - assert.Equal(t, int64(1), proposal1.ProposalID) - assert.Equal(t, gov.StatusToString(gov.StatusVotingPeriod), proposal1.Status) + require.Equal(t, int64(1), proposal1.ProposalID) + require.Equal(t, gov.StatusToString(gov.StatusVotingPeriod), proposal1.Status) executeWrite(t, fmt.Sprintf("gaiacli gov vote %v --proposalID=1 --voter=%v --option=Yes --name=foo", flags, fooCech), pass) tests.WaitForNextHeightTM(port) vote := executeGetVote(t, fmt.Sprintf("gaiacli gov query-vote --proposalID=1 --voter=%v --output=json %v", fooCech, flags)) - assert.Equal(t, int64(1), vote.ProposalID) - assert.Equal(t, gov.VoteOptionToString(gov.OptionYes), vote.Option) + require.Equal(t, int64(1), vote.ProposalID) + require.Equal(t, gov.VoteOptionToString(gov.OptionYes), vote.Option) } //___________________________________________________________________________________ diff --git a/crypto/encode_test.go b/crypto/encode_test.go index f9ab851b40a6..99dd727cf736 100644 --- a/crypto/encode_test.go +++ b/crypto/encode_test.go @@ -1,7 +1,6 @@ package crypto import ( - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "os" "testing" @@ -18,10 +17,10 @@ func checkAminoBinary(t *testing.T, src byter, dst interface{}, size int) { bz, err := cdc.MarshalBinaryBare(src) require.Nil(t, err, "%+v", err) // Make sure this is compatible with current (Bytes()) encoding. - assert.Equal(t, src.Bytes(), bz, "Amino binary vs Bytes() mismatch") + require.Equal(t, src.Bytes(), bz, "Amino binary vs Bytes() mismatch") // Make sure we have the expected length. if size != -1 { - assert.Equal(t, size, len(bz), "Amino binary size mismatch") + require.Equal(t, size, len(bz), "Amino binary size mismatch") } // Unmarshal. err = cdc.UnmarshalBinaryBare(bz, dst) @@ -33,10 +32,10 @@ func checkAminoJSON(t *testing.T, src interface{}, dst interface{}, isNil bool) js, err := cdc.MarshalJSON(src) require.Nil(t, err, "%+v", err) if isNil { - assert.Equal(t, string(js), `null`) + require.Equal(t, string(js), `null`) } else { - assert.Contains(t, string(js), `"type":`) - assert.Contains(t, string(js), `"value":`) + require.Contains(t, string(js), `"type":`) + require.Contains(t, string(js), `"value":`) } // Unmarshal. err = cdc.UnmarshalJSON(js, dst) @@ -79,26 +78,26 @@ func TestKeyEncodings(t *testing.T) { // Check (de/en)codings of PrivKeys. var priv2, priv3 tcrypto.PrivKey checkAminoBinary(t, tc.privKey, &priv2, tc.privSize) - assert.EqualValues(t, tc.privKey, priv2) + require.EqualValues(t, tc.privKey, priv2) checkAminoJSON(t, tc.privKey, &priv3, false) // TODO also check Prefix bytes. - assert.EqualValues(t, tc.privKey, priv3) + require.EqualValues(t, tc.privKey, priv3) // Check (de/en)codings of Signatures. var sig1, sig2, sig3 tcrypto.Signature sig1, err := tc.privKey.Sign([]byte("something")) - assert.NoError(t, err) + require.NoError(t, err) checkAminoBinary(t, sig1, &sig2, -1) // Signature size changes for Secp anyways. - assert.EqualValues(t, sig1, sig2) + require.EqualValues(t, sig1, sig2) checkAminoJSON(t, sig1, &sig3, false) // TODO also check Prefix bytes. - assert.EqualValues(t, sig1, sig3) + require.EqualValues(t, sig1, sig3) // Check (de/en)codings of PubKeys. pubKey := tc.privKey.PubKey() var pub2, pub3 tcrypto.PubKey checkAminoBinary(t, pubKey, &pub2, tc.pubSize) - assert.EqualValues(t, pubKey, pub2) + require.EqualValues(t, pubKey, pub2) checkAminoJSON(t, pubKey, &pub3, false) // TODO also check Prefix bytes. - assert.EqualValues(t, pubKey, pub3) + require.EqualValues(t, pubKey, pub3) } } @@ -107,16 +106,16 @@ func TestNilEncodings(t *testing.T) { // Check nil Signature. var a, b tcrypto.Signature checkAminoJSON(t, &a, &b, true) - assert.EqualValues(t, a, b) + require.EqualValues(t, a, b) // Check nil PubKey. var c, d tcrypto.PubKey checkAminoJSON(t, &c, &d, true) - assert.EqualValues(t, c, d) + require.EqualValues(t, c, d) // Check nil PrivKey. var e, f tcrypto.PrivKey checkAminoJSON(t, &e, &f, true) - assert.EqualValues(t, e, f) + require.EqualValues(t, e, f) } diff --git a/crypto/keys/bip39/wordcodec_test.go b/crypto/keys/bip39/wordcodec_test.go index dbc5c0d020ec..a821239d7b40 100644 --- a/crypto/keys/bip39/wordcodec_test.go +++ b/crypto/keys/bip39/wordcodec_test.go @@ -3,13 +3,13 @@ package bip39 import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestWordCodec_NewMnemonic(t *testing.T) { _, err := NewMnemonic(FundRaiser) - assert.NoError(t, err, "unexpected error generating fundraiser mnemonic") + require.NoError(t, err, "unexpected error generating fundraiser mnemonic") _, err = NewMnemonic(FreshKey) - assert.NoError(t, err, "unexpected error generating new 24-word mnemonic") + require.NoError(t, err, "unexpected error generating new 24-word mnemonic") } diff --git a/crypto/keys/hd/fundraiser_test.go b/crypto/keys/hd/fundraiser_test.go index 3e45de7e2d1c..f4112d958bc4 100644 --- a/crypto/keys/hd/fundraiser_test.go +++ b/crypto/keys/hd/fundraiser_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/bartekn/go-bip39" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" ) @@ -56,7 +56,7 @@ func TestFundraiserCompatibility(t *testing.T) { master, ch := ComputeMastersFromSeed(seed) priv, err := DerivePrivateKeyForPath(master, ch, "44'/118'/0'/0/0") - assert.NoError(t, err) + require.NoError(t, err) pub := crypto.PrivKeySecp256k1(priv).PubKey() t.Log("\tNODEJS GOLANG\n") @@ -65,16 +65,16 @@ func TestFundraiserCompatibility(t *testing.T) { t.Logf("PRIV \t%X %X\n", privB, priv) t.Logf("PUB \t%X %X\n", pubB, pub) - assert.Equal(t, seedB, seed) - assert.Equal(t, master[:], masterB, fmt.Sprintf("Expected masters to match for %d", i)) - assert.Equal(t, priv[:], privB, "Expected priv keys to match") + require.Equal(t, seedB, seed) + require.Equal(t, master[:], masterB, fmt.Sprintf("Expected masters to match for %d", i)) + require.Equal(t, priv[:], privB, "Expected priv keys to match") var pubBFixed [33]byte copy(pubBFixed[:], pubB) - assert.Equal(t, pub, crypto.PubKeySecp256k1(pubBFixed), fmt.Sprintf("Expected pub keys to match for %d", i)) + require.Equal(t, pub, crypto.PubKeySecp256k1(pubBFixed), fmt.Sprintf("Expected pub keys to match for %d", i)) addr := pub.Address() t.Logf("ADDR \t%X %X\n", addrB, addr) - assert.Equal(t, addr, crypto.Address(addrB), fmt.Sprintf("Expected addresses to match %d", i)) + require.Equal(t, addr, crypto.Address(addrB), fmt.Sprintf("Expected addresses to match %d", i)) } } diff --git a/crypto/keys/keybase_test.go b/crypto/keys/keybase_test.go index d2f093bf2deb..ac0f7fa4da96 100644 --- a/crypto/keys/keybase_test.go +++ b/crypto/keys/keybase_test.go @@ -29,11 +29,11 @@ func TestKeyManagement(t *testing.T) { assert.Empty(t, l) _, _, err = cstore.CreateMnemonic(n1, English, p1, Ed25519) - assert.Error(t, err, "ed25519 keys are currently not supported by keybase") + require.Error(t, err, "ed25519 keys are currently not supported by keybase") // create some keys _, err = cstore.Get(n1) - assert.Error(t, err) + require.Error(t, err) i, _, err := cstore.CreateMnemonic(n1, English, p1, algo) require.NoError(t, err) @@ -43,18 +43,18 @@ func TestKeyManagement(t *testing.T) { // we can get these keys i2, err := cstore.Get(n2) - assert.NoError(t, err) + require.NoError(t, err) _, err = cstore.Get(n3) - assert.NotNil(t, err) + require.NotNil(t, err) // list shows them in order keyS, err := cstore.List() require.NoError(t, err) require.Equal(t, 2, len(keyS)) // note these are in alphabetical order - assert.Equal(t, n2, keyS[0].GetName()) - assert.Equal(t, n1, keyS[1].GetName()) - assert.Equal(t, i2.GetPubKey(), keyS[0].GetPubKey()) + require.Equal(t, n2, keyS[0].GetName()) + require.Equal(t, n1, keyS[1].GetName()) + require.Equal(t, i2.GetPubKey(), keyS[0].GetPubKey()) // deleting a key removes it err = cstore.Delete("bad name", "foo") @@ -63,9 +63,9 @@ func TestKeyManagement(t *testing.T) { require.NoError(t, err) keyS, err = cstore.List() require.NoError(t, err) - assert.Equal(t, 1, len(keyS)) + require.Equal(t, 1, len(keyS)) _, err = cstore.Get(n1) - assert.Error(t, err) + require.Error(t, err) // create an offline key o1 := "offline" @@ -158,19 +158,19 @@ func TestSignVerify(t *testing.T) { for i, tc := range cases { valid := tc.key.VerifyBytes(tc.data, tc.sig) - assert.Equal(t, tc.valid, valid, "%d", i) + require.Equal(t, tc.valid, valid, "%d", i) } // Now try to sign data with a secret-less key _, _, err = cstore.Sign(n3, p3, d3) - assert.NotNil(t, err) + require.NotNil(t, err) } func assertPassword(t *testing.T, cstore Keybase, name, pass, badpass string) { err := cstore.Update(name, badpass, pass) - assert.NotNil(t, err) + require.NotNil(t, err) err = cstore.Update(name, pass, pass) - assert.Nil(t, err, "%+v", err) + require.Nil(t, err, "%+v", err) } // TestExportImport tests exporting and importing @@ -183,26 +183,26 @@ func TestExportImport(t *testing.T) { ) info, _, err := cstore.CreateMnemonic("john", English, "secretcpw", Secp256k1) - assert.NoError(t, err) - assert.Equal(t, info.GetName(), "john") + require.NoError(t, err) + require.Equal(t, info.GetName(), "john") john, err := cstore.Get("john") - assert.NoError(t, err) - assert.Equal(t, info.GetName(), "john") + require.NoError(t, err) + require.Equal(t, info.GetName(), "john") johnAddr := info.GetPubKey().Address() armor, err := cstore.Export("john") - assert.NoError(t, err) + require.NoError(t, err) err = cstore.Import("john2", armor) - assert.NoError(t, err) + require.NoError(t, err) john2, err := cstore.Get("john2") - assert.NoError(t, err) + require.NoError(t, err) - assert.Equal(t, john.GetPubKey().Address(), johnAddr) - assert.Equal(t, john.GetName(), "john") - assert.Equal(t, john, john2) + require.Equal(t, john.GetPubKey().Address(), johnAddr) + require.Equal(t, john.GetName(), "john") + require.Equal(t, john, john2) } // @@ -216,35 +216,35 @@ func TestExportImportPubKey(t *testing.T) { // CreateMnemonic a private-public key pair and ensure consistency notPasswd := "n9y25ah7" info, _, err := cstore.CreateMnemonic("john", English, notPasswd, Secp256k1) - assert.Nil(t, err) - assert.NotEqual(t, info, "") - assert.Equal(t, info.GetName(), "john") + require.Nil(t, err) + require.NotEqual(t, info, "") + require.Equal(t, info.GetName(), "john") addr := info.GetPubKey().Address() john, err := cstore.Get("john") - assert.NoError(t, err) - assert.Equal(t, john.GetName(), "john") - assert.Equal(t, john.GetPubKey().Address(), addr) + require.NoError(t, err) + require.Equal(t, john.GetName(), "john") + require.Equal(t, john.GetPubKey().Address(), addr) // Export the public key only armor, err := cstore.ExportPubKey("john") - assert.NoError(t, err) + require.NoError(t, err) // Import it under a different name err = cstore.ImportPubKey("john-pubkey-only", armor) - assert.NoError(t, err) + require.NoError(t, err) // Ensure consistency john2, err := cstore.Get("john-pubkey-only") - assert.NoError(t, err) + require.NoError(t, err) // Compare the public keys - assert.True(t, john.GetPubKey().Equals(john2.GetPubKey())) + require.True(t, john.GetPubKey().Equals(john2.GetPubKey())) // Ensure the original key hasn't changed john, err = cstore.Get("john") - assert.NoError(t, err) - assert.Equal(t, john.GetPubKey().Address(), addr) - assert.Equal(t, john.GetName(), "john") + require.NoError(t, err) + require.Equal(t, john.GetPubKey().Address(), addr) + require.Equal(t, john.GetName(), "john") // Ensure keys cannot be overwritten err = cstore.ImportPubKey("john-pubkey-only", armor) - assert.NotNil(t, err) + require.NotNil(t, err) } // TestAdvancedKeyManagement verifies update, import, export functionality @@ -266,34 +266,34 @@ func TestAdvancedKeyManagement(t *testing.T) { // update password requires the existing password err = cstore.Update(n1, "jkkgkg", p2) - assert.NotNil(t, err) + require.NotNil(t, err) assertPassword(t, cstore, n1, p1, p2) // then it changes the password when correct err = cstore.Update(n1, p1, p2) - assert.NoError(t, err) + require.NoError(t, err) // p2 is now the proper one! assertPassword(t, cstore, n1, p2, p1) // exporting requires the proper name and passphrase _, err = cstore.Export(n1 + ".notreal") - assert.NotNil(t, err) + require.NotNil(t, err) _, err = cstore.Export(" " + n1) - assert.NotNil(t, err) + require.NotNil(t, err) _, err = cstore.Export(n1 + " ") - assert.NotNil(t, err) + require.NotNil(t, err) _, err = cstore.Export("") - assert.NotNil(t, err) + require.NotNil(t, err) exported, err := cstore.Export(n1) require.Nil(t, err, "%+v", err) // import succeeds err = cstore.Import(n2, exported) - assert.NoError(t, err) + require.NoError(t, err) // second import fails err = cstore.Import(n2, exported) - assert.NotNil(t, err) + require.NotNil(t, err) } // TestSeedPhrase verifies restoring from a seed phrase @@ -311,7 +311,7 @@ func TestSeedPhrase(t *testing.T) { // make sure key works with initial password info, mnemonic, err := cstore.CreateMnemonic(n1, English, p1, algo) require.Nil(t, err, "%+v", err) - assert.Equal(t, n1, info.GetName()) + require.Equal(t, n1, info.GetName()) assert.NotEmpty(t, mnemonic) // now, let us delete this key @@ -324,9 +324,9 @@ func TestSeedPhrase(t *testing.T) { params := *hd.NewFundraiserParams(0, 0) newInfo, err := cstore.Derive(n2, mnemonic, p2, params) require.NoError(t, err) - assert.Equal(t, n2, newInfo.GetName()) - assert.Equal(t, info.GetPubKey().Address(), newInfo.GetPubKey().Address()) - assert.Equal(t, info.GetPubKey(), newInfo.GetPubKey()) + require.Equal(t, n2, newInfo.GetName()) + require.Equal(t, info.GetPubKey().Address(), newInfo.GetPubKey().Address()) + require.Equal(t, info.GetPubKey(), newInfo.GetPubKey()) } func ExampleNew() { diff --git a/crypto/ledger_test.go b/crypto/ledger_test.go index 072d846473b4..997dfbc3bc60 100644 --- a/crypto/ledger_test.go +++ b/crypto/ledger_test.go @@ -4,7 +4,6 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" tcrypto "github.com/tendermint/tendermint/crypto" @@ -26,7 +25,7 @@ func TestRealLedgerSecp256k1(t *testing.T) { require.Nil(t, err) valid := pub.VerifyBytes(msg, sig) - assert.True(t, valid) + require.True(t, valid) // now, let's serialize the key and make sure it still works bs := priv.Bytes() @@ -41,13 +40,13 @@ func TestRealLedgerSecp256k1(t *testing.T) { sig, err = priv2.Sign(msg) require.Nil(t, err) valid = pub.VerifyBytes(msg, sig) - assert.True(t, valid) + require.True(t, valid) // make sure pubkeys serialize properly as well bs = pub.Bytes() bpub, err := tcrypto.PubKeyFromBytes(bs) require.NoError(t, err) - assert.Equal(t, pub, bpub) + require.Equal(t, pub, bpub) } // TestRealLedgerErrorHandling calls. These tests assume diff --git a/examples/basecoin/app/app_test.go b/examples/basecoin/app/app_test.go index 539a52c731b2..499c0e4082d3 100644 --- a/examples/basecoin/app/app_test.go +++ b/examples/basecoin/app/app_test.go @@ -5,7 +5,6 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/examples/basecoin/types" @@ -69,7 +68,7 @@ func TestGenesis(t *testing.T) { // A checkTx context ctx := bapp.BaseApp.NewContext(true, abci.Header{}) res1 := bapp.accountMapper.GetAccount(ctx, baseAcc.Address) - assert.Equal(t, acc, res1) + require.Equal(t, acc, res1) // reload app and ensure the account is still there bapp = NewBasecoinApp(logger, db) @@ -85,5 +84,5 @@ func TestGenesis(t *testing.T) { ctx = bapp.BaseApp.NewContext(true, abci.Header{}) res1 = bapp.accountMapper.GetAccount(ctx, baseAcc.Address) - assert.Equal(t, acc, res1) + require.Equal(t, acc, res1) } diff --git a/examples/democoin/app/app_test.go b/examples/democoin/app/app_test.go index d67e4f706438..36aca760f1e4 100644 --- a/examples/democoin/app/app_test.go +++ b/examples/democoin/app/app_test.go @@ -4,7 +4,6 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/examples/democoin/types" @@ -64,12 +63,12 @@ func TestGenesis(t *testing.T) { // A checkTx context ctx := bapp.BaseApp.NewContext(true, abci.Header{}) res1 := bapp.accountMapper.GetAccount(ctx, baseAcc.Address) - assert.Equal(t, acc, res1) + require.Equal(t, acc, res1) // reload app and ensure the account is still there bapp = NewDemocoinApp(logger, db) bapp.InitChain(abci.RequestInitChain{AppStateBytes: []byte("{}")}) ctx = bapp.BaseApp.NewContext(true, abci.Header{}) res1 = bapp.accountMapper.GetAccount(ctx, baseAcc.Address) - assert.Equal(t, acc, res1) + require.Equal(t, acc, res1) } diff --git a/examples/democoin/x/assoc/validator_set_test.go b/examples/democoin/x/assoc/validator_set_test.go index 289604149bb0..c20aeb85714e 100644 --- a/examples/democoin/x/assoc/validator_set_test.go +++ b/examples/democoin/x/assoc/validator_set_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" dbm "github.com/tendermint/tmlibs/db" @@ -38,34 +38,34 @@ func TestValidatorSet(t *testing.T) { valset := NewValidatorSet(wire.NewCodec(), sdk.NewPrefixStoreGetter(key, []byte("assoc")), base, 1, 5) - assert.Equal(t, base.Validator(ctx, addr1), valset.Validator(ctx, addr1)) - assert.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, addr2)) + require.Equal(t, base.Validator(ctx, addr1), valset.Validator(ctx, addr1)) + require.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, addr2)) assoc1 := []byte("asso1") assoc2 := []byte("asso2") - assert.True(t, valset.Associate(ctx, addr1, assoc1)) - assert.True(t, valset.Associate(ctx, addr2, assoc2)) + require.True(t, valset.Associate(ctx, addr1, assoc1)) + require.True(t, valset.Associate(ctx, addr2, assoc2)) - assert.Equal(t, base.Validator(ctx, addr1), valset.Validator(ctx, assoc1)) - assert.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, assoc2)) + require.Equal(t, base.Validator(ctx, addr1), valset.Validator(ctx, assoc1)) + require.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, assoc2)) - assert.Equal(t, base.Validator(ctx, addr1), valset.Validator(ctx, addr1)) - assert.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, addr2)) + require.Equal(t, base.Validator(ctx, addr1), valset.Validator(ctx, addr1)) + require.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, addr2)) assocs := valset.Associations(ctx, addr1) - assert.Equal(t, 1, len(assocs)) - assert.True(t, bytes.Equal(assoc1, assocs[0])) + require.Equal(t, 1, len(assocs)) + require.True(t, bytes.Equal(assoc1, assocs[0])) - assert.False(t, valset.Associate(ctx, addr1, assoc2)) - assert.False(t, valset.Associate(ctx, addr2, assoc1)) + require.False(t, valset.Associate(ctx, addr1, assoc2)) + require.False(t, valset.Associate(ctx, addr2, assoc1)) valset.Dissociate(ctx, addr1, assoc1) valset.Dissociate(ctx, addr2, assoc2) - assert.Equal(t, base.Validator(ctx, addr1), valset.Validator(ctx, addr1)) - assert.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, addr2)) + require.Equal(t, base.Validator(ctx, addr1), valset.Validator(ctx, addr1)) + require.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, addr2)) - assert.Nil(t, valset.Validator(ctx, assoc1)) - assert.Nil(t, valset.Validator(ctx, assoc2)) + require.Nil(t, valset.Validator(ctx, assoc1)) + require.Nil(t, valset.Validator(ctx, assoc2)) } diff --git a/examples/democoin/x/cool/app_test.go b/examples/democoin/x/cool/app_test.go index efcc6c1bf22f..e93f6d99c56b 100644 --- a/examples/democoin/x/cool/app_test.go +++ b/examples/democoin/x/cool/app_test.go @@ -3,7 +3,6 @@ package cool import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -88,7 +87,7 @@ func TestMsgQuiz(t *testing.T) { // A checkTx context (true) ctxCheck := mapp.BaseApp.NewContext(true, abci.Header{}) res1 := mapp.AccountMapper.GetAccount(ctxCheck, addr1) - assert.Equal(t, acc1, res1) + require.Equal(t, acc1, res1) // Set the trend, submit a really cool quiz and check for reward mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{setTrendMsg1}, []int64{0}, []int64{0}, true, priv1) diff --git a/examples/democoin/x/cool/keeper_test.go b/examples/democoin/x/cool/keeper_test.go index 3dfad91f13e1..ee2e529f260a 100644 --- a/examples/democoin/x/cool/keeper_test.go +++ b/examples/democoin/x/cool/keeper_test.go @@ -3,7 +3,7 @@ package cool import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" dbm "github.com/tendermint/tmlibs/db" @@ -35,16 +35,16 @@ func TestCoolKeeper(t *testing.T) { keeper := NewKeeper(capKey, ck, DefaultCodespace) err := InitGenesis(ctx, keeper, Genesis{"icy"}) - assert.Nil(t, err) + require.Nil(t, err) genesis := WriteGenesis(ctx, keeper) - assert.Nil(t, err) - assert.Equal(t, genesis, Genesis{"icy"}) + require.Nil(t, err) + require.Equal(t, genesis, Genesis{"icy"}) res := keeper.GetTrend(ctx) - assert.Equal(t, res, "icy") + require.Equal(t, res, "icy") keeper.setTrend(ctx, "fiery") res = keeper.GetTrend(ctx) - assert.Equal(t, res, "fiery") + require.Equal(t, res, "fiery") } diff --git a/examples/democoin/x/oracle/oracle_test.go b/examples/democoin/x/oracle/oracle_test.go index 01885e0d5e08..228378c34a7e 100644 --- a/examples/democoin/x/oracle/oracle_test.go +++ b/examples/democoin/x/oracle/oracle_test.go @@ -4,7 +4,6 @@ import ( "encoding/json" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -124,50 +123,50 @@ func TestOracle(t *testing.T) { // Nonmock.Validator signed, transaction failed msg := Msg{seqOracle{0, 0}, []byte("randomguy")} res := h(ctx, msg) - assert.False(t, res.IsOK()) - assert.Equal(t, 0, getSequence(ctx, key)) + require.False(t, res.IsOK()) + require.Equal(t, 0, getSequence(ctx, key)) // Less than 2/3 signed, msg not processed msg.Signer = addr1 res = h(ctx, msg) - assert.True(t, res.IsOK()) - assert.Equal(t, 0, getSequence(ctx, key)) + require.True(t, res.IsOK()) + require.Equal(t, 0, getSequence(ctx, key)) // Double signed, transaction failed res = h(ctx, msg) - assert.False(t, res.IsOK()) - assert.Equal(t, 0, getSequence(ctx, key)) + require.False(t, res.IsOK()) + require.Equal(t, 0, getSequence(ctx, key)) // More than 2/3 signed, msg processed msg.Signer = addr2 res = h(ctx, msg) - assert.True(t, res.IsOK()) - assert.Equal(t, 1, getSequence(ctx, key)) + require.True(t, res.IsOK()) + require.Equal(t, 1, getSequence(ctx, key)) // Already processed, transaction failed msg.Signer = addr3 res = h(ctx, msg) - assert.False(t, res.IsOK()) - assert.Equal(t, 1, getSequence(ctx, key)) + require.False(t, res.IsOK()) + require.Equal(t, 1, getSequence(ctx, key)) // Less than 2/3 signed, msg not processed msg = Msg{seqOracle{100, 1}, addr1} res = h(ctx, msg) - assert.True(t, res.IsOK()) - assert.Equal(t, 1, getSequence(ctx, key)) + require.True(t, res.IsOK()) + require.Equal(t, 1, getSequence(ctx, key)) // More than 2/3 signed but payload is invalid msg.Signer = addr2 res = h(ctx, msg) - assert.True(t, res.IsOK()) - assert.NotEqual(t, "", res.Log) - assert.Equal(t, 1, getSequence(ctx, key)) + require.True(t, res.IsOK()) + require.NotEqual(t, "", res.Log) + require.Equal(t, 1, getSequence(ctx, key)) // Already processed, transaction failed msg.Signer = addr3 res = h(ctx, msg) - assert.False(t, res.IsOK()) - assert.Equal(t, 1, getSequence(ctx, key)) + require.False(t, res.IsOK()) + require.Equal(t, 1, getSequence(ctx, key)) // Should handle mock.Validator set change valset.AddValidator(mock.Validator{addr4, sdk.NewRat(12)}) @@ -178,28 +177,28 @@ func TestOracle(t *testing.T) { // Less than 2/3 signed, msg not processed msg = Msg{seqOracle{1, 2}, addr1} res = h(ctx, msg) - assert.True(t, res.IsOK()) - assert.Equal(t, 1, getSequence(ctx, key)) + require.True(t, res.IsOK()) + require.Equal(t, 1, getSequence(ctx, key)) // Less than 2/3 signed, msg not processed msg.Signer = addr2 res = h(ctx, msg) - assert.True(t, res.IsOK()) - assert.Equal(t, 1, getSequence(ctx, key)) + require.True(t, res.IsOK()) + require.Equal(t, 1, getSequence(ctx, key)) // More than 2/3 signed, msg processed msg.Signer = addr4 res = h(ctx, msg) - assert.True(t, res.IsOK()) - assert.Equal(t, 2, getSequence(ctx, key)) + require.True(t, res.IsOK()) + require.Equal(t, 2, getSequence(ctx, key)) // Should handle mock.Validator set change while oracle process is happening msg = Msg{seqOracle{2, 3}, addr4} // Less than 2/3 signed, msg not processed res = h(ctx, msg) - assert.True(t, res.IsOK()) - assert.Equal(t, 2, getSequence(ctx, key)) + require.True(t, res.IsOK()) + require.Equal(t, 2, getSequence(ctx, key)) // Signed mock.Validator is kicked out valset.RemoveValidator(addr4) @@ -210,12 +209,12 @@ func TestOracle(t *testing.T) { // Less than 2/3 signed, msg not processed msg.Signer = addr1 res = h(ctx, msg) - assert.True(t, res.IsOK()) - assert.Equal(t, 2, getSequence(ctx, key)) + require.True(t, res.IsOK()) + require.Equal(t, 2, getSequence(ctx, key)) // More than 2/3 signed, msg processed msg.Signer = addr2 res = h(ctx, msg) - assert.True(t, res.IsOK()) - assert.Equal(t, 3, getSequence(ctx, key)) + require.True(t, res.IsOK()) + require.Equal(t, 3, getSequence(ctx, key)) } diff --git a/examples/democoin/x/pow/app_test.go b/examples/democoin/x/pow/app_test.go index 6dab19388614..d223a1f107d7 100644 --- a/examples/democoin/x/pow/app_test.go +++ b/examples/democoin/x/pow/app_test.go @@ -3,7 +3,6 @@ package pow import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" @@ -68,7 +67,7 @@ func TestMsgMine(t *testing.T) { // A checkTx context (true) ctxCheck := mapp.BaseApp.NewContext(true, abci.Header{}) res1 := mapp.AccountMapper.GetAccount(ctxCheck, addr1) - assert.Equal(t, acc1, res1) + require.Equal(t, acc1, res1) // Mine and check for reward mineMsg1 := GenerateMsgMine(addr1, 1, 2) diff --git a/examples/democoin/x/pow/handler_test.go b/examples/democoin/x/pow/handler_test.go index 5aaba48bbbbe..77a22057bce2 100644 --- a/examples/democoin/x/pow/handler_test.go +++ b/examples/democoin/x/pow/handler_test.go @@ -3,7 +3,7 @@ package pow import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tmlibs/log" @@ -32,21 +32,21 @@ func TestPowHandler(t *testing.T) { difficulty := uint64(2) err := InitGenesis(ctx, keeper, Genesis{uint64(1), uint64(0)}) - assert.Nil(t, err) + require.Nil(t, err) nonce, proof := mine(addr, count, difficulty) msg := NewMsgMine(addr, difficulty, count, nonce, proof) result := handler(ctx, msg) - assert.Equal(t, result, sdk.Result{}) + require.Equal(t, result, sdk.Result{}) newDiff, err := keeper.GetLastDifficulty(ctx) - assert.Nil(t, err) - assert.Equal(t, newDiff, uint64(2)) + require.Nil(t, err) + require.Equal(t, newDiff, uint64(2)) newCount, err := keeper.GetLastCount(ctx) - assert.Nil(t, err) - assert.Equal(t, newCount, uint64(1)) + require.Nil(t, err) + require.Equal(t, newCount, uint64(1)) // todo assert correct coin change, awaiting https://github.com/cosmos/cosmos-sdk/pull/691 @@ -55,5 +55,5 @@ func TestPowHandler(t *testing.T) { msg = NewMsgMine(addr, difficulty, count, nonce, proof) result = handler(ctx, msg) - assert.NotEqual(t, result, sdk.Result{}) + require.NotEqual(t, result, sdk.Result{}) } diff --git a/examples/democoin/x/pow/keeper_test.go b/examples/democoin/x/pow/keeper_test.go index 53c3e83b4bb2..31ad2fc121c5 100644 --- a/examples/democoin/x/pow/keeper_test.go +++ b/examples/democoin/x/pow/keeper_test.go @@ -3,7 +3,7 @@ package pow import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" dbm "github.com/tendermint/tmlibs/db" @@ -39,19 +39,19 @@ func TestPowKeeperGetSet(t *testing.T) { keeper := NewKeeper(capKey, config, ck, DefaultCodespace) err := InitGenesis(ctx, keeper, Genesis{uint64(1), uint64(0)}) - assert.Nil(t, err) + require.Nil(t, err) genesis := WriteGenesis(ctx, keeper) - assert.Nil(t, err) - assert.Equal(t, genesis, Genesis{uint64(1), uint64(0)}) + require.Nil(t, err) + require.Equal(t, genesis, Genesis{uint64(1), uint64(0)}) res, err := keeper.GetLastDifficulty(ctx) - assert.Nil(t, err) - assert.Equal(t, res, uint64(1)) + require.Nil(t, err) + require.Equal(t, res, uint64(1)) keeper.SetLastDifficulty(ctx, 2) res, err = keeper.GetLastDifficulty(ctx) - assert.Nil(t, err) - assert.Equal(t, res, uint64(2)) + require.Nil(t, err) + require.Equal(t, res, uint64(2)) } diff --git a/examples/democoin/x/pow/types_test.go b/examples/democoin/x/pow/types_test.go index e69e59559216..9ed5dc102c93 100644 --- a/examples/democoin/x/pow/types_test.go +++ b/examples/democoin/x/pow/types_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -13,13 +13,13 @@ func TestNewMsgMine(t *testing.T) { addr := sdk.Address([]byte("sender")) msg := MsgMine{addr, 0, 0, 0, []byte("")} equiv := NewMsgMine(addr, 0, 0, 0, []byte("")) - assert.Equal(t, msg, equiv, "%s != %s", msg, equiv) + require.Equal(t, msg, equiv, "%s != %s", msg, equiv) } func TestMsgMineType(t *testing.T) { addr := sdk.Address([]byte("sender")) msg := MsgMine{addr, 0, 0, 0, []byte("")} - assert.Equal(t, msg.Type(), "pow") + require.Equal(t, msg.Type(), "pow") } func TestMsgMineValidation(t *testing.T) { @@ -33,21 +33,21 @@ func TestMsgMineValidation(t *testing.T) { nonce, proof := mine(addr, count, difficulty) msg := MsgMine{addr, difficulty, count, nonce, proof} err := msg.ValidateBasic() - assert.Nil(t, err, "error with difficulty %d - %+v", difficulty, err) + require.Nil(t, err, "error with difficulty %d - %+v", difficulty, err) msg.Count++ err = msg.ValidateBasic() - assert.NotNil(t, err, "count was wrong, should have thrown error with msg %s", msg) + require.NotNil(t, err, "count was wrong, should have thrown error with msg %s", msg) msg.Count-- msg.Nonce++ err = msg.ValidateBasic() - assert.NotNil(t, err, "nonce was wrong, should have thrown error with msg %s", msg) + require.NotNil(t, err, "nonce was wrong, should have thrown error with msg %s", msg) msg.Nonce-- msg.Sender = otherAddr err = msg.ValidateBasic() - assert.NotNil(t, err, "sender was wrong, should have thrown error with msg %s", msg) + require.NotNil(t, err, "sender was wrong, should have thrown error with msg %s", msg) } } @@ -55,19 +55,19 @@ func TestMsgMineString(t *testing.T) { addr := sdk.Address([]byte("sender")) msg := MsgMine{addr, 0, 0, 0, []byte("abc")} res := msg.String() - assert.Equal(t, res, "MsgMine{Sender: 73656E646572, Difficulty: 0, Count: 0, Nonce: 0, Proof: abc}") + require.Equal(t, res, "MsgMine{Sender: 73656E646572, Difficulty: 0, Count: 0, Nonce: 0, Proof: abc}") } func TestMsgMineGetSignBytes(t *testing.T) { addr := sdk.Address([]byte("sender")) msg := MsgMine{addr, 1, 1, 1, []byte("abc")} res := msg.GetSignBytes() - assert.Equal(t, string(res), `{"sender":"73656E646572","difficulty":1,"count":1,"nonce":1,"proof":"YWJj"}`) + require.Equal(t, string(res), `{"sender":"73656E646572","difficulty":1,"count":1,"nonce":1,"proof":"YWJj"}`) } func TestMsgMineGetSigners(t *testing.T) { addr := sdk.Address([]byte("sender")) msg := MsgMine{addr, 1, 1, 1, []byte("abc")} res := msg.GetSigners() - assert.Equal(t, fmt.Sprintf("%v", res), "[73656E646572]") + require.Equal(t, fmt.Sprintf("%v", res), "[73656E646572]") } diff --git a/examples/democoin/x/simplestake/keeper_test.go b/examples/democoin/x/simplestake/keeper_test.go index 9cb02afd7d87..be8e335e2b1d 100644 --- a/examples/democoin/x/simplestake/keeper_test.go +++ b/examples/democoin/x/simplestake/keeper_test.go @@ -5,7 +5,6 @@ import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -42,7 +41,7 @@ func TestKeeperGetSet(t *testing.T) { addr := sdk.Address([]byte("some-address")) bi := stakeKeeper.getBondInfo(ctx, addr) - assert.Equal(t, bi, bondInfo{}) + require.Equal(t, bi, bondInfo{}) privKey := crypto.GenPrivKeyEd25519() @@ -54,9 +53,9 @@ func TestKeeperGetSet(t *testing.T) { stakeKeeper.setBondInfo(ctx, addr, bi) savedBi := stakeKeeper.getBondInfo(ctx, addr) - assert.NotNil(t, savedBi) + require.NotNil(t, savedBi) fmt.Printf("Bond Info: %v\n", savedBi) - assert.Equal(t, int64(10), savedBi.Power) + require.Equal(t, int64(10), savedBi.Power) } func TestBonding(t *testing.T) { @@ -74,19 +73,19 @@ func TestBonding(t *testing.T) { pubKey := privKey.PubKey() _, _, err := stakeKeeper.unbondWithoutCoins(ctx, addr) - assert.Equal(t, err, ErrInvalidUnbond(DefaultCodespace)) + require.Equal(t, err, ErrInvalidUnbond(DefaultCodespace)) _, err = stakeKeeper.bondWithoutCoins(ctx, addr, pubKey, sdk.NewCoin("steak", 10)) - assert.Nil(t, err) + require.Nil(t, err) power, err := stakeKeeper.bondWithoutCoins(ctx, addr, pubKey, sdk.NewCoin("steak", 10)) require.Nil(t, err) - assert.Equal(t, int64(20), power) + require.Equal(t, int64(20), power) pk, _, err := stakeKeeper.unbondWithoutCoins(ctx, addr) - assert.Nil(t, err) - assert.Equal(t, pubKey, pk) + require.Nil(t, err) + require.Equal(t, pubKey, pk) _, _, err = stakeKeeper.unbondWithoutCoins(ctx, addr) - assert.Equal(t, err, ErrInvalidUnbond(DefaultCodespace)) + require.Equal(t, err, ErrInvalidUnbond(DefaultCodespace)) } diff --git a/examples/democoin/x/simplestake/msgs_test.go b/examples/democoin/x/simplestake/msgs_test.go index 188a4ec3a8e7..9baf0dd1a95c 100644 --- a/examples/democoin/x/simplestake/msgs_test.go +++ b/examples/democoin/x/simplestake/msgs_test.go @@ -3,7 +3,7 @@ package simplestake import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" @@ -23,9 +23,9 @@ func TestBondMsgValidation(t *testing.T) { for i, tc := range cases { err := tc.msgBond.ValidateBasic() if tc.valid { - assert.Nil(t, err, "%d: %+v", i, err) + require.Nil(t, err, "%d: %+v", i, err) } else { - assert.NotNil(t, err, "%d", i) + require.NotNil(t, err, "%d", i) } } } diff --git a/server/mock/app_test.go b/server/mock/app_test.go index 7c0b70da254f..05ec86521943 100644 --- a/server/mock/app_test.go +++ b/server/mock/app_test.go @@ -3,7 +3,6 @@ package mock import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -38,7 +37,7 @@ func TestInitApp(t *testing.T) { } qres := app.Query(query) require.Equal(t, uint32(0), qres.Code, qres.Log) - assert.Equal(t, []byte("bar"), qres.Value) + require.Equal(t, []byte("bar"), qres.Value) } // TextDeliverTx ensures we can write a tx @@ -74,5 +73,5 @@ func TestDeliverTx(t *testing.T) { } qres := app.Query(query) require.Equal(t, uint32(0), qres.Code, qres.Log) - assert.Equal(t, []byte(value), qres.Value) + require.Equal(t, []byte(value), qres.Value) } diff --git a/server/mock/store_test.go b/server/mock/store_test.go index bd012446678b..bf6a1007b605 100644 --- a/server/mock/store_test.go +++ b/server/mock/store_test.go @@ -3,7 +3,7 @@ package mock import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" dbm "github.com/tendermint/tmlibs/db" @@ -17,17 +17,17 @@ func TestStore(t *testing.T) { key := sdk.NewKVStoreKey("test") cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) err := cms.LoadLatestVersion() - assert.Nil(t, err) + require.Nil(t, err) store := cms.GetKVStore(key) - assert.NotNil(t, store) + require.NotNil(t, store) k := []byte("hello") v := []byte("world") - assert.False(t, store.Has(k)) + require.False(t, store.Has(k)) store.Set(k, v) - assert.True(t, store.Has(k)) - assert.Equal(t, v, store.Get(k)) + require.True(t, store.Has(k)) + require.Equal(t, v, store.Get(k)) store.Delete(k) - assert.False(t, store.Has(k)) + require.False(t, store.Has(k)) } diff --git a/server/util_test.go b/server/util_test.go index 13f8ad5dbc37..8f1ab21dbc6b 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/wire" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -37,5 +36,5 @@ func TestAppendJSON(t *testing.T) { err = cdc.UnmarshalJSON(appended["barOuter"], &resBar) require.NoError(t, err) - assert.Equal(t, bar, resBar, "appended: %v", appended) + require.Equal(t, bar, resBar, "appended: %v", appended) } diff --git a/store/cachekvstore_test.go b/store/cachekvstore_test.go index 0c88ca27d091..f9be76dae3d7 100644 --- a/store/cachekvstore_test.go +++ b/store/cachekvstore_test.go @@ -3,7 +3,6 @@ package store import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" cmn "github.com/tendermint/tmlibs/common" dbm "github.com/tendermint/tmlibs/db" @@ -103,11 +102,11 @@ func TestCacheKVIteratorBounds(t *testing.T) { var i = 0 for ; itr.Valid(); itr.Next() { k, v := itr.Key(), itr.Value() - assert.Equal(t, keyFmt(i), k) - assert.Equal(t, valFmt(i), v) + require.Equal(t, keyFmt(i), k) + require.Equal(t, valFmt(i), v) i++ } - assert.Equal(t, nItems, i) + require.Equal(t, nItems, i) // iterate over none itr = st.Iterator(bz("money"), nil) @@ -115,29 +114,29 @@ func TestCacheKVIteratorBounds(t *testing.T) { for ; itr.Valid(); itr.Next() { i++ } - assert.Equal(t, 0, i) + require.Equal(t, 0, i) // iterate over lower itr = st.Iterator(keyFmt(0), keyFmt(3)) i = 0 for ; itr.Valid(); itr.Next() { k, v := itr.Key(), itr.Value() - assert.Equal(t, keyFmt(i), k) - assert.Equal(t, valFmt(i), v) + require.Equal(t, keyFmt(i), k) + require.Equal(t, valFmt(i), v) i++ } - assert.Equal(t, 3, i) + require.Equal(t, 3, i) // iterate over upper itr = st.Iterator(keyFmt(2), keyFmt(4)) i = 2 for ; itr.Valid(); itr.Next() { k, v := itr.Key(), itr.Value() - assert.Equal(t, keyFmt(i), k) - assert.Equal(t, valFmt(i), v) + require.Equal(t, keyFmt(i), k) + require.Equal(t, valFmt(i), v) i++ } - assert.Equal(t, 4, i) + require.Equal(t, 4, i) } func TestCacheKVMergeIteratorBasics(t *testing.T) { @@ -367,11 +366,11 @@ func assertIterateDomain(t *testing.T, st KVStore, expectedN int) { var i = 0 for ; itr.Valid(); itr.Next() { k, v := itr.Key(), itr.Value() - assert.Equal(t, keyFmt(i), k) - assert.Equal(t, valFmt(i), v) + require.Equal(t, keyFmt(i), k) + require.Equal(t, valFmt(i), v) i++ } - assert.Equal(t, expectedN, i) + require.Equal(t, expectedN, i) } func assertIterateDomainCheck(t *testing.T, st KVStore, mem dbm.DB, r []keyRange) { @@ -383,25 +382,25 @@ func assertIterateDomainCheck(t *testing.T, st KVStore, mem dbm.DB, r []keyRange i := 0 for ; krc.valid(); krc.next() { - assert.True(t, itr.Valid()) - assert.True(t, itr2.Valid()) + require.True(t, itr.Valid()) + require.True(t, itr2.Valid()) // check the key/val matches the ground truth k, v := itr.Key(), itr.Value() k2, v2 := itr2.Key(), itr2.Value() - assert.Equal(t, k, k2) - assert.Equal(t, v, v2) + require.Equal(t, k, k2) + require.Equal(t, v, v2) // check they match the counter - assert.Equal(t, k, keyFmt(krc.key())) + require.Equal(t, k, keyFmt(krc.key())) itr.Next() itr2.Next() i++ } - assert.False(t, itr.Valid()) - assert.False(t, itr2.Valid()) + require.False(t, itr.Valid()) + require.False(t, itr2.Valid()) } func assertIterateDomainCompare(t *testing.T, st KVStore, mem dbm.DB) { @@ -414,15 +413,15 @@ func assertIterateDomainCompare(t *testing.T, st KVStore, mem dbm.DB) { func checkIterators(t *testing.T, itr, itr2 Iterator) { for ; itr.Valid(); itr.Next() { - assert.True(t, itr2.Valid()) + require.True(t, itr2.Valid()) k, v := itr.Key(), itr.Value() k2, v2 := itr2.Key(), itr2.Value() - assert.Equal(t, k, k2) - assert.Equal(t, v, v2) + require.Equal(t, k, k2) + require.Equal(t, v, v2) itr2.Next() } - assert.False(t, itr.Valid()) - assert.False(t, itr2.Valid()) + require.False(t, itr.Valid()) + require.False(t, itr2.Valid()) } //-------------------------------------------------------- diff --git a/store/iavlstore_test.go b/store/iavlstore_test.go index 25e08aefd9e5..b23f04e5cd71 100644 --- a/store/iavlstore_test.go +++ b/store/iavlstore_test.go @@ -3,7 +3,7 @@ package store import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tendermint/iavl" abci "github.com/tendermint/tendermint/abci/types" @@ -38,7 +38,7 @@ func newTree(t *testing.T, db dbm.DB) (*iavl.VersionedTree, CommitID) { tree.Set(key, value) } hash, ver, err := tree.SaveVersion() - assert.Nil(t, err) + require.Nil(t, err) return tree, CommitID{ver, hash} } @@ -50,21 +50,21 @@ func TestIAVLStoreGetSetHasDelete(t *testing.T) { key := "hello" exists := iavlStore.Has([]byte(key)) - assert.True(t, exists) + require.True(t, exists) value := iavlStore.Get([]byte(key)) - assert.EqualValues(t, value, treeData[key]) + require.EqualValues(t, value, treeData[key]) value2 := "notgoodbye" iavlStore.Set([]byte(key), []byte(value2)) value = iavlStore.Get([]byte(key)) - assert.EqualValues(t, value, value2) + require.EqualValues(t, value, value2) iavlStore.Delete([]byte(key)) exists = iavlStore.Has([]byte(key)) - assert.False(t, exists) + require.False(t, exists) } func TestIAVLIterator(t *testing.T) { @@ -78,66 +78,66 @@ func TestIAVLIterator(t *testing.T) { for i = 0; iter.Valid(); iter.Next() { expectedKey := expected[i] key, value := iter.Key(), iter.Value() - assert.EqualValues(t, key, expectedKey) - assert.EqualValues(t, value, treeData[expectedKey]) + require.EqualValues(t, key, expectedKey) + require.EqualValues(t, value, treeData[expectedKey]) i++ } - assert.Equal(t, len(expected), i) + require.Equal(t, len(expected), i) iter = iavlStore.Iterator([]byte("golang"), []byte("rocks")) expected = []string{"hello"} for i = 0; iter.Valid(); iter.Next() { expectedKey := expected[i] key, value := iter.Key(), iter.Value() - assert.EqualValues(t, key, expectedKey) - assert.EqualValues(t, value, treeData[expectedKey]) + require.EqualValues(t, key, expectedKey) + require.EqualValues(t, value, treeData[expectedKey]) i++ } - assert.Equal(t, len(expected), i) + require.Equal(t, len(expected), i) iter = iavlStore.Iterator(nil, []byte("golang")) expected = []string{"aloha"} for i = 0; iter.Valid(); iter.Next() { expectedKey := expected[i] key, value := iter.Key(), iter.Value() - assert.EqualValues(t, key, expectedKey) - assert.EqualValues(t, value, treeData[expectedKey]) + require.EqualValues(t, key, expectedKey) + require.EqualValues(t, value, treeData[expectedKey]) i++ } - assert.Equal(t, len(expected), i) + require.Equal(t, len(expected), i) iter = iavlStore.Iterator(nil, []byte("shalom")) expected = []string{"aloha", "hello"} for i = 0; iter.Valid(); iter.Next() { expectedKey := expected[i] key, value := iter.Key(), iter.Value() - assert.EqualValues(t, key, expectedKey) - assert.EqualValues(t, value, treeData[expectedKey]) + require.EqualValues(t, key, expectedKey) + require.EqualValues(t, value, treeData[expectedKey]) i++ } - assert.Equal(t, len(expected), i) + require.Equal(t, len(expected), i) iter = iavlStore.Iterator(nil, nil) expected = []string{"aloha", "hello"} for i = 0; iter.Valid(); iter.Next() { expectedKey := expected[i] key, value := iter.Key(), iter.Value() - assert.EqualValues(t, key, expectedKey) - assert.EqualValues(t, value, treeData[expectedKey]) + require.EqualValues(t, key, expectedKey) + require.EqualValues(t, value, treeData[expectedKey]) i++ } - assert.Equal(t, len(expected), i) + require.Equal(t, len(expected), i) iter = iavlStore.Iterator([]byte("golang"), nil) expected = []string{"hello"} for i = 0; iter.Valid(); iter.Next() { expectedKey := expected[i] key, value := iter.Key(), iter.Value() - assert.EqualValues(t, key, expectedKey) - assert.EqualValues(t, value, treeData[expectedKey]) + require.EqualValues(t, key, expectedKey) + require.EqualValues(t, value, treeData[expectedKey]) i++ } - assert.Equal(t, len(expected), i) + require.Equal(t, len(expected), i) } func TestIAVLSubspaceIterator(t *testing.T) { @@ -162,11 +162,11 @@ func TestIAVLSubspaceIterator(t *testing.T) { for i = 0; iter.Valid(); iter.Next() { expectedKey := expected[i] key, value := iter.Key(), iter.Value() - assert.EqualValues(t, key, expectedKey) - assert.EqualValues(t, value, expectedKey) + require.EqualValues(t, key, expectedKey) + require.EqualValues(t, value, expectedKey) i++ } - assert.Equal(t, len(expected), i) + require.Equal(t, len(expected), i) iter = sdk.KVStorePrefixIterator(iavlStore, []byte{byte(55), byte(255), byte(255)}) expected2 := [][]byte{ @@ -177,11 +177,11 @@ func TestIAVLSubspaceIterator(t *testing.T) { for i = 0; iter.Valid(); iter.Next() { expectedKey := expected2[i] key, value := iter.Key(), iter.Value() - assert.EqualValues(t, key, expectedKey) - assert.EqualValues(t, value, []byte("test4")) + require.EqualValues(t, key, expectedKey) + require.EqualValues(t, value, []byte("test4")) i++ } - assert.Equal(t, len(expected), i) + require.Equal(t, len(expected), i) iter = sdk.KVStorePrefixIterator(iavlStore, []byte{byte(255), byte(255)}) expected2 = [][]byte{ @@ -192,11 +192,11 @@ func TestIAVLSubspaceIterator(t *testing.T) { for i = 0; iter.Valid(); iter.Next() { expectedKey := expected2[i] key, value := iter.Key(), iter.Value() - assert.EqualValues(t, key, expectedKey) - assert.EqualValues(t, value, []byte("test4")) + require.EqualValues(t, key, expectedKey) + require.EqualValues(t, value, []byte("test4")) i++ } - assert.Equal(t, len(expected), i) + require.Equal(t, len(expected), i) } func TestIAVLReverseSubspaceIterator(t *testing.T) { @@ -221,11 +221,11 @@ func TestIAVLReverseSubspaceIterator(t *testing.T) { for i = 0; iter.Valid(); iter.Next() { expectedKey := expected[i] key, value := iter.Key(), iter.Value() - assert.EqualValues(t, key, expectedKey) - assert.EqualValues(t, value, expectedKey) + require.EqualValues(t, key, expectedKey) + require.EqualValues(t, value, expectedKey) i++ } - assert.Equal(t, len(expected), i) + require.Equal(t, len(expected), i) iter = sdk.KVStoreReversePrefixIterator(iavlStore, []byte{byte(55), byte(255), byte(255)}) expected2 := [][]byte{ @@ -236,11 +236,11 @@ func TestIAVLReverseSubspaceIterator(t *testing.T) { for i = 0; iter.Valid(); iter.Next() { expectedKey := expected2[i] key, value := iter.Key(), iter.Value() - assert.EqualValues(t, key, expectedKey) - assert.EqualValues(t, value, []byte("test4")) + require.EqualValues(t, key, expectedKey) + require.EqualValues(t, value, []byte("test4")) i++ } - assert.Equal(t, len(expected), i) + require.Equal(t, len(expected), i) iter = sdk.KVStoreReversePrefixIterator(iavlStore, []byte{byte(255), byte(255)}) expected2 = [][]byte{ @@ -251,11 +251,11 @@ func TestIAVLReverseSubspaceIterator(t *testing.T) { for i = 0; iter.Valid(); iter.Next() { expectedKey := expected2[i] key, value := iter.Key(), iter.Value() - assert.EqualValues(t, key, expectedKey) - assert.EqualValues(t, value, []byte("test4")) + require.EqualValues(t, key, expectedKey) + require.EqualValues(t, value, []byte("test4")) i++ } - assert.Equal(t, len(expected), i) + require.Equal(t, len(expected), i) } func TestIAVLStoreQuery(t *testing.T) { @@ -288,8 +288,8 @@ func TestIAVLStoreQuery(t *testing.T) { // query subspace before anything set qres := iavlStore.Query(querySub) - assert.Equal(t, uint32(sdk.CodeOK), qres.Code) - assert.Equal(t, valExpSubEmpty, qres.Value) + require.Equal(t, uint32(sdk.CodeOK), qres.Code) + require.Equal(t, valExpSubEmpty, qres.Value) // set data iavlStore.Set(k1, v1) @@ -297,25 +297,25 @@ func TestIAVLStoreQuery(t *testing.T) { // set data without commit, doesn't show up qres = iavlStore.Query(query) - assert.Equal(t, uint32(sdk.CodeOK), qres.Code) - assert.Nil(t, qres.Value) + require.Equal(t, uint32(sdk.CodeOK), qres.Code) + require.Nil(t, qres.Value) // commit it, but still don't see on old version cid = iavlStore.Commit() qres = iavlStore.Query(query) - assert.Equal(t, uint32(sdk.CodeOK), qres.Code) - assert.Nil(t, qres.Value) + require.Equal(t, uint32(sdk.CodeOK), qres.Code) + require.Nil(t, qres.Value) // but yes on the new version query.Height = cid.Version qres = iavlStore.Query(query) - assert.Equal(t, uint32(sdk.CodeOK), qres.Code) - assert.Equal(t, v1, qres.Value) + require.Equal(t, uint32(sdk.CodeOK), qres.Code) + require.Equal(t, v1, qres.Value) // and for the subspace qres = iavlStore.Query(querySub) - assert.Equal(t, uint32(sdk.CodeOK), qres.Code) - assert.Equal(t, valExpSub1, qres.Value) + require.Equal(t, uint32(sdk.CodeOK), qres.Code) + require.Equal(t, valExpSub1, qres.Value) // modify iavlStore.Set(k1, v3) @@ -323,26 +323,26 @@ func TestIAVLStoreQuery(t *testing.T) { // query will return old values, as height is fixed qres = iavlStore.Query(query) - assert.Equal(t, uint32(sdk.CodeOK), qres.Code) - assert.Equal(t, v1, qres.Value) + require.Equal(t, uint32(sdk.CodeOK), qres.Code) + require.Equal(t, v1, qres.Value) // update to latest in the query and we are happy query.Height = cid.Version qres = iavlStore.Query(query) - assert.Equal(t, uint32(sdk.CodeOK), qres.Code) - assert.Equal(t, v3, qres.Value) + require.Equal(t, uint32(sdk.CodeOK), qres.Code) + require.Equal(t, v3, qres.Value) query2 := abci.RequestQuery{Path: "/key", Data: k2, Height: cid.Version} qres = iavlStore.Query(query2) - assert.Equal(t, uint32(sdk.CodeOK), qres.Code) - assert.Equal(t, v2, qres.Value) + require.Equal(t, uint32(sdk.CodeOK), qres.Code) + require.Equal(t, v2, qres.Value) // and for the subspace qres = iavlStore.Query(querySub) - assert.Equal(t, uint32(sdk.CodeOK), qres.Code) - assert.Equal(t, valExpSub2, qres.Value) + require.Equal(t, uint32(sdk.CodeOK), qres.Code) + require.Equal(t, valExpSub2, qres.Value) // default (height 0) will show latest -1 query0 := abci.RequestQuery{Path: "/store", Data: k1} qres = iavlStore.Query(query0) - assert.Equal(t, uint32(sdk.CodeOK), qres.Code) - assert.Equal(t, v1, qres.Value) + require.Equal(t, uint32(sdk.CodeOK), qres.Code) + require.Equal(t, v1, qres.Value) } diff --git a/store/prefixstore_test.go b/store/prefixstore_test.go index d41d1205537e..76fb7f481fdf 100644 --- a/store/prefixstore_test.go +++ b/store/prefixstore_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tendermint/iavl" dbm "github.com/tendermint/tmlibs/db" @@ -96,14 +97,14 @@ func TestPrefixStoreIterate(t *testing.T) { pIter := sdk.KVStorePrefixIterator(prefixStore, nil) for bIter.Valid() && pIter.Valid() { - assert.Equal(t, bIter.Key(), append(prefix, pIter.Key()...)) - assert.Equal(t, bIter.Value(), pIter.Value()) + require.Equal(t, bIter.Key(), append(prefix, pIter.Key()...)) + require.Equal(t, bIter.Value(), pIter.Value()) bIter.Next() pIter.Next() } - assert.Equal(t, bIter.Valid(), pIter.Valid()) + require.Equal(t, bIter.Valid(), pIter.Valid()) bIter.Close() pIter.Close() } diff --git a/store/rootmultistore_test.go b/store/rootmultistore_test.go index 89d40f761cd7..197726f4ac72 100644 --- a/store/rootmultistore_test.go +++ b/store/rootmultistore_test.go @@ -3,7 +3,7 @@ package store import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" dbm "github.com/tendermint/tmlibs/db" "github.com/tendermint/tmlibs/merkle" @@ -20,7 +20,7 @@ func TestMultistoreCommitLoad(t *testing.T) { } store := newMultiStoreWithMounts(db) err := store.LoadLatestVersion() - assert.Nil(t, err) + require.Nil(t, err) // New store has empty last commit. commitID := CommitID{} @@ -28,11 +28,11 @@ func TestMultistoreCommitLoad(t *testing.T) { // Make sure we can get stores by name. s1 := store.getStoreByName("store1") - assert.NotNil(t, s1) + require.NotNil(t, s1) s3 := store.getStoreByName("store3") - assert.NotNil(t, s3) + require.NotNil(t, s3) s77 := store.getStoreByName("store77") - assert.Nil(t, s77) + require.Nil(t, s77) // Make a few commits and check them. nCommits := int64(3) @@ -45,7 +45,7 @@ func TestMultistoreCommitLoad(t *testing.T) { // Load the latest multistore again and check version. store = newMultiStoreWithMounts(db) err = store.LoadLatestVersion() - assert.Nil(t, err) + require.Nil(t, err) commitID = getExpectedCommitID(store, nCommits) checkStore(t, store, commitID, commitID) @@ -58,7 +58,7 @@ func TestMultistoreCommitLoad(t *testing.T) { ver := nCommits - 1 store = newMultiStoreWithMounts(db) err = store.LoadVersion(ver) - assert.Nil(t, err) + require.Nil(t, err) commitID = getExpectedCommitID(store, ver) checkStore(t, store, commitID, commitID) @@ -71,29 +71,29 @@ func TestMultistoreCommitLoad(t *testing.T) { // LatestVersion store = newMultiStoreWithMounts(db) err = store.LoadLatestVersion() - assert.Nil(t, err) + require.Nil(t, err) commitID = getExpectedCommitID(store, ver+1) checkStore(t, store, commitID, commitID) } func TestParsePath(t *testing.T) { _, _, err := parsePath("foo") - assert.Error(t, err) + require.Error(t, err) store, subpath, err := parsePath("/foo") - assert.NoError(t, err) - assert.Equal(t, store, "foo") - assert.Equal(t, subpath, "") + require.NoError(t, err) + require.Equal(t, store, "foo") + require.Equal(t, subpath, "") store, subpath, err = parsePath("/fizz/bang/baz") - assert.NoError(t, err) - assert.Equal(t, store, "fizz") - assert.Equal(t, subpath, "/bang/baz") + require.NoError(t, err) + require.Equal(t, store, "fizz") + require.Equal(t, subpath, "/bang/baz") substore, subsubpath, err := parsePath(subpath) - assert.NoError(t, err) - assert.Equal(t, substore, "bang") - assert.Equal(t, subsubpath, "/baz") + require.NoError(t, err) + require.Equal(t, substore, "bang") + require.Equal(t, subsubpath, "/baz") } @@ -101,7 +101,7 @@ func TestMultiStoreQuery(t *testing.T) { db := dbm.NewMemDB() multi := newMultiStoreWithMounts(db) err := multi.LoadLatestVersion() - assert.Nil(t, err) + require.Nil(t, err) k, v := []byte("wind"), []byte("blows") k2, v2 := []byte("water"), []byte("flows") @@ -111,7 +111,7 @@ func TestMultiStoreQuery(t *testing.T) { // Make sure we can get by name. garbage := multi.getStoreByName("bad-name") - assert.Nil(t, garbage) + require.Nil(t, garbage) // Set and commit data in one store. store1 := multi.getStoreByName("store1").(KVStore) @@ -128,35 +128,35 @@ func TestMultiStoreQuery(t *testing.T) { // Test bad path. query := abci.RequestQuery{Path: "/key", Data: k, Height: ver} qres := multi.Query(query) - assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnknownRequest), sdk.ABCICodeType(qres.Code)) + require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnknownRequest), sdk.ABCICodeType(qres.Code)) query.Path = "h897fy32890rf63296r92" qres = multi.Query(query) - assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnknownRequest), sdk.ABCICodeType(qres.Code)) + require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnknownRequest), sdk.ABCICodeType(qres.Code)) // Test invalid store name. query.Path = "/garbage/key" qres = multi.Query(query) - assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnknownRequest), sdk.ABCICodeType(qres.Code)) + require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnknownRequest), sdk.ABCICodeType(qres.Code)) // Test valid query with data. query.Path = "/store1/key" qres = multi.Query(query) - assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOK), sdk.ABCICodeType(qres.Code)) - assert.Equal(t, v, qres.Value) + require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOK), sdk.ABCICodeType(qres.Code)) + require.Equal(t, v, qres.Value) // Test valid but empty query. query.Path = "/store2/key" query.Prove = true qres = multi.Query(query) - assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOK), sdk.ABCICodeType(qres.Code)) - assert.Nil(t, qres.Value) + require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOK), sdk.ABCICodeType(qres.Code)) + require.Nil(t, qres.Value) // Test store2 data. query.Data = k2 qres = multi.Query(query) - assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOK), sdk.ABCICodeType(qres.Code)) - assert.Equal(t, v2, qres.Value) + require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOK), sdk.ABCICodeType(qres.Code)) + require.Equal(t, v2, qres.Value) } //----------------------------------------------------------------------- @@ -174,8 +174,8 @@ func newMultiStoreWithMounts(db dbm.DB) *rootMultiStore { } func checkStore(t *testing.T, store *rootMultiStore, expect, got CommitID) { - assert.Equal(t, expect, got) - assert.Equal(t, expect, store.LastCommitID()) + require.Equal(t, expect, got) + require.Equal(t, expect, store.LastCommitID()) } diff --git a/types/coin_test.go b/types/coin_test.go index 5f5c82087bf5..c7ccc5746c72 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -4,11 +4,10 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestIsPositiveCoin(t *testing.T) { - assert := assert.New(t) - cases := []struct { inputOne Coin expected bool @@ -20,13 +19,11 @@ func TestIsPositiveCoin(t *testing.T) { for _, tc := range cases { res := tc.inputOne.IsPositive() - assert.Equal(tc.expected, res) + require.Equal(t, tc.expected, res) } } func TestIsNotNegativeCoin(t *testing.T) { - assert := assert.New(t) - cases := []struct { inputOne Coin expected bool @@ -38,13 +35,11 @@ func TestIsNotNegativeCoin(t *testing.T) { for _, tc := range cases { res := tc.inputOne.IsNotNegative() - assert.Equal(tc.expected, res) + require.Equal(t, tc.expected, res) } } func TestSameDenomAsCoin(t *testing.T) { - assert := assert.New(t) - cases := []struct { inputOne Coin inputTwo Coin @@ -59,13 +54,11 @@ func TestSameDenomAsCoin(t *testing.T) { for _, tc := range cases { res := tc.inputOne.SameDenomAs(tc.inputTwo) - assert.Equal(tc.expected, res) + require.Equal(t, tc.expected, res) } } func TestIsGTECoin(t *testing.T) { - assert := assert.New(t) - cases := []struct { inputOne Coin inputTwo Coin @@ -79,13 +72,11 @@ func TestIsGTECoin(t *testing.T) { for _, tc := range cases { res := tc.inputOne.IsGTE(tc.inputTwo) - assert.Equal(tc.expected, res) + require.Equal(t, tc.expected, res) } } func TestIsEqualCoin(t *testing.T) { - assert := assert.New(t) - cases := []struct { inputOne Coin inputTwo Coin @@ -100,13 +91,11 @@ func TestIsEqualCoin(t *testing.T) { for _, tc := range cases { res := tc.inputOne.IsEqual(tc.inputTwo) - assert.Equal(tc.expected, res) + require.Equal(t, tc.expected, res) } } func TestPlusCoin(t *testing.T) { - assert := assert.New(t) - cases := []struct { inputOne Coin inputTwo Coin @@ -119,7 +108,7 @@ func TestPlusCoin(t *testing.T) { for _, tc := range cases { res := tc.inputOne.Plus(tc.inputTwo) - assert.Equal(tc.expected, res) + require.Equal(t, tc.expected, res) } tc := struct { @@ -128,12 +117,10 @@ func TestPlusCoin(t *testing.T) { expected int64 }{NewCoin("asdf", -1), NewCoin("asdf", 1), 0} res := tc.inputOne.Plus(tc.inputTwo) - assert.Equal(tc.expected, res.Amount.Int64()) + require.Equal(t, tc.expected, res.Amount.Int64()) } func TestMinusCoin(t *testing.T) { - assert := assert.New(t) - cases := []struct { inputOne Coin inputTwo Coin @@ -147,7 +134,7 @@ func TestMinusCoin(t *testing.T) { for _, tc := range cases { res := tc.inputOne.Minus(tc.inputTwo) - assert.Equal(tc.expected, res) + require.Equal(t, tc.expected, res) } tc := struct { @@ -156,7 +143,7 @@ func TestMinusCoin(t *testing.T) { expected int64 }{NewCoin("A", 1), NewCoin("A", 1), 0} res := tc.inputOne.Minus(tc.inputTwo) - assert.Equal(tc.expected, res.Amount.Int64()) + require.Equal(t, tc.expected, res.Amount.Int64()) } @@ -208,8 +195,6 @@ func TestCoins(t *testing.T) { } func TestPlusCoins(t *testing.T) { - assert := assert.New(t) - one := NewInt(1) zero := NewInt(0) negone := NewInt(-1) @@ -229,8 +214,8 @@ func TestPlusCoins(t *testing.T) { for _, tc := range cases { res := tc.inputOne.Plus(tc.inputTwo) - assert.True(res.IsValid()) - assert.Equal(tc.expected, res) + assert.True(t, res.IsValid()) + require.Equal(t, tc.expected, res) } } @@ -260,9 +245,9 @@ func TestParse(t *testing.T) { for _, tc := range cases { res, err := ParseCoins(tc.input) if !tc.valid { - assert.NotNil(t, err, "%s: %#v", tc.input, res) + require.NotNil(t, err, "%s: %#v", tc.input, res) } else if assert.Nil(t, err, "%s: %+v", tc.input, err) { - assert.Equal(t, tc.expected, res) + require.Equal(t, tc.expected, res) } } @@ -312,9 +297,9 @@ func TestSortCoins(t *testing.T) { } for _, tc := range cases { - assert.Equal(t, tc.before, tc.coins.IsValid()) + require.Equal(t, tc.before, tc.coins.IsValid()) tc.coins.Sort() - assert.Equal(t, tc.after, tc.coins.IsValid()) + require.Equal(t, tc.after, tc.coins.IsValid()) } } diff --git a/types/context_test.go b/types/context_test.go index e5b31a9a74ba..cad207664013 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -3,7 +3,6 @@ package types_test import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" dbm "github.com/tendermint/tmlibs/db" @@ -72,21 +71,21 @@ func TestCacheContext(t *testing.T) { ctx := defaultContext(key) store := ctx.KVStore(key) store.Set(k1, v1) - assert.Equal(t, v1, store.Get(k1)) - assert.Nil(t, store.Get(k2)) + require.Equal(t, v1, store.Get(k1)) + require.Nil(t, store.Get(k2)) cctx, write := ctx.CacheContext() cstore := cctx.KVStore(key) - assert.Equal(t, v1, cstore.Get(k1)) - assert.Nil(t, cstore.Get(k2)) + require.Equal(t, v1, cstore.Get(k1)) + require.Nil(t, cstore.Get(k2)) cstore.Set(k2, v2) - assert.Equal(t, v2, cstore.Get(k2)) - assert.Nil(t, store.Get(k2)) + require.Equal(t, v2, cstore.Get(k2)) + require.Nil(t, store.Get(k2)) write() - assert.Equal(t, v2, store.Get(k2)) + require.Equal(t, v2, store.Get(k2)) } func TestLogContext(t *testing.T) { diff --git a/types/errors_test.go b/types/errors_test.go index 798eafefcbfa..959f059d00c4 100644 --- a/types/errors_test.go +++ b/types/errors_test.go @@ -4,7 +4,7 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var codeTypes = []CodeType{ @@ -32,11 +32,11 @@ var errFns = []errFn{ } func TestCodeType(t *testing.T) { - assert.True(t, ABCICodeOK.IsOK()) + require.True(t, ABCICodeOK.IsOK()) for _, c := range codeTypes { msg := CodeToDefaultMsg(c) - assert.False(t, strings.HasPrefix(msg, "Unknown code")) + require.False(t, strings.HasPrefix(msg, "Unknown code")) } } @@ -44,7 +44,7 @@ func TestErrFn(t *testing.T) { for i, errFn := range errFns { err := errFn("") codeType := codeTypes[i] - assert.Equal(t, err.Code(), codeType) - assert.Equal(t, err.Result().Code, ToABCICode(CodespaceRoot, codeType)) + require.Equal(t, err.Code(), codeType) + require.Equal(t, err.Result().Code, ToABCICode(CodespaceRoot, codeType)) } } diff --git a/types/int_test.go b/types/int_test.go index 310325133bb6..e81bd6d7ed6a 100644 --- a/types/int_test.go +++ b/types/int_test.go @@ -5,107 +5,107 @@ import ( "math/rand" "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestFromInt64(t *testing.T) { for n := 0; n < 20; n++ { r := rand.Int63() - assert.Equal(t, r, NewInt(r).Int64()) + require.Equal(t, r, NewInt(r).Int64()) } } func TestInt(t *testing.T) { // Max Int = 2^255-1 = 5.789e+76 // Min Int = -(2^255-1) = -5.789e+76 - assert.NotPanics(t, func() { NewIntWithDecimal(1, 76) }) + require.NotPanics(t, func() { NewIntWithDecimal(1, 76) }) i1 := NewIntWithDecimal(1, 76) - assert.NotPanics(t, func() { NewIntWithDecimal(2, 76) }) + require.NotPanics(t, func() { NewIntWithDecimal(2, 76) }) i2 := NewIntWithDecimal(2, 76) - assert.NotPanics(t, func() { NewIntWithDecimal(3, 76) }) + require.NotPanics(t, func() { NewIntWithDecimal(3, 76) }) i3 := NewIntWithDecimal(3, 76) - assert.Panics(t, func() { NewIntWithDecimal(6, 76) }) - assert.Panics(t, func() { NewIntWithDecimal(9, 80) }) + require.Panics(t, func() { NewIntWithDecimal(6, 76) }) + require.Panics(t, func() { NewIntWithDecimal(9, 80) }) // Overflow check - assert.NotPanics(t, func() { i1.Add(i1) }) - assert.NotPanics(t, func() { i2.Add(i2) }) - assert.Panics(t, func() { i3.Add(i3) }) + require.NotPanics(t, func() { i1.Add(i1) }) + require.NotPanics(t, func() { i2.Add(i2) }) + require.Panics(t, func() { i3.Add(i3) }) - assert.NotPanics(t, func() { i1.Sub(i1.Neg()) }) - assert.NotPanics(t, func() { i2.Sub(i2.Neg()) }) - assert.Panics(t, func() { i3.Sub(i3.Neg()) }) + require.NotPanics(t, func() { i1.Sub(i1.Neg()) }) + require.NotPanics(t, func() { i2.Sub(i2.Neg()) }) + require.Panics(t, func() { i3.Sub(i3.Neg()) }) - assert.Panics(t, func() { i1.Mul(i1) }) - assert.Panics(t, func() { i2.Mul(i2) }) - assert.Panics(t, func() { i3.Mul(i3) }) + require.Panics(t, func() { i1.Mul(i1) }) + require.Panics(t, func() { i2.Mul(i2) }) + require.Panics(t, func() { i3.Mul(i3) }) - assert.Panics(t, func() { i1.Neg().Mul(i1.Neg()) }) - assert.Panics(t, func() { i2.Neg().Mul(i2.Neg()) }) - assert.Panics(t, func() { i3.Neg().Mul(i3.Neg()) }) + require.Panics(t, func() { i1.Neg().Mul(i1.Neg()) }) + require.Panics(t, func() { i2.Neg().Mul(i2.Neg()) }) + require.Panics(t, func() { i3.Neg().Mul(i3.Neg()) }) // Underflow check i3n := i3.Neg() - assert.NotPanics(t, func() { i3n.Sub(i1) }) - assert.NotPanics(t, func() { i3n.Sub(i2) }) - assert.Panics(t, func() { i3n.Sub(i3) }) + require.NotPanics(t, func() { i3n.Sub(i1) }) + require.NotPanics(t, func() { i3n.Sub(i2) }) + require.Panics(t, func() { i3n.Sub(i3) }) - assert.NotPanics(t, func() { i3n.Add(i1.Neg()) }) - assert.NotPanics(t, func() { i3n.Add(i2.Neg()) }) - assert.Panics(t, func() { i3n.Add(i3.Neg()) }) + require.NotPanics(t, func() { i3n.Add(i1.Neg()) }) + require.NotPanics(t, func() { i3n.Add(i2.Neg()) }) + require.Panics(t, func() { i3n.Add(i3.Neg()) }) - assert.Panics(t, func() { i1.Mul(i1.Neg()) }) - assert.Panics(t, func() { i2.Mul(i2.Neg()) }) - assert.Panics(t, func() { i3.Mul(i3.Neg()) }) + require.Panics(t, func() { i1.Mul(i1.Neg()) }) + require.Panics(t, func() { i2.Mul(i2.Neg()) }) + require.Panics(t, func() { i3.Mul(i3.Neg()) }) // Bound check intmax := NewIntFromBigInt(new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(255), nil), big.NewInt(1))) intmin := intmax.Neg() - assert.NotPanics(t, func() { intmax.Add(ZeroInt()) }) - assert.NotPanics(t, func() { intmin.Sub(ZeroInt()) }) - assert.Panics(t, func() { intmax.Add(OneInt()) }) - assert.Panics(t, func() { intmin.Sub(OneInt()) }) + require.NotPanics(t, func() { intmax.Add(ZeroInt()) }) + require.NotPanics(t, func() { intmin.Sub(ZeroInt()) }) + require.Panics(t, func() { intmax.Add(OneInt()) }) + require.Panics(t, func() { intmin.Sub(OneInt()) }) // Division-by-zero check - assert.Panics(t, func() { i1.Div(NewInt(0)) }) + require.Panics(t, func() { i1.Div(NewInt(0)) }) } func TestUint(t *testing.T) { // Max Uint = 1.15e+77 // Min Uint = 0 - assert.NotPanics(t, func() { NewUintWithDecimal(5, 76) }) + require.NotPanics(t, func() { NewUintWithDecimal(5, 76) }) i1 := NewUintWithDecimal(5, 76) - assert.NotPanics(t, func() { NewUintWithDecimal(10, 76) }) + require.NotPanics(t, func() { NewUintWithDecimal(10, 76) }) i2 := NewUintWithDecimal(10, 76) - assert.NotPanics(t, func() { NewUintWithDecimal(11, 76) }) + require.NotPanics(t, func() { NewUintWithDecimal(11, 76) }) i3 := NewUintWithDecimal(11, 76) - assert.Panics(t, func() { NewUintWithDecimal(12, 76) }) - assert.Panics(t, func() { NewUintWithDecimal(1, 80) }) + require.Panics(t, func() { NewUintWithDecimal(12, 76) }) + require.Panics(t, func() { NewUintWithDecimal(1, 80) }) // Overflow check - assert.NotPanics(t, func() { i1.Add(i1) }) - assert.Panics(t, func() { i2.Add(i2) }) - assert.Panics(t, func() { i3.Add(i3) }) + require.NotPanics(t, func() { i1.Add(i1) }) + require.Panics(t, func() { i2.Add(i2) }) + require.Panics(t, func() { i3.Add(i3) }) - assert.Panics(t, func() { i1.Mul(i1) }) - assert.Panics(t, func() { i2.Mul(i2) }) - assert.Panics(t, func() { i3.Mul(i3) }) + require.Panics(t, func() { i1.Mul(i1) }) + require.Panics(t, func() { i2.Mul(i2) }) + require.Panics(t, func() { i3.Mul(i3) }) // Underflow check - assert.NotPanics(t, func() { i2.Sub(i1) }) - assert.NotPanics(t, func() { i2.Sub(i2) }) - assert.Panics(t, func() { i2.Sub(i3) }) + require.NotPanics(t, func() { i2.Sub(i1) }) + require.NotPanics(t, func() { i2.Sub(i2) }) + require.Panics(t, func() { i2.Sub(i3) }) // Bound check uintmax := NewUintFromBigInt(new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(256), nil), big.NewInt(1))) uintmin := NewUint(0) - assert.NotPanics(t, func() { uintmax.Add(ZeroUint()) }) - assert.NotPanics(t, func() { uintmin.Sub(ZeroUint()) }) - assert.Panics(t, func() { uintmax.Add(OneUint()) }) - assert.Panics(t, func() { uintmin.Sub(OneUint()) }) + require.NotPanics(t, func() { uintmax.Add(ZeroUint()) }) + require.NotPanics(t, func() { uintmin.Sub(ZeroUint()) }) + require.Panics(t, func() { uintmax.Add(OneUint()) }) + require.Panics(t, func() { uintmin.Sub(OneUint()) }) // Division-by-zero check - assert.Panics(t, func() { i1.Div(uintmin) }) + require.Panics(t, func() { i1.Div(uintmin) }) } diff --git a/types/lib/linear_test.go b/types/lib/linear_test.go index 8ee3276b5a7d..8b5a63fd416e 100644 --- a/types/lib/linear_test.go +++ b/types/lib/linear_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" dbm "github.com/tendermint/tmlibs/db" "github.com/tendermint/tmlibs/log" @@ -41,30 +41,30 @@ func TestList(t *testing.T) { var res S lm.Push(val) - assert.Equal(t, uint64(1), lm.Len()) + require.Equal(t, uint64(1), lm.Len()) lm.Get(uint64(0), &res) - assert.Equal(t, val, res) + require.Equal(t, val, res) val = S{2, false} lm.Set(uint64(0), val) lm.Get(uint64(0), &res) - assert.Equal(t, val, res) + require.Equal(t, val, res) val = S{100, false} lm.Push(val) - assert.Equal(t, uint64(2), lm.Len()) + require.Equal(t, uint64(2), lm.Len()) lm.Get(uint64(1), &res) - assert.Equal(t, val, res) + require.Equal(t, val, res) lm.Delete(uint64(1)) - assert.Equal(t, uint64(2), lm.Len()) + require.Equal(t, uint64(2), lm.Len()) lm.Iterate(&res, func(index uint64) (brk bool) { var temp S lm.Get(index, &temp) - assert.Equal(t, temp, res) + require.Equal(t, temp, res) - assert.True(t, index != 1) + require.True(t, index != 1) return }) @@ -74,7 +74,7 @@ func TestList(t *testing.T) { }) lm.Get(uint64(0), &res) - assert.Equal(t, S{3, true}, res) + require.Equal(t, S{3, true}, res) } func TestQueue(t *testing.T) { @@ -89,13 +89,13 @@ func TestQueue(t *testing.T) { qm.Push(val) qm.Peek(&res) - assert.Equal(t, val, res) + require.Equal(t, val, res) qm.Pop() empty := qm.IsEmpty() - assert.True(t, empty) - assert.NotNil(t, qm.Peek(&res)) + require.True(t, empty) + require.NotNil(t, qm.Peek(&res)) qm.Push(S{1, true}) qm.Push(S{2, true}) @@ -107,10 +107,10 @@ func TestQueue(t *testing.T) { return }) - assert.False(t, qm.IsEmpty()) + require.False(t, qm.IsEmpty()) qm.Pop() - assert.True(t, qm.IsEmpty()) + require.True(t, qm.IsEmpty()) } func TestOptions(t *testing.T) { @@ -136,22 +136,22 @@ func TestOptions(t *testing.T) { // Checking keys.LengthKey err := cdc.UnmarshalBinary(store.Get(keys.LengthKey), &len) - assert.Nil(t, err) - assert.Equal(t, len, linear.Len()) + require.Nil(t, err) + require.Equal(t, len, linear.Len()) // Checking keys.ElemKey for i := 0; i < 10; i++ { linear.Get(uint64(i), &expected) bz := store.Get(append(keys.ElemKey, []byte(fmt.Sprintf("%020d", i))...)) err = cdc.UnmarshalBinary(bz, &actual) - assert.Nil(t, err) - assert.Equal(t, expected, actual) + require.Nil(t, err) + require.Equal(t, expected, actual) } linear.Pop() err = cdc.UnmarshalBinary(store.Get(keys.TopKey), &top) - assert.Nil(t, err) - assert.Equal(t, top, linear.getTop()) + require.Nil(t, err) + require.Equal(t, top, linear.getTop()) } diff --git a/types/rational_test.go b/types/rational_test.go index a137ca498eb4..db875c83e8b5 100644 --- a/types/rational_test.go +++ b/types/rational_test.go @@ -5,19 +5,18 @@ import ( "testing" wire "github.com/cosmos/cosmos-sdk/wire" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestNew(t *testing.T) { - assert.Equal(t, NewRat(1), NewRat(1, 1)) - assert.Equal(t, NewRat(100), NewRat(100, 1)) - assert.Equal(t, NewRat(-1), NewRat(-1, 1)) - assert.Equal(t, NewRat(-100), NewRat(-100, 1)) - assert.Equal(t, NewRat(0), NewRat(0, 1)) + require.Equal(t, NewRat(1), NewRat(1, 1)) + require.Equal(t, NewRat(100), NewRat(100, 1)) + require.Equal(t, NewRat(-1), NewRat(-1, 1)) + require.Equal(t, NewRat(-100), NewRat(-100, 1)) + require.Equal(t, NewRat(0), NewRat(0, 1)) // do not allow for more than 2 variables - assert.Panics(t, func() { NewRat(1, 1, 1) }) + require.Panics(t, func() { NewRat(1, 1, 1) }) } func TestNewFromDecimal(t *testing.T) { @@ -51,7 +50,7 @@ func TestNewFromDecimal(t *testing.T) { for _, tc := range tests { res, err := NewRatFromDecimal(tc.decimalStr, 4) if tc.expErr { - assert.NotNil(t, err, tc.decimalStr) + require.NotNil(t, err, tc.decimalStr) } else { require.Nil(t, err, tc.decimalStr) require.True(t, res.Equal(tc.exp), tc.decimalStr) @@ -60,10 +59,10 @@ func TestNewFromDecimal(t *testing.T) { // negative tc res, err = NewRatFromDecimal("-"+tc.decimalStr, 4) if tc.expErr { - assert.NotNil(t, err, tc.decimalStr) + require.NotNil(t, err, tc.decimalStr) } else { - assert.Nil(t, err, tc.decimalStr) - assert.True(t, res.Equal(tc.exp.Mul(NewRat(-1))), tc.decimalStr) + require.Nil(t, err, tc.decimalStr) + require.True(t, res.Equal(tc.exp.Mul(NewRat(-1))), tc.decimalStr) } } } @@ -100,9 +99,9 @@ func TestEqualities(t *testing.T) { } for _, tc := range tests { - assert.Equal(t, tc.gt, tc.r1.GT(tc.r2)) - assert.Equal(t, tc.lt, tc.r1.LT(tc.r2)) - assert.Equal(t, tc.eq, tc.r1.Equal(tc.r2)) + require.Equal(t, tc.gt, tc.r1.GT(tc.r2)) + require.Equal(t, tc.lt, tc.r1.LT(tc.r2)) + require.Equal(t, tc.eq, tc.r1.Equal(tc.r2)) } } @@ -136,14 +135,14 @@ func TestArithmetic(t *testing.T) { } for _, tc := range tests { - assert.True(t, tc.resMul.Equal(tc.r1.Mul(tc.r2)), "r1 %v, r2 %v", tc.r1.Rat, tc.r2.Rat) - assert.True(t, tc.resAdd.Equal(tc.r1.Add(tc.r2)), "r1 %v, r2 %v", tc.r1.Rat, tc.r2.Rat) - assert.True(t, tc.resSub.Equal(tc.r1.Sub(tc.r2)), "r1 %v, r2 %v", tc.r1.Rat, tc.r2.Rat) + require.True(t, tc.resMul.Equal(tc.r1.Mul(tc.r2)), "r1 %v, r2 %v", tc.r1.Rat, tc.r2.Rat) + require.True(t, tc.resAdd.Equal(tc.r1.Add(tc.r2)), "r1 %v, r2 %v", tc.r1.Rat, tc.r2.Rat) + require.True(t, tc.resSub.Equal(tc.r1.Sub(tc.r2)), "r1 %v, r2 %v", tc.r1.Rat, tc.r2.Rat) if tc.r2.Num().IsZero() { // panic for divide by zero - assert.Panics(t, func() { tc.r1.Quo(tc.r2) }) + require.Panics(t, func() { tc.r1.Quo(tc.r2) }) } else { - assert.True(t, tc.resDiv.Equal(tc.r1.Quo(tc.r2)), "r1 %v, r2 %v", tc.r1.Rat, tc.r2.Rat) + require.True(t, tc.resDiv.Equal(tc.r1.Quo(tc.r2)), "r1 %v, r2 %v", tc.r1.Rat, tc.r2.Rat) } } } @@ -169,8 +168,8 @@ func TestEvaluate(t *testing.T) { } for _, tc := range tests { - assert.Equal(t, tc.res, tc.r1.Evaluate(), "%v", tc.r1) - assert.Equal(t, tc.res*-1, tc.r1.Mul(NewRat(-1)).Evaluate(), "%v", tc.r1.Mul(NewRat(-1))) + require.Equal(t, tc.res, tc.r1.Evaluate(), "%v", tc.r1) + require.Equal(t, tc.res*-1, tc.r1.Mul(NewRat(-1)).Evaluate(), "%v", tc.r1.Mul(NewRat(-1))) } } @@ -193,9 +192,9 @@ func TestRound(t *testing.T) { } for _, tc := range tests { - assert.Equal(t, tc.res, tc.r.Round(tc.precFactor), "%v", tc.r) + require.Equal(t, tc.res, tc.r.Round(tc.precFactor), "%v", tc.r) negR1, negRes := tc.r.Mul(NewRat(-1)), tc.res.Mul(NewRat(-1)) - assert.Equal(t, negRes, negR1.Round(tc.precFactor), "%v", negR1) + require.Equal(t, negRes, negR1.Round(tc.precFactor), "%v", negR1) } } @@ -212,7 +211,7 @@ func TestToLeftPadded(t *testing.T) { {NewRat(1000, 3), 12, "000000000333"}, } for _, tc := range tests { - assert.Equal(t, tc.res, tc.rat.ToLeftPadded(tc.digits)) + require.Equal(t, tc.res, tc.rat.ToLeftPadded(tc.digits)) } } @@ -221,13 +220,13 @@ var cdc = wire.NewCodec() //var jsonCdc JSONCodec // TODO wire.Codec func TestZeroSerializationJSON(t *testing.T) { r := NewRat(0, 1) err := cdc.UnmarshalJSON([]byte(`"0/1"`), &r) - assert.Nil(t, err) + require.Nil(t, err) err = cdc.UnmarshalJSON([]byte(`"0/0"`), &r) - assert.NotNil(t, err) + require.NotNil(t, err) err = cdc.UnmarshalJSON([]byte(`"1/0"`), &r) - assert.NotNil(t, err) + require.NotNil(t, err) err = cdc.UnmarshalJSON([]byte(`"{}"`), &r) - assert.NotNil(t, err) + require.NotNil(t, err) } func TestSerializationText(t *testing.T) { @@ -239,7 +238,7 @@ func TestSerializationText(t *testing.T) { var r2 = Rat{new(big.Rat)} err = r2.UnmarshalText(bz) require.NoError(t, err) - assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2) + require.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2) } func TestSerializationGoWireJSON(t *testing.T) { @@ -250,7 +249,7 @@ func TestSerializationGoWireJSON(t *testing.T) { var r2 Rat err = cdc.UnmarshalJSON(bz, &r2) require.NoError(t, err) - assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2) + require.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2) } func TestSerializationGoWireBinary(t *testing.T) { @@ -261,7 +260,7 @@ func TestSerializationGoWireBinary(t *testing.T) { var r2 Rat err = cdc.UnmarshalBinary(bz, &r2) require.NoError(t, err) - assert.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2) + require.True(t, r.Equal(r2), "original: %v, unmarshalled: %v", r, r2) } type testEmbedStruct struct { @@ -279,9 +278,9 @@ func TestEmbeddedStructSerializationGoWire(t *testing.T) { err = cdc.UnmarshalJSON(bz, &obj2) require.Nil(t, err) - assert.Equal(t, obj.Field1, obj2.Field1) - assert.Equal(t, obj.Field2, obj2.Field2) - assert.True(t, obj.Field3.Equal(obj2.Field3), "original: %v, unmarshalled: %v", obj, obj2) + 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 TestRatsEqual(t *testing.T) { @@ -299,8 +298,8 @@ func TestRatsEqual(t *testing.T) { } for _, tc := range tests { - assert.Equal(t, tc.eq, RatsEqual(tc.r1s, tc.r2s)) - assert.Equal(t, tc.eq, RatsEqual(tc.r2s, tc.r1s)) + require.Equal(t, tc.eq, RatsEqual(tc.r1s, tc.r2s)) + require.Equal(t, tc.eq, RatsEqual(tc.r2s, tc.r1s)) } } @@ -310,7 +309,7 @@ func TestStringOverflow(t *testing.T) { rat1 := NewRat(5164315003622678713, 4389711697696177267) rat2 := NewRat(-3179849666053572961, 8459429845579852627) rat3 := rat1.Add(rat2) - assert.Equal(t, + require.Equal(t, "29728537197630860939575850336935951464/37134458148982045574552091851127630409", rat3.String(), ) diff --git a/types/store_test.go b/types/store_test.go index 43dd1f5d3f52..f376f3be1e61 100644 --- a/types/store_test.go +++ b/types/store_test.go @@ -3,12 +3,10 @@ package types import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestPrefixEndBytes(t *testing.T) { - assert := assert.New(t) - var testCases = []struct { prefix []byte expected []byte @@ -24,6 +22,6 @@ func TestPrefixEndBytes(t *testing.T) { for _, test := range testCases { end := PrefixEndBytes(test.prefix) - assert.Equal(test.expected, end) + require.Equal(t, test.expected, end) } } diff --git a/x/auth/account_test.go b/x/auth/account_test.go index 55cef7cda5aa..bc7a195097a8 100644 --- a/x/auth/account_test.go +++ b/x/auth/account_test.go @@ -3,7 +3,7 @@ package auth import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" @@ -24,31 +24,31 @@ func TestBaseAddressPubKey(t *testing.T) { acc := NewBaseAccountWithAddress(addr1) // check the address (set) and pubkey (not set) - assert.EqualValues(t, addr1, acc.GetAddress()) - assert.EqualValues(t, nil, acc.GetPubKey()) + require.EqualValues(t, addr1, acc.GetAddress()) + require.EqualValues(t, nil, acc.GetPubKey()) // can't override address err := acc.SetAddress(addr2) - assert.NotNil(t, err) - assert.EqualValues(t, addr1, acc.GetAddress()) + require.NotNil(t, err) + require.EqualValues(t, addr1, acc.GetAddress()) // set the pubkey err = acc.SetPubKey(pub1) - assert.Nil(t, err) - assert.Equal(t, pub1, acc.GetPubKey()) + require.Nil(t, err) + require.Equal(t, pub1, acc.GetPubKey()) // can override pubkey err = acc.SetPubKey(pub2) - assert.Nil(t, err) - assert.Equal(t, pub2, acc.GetPubKey()) + require.Nil(t, err) + require.Equal(t, pub2, acc.GetPubKey()) //------------------------------------ // can set address on empty account acc2 := BaseAccount{} err = acc2.SetAddress(addr2) - assert.Nil(t, err) - assert.EqualValues(t, addr2, acc2.GetAddress()) + require.Nil(t, err) + require.EqualValues(t, addr2, acc2.GetAddress()) } func TestBaseAccountCoins(t *testing.T) { @@ -58,8 +58,8 @@ func TestBaseAccountCoins(t *testing.T) { someCoins := sdk.Coins{sdk.NewCoin("atom", 123), sdk.NewCoin("eth", 246)} err := acc.SetCoins(someCoins) - assert.Nil(t, err) - assert.Equal(t, someCoins, acc.GetCoins()) + require.Nil(t, err) + require.Equal(t, someCoins, acc.GetCoins()) } func TestBaseAccountSequence(t *testing.T) { @@ -69,8 +69,8 @@ func TestBaseAccountSequence(t *testing.T) { seq := int64(7) err := acc.SetSequence(seq) - assert.Nil(t, err) - assert.Equal(t, seq, acc.GetSequence()) + require.Nil(t, err) + require.Equal(t, seq, acc.GetSequence()) } func TestBaseAccountMarshal(t *testing.T) { @@ -82,27 +82,27 @@ func TestBaseAccountMarshal(t *testing.T) { // set everything on the account err := acc.SetPubKey(pub) - assert.Nil(t, err) + require.Nil(t, err) err = acc.SetSequence(seq) - assert.Nil(t, err) + require.Nil(t, err) err = acc.SetCoins(someCoins) - assert.Nil(t, err) + require.Nil(t, err) // need a codec for marshaling codec := wire.NewCodec() wire.RegisterCrypto(codec) b, err := codec.MarshalBinary(acc) - assert.Nil(t, err) + require.Nil(t, err) acc2 := BaseAccount{} err = codec.UnmarshalBinary(b, &acc2) - assert.Nil(t, err) - assert.Equal(t, acc, acc2) + require.Nil(t, err) + require.Equal(t, acc, acc2) // error on bad bytes acc2 = BaseAccount{} err = codec.UnmarshalBinary(b[:len(b)/2], &acc2) - assert.NotNil(t, err) + require.NotNil(t, err) } diff --git a/x/auth/ante_test.go b/x/auth/ante_test.go index 2ddb96872eea..1808afc99ccf 100644 --- a/x/auth/ante_test.go +++ b/x/auth/ante_test.go @@ -4,7 +4,6 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" @@ -41,9 +40,9 @@ func privAndAddr() (crypto.PrivKey, sdk.Address) { // run the tx through the anteHandler and ensure its valid func checkValidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx sdk.Tx) { _, result, abort := anteHandler(ctx, tx) - assert.False(t, abort) - assert.Equal(t, sdk.ABCICodeOK, result.Code) - assert.True(t, result.IsOK()) + require.False(t, abort) + require.Equal(t, sdk.ABCICodeOK, result.Code) + require.True(t, result.IsOK()) } // run the tx through the anteHandler and ensure it fails with the given code @@ -52,7 +51,7 @@ func checkInvalidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, if r := recover(); r != nil { switch r.(type) { case sdk.ErrorOutOfGas: - assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, code), sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOutOfGas), + require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, code), sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOutOfGas), fmt.Sprintf("Expected ErrorOutOfGas, got %v", r)) default: panic(r) @@ -60,8 +59,8 @@ func checkInvalidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, } }() _, result, abort := anteHandler(ctx, tx) - assert.True(t, abort) - assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, code), result.Code, + require.True(t, abort) + require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, code), result.Code, fmt.Sprintf("Expected %v, got %v", sdk.ToABCICode(sdk.CodespaceRoot, code), result)) } @@ -138,7 +137,7 @@ func TestAnteHandlerSigErrors(t *testing.T) { // tx.GetSigners returns addresses in correct order: addr1, addr2, addr3 expectedSigners := []sdk.Address{addr1, addr2, addr3} stdTx := tx.(StdTx) - assert.Equal(t, expectedSigners, stdTx.GetSigners()) + require.Equal(t, expectedSigners, stdTx.GetSigners()) // Check no signatures fails checkInvalidTx(t, anteHandler, ctx, tx, sdk.CodeUnauthorized) @@ -330,13 +329,13 @@ func TestAnteHandlerFees(t *testing.T) { mapper.SetAccount(ctx, acc1) checkInvalidTx(t, anteHandler, ctx, tx, sdk.CodeInsufficientFunds) - assert.True(t, feeCollector.GetCollectedFees(ctx).IsEqual(emptyCoins)) + require.True(t, feeCollector.GetCollectedFees(ctx).IsEqual(emptyCoins)) acc1.SetCoins(sdk.Coins{sdk.NewCoin("atom", 150)}) mapper.SetAccount(ctx, acc1) checkValidTx(t, anteHandler, ctx, tx) - assert.True(t, feeCollector.GetCollectedFees(ctx).IsEqual(sdk.Coins{sdk.NewCoin("atom", 150)})) + require.True(t, feeCollector.GetCollectedFees(ctx).IsEqual(sdk.Coins{sdk.NewCoin("atom", 150)})) } // Test logic around memo gas consumption. @@ -559,12 +558,12 @@ func TestAnteHandlerSetPubKey(t *testing.T) { checkInvalidTx(t, anteHandler, ctx, tx, sdk.CodeInvalidPubKey) acc2 = mapper.GetAccount(ctx, addr2) - assert.Nil(t, acc2.GetPubKey()) + require.Nil(t, acc2.GetPubKey()) // test invalid signature and public key tx = newTestTx(ctx, msgs, privs, []int64{1}, seqs, fee) checkInvalidTx(t, anteHandler, ctx, tx, sdk.CodeInvalidPubKey) acc2 = mapper.GetAccount(ctx, addr2) - assert.Nil(t, acc2.GetPubKey()) + require.Nil(t, acc2.GetPubKey()) } diff --git a/x/auth/context_test.go b/x/auth/context_test.go index 53ff7b1db661..5f432be35720 100644 --- a/x/auth/context_test.go +++ b/x/auth/context_test.go @@ -3,7 +3,7 @@ package auth import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tmlibs/log" @@ -24,17 +24,17 @@ func TestContextWithSigners(t *testing.T) { // new ctx has no signers signers := GetSigners(ctx) - assert.Equal(t, 0, len(signers)) + require.Equal(t, 0, len(signers)) ctx2 := WithSigners(ctx, []Account{&acc1, &acc2}) // original context is unchanged signers = GetSigners(ctx) - assert.Equal(t, 0, len(signers)) + require.Equal(t, 0, len(signers)) // new context has signers signers = GetSigners(ctx2) - assert.Equal(t, 2, len(signers)) - assert.Equal(t, acc1, *(signers[0].(*BaseAccount))) - assert.Equal(t, acc2, *(signers[1].(*BaseAccount))) + require.Equal(t, 2, len(signers)) + require.Equal(t, acc1, *(signers[0].(*BaseAccount))) + require.Equal(t, acc2, *(signers[1].(*BaseAccount))) } diff --git a/x/auth/feekeeper_test.go b/x/auth/feekeeper_test.go index a6ce8e3e5ad3..e935bb4c49b2 100644 --- a/x/auth/feekeeper_test.go +++ b/x/auth/feekeeper_test.go @@ -3,7 +3,7 @@ package auth import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tmlibs/log" @@ -28,13 +28,13 @@ func TestFeeCollectionKeeperGetSet(t *testing.T) { // no coins initially currFees := fck.GetCollectedFees(ctx) - assert.True(t, currFees.IsEqual(emptyCoins)) + require.True(t, currFees.IsEqual(emptyCoins)) // set feeCollection to oneCoin fck.setCollectedFees(ctx, oneCoin) // check that it is equal to oneCoin - assert.True(t, fck.GetCollectedFees(ctx).IsEqual(oneCoin)) + require.True(t, fck.GetCollectedFees(ctx).IsEqual(oneCoin)) } func TestFeeCollectionKeeperAdd(t *testing.T) { @@ -46,15 +46,15 @@ func TestFeeCollectionKeeperAdd(t *testing.T) { fck := NewFeeCollectionKeeper(cdc, capKey2) // no coins initially - assert.True(t, fck.GetCollectedFees(ctx).IsEqual(emptyCoins)) + require.True(t, fck.GetCollectedFees(ctx).IsEqual(emptyCoins)) // add oneCoin and check that pool is now oneCoin fck.addCollectedFees(ctx, oneCoin) - assert.True(t, fck.GetCollectedFees(ctx).IsEqual(oneCoin)) + require.True(t, fck.GetCollectedFees(ctx).IsEqual(oneCoin)) // add oneCoin again and check that pool is now twoCoins fck.addCollectedFees(ctx, oneCoin) - assert.True(t, fck.GetCollectedFees(ctx).IsEqual(twoCoins)) + require.True(t, fck.GetCollectedFees(ctx).IsEqual(twoCoins)) } func TestFeeCollectionKeeperClear(t *testing.T) { @@ -67,9 +67,9 @@ func TestFeeCollectionKeeperClear(t *testing.T) { // set coins initially fck.setCollectedFees(ctx, twoCoins) - assert.True(t, fck.GetCollectedFees(ctx).IsEqual(twoCoins)) + require.True(t, fck.GetCollectedFees(ctx).IsEqual(twoCoins)) // clear fees and see that pool is now empty fck.ClearCollectedFees(ctx) - assert.True(t, fck.GetCollectedFees(ctx).IsEqual(emptyCoins)) + require.True(t, fck.GetCollectedFees(ctx).IsEqual(emptyCoins)) } diff --git a/x/auth/mapper_test.go b/x/auth/mapper_test.go index a5f96d5e90f2..4b270f0225ca 100644 --- a/x/auth/mapper_test.go +++ b/x/auth/mapper_test.go @@ -3,7 +3,7 @@ package auth import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" dbm "github.com/tendermint/tmlibs/db" @@ -38,17 +38,17 @@ func TestAccountMapperGetSet(t *testing.T) { // no account before its created acc := mapper.GetAccount(ctx, addr) - assert.Nil(t, acc) + require.Nil(t, acc) // create account and check default values acc = mapper.NewAccountWithAddress(ctx, addr) - assert.NotNil(t, acc) - assert.Equal(t, addr, acc.GetAddress()) - assert.EqualValues(t, nil, acc.GetPubKey()) - assert.EqualValues(t, 0, acc.GetSequence()) + require.NotNil(t, acc) + require.Equal(t, addr, acc.GetAddress()) + require.EqualValues(t, nil, acc.GetPubKey()) + require.EqualValues(t, 0, acc.GetSequence()) // NewAccount doesn't call Set, so it's still nil - assert.Nil(t, mapper.GetAccount(ctx, addr)) + require.Nil(t, mapper.GetAccount(ctx, addr)) // set some values on the account and save it newSequence := int64(20) @@ -57,6 +57,6 @@ func TestAccountMapperGetSet(t *testing.T) { // check the new values acc = mapper.GetAccount(ctx, addr) - assert.NotNil(t, acc) - assert.Equal(t, newSequence, acc.GetSequence()) + require.NotNil(t, acc) + require.Equal(t, newSequence, acc.GetSequence()) } diff --git a/x/auth/mock/auth_app_test.go b/x/auth/mock/auth_app_test.go index 0a7a03534d87..3f340bbf906e 100644 --- a/x/auth/mock/auth_app_test.go +++ b/x/auth/mock/auth_app_test.go @@ -3,7 +3,6 @@ package mock import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" @@ -75,7 +74,7 @@ func TestMsgPrivKeys(t *testing.T) { // A checkTx context (true) ctxCheck := mapp.BaseApp.NewContext(true, abci.Header{}) res1 := mapp.AccountMapper.GetAccount(ctxCheck, addr1) - assert.Equal(t, acc1, res1.(*auth.BaseAccount)) + require.Equal(t, acc1, res1.(*auth.BaseAccount)) // Run a CheckDeliver SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{testMsg1}, []int64{0}, []int64{0}, true, priv1) @@ -84,10 +83,10 @@ func TestMsgPrivKeys(t *testing.T) { mapp.BeginBlock(abci.RequestBeginBlock{}) tx := GenTx([]sdk.Msg{testMsg1}, []int64{0}, []int64{1}, priv2) res := mapp.Deliver(tx) - assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnauthorized), res.Code, res.Log) + require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnauthorized), res.Code, res.Log) // resigning the tx with the correct priv key should still work res = SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{testMsg1}, []int64{0}, []int64{1}, true, priv1) - assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOK), res.Code, res.Log) + require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeOK), res.Code, res.Log) } diff --git a/x/auth/mock/simulate_block.go b/x/auth/mock/simulate_block.go index a047fbf4b605..f85fdf1803ef 100644 --- a/x/auth/mock/simulate_block.go +++ b/x/auth/mock/simulate_block.go @@ -6,7 +6,6 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" @@ -29,7 +28,7 @@ func SetGenesis(app *App, accs []auth.Account) { func CheckBalance(t *testing.T, app *App, addr sdk.Address, exp sdk.Coins) { ctxCheck := app.BaseApp.NewContext(true, abci.Header{}) res := app.AccountMapper.GetAccount(ctxCheck, addr) - assert.Equal(t, exp, res.GetCoins()) + require.Equal(t, exp, res.GetCoins()) } // generate a signed transaction diff --git a/x/auth/stdtx_test.go b/x/auth/stdtx_test.go index 43712e5a5ea6..533596431a13 100644 --- a/x/auth/stdtx_test.go +++ b/x/auth/stdtx_test.go @@ -3,7 +3,7 @@ package auth import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" @@ -24,9 +24,9 @@ func TestStdTx(t *testing.T) { sigs := []StdSignature{} tx := NewStdTx(msgs, fee, sigs, "") - assert.Equal(t, msgs, tx.GetMsgs()) - assert.Equal(t, sigs, tx.GetSignatures()) + require.Equal(t, msgs, tx.GetMsgs()) + require.Equal(t, sigs, tx.GetSignatures()) feePayer := FeePayer(tx) - assert.Equal(t, addr, feePayer) + require.Equal(t, addr, feePayer) } diff --git a/x/bank/app_test.go b/x/bank/app_test.go index 2d6efc3ca1f3..72ea312a9aea 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -3,7 +3,6 @@ package bank import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" @@ -112,7 +111,7 @@ func TestMsgSendWithAccounts(t *testing.T) { ctxCheck := mapp.BaseApp.NewContext(true, abci.Header{}) res1 := mapp.AccountMapper.GetAccount(ctxCheck, addr1) require.NotNil(t, res1) - assert.Equal(t, acc, res1.(*auth.BaseAccount)) + require.Equal(t, acc, res1.(*auth.BaseAccount)) // Run a CheckDeliver mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{sendMsg1}, []int64{0}, []int64{0}, true, priv1) @@ -130,7 +129,7 @@ func TestMsgSendWithAccounts(t *testing.T) { tx.Signatures[0].Sequence = 1 res := mapp.Deliver(tx) - assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnauthorized), res.Code, res.Log) + require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnauthorized), res.Code, res.Log) // resigning the tx with the bumped sequence should work mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{sendMsg1, sendMsg2}, []int64{0}, []int64{1}, true, priv1) diff --git a/x/bank/keeper_test.go b/x/bank/keeper_test.go index 2eae4e815c66..b35298be9d97 100644 --- a/x/bank/keeper_test.go +++ b/x/bank/keeper_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" dbm "github.com/tendermint/tmlibs/db" @@ -42,57 +43,57 @@ func TestKeeper(t *testing.T) { // Test GetCoins/SetCoins accountMapper.SetAccount(ctx, acc) - assert.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{})) + require.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{})) coinKeeper.SetCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 10)}) - assert.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 10)})) + require.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 10)})) // Test HasCoins - assert.True(t, coinKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 10)})) - assert.True(t, coinKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 5)})) - assert.False(t, coinKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 15)})) - assert.False(t, coinKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("barcoin", 5)})) + require.True(t, coinKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 10)})) + require.True(t, coinKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 5)})) + require.False(t, coinKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 15)})) + require.False(t, coinKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("barcoin", 5)})) // Test AddCoins coinKeeper.AddCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 15)}) - assert.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 25)})) + require.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 25)})) coinKeeper.AddCoins(ctx, addr, sdk.Coins{sdk.NewCoin("barcoin", 15)}) - assert.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 15), sdk.NewCoin("foocoin", 25)})) + require.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 15), sdk.NewCoin("foocoin", 25)})) // Test SubtractCoins coinKeeper.SubtractCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 10)}) coinKeeper.SubtractCoins(ctx, addr, sdk.Coins{sdk.NewCoin("barcoin", 5)}) - assert.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 10), sdk.NewCoin("foocoin", 15)})) + require.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 10), sdk.NewCoin("foocoin", 15)})) coinKeeper.SubtractCoins(ctx, addr, sdk.Coins{sdk.NewCoin("barcoin", 11)}) - assert.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 10), sdk.NewCoin("foocoin", 15)})) + require.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 10), sdk.NewCoin("foocoin", 15)})) coinKeeper.SubtractCoins(ctx, addr, sdk.Coins{sdk.NewCoin("barcoin", 10)}) - assert.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 15)})) - assert.False(t, coinKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("barcoin", 1)})) + require.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 15)})) + require.False(t, coinKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("barcoin", 1)})) // Test SendCoins coinKeeper.SendCoins(ctx, addr, addr2, sdk.Coins{sdk.NewCoin("foocoin", 5)}) - assert.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 10)})) - assert.True(t, coinKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 5)})) + require.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 10)})) + require.True(t, coinKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 5)})) _, err2 := coinKeeper.SendCoins(ctx, addr, addr2, sdk.Coins{sdk.NewCoin("foocoin", 50)}) assert.Implements(t, (*sdk.Error)(nil), err2) - assert.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 10)})) - assert.True(t, coinKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 5)})) + require.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 10)})) + require.True(t, coinKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 5)})) coinKeeper.AddCoins(ctx, addr, sdk.Coins{sdk.NewCoin("barcoin", 30)}) coinKeeper.SendCoins(ctx, addr, addr2, sdk.Coins{sdk.NewCoin("barcoin", 10), sdk.NewCoin("foocoin", 5)}) - assert.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 20), sdk.NewCoin("foocoin", 5)})) - assert.True(t, coinKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 10), sdk.NewCoin("foocoin", 10)})) + require.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 20), sdk.NewCoin("foocoin", 5)})) + require.True(t, coinKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 10), sdk.NewCoin("foocoin", 10)})) // Test InputOutputCoins input1 := NewInput(addr2, sdk.Coins{sdk.NewCoin("foocoin", 2)}) output1 := NewOutput(addr, sdk.Coins{sdk.NewCoin("foocoin", 2)}) coinKeeper.InputOutputCoins(ctx, []Input{input1}, []Output{output1}) - assert.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 20), sdk.NewCoin("foocoin", 7)})) - assert.True(t, coinKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 10), sdk.NewCoin("foocoin", 8)})) + require.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 20), sdk.NewCoin("foocoin", 7)})) + require.True(t, coinKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 10), sdk.NewCoin("foocoin", 8)})) inputs := []Input{ NewInput(addr, sdk.Coins{sdk.NewCoin("foocoin", 3)}), @@ -104,9 +105,9 @@ func TestKeeper(t *testing.T) { NewOutput(addr3, sdk.Coins{sdk.NewCoin("barcoin", 2), sdk.NewCoin("foocoin", 5)}), } coinKeeper.InputOutputCoins(ctx, inputs, outputs) - assert.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 21), sdk.NewCoin("foocoin", 4)})) - assert.True(t, coinKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 7), sdk.NewCoin("foocoin", 6)})) - assert.True(t, coinKeeper.GetCoins(ctx, addr3).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 2), sdk.NewCoin("foocoin", 5)})) + require.True(t, coinKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 21), sdk.NewCoin("foocoin", 4)})) + require.True(t, coinKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 7), sdk.NewCoin("foocoin", 6)})) + require.True(t, coinKeeper.GetCoins(ctx, addr3).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 2), sdk.NewCoin("foocoin", 5)})) } @@ -128,40 +129,40 @@ func TestSendKeeper(t *testing.T) { // Test GetCoins/SetCoins accountMapper.SetAccount(ctx, acc) - assert.True(t, sendKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{})) + require.True(t, sendKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{})) coinKeeper.SetCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 10)}) - assert.True(t, sendKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 10)})) + require.True(t, sendKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 10)})) // Test HasCoins - assert.True(t, sendKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 10)})) - assert.True(t, sendKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 5)})) - assert.False(t, sendKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 15)})) - assert.False(t, sendKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("barcoin", 5)})) + require.True(t, sendKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 10)})) + require.True(t, sendKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 5)})) + require.False(t, sendKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 15)})) + require.False(t, sendKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("barcoin", 5)})) coinKeeper.SetCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 15)}) // Test SendCoins sendKeeper.SendCoins(ctx, addr, addr2, sdk.Coins{sdk.NewCoin("foocoin", 5)}) - assert.True(t, sendKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 10)})) - assert.True(t, sendKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 5)})) + require.True(t, sendKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 10)})) + require.True(t, sendKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 5)})) _, err2 := sendKeeper.SendCoins(ctx, addr, addr2, sdk.Coins{sdk.NewCoin("foocoin", 50)}) assert.Implements(t, (*sdk.Error)(nil), err2) - assert.True(t, sendKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 10)})) - assert.True(t, sendKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 5)})) + require.True(t, sendKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 10)})) + require.True(t, sendKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 5)})) coinKeeper.AddCoins(ctx, addr, sdk.Coins{sdk.NewCoin("barcoin", 30)}) sendKeeper.SendCoins(ctx, addr, addr2, sdk.Coins{sdk.NewCoin("barcoin", 10), sdk.NewCoin("foocoin", 5)}) - assert.True(t, sendKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 20), sdk.NewCoin("foocoin", 5)})) - assert.True(t, sendKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 10), sdk.NewCoin("foocoin", 10)})) + require.True(t, sendKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 20), sdk.NewCoin("foocoin", 5)})) + require.True(t, sendKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 10), sdk.NewCoin("foocoin", 10)})) // Test InputOutputCoins input1 := NewInput(addr2, sdk.Coins{sdk.NewCoin("foocoin", 2)}) output1 := NewOutput(addr, sdk.Coins{sdk.NewCoin("foocoin", 2)}) sendKeeper.InputOutputCoins(ctx, []Input{input1}, []Output{output1}) - assert.True(t, sendKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 20), sdk.NewCoin("foocoin", 7)})) - assert.True(t, sendKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 10), sdk.NewCoin("foocoin", 8)})) + require.True(t, sendKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 20), sdk.NewCoin("foocoin", 7)})) + require.True(t, sendKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 10), sdk.NewCoin("foocoin", 8)})) inputs := []Input{ NewInput(addr, sdk.Coins{sdk.NewCoin("foocoin", 3)}), @@ -173,9 +174,9 @@ func TestSendKeeper(t *testing.T) { NewOutput(addr3, sdk.Coins{sdk.NewCoin("barcoin", 2), sdk.NewCoin("foocoin", 5)}), } sendKeeper.InputOutputCoins(ctx, inputs, outputs) - assert.True(t, sendKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 21), sdk.NewCoin("foocoin", 4)})) - assert.True(t, sendKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 7), sdk.NewCoin("foocoin", 6)})) - assert.True(t, sendKeeper.GetCoins(ctx, addr3).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 2), sdk.NewCoin("foocoin", 5)})) + require.True(t, sendKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 21), sdk.NewCoin("foocoin", 4)})) + require.True(t, sendKeeper.GetCoins(ctx, addr2).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 7), sdk.NewCoin("foocoin", 6)})) + require.True(t, sendKeeper.GetCoins(ctx, addr3).IsEqual(sdk.Coins{sdk.NewCoin("barcoin", 2), sdk.NewCoin("foocoin", 5)})) } @@ -195,14 +196,14 @@ func TestViewKeeper(t *testing.T) { // Test GetCoins/SetCoins accountMapper.SetAccount(ctx, acc) - assert.True(t, viewKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{})) + require.True(t, viewKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{})) coinKeeper.SetCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 10)}) - assert.True(t, viewKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 10)})) + require.True(t, viewKeeper.GetCoins(ctx, addr).IsEqual(sdk.Coins{sdk.NewCoin("foocoin", 10)})) // Test HasCoins - assert.True(t, viewKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 10)})) - assert.True(t, viewKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 5)})) - assert.False(t, viewKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 15)})) - assert.False(t, viewKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("barcoin", 5)})) + require.True(t, viewKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 10)})) + require.True(t, viewKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 5)})) + require.False(t, viewKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("foocoin", 15)})) + require.False(t, viewKeeper.HasCoins(ctx, addr, sdk.Coins{sdk.NewCoin("barcoin", 5)})) } diff --git a/x/bank/msgs_test.go b/x/bank/msgs_test.go index 350a51d7aab0..3754858ec70e 100644 --- a/x/bank/msgs_test.go +++ b/x/bank/msgs_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -22,7 +22,7 @@ func TestMsgSendType(t *testing.T) { } // TODO some failures for bad result - assert.Equal(t, msg.Type(), "bank") + require.Equal(t, msg.Type(), "bank") } func TestInputValidation(t *testing.T) { @@ -60,9 +60,9 @@ func TestInputValidation(t *testing.T) { for i, tc := range cases { err := tc.txIn.ValidateBasic() if tc.valid { - assert.Nil(t, err, "%d: %+v", i, err) + require.Nil(t, err, "%d: %+v", i, err) } else { - assert.NotNil(t, err, "%d", i) + require.NotNil(t, err, "%d", i) } } } @@ -102,9 +102,9 @@ func TestOutputValidation(t *testing.T) { for i, tc := range cases { err := tc.txOut.ValidateBasic() if tc.valid { - assert.Nil(t, err, "%d: %+v", i, err) + require.Nil(t, err, "%d: %+v", i, err) } else { - assert.NotNil(t, err, "%d", i) + require.NotNil(t, err, "%d", i) } } } @@ -170,9 +170,9 @@ func TestMsgSendValidation(t *testing.T) { for i, tc := range cases { err := tc.tx.ValidateBasic() if tc.valid { - assert.Nil(t, err, "%d: %+v", i, err) + require.Nil(t, err, "%d: %+v", i, err) } else { - assert.NotNil(t, err, "%d", i) + require.NotNil(t, err, "%d", i) } } } @@ -188,7 +188,7 @@ func TestMsgSendGetSignBytes(t *testing.T) { res := msg.GetSignBytes() expected := `{"inputs":[{"address":"cosmosaccaddr1d9h8qat5e4ehc5","coins":[{"denom":"atom","amount":"10"}]}],"outputs":[{"address":"cosmosaccaddr1da6hgur4wse3jx32","coins":[{"denom":"atom","amount":"10"}]}]}` - assert.Equal(t, expected, string(res)) + require.Equal(t, expected, string(res)) } func TestMsgSendGetSigners(t *testing.T) { @@ -201,7 +201,7 @@ func TestMsgSendGetSigners(t *testing.T) { } res := msg.GetSigners() // TODO: fix this ! - assert.Equal(t, fmt.Sprintf("%v", res), "[696E70757431 696E70757432 696E70757433]") + require.Equal(t, fmt.Sprintf("%v", res), "[696E70757431 696E70757432 696E70757433]") } /* @@ -220,7 +220,7 @@ func TestMsgSendSigners(t *testing.T) { } tx := NewMsgSend(inputs, nil) - assert.Equal(t, signers, tx.Signers()) + require.Equal(t, signers, tx.Signers()) } */ @@ -241,7 +241,7 @@ func TestMsgIssueType(t *testing.T) { } // TODO some failures for bad result - assert.Equal(t, msg.Type(), "bank") + require.Equal(t, msg.Type(), "bank") } func TestMsgIssueValidation(t *testing.T) { @@ -258,7 +258,7 @@ func TestMsgIssueGetSignBytes(t *testing.T) { res := msg.GetSignBytes() expected := `{"banker":"cosmosaccaddr1d9h8qat5e4ehc5","outputs":[{"address":"cosmosaccaddr1d3hkzm3dveex7mfdvfsku6cwsauqd","coins":[{"denom":"atom","amount":"10"}]}]}` - assert.Equal(t, expected, string(res)) + require.Equal(t, expected, string(res)) } func TestMsgIssueGetSigners(t *testing.T) { @@ -266,5 +266,5 @@ func TestMsgIssueGetSigners(t *testing.T) { Banker: sdk.Address([]byte("onlyone")), } res := msg.GetSigners() - assert.Equal(t, fmt.Sprintf("%v", res), "[6F6E6C796F6E65]") + require.Equal(t, fmt.Sprintf("%v", res), "[6F6E6C796F6E65]") } diff --git a/x/fee_distribution/keeper_test.go b/x/fee_distribution/keeper_test.go index 4ad8180e1784..0d732f8a1917 100644 --- a/x/fee_distribution/keeper_test.go +++ b/x/fee_distribution/keeper_test.go @@ -15,11 +15,11 @@ package stake //// test that an empty gotValidator set doesn't have any gotValidators //gotValidators := keeper.GetValidators(ctx) -//assert.Equal(t, 5, len(gotValidators)) +//require.Equal(t, 5, len(gotValidators)) //totPow := keeper.GetTotalPrecommitVotingPower(ctx) //exp := sdk.NewRat(11111) -//assert.True(t, exp.Equal(totPow), "exp %v, got %v", exp, totPow) +//require.True(t, exp.Equal(totPow), "exp %v, got %v", exp, totPow) //// set absent gotValidators to be the 1st and 3rd record sorted by pubKey address //ctx = ctx.WithAbsentValidators([]int32{1, 3}) @@ -27,5 +27,5 @@ package stake //// XXX verify that this order should infact exclude these two records //exp = sdk.NewRat(11100) -//assert.True(t, exp.Equal(totPow), "exp %v, got %v", exp, totPow) +//require.True(t, exp.Equal(totPow), "exp %v, got %v", exp, totPow) //} diff --git a/x/gov/endblocker_test.go b/x/gov/endblocker_test.go index 4aeac9417ec0..0070bb5777d1 100644 --- a/x/gov/endblocker_test.go +++ b/x/gov/endblocker_test.go @@ -3,7 +3,7 @@ package gov import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" @@ -15,29 +15,29 @@ func TestTickExpiredDepositPeriod(t *testing.T) { ctx := mapp.BaseApp.NewContext(false, abci.Header{}) govHandler := NewHandler(keeper) - assert.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) newProposalMsg := NewMsgSubmitProposal("Test", "test", ProposalTypeText, addrs[0], sdk.Coins{sdk.NewCoin("steak", 5)}) res := govHandler(ctx, newProposalMsg) - assert.True(t, res.IsOK()) + require.True(t, res.IsOK()) EndBlocker(ctx, keeper) - assert.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) ctx = ctx.WithBlockHeight(10) EndBlocker(ctx, keeper) - assert.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) ctx = ctx.WithBlockHeight(250) - assert.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.True(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.True(t, shouldPopInactiveProposalQueue(ctx, keeper)) EndBlocker(ctx, keeper) - assert.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) } func TestTickMultipleExpiredDepositPeriod(t *testing.T) { @@ -46,40 +46,40 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) { ctx := mapp.BaseApp.NewContext(false, abci.Header{}) govHandler := NewHandler(keeper) - assert.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) newProposalMsg := NewMsgSubmitProposal("Test", "test", ProposalTypeText, addrs[0], sdk.Coins{sdk.NewCoin("steak", 5)}) res := govHandler(ctx, newProposalMsg) - assert.True(t, res.IsOK()) + require.True(t, res.IsOK()) EndBlocker(ctx, keeper) - assert.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) ctx = ctx.WithBlockHeight(10) EndBlocker(ctx, keeper) - assert.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) newProposalMsg2 := NewMsgSubmitProposal("Test2", "test2", ProposalTypeText, addrs[1], sdk.Coins{sdk.NewCoin("steak", 5)}) res = govHandler(ctx, newProposalMsg2) - assert.True(t, res.IsOK()) + require.True(t, res.IsOK()) ctx = ctx.WithBlockHeight(205) - assert.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.True(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.True(t, shouldPopInactiveProposalQueue(ctx, keeper)) EndBlocker(ctx, keeper) - assert.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) ctx = ctx.WithBlockHeight(215) - assert.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.True(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.True(t, shouldPopInactiveProposalQueue(ctx, keeper)) EndBlocker(ctx, keeper) - assert.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) } func TestTickPassedDepositPeriod(t *testing.T) { @@ -88,41 +88,41 @@ func TestTickPassedDepositPeriod(t *testing.T) { ctx := mapp.BaseApp.NewContext(false, abci.Header{}) govHandler := NewHandler(keeper) - assert.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) - assert.Nil(t, keeper.ActiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopActiveProposalQueue(ctx, keeper)) + require.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.Nil(t, keeper.ActiveProposalQueuePeek(ctx)) + require.False(t, shouldPopActiveProposalQueue(ctx, keeper)) newProposalMsg := NewMsgSubmitProposal("Test", "test", ProposalTypeText, addrs[0], sdk.Coins{sdk.NewCoin("steak", 5)}) res := govHandler(ctx, newProposalMsg) - assert.True(t, res.IsOK()) + require.True(t, res.IsOK()) var proposalID int64 keeper.cdc.UnmarshalBinaryBare(res.Data, &proposalID) EndBlocker(ctx, keeper) - assert.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) ctx = ctx.WithBlockHeight(10) EndBlocker(ctx, keeper) - assert.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) newDepositMsg := NewMsgDeposit(addrs[1], proposalID, sdk.Coins{sdk.NewCoin("steak", 5)}) res = govHandler(ctx, newDepositMsg) - assert.True(t, res.IsOK()) + require.True(t, res.IsOK()) - assert.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.True(t, shouldPopInactiveProposalQueue(ctx, keeper)) - assert.NotNil(t, keeper.ActiveProposalQueuePeek(ctx)) + require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.True(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.NotNil(t, keeper.ActiveProposalQueuePeek(ctx)) EndBlocker(ctx, keeper) - assert.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) - assert.NotNil(t, keeper.ActiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopActiveProposalQueue(ctx, keeper)) + require.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.NotNil(t, keeper.ActiveProposalQueuePeek(ctx)) + require.False(t, shouldPopActiveProposalQueue(ctx, keeper)) } func TestTickPassedVotingPeriod(t *testing.T) { @@ -132,37 +132,37 @@ func TestTickPassedVotingPeriod(t *testing.T) { ctx := mapp.BaseApp.NewContext(false, abci.Header{}) govHandler := NewHandler(keeper) - assert.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) - assert.Nil(t, keeper.ActiveProposalQueuePeek(ctx)) - assert.False(t, shouldPopActiveProposalQueue(ctx, keeper)) + require.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.False(t, shouldPopInactiveProposalQueue(ctx, keeper)) + require.Nil(t, keeper.ActiveProposalQueuePeek(ctx)) + require.False(t, shouldPopActiveProposalQueue(ctx, keeper)) newProposalMsg := NewMsgSubmitProposal("Test", "test", ProposalTypeText, addrs[0], sdk.Coins{sdk.NewCoin("steak", 5)}) res := govHandler(ctx, newProposalMsg) - assert.True(t, res.IsOK()) + require.True(t, res.IsOK()) var proposalID int64 keeper.cdc.UnmarshalBinaryBare(res.Data, &proposalID) ctx = ctx.WithBlockHeight(10) newDepositMsg := NewMsgDeposit(addrs[1], proposalID, sdk.Coins{sdk.NewCoin("steak", 5)}) res = govHandler(ctx, newDepositMsg) - assert.True(t, res.IsOK()) + require.True(t, res.IsOK()) EndBlocker(ctx, keeper) ctx = ctx.WithBlockHeight(215) - assert.True(t, shouldPopActiveProposalQueue(ctx, keeper)) + require.True(t, shouldPopActiveProposalQueue(ctx, keeper)) depositsIterator := keeper.GetDeposits(ctx, proposalID) - assert.True(t, depositsIterator.Valid()) + require.True(t, depositsIterator.Valid()) depositsIterator.Close() - assert.Equal(t, StatusVotingPeriod, keeper.GetProposal(ctx, proposalID).GetStatus()) + require.Equal(t, StatusVotingPeriod, keeper.GetProposal(ctx, proposalID).GetStatus()) EndBlocker(ctx, keeper) - assert.Nil(t, keeper.ActiveProposalQueuePeek(ctx)) + require.Nil(t, keeper.ActiveProposalQueuePeek(ctx)) depositsIterator = keeper.GetDeposits(ctx, proposalID) - assert.False(t, depositsIterator.Valid()) + require.False(t, depositsIterator.Valid()) depositsIterator.Close() - assert.Equal(t, StatusRejected, keeper.GetProposal(ctx, proposalID).GetStatus()) + require.Equal(t, StatusRejected, keeper.GetProposal(ctx, proposalID).GetStatus()) } diff --git a/x/gov/keeper_test.go b/x/gov/keeper_test.go index 1033600e65d4..786953fd3aa5 100644 --- a/x/gov/keeper_test.go +++ b/x/gov/keeper_test.go @@ -3,7 +3,7 @@ package gov import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -20,7 +20,7 @@ func TestGetSetProposal(t *testing.T) { keeper.SetProposal(ctx, proposal) gotProposal := keeper.GetProposal(ctx, proposalID) - assert.True(t, ProposalEqual(proposal, gotProposal)) + require.True(t, ProposalEqual(proposal, gotProposal)) } func TestIncrementProposalNumber(t *testing.T) { @@ -35,7 +35,7 @@ func TestIncrementProposalNumber(t *testing.T) { keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText) proposal6 := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText) - assert.Equal(t, int64(6), proposal6.GetProposalID()) + require.Equal(t, int64(6), proposal6.GetProposalID()) } func TestActivateVotingPeriod(t *testing.T) { @@ -45,13 +45,13 @@ func TestActivateVotingPeriod(t *testing.T) { proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText) - assert.Equal(t, int64(-1), proposal.GetVotingStartBlock()) - assert.Nil(t, keeper.ActiveProposalQueuePeek(ctx)) + require.Equal(t, int64(-1), proposal.GetVotingStartBlock()) + require.Nil(t, keeper.ActiveProposalQueuePeek(ctx)) keeper.activateVotingPeriod(ctx, proposal) - assert.Equal(t, proposal.GetVotingStartBlock(), ctx.BlockHeight()) - assert.Equal(t, proposal.GetProposalID(), keeper.ActiveProposalQueuePeek(ctx).GetProposalID()) + require.Equal(t, proposal.GetVotingStartBlock(), ctx.BlockHeight()) + require.Equal(t, proposal.GetProposalID(), keeper.ActiveProposalQueuePeek(ctx).GetProposalID()) } func TestDeposits(t *testing.T) { @@ -69,77 +69,77 @@ func TestDeposits(t *testing.T) { addr0Initial := keeper.ck.GetCoins(ctx, addrs[0]) addr1Initial := keeper.ck.GetCoins(ctx, addrs[1]) - // assert.True(t, addr0Initial.IsEqual(sdk.Coins{sdk.NewCoin("steak", 42)})) - assert.Equal(t, sdk.Coins{sdk.NewCoin("steak", 42)}, addr0Initial) + // require.True(t, addr0Initial.IsEqual(sdk.Coins{sdk.NewCoin("steak", 42)})) + require.Equal(t, sdk.Coins{sdk.NewCoin("steak", 42)}, addr0Initial) - assert.True(t, proposal.GetTotalDeposit().IsEqual(sdk.Coins{})) + require.True(t, proposal.GetTotalDeposit().IsEqual(sdk.Coins{})) // Check no deposits at beginning deposit, found := keeper.GetDeposit(ctx, proposalID, addrs[1]) - assert.False(t, found) - assert.Equal(t, keeper.GetProposal(ctx, proposalID).GetVotingStartBlock(), int64(-1)) - assert.Nil(t, keeper.ActiveProposalQueuePeek(ctx)) + require.False(t, found) + require.Equal(t, keeper.GetProposal(ctx, proposalID).GetVotingStartBlock(), int64(-1)) + require.Nil(t, keeper.ActiveProposalQueuePeek(ctx)) // Check first deposit err, votingStarted := keeper.AddDeposit(ctx, proposalID, addrs[0], fourSteak) - assert.Nil(t, err) - assert.False(t, votingStarted) + require.Nil(t, err) + require.False(t, votingStarted) deposit, found = keeper.GetDeposit(ctx, proposalID, addrs[0]) - assert.True(t, found) - assert.Equal(t, fourSteak, deposit.Amount) - assert.Equal(t, addrs[0], deposit.Depositer) - assert.Equal(t, fourSteak, keeper.GetProposal(ctx, proposalID).GetTotalDeposit()) - assert.Equal(t, addr0Initial.Minus(fourSteak), keeper.ck.GetCoins(ctx, addrs[0])) + require.True(t, found) + require.Equal(t, fourSteak, deposit.Amount) + require.Equal(t, addrs[0], deposit.Depositer) + require.Equal(t, fourSteak, keeper.GetProposal(ctx, proposalID).GetTotalDeposit()) + require.Equal(t, addr0Initial.Minus(fourSteak), keeper.ck.GetCoins(ctx, addrs[0])) // Check a second deposit from same address err, votingStarted = keeper.AddDeposit(ctx, proposalID, addrs[0], fiveSteak) - assert.Nil(t, err) - assert.False(t, votingStarted) + require.Nil(t, err) + require.False(t, votingStarted) deposit, found = keeper.GetDeposit(ctx, proposalID, addrs[0]) - assert.True(t, found) - assert.Equal(t, fourSteak.Plus(fiveSteak), deposit.Amount) - assert.Equal(t, addrs[0], deposit.Depositer) - assert.Equal(t, fourSteak.Plus(fiveSteak), keeper.GetProposal(ctx, proposalID).GetTotalDeposit()) - assert.Equal(t, addr0Initial.Minus(fourSteak).Minus(fiveSteak), keeper.ck.GetCoins(ctx, addrs[0])) + require.True(t, found) + require.Equal(t, fourSteak.Plus(fiveSteak), deposit.Amount) + require.Equal(t, addrs[0], deposit.Depositer) + require.Equal(t, fourSteak.Plus(fiveSteak), keeper.GetProposal(ctx, proposalID).GetTotalDeposit()) + require.Equal(t, addr0Initial.Minus(fourSteak).Minus(fiveSteak), keeper.ck.GetCoins(ctx, addrs[0])) // Check third deposit from a new address err, votingStarted = keeper.AddDeposit(ctx, proposalID, addrs[1], fourSteak) - assert.Nil(t, err) - assert.True(t, votingStarted) + require.Nil(t, err) + require.True(t, votingStarted) deposit, found = keeper.GetDeposit(ctx, proposalID, addrs[1]) - assert.True(t, found) - assert.Equal(t, addrs[1], deposit.Depositer) - assert.Equal(t, fourSteak, deposit.Amount) - assert.Equal(t, fourSteak.Plus(fiveSteak).Plus(fourSteak), keeper.GetProposal(ctx, proposalID).GetTotalDeposit()) - assert.Equal(t, addr1Initial.Minus(fourSteak), keeper.ck.GetCoins(ctx, addrs[1])) + require.True(t, found) + require.Equal(t, addrs[1], deposit.Depositer) + require.Equal(t, fourSteak, deposit.Amount) + require.Equal(t, fourSteak.Plus(fiveSteak).Plus(fourSteak), keeper.GetProposal(ctx, proposalID).GetTotalDeposit()) + require.Equal(t, addr1Initial.Minus(fourSteak), keeper.ck.GetCoins(ctx, addrs[1])) // Check that proposal moved to voting period - assert.Equal(t, ctx.BlockHeight(), keeper.GetProposal(ctx, proposalID).GetVotingStartBlock()) - assert.NotNil(t, keeper.ActiveProposalQueuePeek(ctx)) - assert.Equal(t, proposalID, keeper.ActiveProposalQueuePeek(ctx).GetProposalID()) + require.Equal(t, ctx.BlockHeight(), keeper.GetProposal(ctx, proposalID).GetVotingStartBlock()) + require.NotNil(t, keeper.ActiveProposalQueuePeek(ctx)) + require.Equal(t, proposalID, keeper.ActiveProposalQueuePeek(ctx).GetProposalID()) // Test deposit iterator depositsIterator := keeper.GetDeposits(ctx, proposalID) - assert.True(t, depositsIterator.Valid()) + require.True(t, depositsIterator.Valid()) keeper.cdc.MustUnmarshalBinary(depositsIterator.Value(), &deposit) - assert.Equal(t, addrs[0], deposit.Depositer) - assert.Equal(t, fourSteak.Plus(fiveSteak), deposit.Amount) + require.Equal(t, addrs[0], deposit.Depositer) + require.Equal(t, fourSteak.Plus(fiveSteak), deposit.Amount) depositsIterator.Next() keeper.cdc.MustUnmarshalBinary(depositsIterator.Value(), &deposit) - assert.Equal(t, addrs[1], deposit.Depositer) - assert.Equal(t, fourSteak, deposit.Amount) + require.Equal(t, addrs[1], deposit.Depositer) + require.Equal(t, fourSteak, deposit.Amount) depositsIterator.Next() - assert.False(t, depositsIterator.Valid()) + require.False(t, depositsIterator.Valid()) // Test Refund Deposits deposit, found = keeper.GetDeposit(ctx, proposalID, addrs[1]) - assert.True(t, found) - assert.Equal(t, fourSteak, deposit.Amount) + require.True(t, found) + require.Equal(t, fourSteak, deposit.Amount) keeper.RefundDeposits(ctx, proposalID) deposit, found = keeper.GetDeposit(ctx, proposalID, addrs[1]) - assert.False(t, found) - assert.Equal(t, addr0Initial, keeper.ck.GetCoins(ctx, addrs[0])) - assert.Equal(t, addr1Initial, keeper.ck.GetCoins(ctx, addrs[1])) + require.False(t, found) + require.Equal(t, addr0Initial, keeper.ck.GetCoins(ctx, addrs[0])) + require.Equal(t, addr1Initial, keeper.ck.GetCoins(ctx, addrs[1])) } @@ -158,44 +158,44 @@ func TestVotes(t *testing.T) { // Test first vote keeper.AddVote(ctx, proposalID, addrs[0], OptionAbstain) vote, found := keeper.GetVote(ctx, proposalID, addrs[0]) - assert.True(t, found) - assert.Equal(t, addrs[0], vote.Voter) - assert.Equal(t, proposalID, vote.ProposalID) - assert.Equal(t, OptionAbstain, vote.Option) + require.True(t, found) + require.Equal(t, addrs[0], vote.Voter) + require.Equal(t, proposalID, vote.ProposalID) + require.Equal(t, OptionAbstain, vote.Option) // Test change of vote keeper.AddVote(ctx, proposalID, addrs[0], OptionYes) vote, found = keeper.GetVote(ctx, proposalID, addrs[0]) - assert.True(t, found) - assert.Equal(t, addrs[0], vote.Voter) - assert.Equal(t, proposalID, vote.ProposalID) - assert.Equal(t, OptionYes, vote.Option) + require.True(t, found) + require.Equal(t, addrs[0], vote.Voter) + require.Equal(t, proposalID, vote.ProposalID) + require.Equal(t, OptionYes, vote.Option) // Test second vote keeper.AddVote(ctx, proposalID, addrs[1], OptionNoWithVeto) vote, found = keeper.GetVote(ctx, proposalID, addrs[1]) - assert.True(t, found) - assert.Equal(t, addrs[1], vote.Voter) - assert.Equal(t, proposalID, vote.ProposalID) - assert.Equal(t, OptionNoWithVeto, vote.Option) + require.True(t, found) + require.Equal(t, addrs[1], vote.Voter) + require.Equal(t, proposalID, vote.ProposalID) + require.Equal(t, OptionNoWithVeto, vote.Option) // Test vote iterator votesIterator := keeper.GetVotes(ctx, proposalID) - assert.True(t, votesIterator.Valid()) + require.True(t, votesIterator.Valid()) keeper.cdc.MustUnmarshalBinary(votesIterator.Value(), &vote) - assert.True(t, votesIterator.Valid()) - assert.Equal(t, addrs[0], vote.Voter) - assert.Equal(t, proposalID, vote.ProposalID) - assert.Equal(t, OptionYes, vote.Option) + require.True(t, votesIterator.Valid()) + require.Equal(t, addrs[0], vote.Voter) + require.Equal(t, proposalID, vote.ProposalID) + require.Equal(t, OptionYes, vote.Option) votesIterator.Next() - assert.True(t, votesIterator.Valid()) + require.True(t, votesIterator.Valid()) keeper.cdc.MustUnmarshalBinary(votesIterator.Value(), &vote) - assert.True(t, votesIterator.Valid()) - assert.Equal(t, addrs[1], vote.Voter) - assert.Equal(t, proposalID, vote.ProposalID) - assert.Equal(t, OptionNoWithVeto, vote.Option) + require.True(t, votesIterator.Valid()) + require.Equal(t, addrs[1], vote.Voter) + require.Equal(t, proposalID, vote.ProposalID) + require.Equal(t, OptionNoWithVeto, vote.Option) votesIterator.Next() - assert.False(t, votesIterator.Valid()) + require.False(t, votesIterator.Valid()) } func TestProposalQueues(t *testing.T) { @@ -204,8 +204,8 @@ func TestProposalQueues(t *testing.T) { ctx := mapp.BaseApp.NewContext(false, abci.Header{}) mapp.InitChainer(ctx, abci.RequestInitChain{}) - assert.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) - assert.Nil(t, keeper.ActiveProposalQueuePeek(ctx)) + require.Nil(t, keeper.InactiveProposalQueuePeek(ctx)) + require.Nil(t, keeper.ActiveProposalQueuePeek(ctx)) // create test proposals proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText) @@ -220,14 +220,14 @@ func TestProposalQueues(t *testing.T) { keeper.InactiveProposalQueuePush(ctx, proposal4) // test peeking and popping from inactive proposal queue - assert.Equal(t, keeper.InactiveProposalQueuePeek(ctx).GetProposalID(), proposal.GetProposalID()) - assert.Equal(t, keeper.InactiveProposalQueuePop(ctx).GetProposalID(), proposal.GetProposalID()) - assert.Equal(t, keeper.InactiveProposalQueuePeek(ctx).GetProposalID(), proposal2.GetProposalID()) - assert.Equal(t, keeper.InactiveProposalQueuePop(ctx).GetProposalID(), proposal2.GetProposalID()) - assert.Equal(t, keeper.InactiveProposalQueuePeek(ctx).GetProposalID(), proposal3.GetProposalID()) - assert.Equal(t, keeper.InactiveProposalQueuePop(ctx).GetProposalID(), proposal3.GetProposalID()) - assert.Equal(t, keeper.InactiveProposalQueuePeek(ctx).GetProposalID(), proposal4.GetProposalID()) - assert.Equal(t, keeper.InactiveProposalQueuePop(ctx).GetProposalID(), proposal4.GetProposalID()) + require.Equal(t, keeper.InactiveProposalQueuePeek(ctx).GetProposalID(), proposal.GetProposalID()) + require.Equal(t, keeper.InactiveProposalQueuePop(ctx).GetProposalID(), proposal.GetProposalID()) + require.Equal(t, keeper.InactiveProposalQueuePeek(ctx).GetProposalID(), proposal2.GetProposalID()) + require.Equal(t, keeper.InactiveProposalQueuePop(ctx).GetProposalID(), proposal2.GetProposalID()) + require.Equal(t, keeper.InactiveProposalQueuePeek(ctx).GetProposalID(), proposal3.GetProposalID()) + require.Equal(t, keeper.InactiveProposalQueuePop(ctx).GetProposalID(), proposal3.GetProposalID()) + require.Equal(t, keeper.InactiveProposalQueuePeek(ctx).GetProposalID(), proposal4.GetProposalID()) + require.Equal(t, keeper.InactiveProposalQueuePop(ctx).GetProposalID(), proposal4.GetProposalID()) // test pushing to active proposal queue keeper.ActiveProposalQueuePush(ctx, proposal) @@ -236,12 +236,12 @@ func TestProposalQueues(t *testing.T) { keeper.ActiveProposalQueuePush(ctx, proposal4) // test peeking and popping from active proposal queue - assert.Equal(t, keeper.ActiveProposalQueuePeek(ctx).GetProposalID(), proposal.GetProposalID()) - assert.Equal(t, keeper.ActiveProposalQueuePop(ctx).GetProposalID(), proposal.GetProposalID()) - assert.Equal(t, keeper.ActiveProposalQueuePeek(ctx).GetProposalID(), proposal2.GetProposalID()) - assert.Equal(t, keeper.ActiveProposalQueuePop(ctx).GetProposalID(), proposal2.GetProposalID()) - assert.Equal(t, keeper.ActiveProposalQueuePeek(ctx).GetProposalID(), proposal3.GetProposalID()) - assert.Equal(t, keeper.ActiveProposalQueuePop(ctx).GetProposalID(), proposal3.GetProposalID()) - assert.Equal(t, keeper.ActiveProposalQueuePeek(ctx).GetProposalID(), proposal4.GetProposalID()) - assert.Equal(t, keeper.ActiveProposalQueuePop(ctx).GetProposalID(), proposal4.GetProposalID()) + require.Equal(t, keeper.ActiveProposalQueuePeek(ctx).GetProposalID(), proposal.GetProposalID()) + require.Equal(t, keeper.ActiveProposalQueuePop(ctx).GetProposalID(), proposal.GetProposalID()) + require.Equal(t, keeper.ActiveProposalQueuePeek(ctx).GetProposalID(), proposal2.GetProposalID()) + require.Equal(t, keeper.ActiveProposalQueuePop(ctx).GetProposalID(), proposal2.GetProposalID()) + require.Equal(t, keeper.ActiveProposalQueuePeek(ctx).GetProposalID(), proposal3.GetProposalID()) + require.Equal(t, keeper.ActiveProposalQueuePop(ctx).GetProposalID(), proposal3.GetProposalID()) + require.Equal(t, keeper.ActiveProposalQueuePeek(ctx).GetProposalID(), proposal4.GetProposalID()) + require.Equal(t, keeper.ActiveProposalQueuePop(ctx).GetProposalID(), proposal4.GetProposalID()) } diff --git a/x/gov/msgs_test.go b/x/gov/msgs_test.go index 3100f98ca0b3..e9be4ded3d53 100644 --- a/x/gov/msgs_test.go +++ b/x/gov/msgs_test.go @@ -3,7 +3,7 @@ package gov import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/mock" @@ -42,9 +42,9 @@ func TestMsgSubmitProposal(t *testing.T) { for i, tc := range tests { msg := NewMsgSubmitProposal(tc.title, tc.description, tc.proposalType, tc.proposerAddr, tc.initialDeposit) if tc.expectPass { - assert.Nil(t, msg.ValidateBasic(), "test: %v", i) + require.Nil(t, msg.ValidateBasic(), "test: %v", i) } else { - assert.NotNil(t, msg.ValidateBasic(), "test: %v", i) + require.NotNil(t, msg.ValidateBasic(), "test: %v", i) } } } @@ -69,9 +69,9 @@ func TestMsgDeposit(t *testing.T) { for i, tc := range tests { msg := NewMsgDeposit(tc.depositerAddr, tc.proposalID, tc.depositAmount) if tc.expectPass { - assert.Nil(t, msg.ValidateBasic(), "test: %v", i) + require.Nil(t, msg.ValidateBasic(), "test: %v", i) } else { - assert.NotNil(t, msg.ValidateBasic(), "test: %v", i) + require.NotNil(t, msg.ValidateBasic(), "test: %v", i) } } } @@ -97,9 +97,9 @@ func TestMsgVote(t *testing.T) { for i, tc := range tests { msg := NewMsgVote(tc.voterAddr, tc.proposalID, tc.option) if tc.expectPass { - assert.Nil(t, msg.ValidateBasic(), "test: %v", i) + require.Nil(t, msg.ValidateBasic(), "test: %v", i) } else { - assert.NotNil(t, msg.ValidateBasic(), "test: %v", i) + require.NotNil(t, msg.ValidateBasic(), "test: %v", i) } } } diff --git a/x/gov/tally_test.go b/x/gov/tally_test.go index 171a2e2e9c47..bcc3f2eb013e 100644 --- a/x/gov/tally_test.go +++ b/x/gov/tally_test.go @@ -3,7 +3,7 @@ package gov import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" @@ -31,7 +31,7 @@ func TestTallyNoOneVotes(t *testing.T) { passes, _ := tally(ctx, keeper, keeper.GetProposal(ctx, proposalID)) - assert.False(t, passes) + require.False(t, passes) } func TestTallyOnlyValidatorsAllYes(t *testing.T) { @@ -43,10 +43,10 @@ func TestTallyOnlyValidatorsAllYes(t *testing.T) { dummyDescription := stake.NewDescription("T", "E", "S", "T") val1CreateMsg := stake.NewMsgCreateValidator(addrs[0], crypto.GenPrivKeyEd25519().PubKey(), sdk.NewCoin("steak", 5), dummyDescription) res := stakeHandler(ctx, val1CreateMsg) - assert.True(t, res.IsOK()) + require.True(t, res.IsOK()) val2CreateMsg := stake.NewMsgCreateValidator(addrs[1], crypto.GenPrivKeyEd25519().PubKey(), sdk.NewCoin("steak", 5), dummyDescription) res = stakeHandler(ctx, val2CreateMsg) - assert.True(t, res.IsOK()) + require.True(t, res.IsOK()) proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText) proposalID := proposal.GetProposalID() @@ -54,13 +54,13 @@ func TestTallyOnlyValidatorsAllYes(t *testing.T) { keeper.SetProposal(ctx, proposal) err := keeper.AddVote(ctx, proposalID, addrs[0], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[1], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) passes, _ := tally(ctx, keeper, keeper.GetProposal(ctx, proposalID)) - assert.True(t, passes) + require.True(t, passes) } func TestTallyOnlyValidators51No(t *testing.T) { @@ -81,13 +81,13 @@ func TestTallyOnlyValidators51No(t *testing.T) { keeper.SetProposal(ctx, proposal) err := keeper.AddVote(ctx, proposalID, addrs[0], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[1], OptionNo) - assert.Nil(t, err) + require.Nil(t, err) passes, _ := tally(ctx, keeper, keeper.GetProposal(ctx, proposalID)) - assert.False(t, passes) + require.False(t, passes) } func TestTallyOnlyValidators51Yes(t *testing.T) { @@ -110,15 +110,15 @@ func TestTallyOnlyValidators51Yes(t *testing.T) { keeper.SetProposal(ctx, proposal) err := keeper.AddVote(ctx, proposalID, addrs[0], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[1], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[2], OptionNo) - assert.Nil(t, err) + require.Nil(t, err) passes, _ := tally(ctx, keeper, keeper.GetProposal(ctx, proposalID)) - assert.True(t, passes) + require.True(t, passes) } func TestTallyOnlyValidatorsVetoed(t *testing.T) { @@ -141,15 +141,15 @@ func TestTallyOnlyValidatorsVetoed(t *testing.T) { keeper.SetProposal(ctx, proposal) err := keeper.AddVote(ctx, proposalID, addrs[0], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[1], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[2], OptionNoWithVeto) - assert.Nil(t, err) + require.Nil(t, err) passes, _ := tally(ctx, keeper, keeper.GetProposal(ctx, proposalID)) - assert.False(t, passes) + require.False(t, passes) } func TestTallyOnlyValidatorsAbstainPasses(t *testing.T) { @@ -172,15 +172,15 @@ func TestTallyOnlyValidatorsAbstainPasses(t *testing.T) { keeper.SetProposal(ctx, proposal) err := keeper.AddVote(ctx, proposalID, addrs[0], OptionAbstain) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[1], OptionNo) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[2], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) passes, _ := tally(ctx, keeper, keeper.GetProposal(ctx, proposalID)) - assert.True(t, passes) + require.True(t, passes) } func TestTallyOnlyValidatorsAbstainFails(t *testing.T) { @@ -203,15 +203,15 @@ func TestTallyOnlyValidatorsAbstainFails(t *testing.T) { keeper.SetProposal(ctx, proposal) err := keeper.AddVote(ctx, proposalID, addrs[0], OptionAbstain) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[1], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[2], OptionNo) - assert.Nil(t, err) + require.Nil(t, err) passes, _ := tally(ctx, keeper, keeper.GetProposal(ctx, proposalID)) - assert.False(t, passes) + require.False(t, passes) } func TestTallyOnlyValidatorsNonVoter(t *testing.T) { @@ -234,15 +234,15 @@ func TestTallyOnlyValidatorsNonVoter(t *testing.T) { keeper.SetProposal(ctx, proposal) err := keeper.AddVote(ctx, proposalID, addrs[1], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[2], OptionNo) - assert.Nil(t, err) + require.Nil(t, err) passes, nonVoting := tally(ctx, keeper, keeper.GetProposal(ctx, proposalID)) - assert.False(t, passes) - assert.Equal(t, 1, len(nonVoting)) - assert.Equal(t, addrs[0], nonVoting[0]) + require.False(t, passes) + require.Equal(t, 1, len(nonVoting)) + require.Equal(t, addrs[0], nonVoting[0]) } func TestTallyDelgatorOverride(t *testing.T) { @@ -268,17 +268,17 @@ func TestTallyDelgatorOverride(t *testing.T) { keeper.SetProposal(ctx, proposal) err := keeper.AddVote(ctx, proposalID, addrs[0], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[1], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[2], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[3], OptionNo) - assert.Nil(t, err) + require.Nil(t, err) passes, _ := tally(ctx, keeper, keeper.GetProposal(ctx, proposalID)) - assert.False(t, passes) + require.False(t, passes) } func TestTallyDelgatorInherit(t *testing.T) { @@ -304,16 +304,16 @@ func TestTallyDelgatorInherit(t *testing.T) { keeper.SetProposal(ctx, proposal) err := keeper.AddVote(ctx, proposalID, addrs[0], OptionNo) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[1], OptionNo) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[2], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) passes, nonVoting := tally(ctx, keeper, keeper.GetProposal(ctx, proposalID)) - assert.True(t, passes) - assert.Equal(t, 0, len(nonVoting)) + require.True(t, passes) + require.Equal(t, 0, len(nonVoting)) } func TestTallyDelgatorMultipleOverride(t *testing.T) { @@ -341,17 +341,17 @@ func TestTallyDelgatorMultipleOverride(t *testing.T) { keeper.SetProposal(ctx, proposal) err := keeper.AddVote(ctx, proposalID, addrs[0], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[1], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[2], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[3], OptionNo) - assert.Nil(t, err) + require.Nil(t, err) passes, _ := tally(ctx, keeper, keeper.GetProposal(ctx, proposalID)) - assert.False(t, passes) + require.False(t, passes) } func TestTallyDelgatorMultipleInherit(t *testing.T) { @@ -379,13 +379,13 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) { keeper.SetProposal(ctx, proposal) err := keeper.AddVote(ctx, proposalID, addrs[0], OptionYes) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[1], OptionNo) - assert.Nil(t, err) + require.Nil(t, err) err = keeper.AddVote(ctx, proposalID, addrs[2], OptionNo) - assert.Nil(t, err) + require.Nil(t, err) passes, _ := tally(ctx, keeper, keeper.GetProposal(ctx, proposalID)) - assert.False(t, passes) + require.False(t, passes) } diff --git a/x/ibc/app_test.go b/x/ibc/app_test.go index 077bc87bb66e..1540bf2ed84f 100644 --- a/x/ibc/app_test.go +++ b/x/ibc/app_test.go @@ -3,7 +3,6 @@ package ibc import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" @@ -51,7 +50,7 @@ func TestIBCMsgs(t *testing.T) { // A checkTx context (true) ctxCheck := mapp.BaseApp.NewContext(true, abci.Header{}) res1 := mapp.AccountMapper.GetAccount(ctxCheck, addr1) - assert.Equal(t, acc, res1) + require.Equal(t, acc, res1) packet := IBCPacket{ SrcAddr: addr1, diff --git a/x/ibc/ibc_test.go b/x/ibc/ibc_test.go index f292fabfe80e..33535145d85a 100644 --- a/x/ibc/ibc_test.go +++ b/x/ibc/ibc_test.go @@ -3,7 +3,7 @@ package ibc import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" @@ -72,8 +72,8 @@ func TestIBC(t *testing.T) { mycoins := sdk.Coins{sdk.NewCoin("mycoin", 10)} coins, _, err := ck.AddCoins(ctx, src, mycoins) - assert.Nil(t, err) - assert.Equal(t, mycoins, coins) + require.Nil(t, err) + require.Equal(t, mycoins, coins) ibcm := NewMapper(cdc, key, DefaultCodespace) h := NewHandler(ibcm, ck) @@ -93,23 +93,23 @@ func TestIBC(t *testing.T) { var igs int64 egl = ibcm.getEgressLength(store, chainid) - assert.Equal(t, egl, int64(0)) + require.Equal(t, egl, int64(0)) msg = IBCTransferMsg{ IBCPacket: packet, } res = h(ctx, msg) - assert.True(t, res.IsOK()) + require.True(t, res.IsOK()) coins, err = getCoins(ck, ctx, src) - assert.Nil(t, err) - assert.Equal(t, zero, coins) + require.Nil(t, err) + require.Equal(t, zero, coins) egl = ibcm.getEgressLength(store, chainid) - assert.Equal(t, egl, int64(1)) + require.Equal(t, egl, int64(1)) igs = ibcm.GetIngressSequence(ctx, chainid) - assert.Equal(t, igs, int64(0)) + require.Equal(t, igs, int64(0)) msg = IBCReceiveMsg{ IBCPacket: packet, @@ -117,18 +117,18 @@ func TestIBC(t *testing.T) { Sequence: 0, } res = h(ctx, msg) - assert.True(t, res.IsOK()) + require.True(t, res.IsOK()) coins, err = getCoins(ck, ctx, dest) - assert.Nil(t, err) - assert.Equal(t, mycoins, coins) + require.Nil(t, err) + require.Equal(t, mycoins, coins) igs = ibcm.GetIngressSequence(ctx, chainid) - assert.Equal(t, igs, int64(1)) + require.Equal(t, igs, int64(1)) res = h(ctx, msg) - assert.False(t, res.IsOK()) + require.False(t, res.IsOK()) igs = ibcm.GetIngressSequence(ctx, chainid) - assert.Equal(t, igs, int64(1)) + require.Equal(t, igs, int64(1)) } diff --git a/x/ibc/types_test.go b/x/ibc/types_test.go index 5127546989da..690179baa16b 100644 --- a/x/ibc/types_test.go +++ b/x/ibc/types_test.go @@ -3,7 +3,7 @@ package ibc import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -23,9 +23,9 @@ func TestIBCPacketValidation(t *testing.T) { for i, tc := range cases { err := tc.packet.ValidateBasic() if tc.valid { - assert.Nil(t, err, "%d: %+v", i, err) + require.Nil(t, err, "%d: %+v", i, err) } else { - assert.NotNil(t, err, "%d", i) + require.NotNil(t, err, "%d", i) } } } @@ -37,7 +37,7 @@ func TestIBCTransferMsg(t *testing.T) { packet := constructIBCPacket(true) msg := IBCTransferMsg{packet} - assert.Equal(t, msg.Type(), "ibc") + require.Equal(t, msg.Type(), "ibc") } func TestIBCTransferMsgValidation(t *testing.T) { @@ -55,9 +55,9 @@ func TestIBCTransferMsgValidation(t *testing.T) { for i, tc := range cases { err := tc.msg.ValidateBasic() if tc.valid { - assert.Nil(t, err, "%d: %+v", i, err) + require.Nil(t, err, "%d: %+v", i, err) } else { - assert.NotNil(t, err, "%d", i) + require.NotNil(t, err, "%d", i) } } } @@ -69,7 +69,7 @@ func TestIBCReceiveMsg(t *testing.T) { packet := constructIBCPacket(true) msg := IBCReceiveMsg{packet, sdk.Address([]byte("relayer")), 0} - assert.Equal(t, msg.Type(), "ibc") + require.Equal(t, msg.Type(), "ibc") } func TestIBCReceiveMsgValidation(t *testing.T) { @@ -87,9 +87,9 @@ func TestIBCReceiveMsgValidation(t *testing.T) { for i, tc := range cases { err := tc.msg.ValidateBasic() if tc.valid { - assert.Nil(t, err, "%d: %+v", i, err) + require.Nil(t, err, "%d: %+v", i, err) } else { - assert.NotNil(t, err, "%d", i) + require.NotNil(t, err, "%d", i) } } } diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index 2120e75b683f..18416174bdb0 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/mock" "github.com/cosmos/cosmos-sdk/x/bank" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/x/stake" @@ -66,7 +65,7 @@ func checkValidator(t *testing.T, mapp *mock.App, keeper stake.Keeper, addr sdk.Address, expFound bool) stake.Validator { ctxCheck := mapp.BaseApp.NewContext(true, abci.Header{}) validator, found := keeper.GetValidator(ctxCheck, addr1) - assert.Equal(t, expFound, found) + require.Equal(t, expFound, found) return validator } @@ -74,7 +73,7 @@ func checkValidatorSigningInfo(t *testing.T, mapp *mock.App, keeper Keeper, addr sdk.Address, expFound bool) ValidatorSigningInfo { ctxCheck := mapp.BaseApp.NewContext(true, abci.Header{}) signingInfo, found := keeper.getValidatorSigningInfo(ctxCheck, addr) - assert.Equal(t, expFound, found) + require.Equal(t, expFound, found) return signingInfo } diff --git a/x/slashing/msg_test.go b/x/slashing/msg_test.go index be7797107e98..a668bc33fab5 100644 --- a/x/slashing/msg_test.go +++ b/x/slashing/msg_test.go @@ -3,7 +3,7 @@ package slashing import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -12,5 +12,5 @@ func TestMsgUnrevokeGetSignBytes(t *testing.T) { addr := sdk.Address("abcd") msg := NewMsgUnrevoke(addr) bytes := msg.GetSignBytes() - assert.Equal(t, string(bytes), `{"address":"cosmosvaladdr1v93xxeqamr0mv"}`) + require.Equal(t, string(bytes), `{"address":"cosmosvaladdr1v93xxeqamr0mv"}`) } diff --git a/x/stake/app_test.go b/x/stake/app_test.go index 2b0253309254..d4fc5bdf0047 100644 --- a/x/stake/app_test.go +++ b/x/stake/app_test.go @@ -75,7 +75,7 @@ func checkValidator(t *testing.T, mapp *mock.App, keeper Keeper, ctxCheck := mapp.BaseApp.NewContext(true, abci.Header{}) validator, found := keeper.GetValidator(ctxCheck, addr1) - assert.Equal(t, expFound, found) + require.Equal(t, expFound, found) return validator } @@ -85,11 +85,11 @@ func checkDelegation(t *testing.T, mapp *mock.App, keeper Keeper, delegatorAddr, ctxCheck := mapp.BaseApp.NewContext(true, abci.Header{}) delegation, found := keeper.GetDelegation(ctxCheck, delegatorAddr, validatorAddr) if expFound { - assert.True(t, found) + require.True(t, found) assert.True(sdk.RatEq(t, expShares, delegation.Shares)) return } - assert.False(t, found) + require.False(t, found) } func TestStakeMsgs(t *testing.T) { diff --git a/x/stake/handler_test.go b/x/stake/handler_test.go index 61acc94d7f0b..ef47318c6872 100644 --- a/x/stake/handler_test.go +++ b/x/stake/handler_test.go @@ -3,7 +3,6 @@ package stake import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" @@ -52,7 +51,7 @@ func TestValidatorByPowerIndex(t *testing.T) { // create validator msgCreateValidator := newTestMsgCreateValidator(validatorAddr, keep.PKs[0], initBond) got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper) - assert.True(t, got.IsOK(), "expected create-validator to be ok, got %v", got) + require.True(t, got.IsOK(), "expected create-validator to be ok, got %v", got) // verify the self-delegation exists bond, found := keeper.GetDelegation(ctx, validatorAddr, validatorAddr) @@ -72,7 +71,7 @@ func TestValidatorByPowerIndex(t *testing.T) { // create a second validator keep it bonded msgCreateValidator = newTestMsgCreateValidator(validatorAddr3, keep.PKs[2], int64(1000000)) got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper) - assert.True(t, got.IsOK(), "expected create-validator to be ok, got %v", got) + require.True(t, got.IsOK(), "expected create-validator to be ok, got %v", got) // slash and revoke the first validator keeper.Slash(ctx, keep.PKs[0], 0, sdk.NewRat(1, 2)) @@ -83,7 +82,7 @@ func TestValidatorByPowerIndex(t *testing.T) { require.Equal(t, int64(500000), validator.PoolShares.Amount.Evaluate()) // ensure is unbonded // the old power record should have been deleted as the power changed - assert.False(t, keep.ValidatorByPowerIndexExists(ctx, keeper, power)) + require.False(t, keep.ValidatorByPowerIndexExists(ctx, keeper, power)) // but the new power record should have been created validator, found = keeper.GetValidator(ctx, validatorAddr) @@ -100,7 +99,7 @@ func TestValidatorByPowerIndex(t *testing.T) { // now the new record power index should be the same as the original record power3 := GetValidatorsByPowerIndexKey(validator, pool) - assert.Equal(t, power2, power3) + require.Equal(t, power2, power3) // unbond self-delegation msgBeginUnbonding := NewMsgBeginUnbonding(validatorAddr, validatorAddr, sdk.NewRat(1000000)) @@ -113,7 +112,7 @@ func TestValidatorByPowerIndex(t *testing.T) { // verify that by power key nolonger exists _, found = keeper.GetValidator(ctx, validatorAddr) require.False(t, found) - assert.False(t, keep.ValidatorByPowerIndexExists(ctx, keeper, power3)) + require.False(t, keep.ValidatorByPowerIndexExists(ctx, keeper, power3)) } func TestDuplicatesMsgCreateValidator(t *testing.T) { @@ -123,21 +122,21 @@ func TestDuplicatesMsgCreateValidator(t *testing.T) { pk := keep.PKs[0] msgCreateValidator := newTestMsgCreateValidator(validatorAddr, pk, 10) got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper) - assert.True(t, got.IsOK(), "%v", got) + require.True(t, got.IsOK(), "%v", got) validator, found := keeper.GetValidator(ctx, validatorAddr) require.True(t, found) - assert.Equal(t, sdk.Bonded, validator.Status()) - assert.Equal(t, validatorAddr, validator.Owner) - assert.Equal(t, pk, validator.PubKey) - assert.Equal(t, sdk.NewRat(10), validator.PoolShares.Bonded()) - assert.Equal(t, sdk.NewRat(10), validator.DelegatorShares) - assert.Equal(t, Description{}, validator.Description) + require.Equal(t, sdk.Bonded, validator.Status()) + require.Equal(t, validatorAddr, validator.Owner) + require.Equal(t, pk, validator.PubKey) + require.Equal(t, sdk.NewRat(10), validator.PoolShares.Bonded()) + require.Equal(t, sdk.NewRat(10), validator.DelegatorShares) + require.Equal(t, Description{}, validator.Description) // one validator cannot bond twice msgCreateValidator.PubKey = keep.PKs[1] got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper) - assert.False(t, got.IsOK(), "%v", got) + require.False(t, got.IsOK(), "%v", got) } func TestIncrementsMsgDelegate(t *testing.T) { @@ -151,26 +150,26 @@ func TestIncrementsMsgDelegate(t *testing.T) { // first create validator msgCreateValidator := newTestMsgCreateValidator(validatorAddr, keep.PKs[0], bondAmount) got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper) - assert.True(t, got.IsOK(), "expected create validator msg to be ok, got %v", got) + require.True(t, got.IsOK(), "expected create validator msg to be ok, got %v", got) validator, found := keeper.GetValidator(ctx, validatorAddr) require.True(t, found) require.Equal(t, sdk.Bonded, validator.Status()) - assert.Equal(t, bondAmount, validator.DelegatorShares.Evaluate()) - assert.Equal(t, bondAmount, validator.PoolShares.Bonded().Evaluate(), "validator: %v", validator) + require.Equal(t, bondAmount, validator.DelegatorShares.Evaluate()) + require.Equal(t, bondAmount, validator.PoolShares.Bonded().Evaluate(), "validator: %v", validator) _, found = keeper.GetDelegation(ctx, delegatorAddr, validatorAddr) require.False(t, found) bond, found := keeper.GetDelegation(ctx, validatorAddr, validatorAddr) require.True(t, found) - assert.Equal(t, bondAmount, bond.Shares.Evaluate()) + require.Equal(t, bondAmount, bond.Shares.Evaluate()) pool := keeper.GetPool(ctx) exRate := validator.DelegatorShareExRate(pool) require.True(t, exRate.Equal(sdk.OneRat()), "expected exRate 1 got %v", exRate) - assert.Equal(t, bondAmount, pool.BondedShares.Evaluate()) - assert.Equal(t, bondAmount, pool.BondedTokens) + require.Equal(t, bondAmount, pool.BondedShares.Evaluate()) + require.Equal(t, bondAmount, pool.BondedTokens) // just send the same msgbond multiple times msgDelegate := newTestMsgDelegate(delegatorAddr, validatorAddr, bondAmount) @@ -223,16 +222,16 @@ func TestIncrementsMsgUnbond(t *testing.T) { msgCreateValidator := newTestMsgCreateValidator(validatorAddr, keep.PKs[0], initBond) got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper) - assert.True(t, got.IsOK(), "expected create-validator to be ok, got %v", got) + require.True(t, got.IsOK(), "expected create-validator to be ok, got %v", got) msgDelegate := newTestMsgDelegate(delegatorAddr, validatorAddr, initBond) got = handleMsgDelegate(ctx, msgDelegate, keeper) - assert.True(t, got.IsOK(), "expected delegation to be ok, got %v", got) + require.True(t, got.IsOK(), "expected delegation to be ok, got %v", got) validator, found := keeper.GetValidator(ctx, validatorAddr) require.True(t, found) - assert.Equal(t, initBond*2, validator.DelegatorShares.Evaluate()) - assert.Equal(t, initBond*2, validator.PoolShares.Bonded().Evaluate()) + require.Equal(t, initBond*2, validator.DelegatorShares.Evaluate()) + require.Equal(t, initBond*2, validator.PoolShares.Bonded().Evaluate()) // just send the same msgUnbond multiple times // TODO use decimals here @@ -292,14 +291,14 @@ func TestIncrementsMsgUnbond(t *testing.T) { unbondShares = sdk.NewRat(leftBonded + 1) msgBeginUnbonding = NewMsgBeginUnbonding(delegatorAddr, validatorAddr, unbondShares) got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) - assert.False(t, got.IsOK(), + require.False(t, got.IsOK(), "got: %v\nmsgUnbond: %v\nshares: %v\nleftBonded: %v\n", got, msgBeginUnbonding, unbondShares.String(), leftBonded) // should be able to unbond just what we have unbondShares = sdk.NewRat(leftBonded) msgBeginUnbonding = NewMsgBeginUnbonding(delegatorAddr, validatorAddr, unbondShares) got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper) - assert.True(t, got.IsOK(), + require.True(t, got.IsOK(), "got: %v\nmsgUnbond: %v\nshares: %v\nleftBonded: %v\n", got, msgBeginUnbonding, unbondShares, leftBonded) } @@ -420,7 +419,7 @@ func TestRevokeValidator(t *testing.T) { // test that this address cannot yet be bonded too because is revoked got = handleMsgDelegate(ctx, msgDelegate, keeper) - assert.False(t, got.IsOK(), "expected error, got %v", got) + require.False(t, got.IsOK(), "expected error, got %v", got) // test that the delegator can still withdraw their bonds msgBeginUnbondingDelegator := NewMsgBeginUnbonding(delegatorAddr, validatorAddr, sdk.NewRat(10)) @@ -432,7 +431,7 @@ func TestRevokeValidator(t *testing.T) { // verify that the pubkey can now be reused got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper) - assert.True(t, got.IsOK(), "expected ok, got %v", got) + require.True(t, got.IsOK(), "expected ok, got %v", got) } func TestUnbondingPeriod(t *testing.T) { diff --git a/x/stake/keeper/delegation_test.go b/x/stake/keeper/delegation_test.go index d7c1ac984956..f20188ccdcea 100644 --- a/x/stake/keeper/delegation_test.go +++ b/x/stake/keeper/delegation_test.go @@ -6,7 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/stake/types" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -37,20 +36,20 @@ func TestDelegation(t *testing.T) { // check the empty keeper first _, found := keeper.GetDelegation(ctx, addrDels[0], addrVals[0]) - assert.False(t, found) + require.False(t, found) // set and retrieve a record keeper.SetDelegation(ctx, bond1to1) resBond, found := keeper.GetDelegation(ctx, addrDels[0], addrVals[0]) - assert.True(t, found) - assert.True(t, bond1to1.Equal(resBond)) + require.True(t, found) + require.True(t, bond1to1.Equal(resBond)) // modify a records, save, and retrieve bond1to1.Shares = sdk.NewRat(99) keeper.SetDelegation(ctx, bond1to1) resBond, found = keeper.GetDelegation(ctx, addrDels[0], addrVals[0]) - assert.True(t, found) - assert.True(t, bond1to1.Equal(resBond)) + require.True(t, found) + require.True(t, bond1to1.Equal(resBond)) // add some more records bond1to2 := types.Delegation{addrDels[0], addrVals[1], sdk.NewRat(9), 0} @@ -67,43 +66,43 @@ func TestDelegation(t *testing.T) { // test all bond retrieve capabilities resBonds := keeper.GetDelegations(ctx, addrDels[0], 5) require.Equal(t, 3, len(resBonds)) - assert.True(t, bond1to1.Equal(resBonds[0])) - assert.True(t, bond1to2.Equal(resBonds[1])) - assert.True(t, bond1to3.Equal(resBonds[2])) + require.True(t, bond1to1.Equal(resBonds[0])) + require.True(t, bond1to2.Equal(resBonds[1])) + require.True(t, bond1to3.Equal(resBonds[2])) resBonds = keeper.GetDelegations(ctx, addrDels[0], 3) require.Equal(t, 3, len(resBonds)) resBonds = keeper.GetDelegations(ctx, addrDels[0], 2) require.Equal(t, 2, len(resBonds)) resBonds = keeper.GetDelegations(ctx, addrDels[1], 5) require.Equal(t, 3, len(resBonds)) - assert.True(t, bond2to1.Equal(resBonds[0])) - assert.True(t, bond2to2.Equal(resBonds[1])) - assert.True(t, bond2to3.Equal(resBonds[2])) + require.True(t, bond2to1.Equal(resBonds[0])) + require.True(t, bond2to2.Equal(resBonds[1])) + require.True(t, bond2to3.Equal(resBonds[2])) allBonds := keeper.GetAllDelegations(ctx) require.Equal(t, 6, len(allBonds)) - assert.True(t, bond1to1.Equal(allBonds[0])) - assert.True(t, bond1to2.Equal(allBonds[1])) - assert.True(t, bond1to3.Equal(allBonds[2])) - assert.True(t, bond2to1.Equal(allBonds[3])) - assert.True(t, bond2to2.Equal(allBonds[4])) - assert.True(t, bond2to3.Equal(allBonds[5])) + require.True(t, bond1to1.Equal(allBonds[0])) + require.True(t, bond1to2.Equal(allBonds[1])) + require.True(t, bond1to3.Equal(allBonds[2])) + require.True(t, bond2to1.Equal(allBonds[3])) + require.True(t, bond2to2.Equal(allBonds[4])) + require.True(t, bond2to3.Equal(allBonds[5])) // delete a record keeper.RemoveDelegation(ctx, bond2to3) _, found = keeper.GetDelegation(ctx, addrDels[1], addrVals[2]) - assert.False(t, found) + require.False(t, found) resBonds = keeper.GetDelegations(ctx, addrDels[1], 5) require.Equal(t, 2, len(resBonds)) - assert.True(t, bond2to1.Equal(resBonds[0])) - assert.True(t, bond2to2.Equal(resBonds[1])) + require.True(t, bond2to1.Equal(resBonds[0])) + require.True(t, bond2to2.Equal(resBonds[1])) // delete all the records from delegator 2 keeper.RemoveDelegation(ctx, bond2to1) keeper.RemoveDelegation(ctx, bond2to2) _, found = keeper.GetDelegation(ctx, addrDels[1], addrVals[0]) - assert.False(t, found) + require.False(t, found) _, found = keeper.GetDelegation(ctx, addrDels[1], addrVals[1]) - assert.False(t, found) + require.False(t, found) resBonds = keeper.GetDelegations(ctx, addrDels[1], 5) require.Equal(t, 0, len(resBonds)) } @@ -123,20 +122,20 @@ func TestUnbondingDelegation(t *testing.T) { // set and retrieve a record keeper.SetUnbondingDelegation(ctx, ubd) resBond, found := keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0]) - assert.True(t, found) - assert.True(t, ubd.Equal(resBond)) + require.True(t, found) + require.True(t, ubd.Equal(resBond)) // modify a records, save, and retrieve ubd.Balance = sdk.NewCoin("steak", 21) keeper.SetUnbondingDelegation(ctx, ubd) resBond, found = keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0]) - assert.True(t, found) - assert.True(t, ubd.Equal(resBond)) + require.True(t, found) + require.True(t, ubd.Equal(resBond)) // delete a record keeper.RemoveUnbondingDelegation(ctx, ubd) _, found = keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0]) - assert.False(t, found) + require.False(t, found) } func TestUnbondDelegation(t *testing.T) { @@ -166,7 +165,7 @@ func TestUnbondDelegation(t *testing.T) { var amount int64 amount, err = keeper.unbond(ctx, addrDels[0], addrVals[0], sdk.NewRat(6)) require.NoError(t, err) - assert.Equal(t, int64(6), amount) // shares to be added to an unbonding delegation / redelegation + require.Equal(t, int64(6), amount) // shares to be added to an unbonding delegation / redelegation delegation, found := keeper.GetDelegation(ctx, addrDels[0], addrVals[0]) require.True(t, found) @@ -174,10 +173,10 @@ func TestUnbondDelegation(t *testing.T) { require.True(t, found) pool = keeper.GetPool(ctx) - assert.Equal(t, int64(4), delegation.Shares.Evaluate()) - assert.Equal(t, int64(4), validator.PoolShares.Bonded().Evaluate()) - assert.Equal(t, int64(6), pool.LooseTokens, "%v", pool) - assert.Equal(t, int64(4), pool.BondedTokens) + require.Equal(t, int64(4), delegation.Shares.Evaluate()) + require.Equal(t, int64(4), validator.PoolShares.Bonded().Evaluate()) + require.Equal(t, int64(6), pool.LooseTokens, "%v", pool) + require.Equal(t, int64(4), pool.BondedTokens) } // tests Get/Set/Remove/Has UnbondingDelegation @@ -196,28 +195,28 @@ func TestRedelegation(t *testing.T) { // test shouldn't have and redelegations has := keeper.HasReceivingRedelegation(ctx, addrDels[0], addrVals[1]) - assert.False(t, has) + require.False(t, has) // set and retrieve a record keeper.SetRedelegation(ctx, rd) resBond, found := keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1]) - assert.True(t, found) - assert.True(t, rd.Equal(resBond)) + require.True(t, found) + require.True(t, rd.Equal(resBond)) // check if has the redelegation has = keeper.HasReceivingRedelegation(ctx, addrDels[0], addrVals[1]) - assert.True(t, has) + require.True(t, has) // modify a records, save, and retrieve rd.SharesSrc = sdk.NewRat(21) rd.SharesDst = sdk.NewRat(21) keeper.SetRedelegation(ctx, rd) resBond, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1]) - assert.True(t, found) - assert.True(t, rd.Equal(resBond)) + require.True(t, found) + require.True(t, rd.Equal(resBond)) // delete a record keeper.RemoveRedelegation(ctx, rd) _, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1]) - assert.False(t, found) + require.False(t, found) } diff --git a/x/stake/keeper/inflation_test.go b/x/stake/keeper/inflation_test.go index d748ce0cb2ae..944559dfc230 100644 --- a/x/stake/keeper/inflation_test.go +++ b/x/stake/keeper/inflation_test.go @@ -5,7 +5,6 @@ import ( "strconv" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" @@ -61,7 +60,7 @@ func TestGetInflation(t *testing.T) { inflation := keeper.NextInflation(ctx) diffInflation := inflation.Sub(tc.setInflation) - assert.True(t, diffInflation.Equal(tc.expectedChange), + require.True(t, diffInflation.Equal(tc.expectedChange), "Name: %v\nDiff: %v\nExpected: %v\n", tc.name, diffInflation, tc.expectedChange) } } @@ -155,7 +154,7 @@ func TestLargeUnbond(t *testing.T) { pool = keeper.GetPool(ctx) validator, found := keeper.GetValidator(ctx, Addrs[0]) - assert.True(t, found) + require.True(t, found) // initialBondedRatio that we can use to compare to the new values after the unbond initialBondedRatio := pool.BondedRatio() @@ -172,9 +171,9 @@ func TestLargeUnbond(t *testing.T) { unbondedShares = unbondedShares.Add(sdk.NewRat(val0UnbondedTokens, 1).Mul(pool.UnbondedShareExRate())) // unbonded shares should increase - assert.True(t, unbondedShares.GT(sdk.NewRat(300000000, 1))) + require.True(t, unbondedShares.GT(sdk.NewRat(300000000, 1))) // Ensure that new bonded ratio is less than old bonded ratio , because before they were increasing (i.e. 50% < 75) - assert.True(t, (pool.BondedRatio().LT(initialBondedRatio))) + require.True(t, (pool.BondedRatio().LT(initialBondedRatio))) // Final check that the pool equals initial values + provisions and adjustments we recorded pool = keeper.GetPool(ctx) @@ -202,7 +201,7 @@ func TestLargeBond(t *testing.T) { pool = keeper.GetPool(ctx) validator, found := keeper.GetValidator(ctx, Addrs[9]) - assert.True(t, found) + require.True(t, found) // initialBondedRatio that we can use to compare to the new values after the unbond initialBondedRatio := pool.BondedRatio() @@ -220,9 +219,9 @@ func TestLargeBond(t *testing.T) { unbondedShares = unbondedShares.Sub(unbondedSharesVal9) // unbonded shares should decrease - assert.True(t, unbondedShares.LT(sdk.NewRat(1200000000, 1))) + require.True(t, unbondedShares.LT(sdk.NewRat(1200000000, 1))) // Ensure that new bonded ratio is greater than old bonded ratio (i.e. 50% > 25%) - assert.True(t, (pool.BondedRatio().GT(initialBondedRatio))) + require.True(t, (pool.BondedRatio().GT(initialBondedRatio))) // Final check that the pool equals initial values + provisions and adjustments we recorded pool = keeper.GetPool(ctx) @@ -289,7 +288,7 @@ func TestInflationWithRandomOperations(t *testing.T) { // Final check on the global pool values for what the total tokens accumulated from each hour of provisions func checkFinalPoolValues(t *testing.T, pool types.Pool, initialTotalTokens, cumulativeExpProvs int64) { calculatedTotalTokens := initialTotalTokens + cumulativeExpProvs - assert.Equal(t, calculatedTotalTokens, pool.TokenSupply()) + require.Equal(t, calculatedTotalTokens, pool.TokenSupply()) } // Processes provisions are added to the pool correctly every hour @@ -332,14 +331,14 @@ func setupTestValidators(pool types.Pool, keeper Keeper, ctx sdk.Context, valida // Checks that the deterministic validator setup you wanted matches the values in the pool func checkValidatorSetup(t *testing.T, pool types.Pool, initialTotalTokens, initialBondedTokens, initialUnbondedTokens int64) { - assert.Equal(t, initialTotalTokens, pool.TokenSupply(), "%v", pool) - assert.Equal(t, initialBondedTokens, pool.BondedTokens, "%v", pool) - assert.Equal(t, initialUnbondedTokens, pool.UnbondedTokens, "%v", pool) + require.Equal(t, initialTotalTokens, pool.TokenSupply(), "%v", pool) + require.Equal(t, initialBondedTokens, pool.BondedTokens, "%v", pool) + require.Equal(t, initialUnbondedTokens, pool.UnbondedTokens, "%v", pool) // test initial bonded ratio - assert.True(t, pool.BondedRatio().Equal(sdk.NewRat(initialBondedTokens, initialTotalTokens)), "%v", pool.BondedRatio()) + require.True(t, pool.BondedRatio().Equal(sdk.NewRat(initialBondedTokens, initialTotalTokens)), "%v", pool.BondedRatio()) // test the value of validator shares - assert.True(t, pool.BondedShareExRate().Equal(sdk.OneRat()), "%v", pool.BondedShareExRate()) + require.True(t, pool.BondedShareExRate().Equal(sdk.OneRat()), "%v", pool.BondedShareExRate()) } // Checks that The inflation will correctly increase or decrease after an update to the pool @@ -349,30 +348,30 @@ func checkInflation(t *testing.T, pool types.Pool, previousInflation, updatedInf switch { //BELOW 67% - Rate of change positive and increasing, while we are between 7% <= and < 20% inflation case pool.BondedRatio().LT(sdk.NewRat(67, 100)) && updatedInflation.LT(sdk.NewRat(20, 100)): - assert.Equal(t, true, inflationChange.GT(sdk.ZeroRat()), msg) + require.Equal(t, true, inflationChange.GT(sdk.ZeroRat()), msg) //BELOW 67% - Rate of change should be 0 while inflation continually stays at 20% until we reach 67% bonded ratio case pool.BondedRatio().LT(sdk.NewRat(67, 100)) && updatedInflation.Equal(sdk.NewRat(20, 100)): if previousInflation.Equal(sdk.NewRat(20, 100)) { - assert.Equal(t, true, inflationChange.IsZero(), msg) + require.Equal(t, true, inflationChange.IsZero(), msg) //This else statement covers the one off case where we first hit 20%, but we still needed a positive ROC to get to 67% bonded ratio (i.e. we went from 19.99999% to 20%) } else { - assert.Equal(t, true, inflationChange.GT(sdk.ZeroRat()), msg) + require.Equal(t, true, inflationChange.GT(sdk.ZeroRat()), msg) } //ABOVE 67% - Rate of change should be negative while the bond is above 67, and should stay negative until we reach inflation of 7% case pool.BondedRatio().GT(sdk.NewRat(67, 100)) && updatedInflation.LT(sdk.NewRat(20, 100)) && updatedInflation.GT(sdk.NewRat(7, 100)): - assert.Equal(t, true, inflationChange.LT(sdk.ZeroRat()), msg) + require.Equal(t, true, inflationChange.LT(sdk.ZeroRat()), msg) //ABOVE 67% - Rate of change should be 0 while inflation continually stays at 7%. case pool.BondedRatio().GT(sdk.NewRat(67, 100)) && updatedInflation.Equal(sdk.NewRat(7, 100)): if previousInflation.Equal(sdk.NewRat(7, 100)) { - assert.Equal(t, true, inflationChange.IsZero(), msg) + require.Equal(t, true, inflationChange.IsZero(), msg) //This else statement covers the one off case where we first hit 7%, but we still needed a negative ROC to continue to get down to 67%. (i.e. we went from 7.00001% to 7%) } else { - assert.Equal(t, true, inflationChange.LT(sdk.ZeroRat()), msg) + require.Equal(t, true, inflationChange.LT(sdk.ZeroRat()), msg) } } } diff --git a/x/stake/keeper/keeper_test.go b/x/stake/keeper/keeper_test.go index 1be58728505b..15fecf3f2541 100644 --- a/x/stake/keeper/keeper_test.go +++ b/x/stake/keeper/keeper_test.go @@ -3,7 +3,7 @@ package keeper import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/x/stake/types" ) @@ -14,13 +14,13 @@ func TestParams(t *testing.T) { //check that the empty keeper loads the default resParams := keeper.GetParams(ctx) - assert.True(t, expParams.Equal(resParams)) + require.True(t, expParams.Equal(resParams)) //modify a params, save, and retrieve expParams.MaxValidators = 777 keeper.SetParams(ctx, expParams) resParams = keeper.GetParams(ctx) - assert.True(t, expParams.Equal(resParams)) + require.True(t, expParams.Equal(resParams)) } func TestPool(t *testing.T) { @@ -29,11 +29,11 @@ func TestPool(t *testing.T) { //check that the empty keeper loads the default resPool := keeper.GetPool(ctx) - assert.True(t, expPool.Equal(resPool)) + require.True(t, expPool.Equal(resPool)) //modify a params, save, and retrieve expPool.BondedTokens = 777 keeper.SetPool(ctx, expPool) resPool = keeper.GetPool(ctx) - assert.True(t, expPool.Equal(resPool)) + require.True(t, expPool.Equal(resPool)) } diff --git a/x/stake/keeper/validator_test.go b/x/stake/keeper/validator_test.go index 098c17e75f25..cf26d055f6d7 100644 --- a/x/stake/keeper/validator_test.go +++ b/x/stake/keeper/validator_test.go @@ -34,7 +34,7 @@ func TestSetValidator(t *testing.T) { // Check each store for being saved resVal, found := keeper.GetValidator(ctx, addrVals[0]) assert.True(ValEq(t, validator, resVal)) - assert.True(t, found) + require.True(t, found) resVals := keeper.GetValidatorsBonded(ctx) require.Equal(t, 1, len(resVals)) @@ -46,7 +46,7 @@ func TestSetValidator(t *testing.T) { updates := keeper.GetTendermintUpdates(ctx) require.Equal(t, 1, len(updates)) - assert.Equal(t, validator.ABCIValidator(), updates[0]) + require.Equal(t, validator.ABCIValidator(), updates[0]) } @@ -68,29 +68,29 @@ func TestUpdateValidatorByPowerIndex(t *testing.T) { validator := types.NewValidator(addrVals[0], PKs[0], types.Description{}) validator, pool, delSharesCreated := validator.AddTokensFromDel(pool, 100) require.Equal(t, sdk.Unbonded, validator.Status()) - assert.Equal(t, int64(100), validator.PoolShares.Tokens(pool).Evaluate()) + require.Equal(t, int64(100), validator.PoolShares.Tokens(pool).Evaluate()) keeper.SetPool(ctx, pool) keeper.UpdateValidator(ctx, validator) validator, found := keeper.GetValidator(ctx, addrVals[0]) require.True(t, found) - assert.Equal(t, int64(100), validator.PoolShares.Tokens(pool).Evaluate(), "\nvalidator %v\npool %v", validator, pool) + require.Equal(t, int64(100), validator.PoolShares.Tokens(pool).Evaluate(), "\nvalidator %v\npool %v", validator, pool) pool = keeper.GetPool(ctx) power := GetValidatorsByPowerIndexKey(validator, pool) - assert.True(t, keeper.validatorByPowerIndexExists(ctx, power)) + require.True(t, keeper.validatorByPowerIndexExists(ctx, power)) // burn half the delegator shares validator, pool, burned := validator.RemoveDelShares(pool, delSharesCreated.Quo(sdk.NewRat(2))) - assert.Equal(t, int64(50), burned) + require.Equal(t, int64(50), burned) keeper.SetPool(ctx, pool) // update the pool keeper.UpdateValidator(ctx, validator) // update the validator, possibly kicking it out - assert.False(t, keeper.validatorByPowerIndexExists(ctx, power)) + require.False(t, keeper.validatorByPowerIndexExists(ctx, power)) pool = keeper.GetPool(ctx) validator, found = keeper.GetValidator(ctx, addrVals[0]) - assert.True(t, found) + require.True(t, found) power = GetValidatorsByPowerIndexKey(validator, pool) - assert.True(t, keeper.validatorByPowerIndexExists(ctx, power)) + require.True(t, keeper.validatorByPowerIndexExists(ctx, power)) } // This function tests UpdateValidator, GetValidator, GetValidatorsBonded, RemoveValidator @@ -109,7 +109,7 @@ func TestValidatorBasics(t *testing.T) { // check the empty keeper first _, found := keeper.GetValidator(ctx, addrVals[0]) - assert.False(t, found) + require.False(t, found) resVals := keeper.GetValidatorsBonded(ctx) assert.Zero(t, len(resVals)) @@ -154,7 +154,7 @@ func TestValidatorBasics(t *testing.T) { // remove a record keeper.RemoveValidator(ctx, validators[1].Owner) _, found = keeper.GetValidator(ctx, addrVals[1]) - assert.False(t, found) + require.False(t, found) } // test how the validators are sorted, tests GetValidatorsByPower @@ -174,7 +174,7 @@ func GetValidatorSortingUnmixed(t *testing.T) { // first make sure everything made it in to the gotValidator group resValidators := keeper.GetValidatorsByPower(ctx) - require.Equal(t, n, len(resValidators)) + assert.Equal(t, n, len(resValidators)) assert.Equal(t, sdk.NewRat(400), resValidators[0].PoolShares.Bonded(), "%v", resValidators) assert.Equal(t, sdk.NewRat(200), resValidators[1].PoolShares.Bonded(), "%v", resValidators) assert.Equal(t, sdk.NewRat(100), resValidators[2].PoolShares.Bonded(), "%v", resValidators) @@ -209,8 +209,8 @@ func GetValidatorSortingUnmixed(t *testing.T) { require.Equal(t, len(resValidators), n) assert.True(ValEq(t, validators[3], resValidators[0])) assert.True(ValEq(t, validators[4], resValidators[1])) - assert.Equal(t, int64(0), resValidators[0].BondHeight, "%v", resValidators) - assert.Equal(t, int64(0), resValidators[1].BondHeight, "%v", resValidators) + require.Equal(t, int64(0), resValidators[0].BondHeight, "%v", resValidators) + require.Equal(t, int64(0), resValidators[1].BondHeight, "%v", resValidators) // no change in voting power - no change in sort ctx = ctx.WithBlockHeight(20) @@ -269,15 +269,15 @@ func GetValidatorSortingMixed(t *testing.T) { require.True(t, found) val4, found := keeper.GetValidator(ctx, Addrs[4]) require.True(t, found) - assert.Equal(t, sdk.Unbonded, val0.Status()) - assert.Equal(t, sdk.Unbonded, val1.Status()) - assert.Equal(t, sdk.Unbonded, val2.Status()) - assert.Equal(t, sdk.Bonded, val3.Status()) - assert.Equal(t, sdk.Bonded, val4.Status()) + require.Equal(t, sdk.Unbonded, val0.Status()) + require.Equal(t, sdk.Unbonded, val1.Status()) + require.Equal(t, sdk.Unbonded, val2.Status()) + require.Equal(t, sdk.Bonded, val3.Status()) + require.Equal(t, sdk.Bonded, val4.Status()) // first make sure everything made it in to the gotValidator group resValidators := keeper.GetValidatorsByPower(ctx) - require.Equal(t, n, len(resValidators)) + assert.Equal(t, n, len(resValidators)) assert.Equal(t, sdk.NewRat(400), resValidators[0].PoolShares.Bonded(), "%v", resValidators) assert.Equal(t, sdk.NewRat(200), resValidators[1].PoolShares.Bonded(), "%v", resValidators) assert.Equal(t, sdk.NewRat(100), resValidators[2].PoolShares.Bonded(), "%v", resValidators) @@ -438,7 +438,7 @@ func TestFullValidatorSetPowerChange(t *testing.T) { assert.Equal(t, sdk.Bonded, validators[3].Status()) assert.Equal(t, sdk.Unbonded, validators[4].Status()) resValidators := keeper.GetValidatorsByPower(ctx) - require.Equal(t, max, len(resValidators)) + assert.Equal(t, max, len(resValidators)) assert.True(ValEq(t, validators[2], resValidators[0])) // in the order of txs assert.True(ValEq(t, validators[3], resValidators[1])) @@ -448,7 +448,7 @@ func TestFullValidatorSetPowerChange(t *testing.T) { keeper.SetPool(ctx, pool) validators[0] = keeper.UpdateValidator(ctx, validators[0]) resValidators = keeper.GetValidatorsByPower(ctx) - require.Equal(t, max, len(resValidators)) + assert.Equal(t, max, len(resValidators)) assert.True(ValEq(t, validators[0], resValidators[0])) assert.True(ValEq(t, validators[2], resValidators[1])) } @@ -468,10 +468,10 @@ func TestClearTendermintUpdates(t *testing.T) { } updates := keeper.GetTendermintUpdates(ctx) - assert.Equal(t, len(amts), len(updates)) + require.Equal(t, len(amts), len(updates)) keeper.ClearTendermintUpdates(ctx) updates = keeper.GetTendermintUpdates(ctx) - assert.Equal(t, 0, len(updates)) + require.Equal(t, 0, len(updates)) } func TestGetTendermintUpdatesAllNone(t *testing.T) { @@ -488,25 +488,25 @@ func TestGetTendermintUpdatesAllNone(t *testing.T) { // test from nothing to something // tendermintUpdate set: {} -> {c1, c3} - assert.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) + require.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) validators[0] = keeper.UpdateValidator(ctx, validators[0]) validators[1] = keeper.UpdateValidator(ctx, validators[1]) updates := keeper.GetTendermintUpdates(ctx) - require.Equal(t, 2, len(updates)) + assert.Equal(t, 2, len(updates)) assert.Equal(t, validators[0].ABCIValidator(), updates[0]) assert.Equal(t, validators[1].ABCIValidator(), updates[1]) // test from something to nothing // tendermintUpdate set: {} -> {c1, c2, c3, c4} keeper.ClearTendermintUpdates(ctx) - assert.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) + require.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) keeper.RemoveValidator(ctx, validators[0].Owner) keeper.RemoveValidator(ctx, validators[1].Owner) updates = keeper.GetTendermintUpdates(ctx) - require.Equal(t, 2, len(updates)) + assert.Equal(t, 2, len(updates)) assert.Equal(t, tmtypes.TM2PB.PubKey(validators[0].PubKey), updates[0].PubKey) assert.Equal(t, tmtypes.TM2PB.PubKey(validators[1].PubKey), updates[1].PubKey) assert.Equal(t, int64(0), updates[0].Power) @@ -527,13 +527,13 @@ func TestGetTendermintUpdatesIdentical(t *testing.T) { validators[0] = keeper.UpdateValidator(ctx, validators[0]) validators[1] = keeper.UpdateValidator(ctx, validators[1]) keeper.ClearTendermintUpdates(ctx) - assert.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) + require.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) // test identical, // tendermintUpdate set: {} -> {} validators[0] = keeper.UpdateValidator(ctx, validators[0]) validators[1] = keeper.UpdateValidator(ctx, validators[1]) - assert.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) + require.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) } func TestGetTendermintUpdatesSingleValueChange(t *testing.T) { @@ -550,7 +550,7 @@ func TestGetTendermintUpdatesSingleValueChange(t *testing.T) { validators[0] = keeper.UpdateValidator(ctx, validators[0]) validators[1] = keeper.UpdateValidator(ctx, validators[1]) keeper.ClearTendermintUpdates(ctx) - assert.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) + require.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) // test single value change // tendermintUpdate set: {} -> {c1'} @@ -560,7 +560,7 @@ func TestGetTendermintUpdatesSingleValueChange(t *testing.T) { updates := keeper.GetTendermintUpdates(ctx) require.Equal(t, 1, len(updates)) - assert.Equal(t, validators[0].ABCIValidator(), updates[0]) + require.Equal(t, validators[0].ABCIValidator(), updates[0]) } func TestGetTendermintUpdatesMultipleValueChange(t *testing.T) { @@ -577,7 +577,7 @@ func TestGetTendermintUpdatesMultipleValueChange(t *testing.T) { validators[0] = keeper.UpdateValidator(ctx, validators[0]) validators[1] = keeper.UpdateValidator(ctx, validators[1]) keeper.ClearTendermintUpdates(ctx) - assert.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) + require.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) // test multiple value change // tendermintUpdate set: {c1, c3} -> {c1', c3'} @@ -608,7 +608,7 @@ func TestGetTendermintUpdatesInserted(t *testing.T) { validators[0] = keeper.UpdateValidator(ctx, validators[0]) validators[1] = keeper.UpdateValidator(ctx, validators[1]) keeper.ClearTendermintUpdates(ctx) - assert.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) + require.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) // test validtor added at the beginning // tendermintUpdate set: {} -> {c0} @@ -651,7 +651,7 @@ func TestGetTendermintUpdatesNotValidatorCliff(t *testing.T) { validators[0] = keeper.UpdateValidator(ctx, validators[0]) validators[1] = keeper.UpdateValidator(ctx, validators[1]) keeper.ClearTendermintUpdates(ctx) - assert.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) + require.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) // test validator added at the end but not inserted in the valset // tendermintUpdate set: {} -> {} @@ -662,7 +662,7 @@ func TestGetTendermintUpdatesNotValidatorCliff(t *testing.T) { // test validator change its power and become a gotValidator (pushing out an existing) // tendermintUpdate set: {} -> {c0, c4} keeper.ClearTendermintUpdates(ctx) - assert.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) + require.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx))) pool := keeper.GetPool(ctx) validators[2], pool, _ = validators[2].AddTokensFromDel(pool, 10) diff --git a/x/stake/types/msg_test.go b/x/stake/types/msg_test.go index 343ceb79f37c..f3d8bc686fb5 100644 --- a/x/stake/types/msg_test.go +++ b/x/stake/types/msg_test.go @@ -3,7 +3,6 @@ package types import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" @@ -39,9 +38,9 @@ func TestMsgCreateValidator(t *testing.T) { description := NewDescription(tc.moniker, tc.identity, tc.website, tc.details) msg := NewMsgCreateValidator(tc.validatorAddr, tc.pubkey, tc.bond, description) if tc.expectPass { - assert.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) + require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) } else { - assert.NotNil(t, msg.ValidateBasic(), "test: %v", tc.name) + require.NotNil(t, msg.ValidateBasic(), "test: %v", tc.name) } } } @@ -63,9 +62,9 @@ func TestMsgEditValidator(t *testing.T) { description := NewDescription(tc.moniker, tc.identity, tc.website, tc.details) msg := NewMsgEditValidator(tc.validatorAddr, description) if tc.expectPass { - assert.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) + require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) } else { - assert.NotNil(t, msg.ValidateBasic(), "test: %v", tc.name) + require.NotNil(t, msg.ValidateBasic(), "test: %v", tc.name) } } } @@ -90,9 +89,9 @@ func TestMsgDelegate(t *testing.T) { for _, tc := range tests { msg := NewMsgDelegate(tc.delegatorAddr, tc.validatorAddr, tc.bond) if tc.expectPass { - assert.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) + require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) } else { - assert.NotNil(t, msg.ValidateBasic(), "test: %v", tc.name) + require.NotNil(t, msg.ValidateBasic(), "test: %v", tc.name) } } } @@ -219,8 +218,8 @@ func TestMsgCompleteUnbonding(t *testing.T) { //var tx sdk.Tx //bs := wire.BinaryBytes(tc.tx) //err := wire.ReadBinaryBytes(bs, &tx) -//if assert.NoError(t, err, "%d", i) { -//assert.Equal(t, tc.tx, tx, "%d", i) +//if require.NoError(t, err, "%d", i) { +//require.Equal(t, tc.tx, tx, "%d", i) //} //} //} diff --git a/x/stake/types/pool_test.go b/x/stake/types/pool_test.go index 21dd4ff4d87a..a62c69d46886 100644 --- a/x/stake/types/pool_test.go +++ b/x/stake/types/pool_test.go @@ -3,7 +3,6 @@ package types import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" @@ -66,48 +65,48 @@ func TestAddTokensBonded(t *testing.T) { poolA := InitialPool() poolA.LooseTokens = 10 - assert.Equal(t, poolA.BondedShareExRate(), sdk.OneRat()) + require.Equal(t, poolA.BondedShareExRate(), sdk.OneRat()) poolB, sharesB := poolA.addTokensBonded(10) - assert.Equal(t, poolB.BondedShareExRate(), sdk.OneRat()) + require.Equal(t, poolB.BondedShareExRate(), sdk.OneRat()) // correct changes to bonded shares and bonded pool - assert.Equal(t, poolB.BondedShares, poolA.BondedShares.Add(sharesB.Amount)) - assert.Equal(t, poolB.BondedTokens, poolA.BondedTokens+10) + require.Equal(t, poolB.BondedShares, poolA.BondedShares.Add(sharesB.Amount)) + require.Equal(t, poolB.BondedTokens, poolA.BondedTokens+10) // same number of bonded shares / tokens when exchange rate is one - assert.True(t, poolB.BondedShares.Equal(sdk.NewRat(poolB.BondedTokens))) + require.True(t, poolB.BondedShares.Equal(sdk.NewRat(poolB.BondedTokens))) } func TestRemoveSharesBonded(t *testing.T) { poolA := InitialPool() poolA.LooseTokens = 10 - assert.Equal(t, poolA.BondedShareExRate(), sdk.OneRat()) + require.Equal(t, poolA.BondedShareExRate(), sdk.OneRat()) poolB, tokensB := poolA.removeSharesBonded(sdk.NewRat(10)) - assert.Equal(t, poolB.BondedShareExRate(), sdk.OneRat()) + require.Equal(t, poolB.BondedShareExRate(), sdk.OneRat()) // correct changes to bonded shares and bonded pool - assert.Equal(t, poolB.BondedShares, poolA.BondedShares.Sub(sdk.NewRat(10))) - assert.Equal(t, poolB.BondedTokens, poolA.BondedTokens-tokensB) + require.Equal(t, poolB.BondedShares, poolA.BondedShares.Sub(sdk.NewRat(10))) + require.Equal(t, poolB.BondedTokens, poolA.BondedTokens-tokensB) // same number of bonded shares / tokens when exchange rate is one - assert.True(t, poolB.BondedShares.Equal(sdk.NewRat(poolB.BondedTokens))) + require.True(t, poolB.BondedShares.Equal(sdk.NewRat(poolB.BondedTokens))) } func TestAddTokensUnbonded(t *testing.T) { poolA := InitialPool() poolA.LooseTokens = 10 - assert.Equal(t, poolA.UnbondedShareExRate(), sdk.OneRat()) + require.Equal(t, poolA.UnbondedShareExRate(), sdk.OneRat()) poolB, sharesB := poolA.addTokensUnbonded(10) - assert.Equal(t, poolB.UnbondedShareExRate(), sdk.OneRat()) + require.Equal(t, poolB.UnbondedShareExRate(), sdk.OneRat()) // correct changes to unbonded shares and unbonded pool - assert.Equal(t, poolB.UnbondedShares, poolA.UnbondedShares.Add(sharesB.Amount)) - assert.Equal(t, poolB.UnbondedTokens, poolA.UnbondedTokens+10) + require.Equal(t, poolB.UnbondedShares, poolA.UnbondedShares.Add(sharesB.Amount)) + require.Equal(t, poolB.UnbondedTokens, poolA.UnbondedTokens+10) // same number of unbonded shares / tokens when exchange rate is one - assert.True(t, poolB.UnbondedShares.Equal(sdk.NewRat(poolB.UnbondedTokens))) + require.True(t, poolB.UnbondedShares.Equal(sdk.NewRat(poolB.UnbondedTokens))) } func TestRemoveSharesUnbonded(t *testing.T) { @@ -115,14 +114,14 @@ func TestRemoveSharesUnbonded(t *testing.T) { poolA := InitialPool() poolA.UnbondedTokens = 10 poolA.UnbondedShares = sdk.NewRat(10) - assert.Equal(t, poolA.UnbondedShareExRate(), sdk.OneRat()) + require.Equal(t, poolA.UnbondedShareExRate(), sdk.OneRat()) poolB, tokensB := poolA.removeSharesUnbonded(sdk.NewRat(10)) - assert.Equal(t, poolB.UnbondedShareExRate(), sdk.OneRat()) + require.Equal(t, poolB.UnbondedShareExRate(), sdk.OneRat()) // correct changes to unbonded shares and bonded pool - assert.Equal(t, poolB.UnbondedShares, poolA.UnbondedShares.Sub(sdk.NewRat(10))) - assert.Equal(t, poolB.UnbondedTokens, poolA.UnbondedTokens-tokensB) + require.Equal(t, poolB.UnbondedShares, poolA.UnbondedShares.Sub(sdk.NewRat(10))) + require.Equal(t, poolB.UnbondedTokens, poolA.UnbondedTokens-tokensB) // same number of unbonded shares / tokens when exchange rate is one - assert.True(t, poolB.UnbondedShares.Equal(sdk.NewRat(poolB.UnbondedTokens))) + require.True(t, poolB.UnbondedShares.Equal(sdk.NewRat(poolB.UnbondedTokens))) } diff --git a/x/stake/types/validator_test.go b/x/stake/types/validator_test.go index 2af3ace407fe..6a8ff777a65d 100644 --- a/x/stake/types/validator_test.go +++ b/x/stake/types/validator_test.go @@ -18,10 +18,10 @@ func TestAddTokensValidatorBonded(t *testing.T) { val, pool = val.UpdateStatus(pool, sdk.Bonded) val, pool, delShares := val.AddTokensFromDel(pool, 10) - assert.Equal(t, sdk.OneRat(), val.DelegatorShareExRate(pool)) - assert.Equal(t, sdk.OneRat(), pool.BondedShareExRate()) - assert.Equal(t, sdk.OneRat(), pool.UnbondingShareExRate()) - assert.Equal(t, sdk.OneRat(), pool.UnbondedShareExRate()) + require.Equal(t, sdk.OneRat(), val.DelegatorShareExRate(pool)) + require.Equal(t, sdk.OneRat(), pool.BondedShareExRate()) + require.Equal(t, sdk.OneRat(), pool.UnbondingShareExRate()) + require.Equal(t, sdk.OneRat(), pool.UnbondedShareExRate()) assert.True(sdk.RatEq(t, sdk.NewRat(10), delShares)) assert.True(sdk.RatEq(t, sdk.NewRat(10), val.PoolShares.Bonded())) @@ -34,10 +34,10 @@ func TestAddTokensValidatorUnbonding(t *testing.T) { val, pool = val.UpdateStatus(pool, sdk.Unbonding) val, pool, delShares := val.AddTokensFromDel(pool, 10) - assert.Equal(t, sdk.OneRat(), val.DelegatorShareExRate(pool)) - assert.Equal(t, sdk.OneRat(), pool.BondedShareExRate()) - assert.Equal(t, sdk.OneRat(), pool.UnbondingShareExRate()) - assert.Equal(t, sdk.OneRat(), pool.UnbondedShareExRate()) + require.Equal(t, sdk.OneRat(), val.DelegatorShareExRate(pool)) + require.Equal(t, sdk.OneRat(), pool.BondedShareExRate()) + require.Equal(t, sdk.OneRat(), pool.UnbondingShareExRate()) + require.Equal(t, sdk.OneRat(), pool.UnbondedShareExRate()) assert.True(sdk.RatEq(t, sdk.NewRat(10), delShares)) assert.True(sdk.RatEq(t, sdk.NewRat(10), val.PoolShares.Unbonding())) @@ -50,10 +50,10 @@ func TestAddTokensValidatorUnbonded(t *testing.T) { val, pool = val.UpdateStatus(pool, sdk.Unbonded) val, pool, delShares := val.AddTokensFromDel(pool, 10) - assert.Equal(t, sdk.OneRat(), val.DelegatorShareExRate(pool)) - assert.Equal(t, sdk.OneRat(), pool.BondedShareExRate()) - assert.Equal(t, sdk.OneRat(), pool.UnbondingShareExRate()) - assert.Equal(t, sdk.OneRat(), pool.UnbondedShareExRate()) + require.Equal(t, sdk.OneRat(), val.DelegatorShareExRate(pool)) + require.Equal(t, sdk.OneRat(), pool.BondedShareExRate()) + require.Equal(t, sdk.OneRat(), pool.UnbondingShareExRate()) + require.Equal(t, sdk.OneRat(), pool.UnbondedShareExRate()) assert.True(sdk.RatEq(t, sdk.NewRat(10), delShares)) assert.True(sdk.RatEq(t, sdk.NewRat(10), val.PoolShares.Unbonded())) @@ -71,17 +71,17 @@ func TestRemoveDelShares(t *testing.T) { } poolA.BondedTokens = valA.PoolShares.Bonded().Evaluate() poolA.BondedShares = valA.PoolShares.Bonded() - assert.Equal(t, valA.DelegatorShareExRate(poolA), sdk.OneRat()) - assert.Equal(t, poolA.BondedShareExRate(), sdk.OneRat()) - assert.Equal(t, poolA.UnbondedShareExRate(), sdk.OneRat()) + require.Equal(t, valA.DelegatorShareExRate(poolA), sdk.OneRat()) + require.Equal(t, poolA.BondedShareExRate(), sdk.OneRat()) + require.Equal(t, poolA.UnbondedShareExRate(), sdk.OneRat()) valB, poolB, coinsB := valA.RemoveDelShares(poolA, sdk.NewRat(10)) // coins were created - assert.Equal(t, coinsB, int64(10)) + require.Equal(t, coinsB, int64(10)) // pool shares were removed - assert.Equal(t, valB.PoolShares.Bonded(), valA.PoolShares.Bonded().Sub(sdk.NewRat(10).Mul(valA.DelegatorShareExRate(poolA)))) + require.Equal(t, valB.PoolShares.Bonded(), valA.PoolShares.Bonded().Sub(sdk.NewRat(10).Mul(valA.DelegatorShareExRate(poolA)))) // conservation of tokens - assert.Equal(t, poolB.UnbondedTokens+poolB.BondedTokens+coinsB, poolA.UnbondedTokens+poolA.BondedTokens) + require.Equal(t, poolB.UnbondedTokens+poolB.BondedTokens+coinsB, poolA.UnbondedTokens+poolA.BondedTokens) // specific case from random tests poolShares := sdk.NewRat(5102) @@ -117,28 +117,28 @@ func TestUpdateStatus(t *testing.T) { val := NewValidator(addr1, pk1, Description{}) val, pool, _ = val.AddTokensFromDel(pool, 100) - assert.Equal(t, int64(0), val.PoolShares.Bonded().Evaluate()) - assert.Equal(t, int64(0), val.PoolShares.Unbonding().Evaluate()) - assert.Equal(t, int64(100), val.PoolShares.Unbonded().Evaluate()) - assert.Equal(t, int64(0), pool.BondedTokens) - assert.Equal(t, int64(0), pool.UnbondingTokens) - assert.Equal(t, int64(100), pool.UnbondedTokens) + require.Equal(t, int64(0), val.PoolShares.Bonded().Evaluate()) + require.Equal(t, int64(0), val.PoolShares.Unbonding().Evaluate()) + require.Equal(t, int64(100), val.PoolShares.Unbonded().Evaluate()) + require.Equal(t, int64(0), pool.BondedTokens) + require.Equal(t, int64(0), pool.UnbondingTokens) + require.Equal(t, int64(100), pool.UnbondedTokens) val, pool = val.UpdateStatus(pool, sdk.Unbonding) - assert.Equal(t, int64(0), val.PoolShares.Bonded().Evaluate()) - assert.Equal(t, int64(100), val.PoolShares.Unbonding().Evaluate()) - assert.Equal(t, int64(0), val.PoolShares.Unbonded().Evaluate()) - assert.Equal(t, int64(0), pool.BondedTokens) - assert.Equal(t, int64(100), pool.UnbondingTokens) - assert.Equal(t, int64(0), pool.UnbondedTokens) + require.Equal(t, int64(0), val.PoolShares.Bonded().Evaluate()) + require.Equal(t, int64(100), val.PoolShares.Unbonding().Evaluate()) + require.Equal(t, int64(0), val.PoolShares.Unbonded().Evaluate()) + require.Equal(t, int64(0), pool.BondedTokens) + require.Equal(t, int64(100), pool.UnbondingTokens) + require.Equal(t, int64(0), pool.UnbondedTokens) val, pool = val.UpdateStatus(pool, sdk.Bonded) - assert.Equal(t, int64(100), val.PoolShares.Bonded().Evaluate()) - assert.Equal(t, int64(0), val.PoolShares.Unbonding().Evaluate()) - assert.Equal(t, int64(0), val.PoolShares.Unbonded().Evaluate()) - assert.Equal(t, int64(100), pool.BondedTokens) - assert.Equal(t, int64(0), pool.UnbondingTokens) - assert.Equal(t, int64(0), pool.UnbondedTokens) + require.Equal(t, int64(100), val.PoolShares.Bonded().Evaluate()) + require.Equal(t, int64(0), val.PoolShares.Unbonding().Evaluate()) + require.Equal(t, int64(0), val.PoolShares.Unbonded().Evaluate()) + require.Equal(t, int64(100), pool.BondedTokens) + require.Equal(t, int64(0), pool.UnbondingTokens) + require.Equal(t, int64(0), pool.UnbondedTokens) } func TestPossibleOverflow(t *testing.T) {