lint: various linting fixs (#5825)
* lint: various linting fixs Signed-off-by: Marko Baricevic <marbar3778@yahoo.com> * more linting * more linting fixes * more errchecking * comment out errcheck for now * undo error check * address some comments * remore require error * change delete to batch delete Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
parent
22f377a858
commit
d657513741
|
@ -9,6 +9,7 @@ linters:
|
|||
- deadcode
|
||||
- depguard
|
||||
- dogsled
|
||||
# - errcheck
|
||||
- goconst
|
||||
- gocritic
|
||||
- gofmt
|
||||
|
|
|
@ -34,8 +34,8 @@ func Test_runAddCmdBasic(t *testing.T) {
|
|||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("keyname1", "", false)
|
||||
kb.Delete("keyname2", "", false)
|
||||
kb.Delete("keyname1", "", false) // nolint:errcheck
|
||||
kb.Delete("keyname2", "", false) // nolint:errcheck
|
||||
})
|
||||
}
|
||||
assert.NoError(t, runAddCmd(cmd, []string{"keyname1"}))
|
||||
|
|
|
@ -30,8 +30,8 @@ func Test_runDeleteCmd(t *testing.T) {
|
|||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("runDeleteCmd_Key1", "", false)
|
||||
kb.Delete("runDeleteCmd_Key2", "", false)
|
||||
kb.Delete("runDeleteCmd_Key1", "", false) // nolint:errcheck
|
||||
kb.Delete("runDeleteCmd_Key2", "", false) // nolint:errcheck
|
||||
|
||||
})
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ func Test_runExportCmd(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
if !runningUnattended {
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("keyname1", "", false)
|
||||
kb.Delete("keyname1", "", false) // nolint:errcheck
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ func Test_runImportCmd(t *testing.T) {
|
|||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("keyname1", "", false)
|
||||
kb.Delete("keyname1", "", false) // nolint:errcheck
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,8 @@ func Test_runListCmd(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("something", "", false)
|
||||
kb.Delete("something", "", false) // nolint:errcheck
|
||||
|
||||
})
|
||||
testData := []struct {
|
||||
name string
|
||||
|
|
|
@ -340,8 +340,7 @@ func (kb dbKeybase) Import(name string, armor string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
kb.db.Set(infoKey(name), infoBytes)
|
||||
return nil
|
||||
return kb.db.Set(infoKey(name), infoBytes)
|
||||
}
|
||||
|
||||
// ImportPubKey imports ASCII-armored public keys. Store a new Info object holding
|
||||
|
@ -388,10 +387,13 @@ func (kb dbKeybase) Delete(name, passphrase string, skipPass bool) error {
|
|||
}
|
||||
}
|
||||
|
||||
kb.db.DeleteSync(addrKey(info.GetAddress()))
|
||||
kb.db.DeleteSync(infoKey(name))
|
||||
batch := kb.db.NewBatch()
|
||||
defer batch.Close()
|
||||
|
||||
return nil
|
||||
batch.Delete(addrKey(info.GetAddress()))
|
||||
batch.Delete(infoKey(name))
|
||||
|
||||
return batch.WriteSync()
|
||||
}
|
||||
|
||||
// Update changes the passphrase with which an already stored key is
|
||||
|
|
|
@ -225,7 +225,8 @@ func TestSignVerify(t *testing.T) {
|
|||
// Import a public key
|
||||
armor, err := cstore.ExportPubKey(n2)
|
||||
require.Nil(t, err)
|
||||
cstore.ImportPubKey(n3, armor)
|
||||
err = cstore.ImportPubKey(n3, armor)
|
||||
require.NoError(t, err)
|
||||
i3, err := cstore.Get(n3)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, i3.GetName(), n3)
|
||||
|
|
|
@ -155,7 +155,8 @@ func TestLazySignVerifyKeyRing(t *testing.T) {
|
|||
// Import a public key
|
||||
armor, err := kb.ExportPubKey(n2)
|
||||
require.Nil(t, err)
|
||||
kb.ImportPubKey(n3, armor)
|
||||
err = kb.ImportPubKey(n3, armor)
|
||||
require.NoError(t, err)
|
||||
i3, err := kb.Get(n3)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, i3.GetName(), n3)
|
||||
|
|
|
@ -128,7 +128,8 @@ func TestLazySignVerify(t *testing.T) {
|
|||
// Import a public key
|
||||
armor, err := kb.ExportPubKey(n2)
|
||||
require.Nil(t, err)
|
||||
kb.ImportPubKey(n3, armor)
|
||||
err = kb.ImportPubKey(n3, armor)
|
||||
require.NoError(t, err)
|
||||
i3, err := kb.Get(n3)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, i3.GetName(), n3)
|
||||
|
|
|
@ -231,13 +231,13 @@ func TestCacheKVMergeIteratorDeletes(t *testing.T) {
|
|||
// set some items and write them
|
||||
nItems := 10
|
||||
for i := 0; i < nItems; i++ {
|
||||
doOp(st, truth, opSet, i)
|
||||
doOp(t, st, truth, opSet, i)
|
||||
}
|
||||
st.Write()
|
||||
|
||||
// delete every other item, starting from 0
|
||||
for i := 0; i < nItems; i += 2 {
|
||||
doOp(st, truth, opDel, i)
|
||||
doOp(t, st, truth, opDel, i)
|
||||
assertIterateDomainCompare(t, st, truth)
|
||||
}
|
||||
|
||||
|
@ -247,13 +247,13 @@ func TestCacheKVMergeIteratorDeletes(t *testing.T) {
|
|||
|
||||
// set some items and write them
|
||||
for i := 0; i < nItems; i++ {
|
||||
doOp(st, truth, opSet, i)
|
||||
doOp(t, st, truth, opSet, i)
|
||||
}
|
||||
st.Write()
|
||||
|
||||
// delete every other item, starting from 1
|
||||
for i := 1; i < nItems; i += 2 {
|
||||
doOp(st, truth, opDel, i)
|
||||
doOp(t, st, truth, opDel, i)
|
||||
assertIterateDomainCompare(t, st, truth)
|
||||
}
|
||||
}
|
||||
|
@ -265,27 +265,27 @@ func TestCacheKVMergeIteratorChunks(t *testing.T) {
|
|||
truth := dbm.NewMemDB()
|
||||
|
||||
// sets to the parent
|
||||
setRange(st, truth, 0, 20)
|
||||
setRange(st, truth, 40, 60)
|
||||
setRange(t, st, truth, 0, 20)
|
||||
setRange(t, st, truth, 40, 60)
|
||||
st.Write()
|
||||
|
||||
// sets to the cache
|
||||
setRange(st, truth, 20, 40)
|
||||
setRange(st, truth, 60, 80)
|
||||
setRange(t, st, truth, 20, 40)
|
||||
setRange(t, st, truth, 60, 80)
|
||||
assertIterateDomainCheck(t, st, truth, []keyRange{{0, 80}})
|
||||
|
||||
// remove some parents and some cache
|
||||
deleteRange(st, truth, 15, 25)
|
||||
deleteRange(t, st, truth, 15, 25)
|
||||
assertIterateDomainCheck(t, st, truth, []keyRange{{0, 15}, {25, 80}})
|
||||
|
||||
// remove some parents and some cache
|
||||
deleteRange(st, truth, 35, 45)
|
||||
deleteRange(t, st, truth, 35, 45)
|
||||
assertIterateDomainCheck(t, st, truth, []keyRange{{0, 15}, {25, 35}, {45, 80}})
|
||||
|
||||
// write, add more to the cache, and delete some cache
|
||||
st.Write()
|
||||
setRange(st, truth, 38, 42)
|
||||
deleteRange(st, truth, 40, 43)
|
||||
setRange(t, st, truth, 38, 42)
|
||||
deleteRange(t, st, truth, 40, 43)
|
||||
assertIterateDomainCheck(t, st, truth, []keyRange{{0, 15}, {25, 35}, {38, 40}, {45, 80}})
|
||||
}
|
||||
|
||||
|
@ -295,11 +295,11 @@ func TestCacheKVMergeIteratorRandom(t *testing.T) {
|
|||
|
||||
start, end := 25, 975
|
||||
max := 1000
|
||||
setRange(st, truth, start, end)
|
||||
setRange(t, st, truth, start, end)
|
||||
|
||||
// do an op, test the iterator
|
||||
for i := 0; i < 2000; i++ {
|
||||
doRandomOp(st, truth, max)
|
||||
doRandomOp(t, st, truth, max)
|
||||
assertIterateDomainCompare(t, st, truth)
|
||||
}
|
||||
}
|
||||
|
@ -322,48 +322,52 @@ func randInt(n int) int {
|
|||
}
|
||||
|
||||
// useful for replaying a error case if we find one
|
||||
func doOp(st types.CacheKVStore, truth dbm.DB, op int, args ...int) {
|
||||
func doOp(t *testing.T, st types.CacheKVStore, truth dbm.DB, op int, args ...int) {
|
||||
switch op {
|
||||
case opSet:
|
||||
k := args[0]
|
||||
st.Set(keyFmt(k), valFmt(k))
|
||||
truth.Set(keyFmt(k), valFmt(k))
|
||||
err := truth.Set(keyFmt(k), valFmt(k))
|
||||
require.NoError(t, err)
|
||||
case opSetRange:
|
||||
start := args[0]
|
||||
end := args[1]
|
||||
setRange(st, truth, start, end)
|
||||
setRange(t, st, truth, start, end)
|
||||
case opDel:
|
||||
k := args[0]
|
||||
st.Delete(keyFmt(k))
|
||||
truth.Delete(keyFmt(k))
|
||||
err := truth.Delete(keyFmt(k))
|
||||
require.NoError(t, err)
|
||||
case opDelRange:
|
||||
start := args[0]
|
||||
end := args[1]
|
||||
deleteRange(st, truth, start, end)
|
||||
deleteRange(t, st, truth, start, end)
|
||||
case opWrite:
|
||||
st.Write()
|
||||
}
|
||||
}
|
||||
|
||||
func doRandomOp(st types.CacheKVStore, truth dbm.DB, maxKey int) {
|
||||
func doRandomOp(t *testing.T, st types.CacheKVStore, truth dbm.DB, maxKey int) {
|
||||
r := randInt(totalOps)
|
||||
switch r {
|
||||
case opSet:
|
||||
k := randInt(maxKey)
|
||||
st.Set(keyFmt(k), valFmt(k))
|
||||
truth.Set(keyFmt(k), valFmt(k))
|
||||
err := truth.Set(keyFmt(k), valFmt(k))
|
||||
require.NoError(t, err)
|
||||
case opSetRange:
|
||||
start := randInt(maxKey - 2)
|
||||
end := randInt(maxKey-start) + start
|
||||
setRange(st, truth, start, end)
|
||||
setRange(t, st, truth, start, end)
|
||||
case opDel:
|
||||
k := randInt(maxKey)
|
||||
st.Delete(keyFmt(k))
|
||||
truth.Delete(keyFmt(k))
|
||||
err := truth.Delete(keyFmt(k))
|
||||
require.NoError(t, err)
|
||||
case opDelRange:
|
||||
start := randInt(maxKey - 2)
|
||||
end := randInt(maxKey-start) + start
|
||||
deleteRange(st, truth, start, end)
|
||||
deleteRange(t, st, truth, start, end)
|
||||
case opWrite:
|
||||
st.Write()
|
||||
}
|
||||
|
@ -439,17 +443,19 @@ func checkIterators(t *testing.T, itr, itr2 types.Iterator) {
|
|||
|
||||
//--------------------------------------------------------
|
||||
|
||||
func setRange(st types.KVStore, mem dbm.DB, start, end int) {
|
||||
func setRange(t *testing.T, st types.KVStore, mem dbm.DB, start, end int) {
|
||||
for i := start; i < end; i++ {
|
||||
st.Set(keyFmt(i), valFmt(i))
|
||||
mem.Set(keyFmt(i), valFmt(i))
|
||||
err := mem.Set(keyFmt(i), valFmt(i))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
func deleteRange(st types.KVStore, mem dbm.DB, start, end int) {
|
||||
func deleteRange(t *testing.T, st types.KVStore, mem dbm.DB, start, end int) {
|
||||
for i := start; i < end; i++ {
|
||||
st.Delete(keyFmt(i))
|
||||
mem.Delete(keyFmt(i))
|
||||
err := mem.Delete(keyFmt(i))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ func TestImmutableTreePanics(t *testing.T) {
|
|||
it := &immutableTree{immTree}
|
||||
require.Panics(t, func() { it.Set([]byte{}, []byte{}) })
|
||||
require.Panics(t, func() { it.Remove([]byte{}) })
|
||||
require.Panics(t, func() { it.SaveVersion() })
|
||||
require.Panics(t, func() { it.DeleteVersion(int64(1)) })
|
||||
require.Panics(t, func() { it.SaveVersion() }) // nolint:errcheck
|
||||
require.Panics(t, func() { it.DeleteVersion(int64(1)) }) // nolint:errcheck
|
||||
v, _ := it.GetVersioned([]byte{0x01}, 1)
|
||||
require.Equal(t, int64(-1), v)
|
||||
v, _ = it.GetVersioned([]byte{0x01}, 0)
|
||||
|
|
|
@ -33,9 +33,11 @@ func genRandomKVPairs(t *testing.T) []kvpair {
|
|||
|
||||
for i := 0; i < 20; i++ {
|
||||
kvps[i].key = make([]byte, 32)
|
||||
rand.Read(kvps[i].key)
|
||||
_, err := rand.Read(kvps[i].key)
|
||||
require.NoError(t, err)
|
||||
kvps[i].value = make([]byte, 32)
|
||||
rand.Read(kvps[i].value)
|
||||
_, err = rand.Read(kvps[i].value)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
return kvps
|
||||
|
|
|
@ -116,7 +116,8 @@ func TestVerifyMultiStoreQueryProofEmptyStore(t *testing.T) {
|
|||
iavlStoreKey := types.NewKVStoreKey("iavlStoreKey")
|
||||
|
||||
store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil)
|
||||
store.LoadVersion(0)
|
||||
err := store.LoadVersion(0)
|
||||
require.NoError(t, err)
|
||||
cid := store.Commit() // Commit with empty iavl store.
|
||||
|
||||
// Get Proof
|
||||
|
@ -129,7 +130,7 @@ func TestVerifyMultiStoreQueryProofEmptyStore(t *testing.T) {
|
|||
|
||||
// Verify proof.
|
||||
prt := DefaultProofRuntime()
|
||||
err := prt.VerifyAbsence(res.Proof, cid.Hash, "/iavlStoreKey/MYKEY")
|
||||
err = prt.VerifyAbsence(res.Proof, cid.Hash, "/iavlStoreKey/MYKEY")
|
||||
require.Nil(t, err)
|
||||
|
||||
// Verify (bad) proof.
|
||||
|
@ -145,7 +146,8 @@ func TestVerifyMultiStoreQueryProofAbsence(t *testing.T) {
|
|||
iavlStoreKey := types.NewKVStoreKey("iavlStoreKey")
|
||||
|
||||
store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil)
|
||||
store.LoadVersion(0)
|
||||
err := store.LoadVersion(0)
|
||||
require.NoError(t, err)
|
||||
|
||||
iavlStore := store.GetCommitStore(iavlStoreKey).(*iavl.Store)
|
||||
iavlStore.Set([]byte("MYKEY"), []byte("MYVALUE"))
|
||||
|
@ -161,7 +163,7 @@ func TestVerifyMultiStoreQueryProofAbsence(t *testing.T) {
|
|||
|
||||
// Verify proof.
|
||||
prt := DefaultProofRuntime()
|
||||
err := prt.VerifyAbsence(res.Proof, cid.Hash, "/iavlStoreKey/MYABSENTKEY")
|
||||
err = prt.VerifyAbsence(res.Proof, cid.Hash, "/iavlStoreKey/MYABSENTKEY")
|
||||
require.Nil(t, err)
|
||||
|
||||
// Verify (bad) proof.
|
||||
|
|
|
@ -691,5 +691,8 @@ func flushCommitInfo(db dbm.DB, version int64, cInfo commitInfo) {
|
|||
|
||||
setCommitInfo(batch, version, cInfo)
|
||||
setLatestVersion(batch, version)
|
||||
batch.Write()
|
||||
err := batch.Write()
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("error on batch write %w", err))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,11 +45,12 @@ func (l MockLogger) With(kvs ...interface{}) log.Logger {
|
|||
panic("not implemented")
|
||||
}
|
||||
|
||||
func defaultContext(key types.StoreKey) types.Context {
|
||||
func defaultContext(t *testing.T, key types.StoreKey) types.Context {
|
||||
db := dbm.NewMemDB()
|
||||
cms := store.NewCommitMultiStore(db)
|
||||
cms.MountStoreWithDB(key, types.StoreTypeIAVL, db)
|
||||
cms.LoadLatestVersion()
|
||||
err := cms.LoadLatestVersion()
|
||||
require.NoError(t, err)
|
||||
ctx := types.NewContext(cms, abci.Header{}, false, log.NewNopLogger())
|
||||
return ctx
|
||||
}
|
||||
|
@ -61,7 +62,7 @@ func TestCacheContext(t *testing.T) {
|
|||
k2 := []byte("key")
|
||||
v2 := []byte("value")
|
||||
|
||||
ctx := defaultContext(key)
|
||||
ctx := defaultContext(t, key)
|
||||
store := ctx.KVStore(key)
|
||||
store.Set(k1, v1)
|
||||
require.Equal(t, v1, store.Get(k1))
|
||||
|
@ -83,7 +84,7 @@ func TestCacheContext(t *testing.T) {
|
|||
|
||||
func TestLogContext(t *testing.T) {
|
||||
key := types.NewKVStoreKey(t.Name())
|
||||
ctx := defaultContext(key)
|
||||
ctx := defaultContext(t, key)
|
||||
logger := NewMockLogger()
|
||||
ctx = ctx.WithLogger(logger)
|
||||
ctx.Logger().Debug("debug")
|
||||
|
|
|
@ -304,7 +304,8 @@ func TestDecMarshalJSON(t *testing.T) {
|
|||
if !tt.wantErr {
|
||||
assert.Equal(t, tt.want, string(got), "incorrect marshalled value")
|
||||
unmarshalledDec := NewDec(0)
|
||||
unmarshalledDec.UnmarshalJSON(got)
|
||||
err := unmarshalledDec.UnmarshalJSON(got)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.d, unmarshalledDec, "incorrect unmarshalled value")
|
||||
}
|
||||
})
|
||||
|
|
|
@ -19,7 +19,7 @@ func TestChainAnteDecorators(t *testing.T) {
|
|||
mockCtrl := gomock.NewController(t)
|
||||
mockAnteDecorator1 := mocks.NewMockAnteDecorator(mockCtrl)
|
||||
mockAnteDecorator1.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, gomock.Any()).Times(1)
|
||||
sdk.ChainAnteDecorators(mockAnteDecorator1)(ctx, tx, true)
|
||||
sdk.ChainAnteDecorators(mockAnteDecorator1)(ctx, tx, true) //nolint:errcheck
|
||||
|
||||
mockAnteDecorator2 := mocks.NewMockAnteDecorator(mockCtrl)
|
||||
mockAnteDecorator1.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, mockAnteDecorator2).Times(1)
|
||||
|
|
|
@ -12,7 +12,7 @@ func TestBondStatus(t *testing.T) {
|
|||
require.False(t, sdk.Unbonded.Equal(sdk.Bonded))
|
||||
require.False(t, sdk.Unbonded.Equal(sdk.Unbonding))
|
||||
require.False(t, sdk.Bonded.Equal(sdk.Unbonding))
|
||||
require.Panicsf(t, func() { _ = sdk.BondStatus(0).String() }, "invalid bond status")
|
||||
require.Panicsf(t, func() { sdk.BondStatus(0).String() }, "invalid bond status") // nolint:govet
|
||||
require.Equal(t, sdk.BondStatusUnbonded, sdk.Unbonded.String())
|
||||
require.Equal(t, sdk.BondStatusBonded, sdk.Bonded.String())
|
||||
require.Equal(t, sdk.BondStatusUnbonding, sdk.Unbonding.String())
|
||||
|
|
|
@ -49,15 +49,18 @@ func TestSimulateGasCost(t *testing.T) {
|
|||
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
|
||||
require.NoError(t, acc1.SetAccountNumber(0))
|
||||
app.AccountKeeper.SetAccount(ctx, acc1)
|
||||
app.BankKeeper.SetBalances(ctx, acc1.GetAddress(), types.NewTestCoins())
|
||||
err := app.BankKeeper.SetBalances(ctx, acc1.GetAddress(), types.NewTestCoins())
|
||||
require.NoError(t, err)
|
||||
acc2 := app.AccountKeeper.NewAccountWithAddress(ctx, addr2)
|
||||
require.NoError(t, acc2.SetAccountNumber(1))
|
||||
app.AccountKeeper.SetAccount(ctx, acc2)
|
||||
app.BankKeeper.SetBalances(ctx, acc2.GetAddress(), types.NewTestCoins())
|
||||
err = app.BankKeeper.SetBalances(ctx, acc2.GetAddress(), types.NewTestCoins())
|
||||
require.NoError(t, err)
|
||||
acc3 := app.AccountKeeper.NewAccountWithAddress(ctx, addr3)
|
||||
require.NoError(t, acc3.SetAccountNumber(2))
|
||||
app.AccountKeeper.SetAccount(ctx, acc3)
|
||||
app.BankKeeper.SetBalances(ctx, acc3.GetAddress(), types.NewTestCoins())
|
||||
err = app.BankKeeper.SetBalances(ctx, acc3.GetAddress(), types.NewTestCoins())
|
||||
require.NoError(t, err)
|
||||
|
||||
// set up msgs and fee
|
||||
var tx sdk.Tx
|
||||
|
@ -129,7 +132,8 @@ func TestAnteHandlerSigErrors(t *testing.T) {
|
|||
// save the first account, but second is still unrecognized
|
||||
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
|
||||
app.AccountKeeper.SetAccount(ctx, acc1)
|
||||
app.BankKeeper.SetBalances(ctx, addr1, fee.Amount)
|
||||
err := app.BankKeeper.SetBalances(ctx, addr1, fee.Amount)
|
||||
require.NoError(t, err)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdkerrors.ErrUnknownAddress)
|
||||
}
|
||||
|
||||
|
@ -148,11 +152,13 @@ func TestAnteHandlerAccountNumbers(t *testing.T) {
|
|||
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
|
||||
require.NoError(t, acc1.SetAccountNumber(0))
|
||||
app.AccountKeeper.SetAccount(ctx, acc1)
|
||||
app.BankKeeper.SetBalances(ctx, addr1, types.NewTestCoins())
|
||||
err := app.BankKeeper.SetBalances(ctx, addr1, types.NewTestCoins())
|
||||
require.NoError(t, err)
|
||||
acc2 := app.AccountKeeper.NewAccountWithAddress(ctx, addr2)
|
||||
require.NoError(t, acc2.SetAccountNumber(1))
|
||||
app.AccountKeeper.SetAccount(ctx, acc2)
|
||||
app.BankKeeper.SetBalances(ctx, addr2, types.NewTestCoins())
|
||||
err = app.BankKeeper.SetBalances(ctx, addr2, types.NewTestCoins())
|
||||
require.NoError(t, err)
|
||||
|
||||
// msg and signatures
|
||||
var tx sdk.Tx
|
||||
|
@ -204,11 +210,13 @@ func TestAnteHandlerAccountNumbersAtBlockHeightZero(t *testing.T) {
|
|||
// set the accounts, we don't need the acc numbers as it is in the genesis block
|
||||
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
|
||||
app.AccountKeeper.SetAccount(ctx, acc1)
|
||||
app.BankKeeper.SetBalances(ctx, addr1, types.NewTestCoins())
|
||||
err := app.BankKeeper.SetBalances(ctx, addr1, types.NewTestCoins())
|
||||
require.NoError(t, err)
|
||||
acc2 := app.AccountKeeper.NewAccountWithAddress(ctx, addr2)
|
||||
require.NoError(t, acc2.SetAccountNumber(1))
|
||||
app.AccountKeeper.SetAccount(ctx, acc2)
|
||||
app.BankKeeper.SetBalances(ctx, addr2, types.NewTestCoins())
|
||||
err = app.BankKeeper.SetBalances(ctx, addr2, types.NewTestCoins())
|
||||
require.NoError(t, err)
|
||||
|
||||
// msg and signatures
|
||||
var tx sdk.Tx
|
||||
|
@ -671,7 +679,8 @@ func TestAnteHandlerSigLimitExceeded(t *testing.T) {
|
|||
// set the accounts
|
||||
for i, addr := range addrs {
|
||||
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
|
||||
acc.SetAccountNumber(uint64(i))
|
||||
err := acc.SetAccountNumber(uint64(i))
|
||||
require.NoError(t, err)
|
||||
app.AccountKeeper.SetAccount(ctx, acc)
|
||||
app.BankKeeper.SetBalances(ctx, addr, types.NewTestCoins())
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ func TestRecoverPanic(t *testing.T) {
|
|||
require.Equal(t, fee.Gas, newCtx.GasMeter().Limit())
|
||||
|
||||
antehandler = sdk.ChainAnteDecorators(sud, PanicDecorator{})
|
||||
require.Panics(t, func() { antehandler(ctx, tx, false) }, "Recovered from non-Out-of-Gas panic")
|
||||
require.Panics(t, func() { antehandler(ctx, tx, false) }, "Recovered from non-Out-of-Gas panic") // nolint:errcheck
|
||||
}
|
||||
|
||||
type OutOfGasDecorator struct{}
|
||||
|
|
|
@ -64,7 +64,8 @@ func TestConsumeSignatureVerificationGas(t *testing.T) {
|
|||
multisignature1 := multisig.NewMultisig(len(pkSet1))
|
||||
expectedCost1 := expectedGasCostByKeys(pkSet1)
|
||||
for i := 0; i < len(pkSet1); i++ {
|
||||
multisignature1.AddSignatureFromPubKey(sigSet1[i], pkSet1[i], pkSet1)
|
||||
err := multisignature1.AddSignatureFromPubKey(sigSet1[i], pkSet1[i], pkSet1)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
type args struct {
|
||||
|
|
|
@ -25,7 +25,7 @@ filename, the command reads from standard input.
|
|||
$ <appcli> tx broadcast ./mytxn.json
|
||||
`),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
|
||||
if cliCtx.Offline {
|
||||
|
@ -34,18 +34,20 @@ $ <appcli> tx broadcast ./mytxn.json
|
|||
|
||||
stdTx, err := client.ReadStdTxFromFile(cliCtx.Codec, args[0])
|
||||
if err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
txBytes, err := cliCtx.Codec.MarshalBinaryBare(stdTx)
|
||||
if err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.BroadcastTx(txBytes)
|
||||
cliCtx.PrintOutput(res)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
return cliCtx.PrintOutput(res)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,8 @@ func TestAccountMapperGetSet(t *testing.T) {
|
|||
|
||||
// set some values on the account and save it
|
||||
newSequence := uint64(20)
|
||||
acc.SetSequence(newSequence)
|
||||
err := acc.SetSequence(newSequence)
|
||||
require.NoError(t, err)
|
||||
app.AccountKeeper.SetAccount(ctx, acc)
|
||||
|
||||
// check the new values
|
||||
|
@ -50,8 +51,10 @@ func TestAccountMapperRemoveAccount(t *testing.T) {
|
|||
accSeq1 := uint64(20)
|
||||
accSeq2 := uint64(40)
|
||||
|
||||
acc1.SetSequence(accSeq1)
|
||||
acc2.SetSequence(accSeq2)
|
||||
err := acc1.SetSequence(accSeq1)
|
||||
require.NoError(t, err)
|
||||
err = acc2.SetSequence(accSeq2)
|
||||
require.NoError(t, err)
|
||||
app.AccountKeeper.SetAccount(ctx, acc1)
|
||||
app.AccountKeeper.SetAccount(ctx, acc2)
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@ import (
|
|||
func TestSanitize(t *testing.T) {
|
||||
addr1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
|
||||
authAcc1 := types.NewBaseAccountWithAddress(addr1)
|
||||
authAcc1.SetAccountNumber(1)
|
||||
err := authAcc1.SetAccountNumber(1)
|
||||
require.NoError(t, err)
|
||||
|
||||
addr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
|
||||
authAcc2 := types.NewBaseAccountWithAddress(addr2)
|
||||
|
|
|
@ -112,7 +112,8 @@ func TestSendNotEnoughBalance(t *testing.T) {
|
|||
|
||||
sendMsg := types.NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin("foocoin", 100)})
|
||||
header := abci.Header{Height: app.LastBlockHeight() + 1}
|
||||
simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{sendMsg}, []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1)
|
||||
_, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{sendMsg}, []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1)
|
||||
require.Error(t, err)
|
||||
|
||||
simapp.CheckBalance(t, app, addr1, sdk.Coins{sdk.NewInt64Coin("foocoin", 67)})
|
||||
|
||||
|
@ -178,7 +179,12 @@ func TestSendToModuleAcc(t *testing.T) {
|
|||
origSeq := res1.GetSequence()
|
||||
|
||||
header := abci.Header{Height: app.LastBlockHeight() + 1}
|
||||
simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{test.msg}, []uint64{origAccNum}, []uint64{origSeq}, test.expSimPass, test.expPass, priv1)
|
||||
_, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{test.msg}, []uint64{origAccNum}, []uint64{origSeq}, test.expSimPass, test.expPass, priv1)
|
||||
if test.expPass {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
simapp.CheckBalance(t, app, test.msg.FromAddress, test.expFromBalance)
|
||||
simapp.CheckBalance(t, app, test.msg.ToAddress, test.expToBalance)
|
||||
|
@ -243,7 +249,12 @@ func TestMsgMultiSendWithAccounts(t *testing.T) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
header := abci.Header{Height: app.LastBlockHeight() + 1}
|
||||
simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
_, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
if tc.expPass {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
for _, eb := range tc.expectedBalances {
|
||||
simapp.CheckBalance(t, app, eb.addr, eb.coins)
|
||||
|
@ -289,7 +300,8 @@ func TestMsgMultiSendMultipleOut(t *testing.T) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
header := abci.Header{Height: app.LastBlockHeight() + 1}
|
||||
simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
_, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, eb := range tc.expectedBalances {
|
||||
simapp.CheckBalance(t, app, eb.addr, eb.coins)
|
||||
|
@ -342,7 +354,8 @@ func TestMsgMultiSendMultipleInOut(t *testing.T) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
header := abci.Header{Height: app.LastBlockHeight() + 1}
|
||||
simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
_, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, eb := range tc.expectedBalances {
|
||||
simapp.CheckBalance(t, app, eb.addr, eb.coins)
|
||||
|
@ -393,7 +406,8 @@ func TestMsgMultiSendDependent(t *testing.T) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
header := abci.Header{Height: app.LastBlockHeight() + 1}
|
||||
simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
_, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, eb := range tc.expectedBalances {
|
||||
simapp.CheckBalance(t, app, eb.addr, eb.coins)
|
||||
|
|
|
@ -48,7 +48,8 @@ func BenchmarkOneBankSendTxPerBlock(b *testing.B) {
|
|||
panic("something is broken in checking transaction")
|
||||
}
|
||||
|
||||
benchmarkApp.Deliver(txs[i])
|
||||
_, _, err = benchmarkApp.Deliver(txs[i])
|
||||
require.NoError(b, err)
|
||||
benchmarkApp.EndBlock(abci.RequestEndBlock{Height: height})
|
||||
benchmarkApp.Commit()
|
||||
height++
|
||||
|
@ -87,7 +88,8 @@ func BenchmarkOneBankMultiSendTxPerBlock(b *testing.B) {
|
|||
panic("something is broken in checking transaction")
|
||||
}
|
||||
|
||||
benchmarkApp.Deliver(txs[i])
|
||||
_, _, err = benchmarkApp.Deliver(txs[i])
|
||||
require.NoError(b, err)
|
||||
benchmarkApp.EndBlock(abci.RequestEndBlock{Height: height})
|
||||
benchmarkApp.Commit()
|
||||
height++
|
||||
|
|
|
@ -16,7 +16,9 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, genState GenesisState) {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
keeper.SetBalances(ctx, balance.Address, balance.Coins)
|
||||
if err := keeper.SetBalances(ctx, balance.Address, balance.Coins); err != nil {
|
||||
panic(fmt.Errorf("error on setting balances %w", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,10 @@ func (k BaseKeeper) DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr
|
|||
}
|
||||
|
||||
balances = balances.Add(balance)
|
||||
k.SetBalance(ctx, delegatorAddr, balance.Sub(coin))
|
||||
err := k.SetBalance(ctx, delegatorAddr, balance.Sub(coin))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := k.trackDelegation(ctx, delegatorAddr, ctx.BlockHeader().Time, balances, amt); err != nil {
|
||||
|
@ -271,7 +274,10 @@ func (k BaseSendKeeper) SubtractCoins(ctx sdk.Context, addr sdk.AccAddress, amt
|
|||
newBalance := balance.Sub(coin)
|
||||
resultCoins = resultCoins.Add(newBalance)
|
||||
|
||||
k.SetBalance(ctx, addr, newBalance)
|
||||
err := k.SetBalance(ctx, addr, newBalance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return resultCoins, nil
|
||||
|
@ -292,7 +298,10 @@ func (k BaseSendKeeper) AddCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.C
|
|||
newBalance := balance.Add(coin)
|
||||
resultCoins = resultCoins.Add(newBalance)
|
||||
|
||||
k.SetBalance(ctx, addr, newBalance)
|
||||
err := k.SetBalance(ctx, addr, newBalance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return resultCoins, nil
|
||||
|
|
|
@ -80,7 +80,7 @@ func TestHandleMsgVerifyInvariant(t *testing.T) {
|
|||
|
||||
case "panic":
|
||||
require.Panics(t, func() {
|
||||
h(ctx, tc.msg)
|
||||
h(ctx, tc.msg) // nolint:errcheck
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
|
@ -85,7 +85,7 @@ func TestParseProposal(t *testing.T) {
|
|||
cdc := codec.New()
|
||||
okJSON, err := ioutil.TempFile("", "proposal")
|
||||
require.Nil(t, err, "unexpected error")
|
||||
okJSON.WriteString(`
|
||||
_, err = okJSON.WriteString(`
|
||||
{
|
||||
"title": "Community Pool Spend",
|
||||
"description": "Pay me some Atoms!",
|
||||
|
@ -94,6 +94,7 @@ func TestParseProposal(t *testing.T) {
|
|||
"deposit": "1000stake"
|
||||
}
|
||||
`)
|
||||
require.NoError(t, err)
|
||||
|
||||
proposal, err := ParseCommunityPoolSpendProposalJSON(cdc, okJSON.Name())
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -607,16 +607,19 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {
|
|||
app.DistrKeeper.AllocateTokensToValidator(ctx, val, tokens)
|
||||
|
||||
// first delegator withdraws
|
||||
app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddrs[0]), valAddrs[0])
|
||||
_, err = app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddrs[0]), valAddrs[0])
|
||||
require.NoError(t, err)
|
||||
|
||||
// second delegator withdraws
|
||||
app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddrs[1]), valAddrs[0])
|
||||
_, err = app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddrs[1]), valAddrs[0])
|
||||
require.NoError(t, err)
|
||||
|
||||
// historical count should be 3 (validator init + two delegations)
|
||||
require.Equal(t, uint64(3), app.DistrKeeper.GetValidatorHistoricalReferenceCount(ctx))
|
||||
|
||||
// validator withdraws commission
|
||||
app.DistrKeeper.WithdrawValidatorCommission(ctx, valAddrs[0])
|
||||
_, err = app.DistrKeeper.WithdrawValidatorCommission(ctx, valAddrs[0])
|
||||
require.NoError(t, err)
|
||||
|
||||
// end period
|
||||
endingPeriod := app.DistrKeeper.IncrementValidatorPeriod(ctx, val)
|
||||
|
@ -643,7 +646,8 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {
|
|||
app.DistrKeeper.AllocateTokensToValidator(ctx, val, tokens)
|
||||
|
||||
// first delegator withdraws again
|
||||
app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddrs[0]), valAddrs[0])
|
||||
_, err = app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddrs[0]), valAddrs[0])
|
||||
require.NoError(t, err)
|
||||
|
||||
// end period
|
||||
endingPeriod = app.DistrKeeper.IncrementValidatorPeriod(ctx, val)
|
||||
|
@ -670,7 +674,8 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {
|
|||
app.DistrKeeper.AllocateTokensToValidator(ctx, val, tokens)
|
||||
|
||||
// withdraw commission
|
||||
app.DistrKeeper.WithdrawValidatorCommission(ctx, valAddrs[0])
|
||||
_, err = app.DistrKeeper.WithdrawValidatorCommission(ctx, valAddrs[0])
|
||||
require.NoError(t, err)
|
||||
|
||||
// end period
|
||||
endingPeriod = app.DistrKeeper.IncrementValidatorPeriod(ctx, val)
|
||||
|
|
|
@ -49,10 +49,11 @@ func TestWithdrawValidatorCommission(t *testing.T) {
|
|||
|
||||
// set module account coins
|
||||
distrAcc := app.DistrKeeper.GetDistributionAccount(ctx)
|
||||
app.BankKeeper.SetBalances(ctx, distrAcc.GetAddress(), sdk.NewCoins(
|
||||
err := app.BankKeeper.SetBalances(ctx, distrAcc.GetAddress(), sdk.NewCoins(
|
||||
sdk.NewCoin("mytoken", sdk.NewInt(2)),
|
||||
sdk.NewCoin("stake", sdk.NewInt(2)),
|
||||
))
|
||||
require.NoError(t, err)
|
||||
app.SupplyKeeper.SetModuleAccount(ctx, distrAcc)
|
||||
|
||||
// check initial balance
|
||||
|
@ -68,7 +69,8 @@ func TestWithdrawValidatorCommission(t *testing.T) {
|
|||
app.DistrKeeper.SetValidatorAccumulatedCommission(ctx, valAddrs[0], types.ValidatorAccumulatedCommission{Commission: valCommission})
|
||||
|
||||
// withdraw commission
|
||||
app.DistrKeeper.WithdrawValidatorCommission(ctx, valAddrs[0])
|
||||
_, err = app.DistrKeeper.WithdrawValidatorCommission(ctx, valAddrs[0])
|
||||
require.NoError(t, err)
|
||||
|
||||
// check balance increase
|
||||
balance = app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(valAddrs[0]))
|
||||
|
|
|
@ -113,11 +113,13 @@ func TestStartStandAlone(t *testing.T) {
|
|||
svr, err := abciServer.NewServer(svrAddr, "socket", app)
|
||||
require.Nil(t, err, "error creating listener")
|
||||
svr.SetLogger(logger.With("module", "abci-server"))
|
||||
svr.Start()
|
||||
err = svr.Start()
|
||||
require.NoError(t, err)
|
||||
|
||||
timer := time.NewTimer(time.Duration(2) * time.Second)
|
||||
for range timer.C {
|
||||
svr.Stop()
|
||||
err = svr.Stop()
|
||||
require.NoError(t, err)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
// Validate genesis command takes
|
||||
func ValidateGenesisCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager) *cobra.Command {
|
||||
func ValidateGenesisCmd(ctx *server.Context, cdc codec.JSONMarshaler, mbm module.BasicManager) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "validate-genesis [file]",
|
||||
Args: cobra.RangeArgs(0, 1),
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
func TestParseSubmitProposalFlags(t *testing.T) {
|
||||
okJSON, err := ioutil.TempFile("", "proposal")
|
||||
require.Nil(t, err, "unexpected error")
|
||||
okJSON.WriteString(`
|
||||
_, err = okJSON.WriteString(`
|
||||
{
|
||||
"title": "Test Proposal",
|
||||
"description": "My awesome proposal",
|
||||
|
@ -19,6 +19,7 @@ func TestParseSubmitProposalFlags(t *testing.T) {
|
|||
"deposit": "1000test"
|
||||
}
|
||||
`)
|
||||
require.NoError(t, err)
|
||||
|
||||
badJSON, err := ioutil.TempFile("", "proposal")
|
||||
require.Nil(t, err, "unexpected error")
|
||||
|
|
|
@ -15,11 +15,16 @@ func TestIncrementProposalNumber(t *testing.T) {
|
|||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
||||
|
||||
tp := TestProposal
|
||||
app.GovKeeper.SubmitProposal(ctx, tp)
|
||||
app.GovKeeper.SubmitProposal(ctx, tp)
|
||||
app.GovKeeper.SubmitProposal(ctx, tp)
|
||||
app.GovKeeper.SubmitProposal(ctx, tp)
|
||||
app.GovKeeper.SubmitProposal(ctx, tp)
|
||||
_, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
_, err = app.GovKeeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
_, err = app.GovKeeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
_, err = app.GovKeeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
_, err = app.GovKeeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposal6, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ func TestParseProposal(t *testing.T) {
|
|||
cdc := codec.New()
|
||||
okJSON, err := ioutil.TempFile("", "proposal")
|
||||
require.Nil(t, err, "unexpected error")
|
||||
okJSON.WriteString(`
|
||||
_, err = okJSON.WriteString(`
|
||||
{
|
||||
"title": "Staking Param Change",
|
||||
"description": "Update max validators",
|
||||
|
@ -28,6 +28,7 @@ func TestParseProposal(t *testing.T) {
|
|||
"deposit": "1000stake"
|
||||
}
|
||||
`)
|
||||
require.NoError(t, err)
|
||||
|
||||
proposal, err := utils.ParseParamChangeProposalJSON(cdc, okJSON.Name())
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -207,19 +207,23 @@ func TestJSONUpdate(t *testing.T) {
|
|||
|
||||
var param paramJSON
|
||||
|
||||
space.Update(ctx, key, []byte(`{"param1": "10241024"}`))
|
||||
err := space.Update(ctx, key, []byte(`{"param1": "10241024"}`))
|
||||
require.NoError(t, err)
|
||||
space.Get(ctx, key, ¶m)
|
||||
require.Equal(t, paramJSON{10241024, ""}, param)
|
||||
|
||||
space.Update(ctx, key, []byte(`{"param2": "helloworld"}`))
|
||||
err = space.Update(ctx, key, []byte(`{"param2": "helloworld"}`))
|
||||
require.NoError(t, err)
|
||||
space.Get(ctx, key, ¶m)
|
||||
require.Equal(t, paramJSON{10241024, "helloworld"}, param)
|
||||
|
||||
space.Update(ctx, key, []byte(`{"param1": "20482048"}`))
|
||||
err = space.Update(ctx, key, []byte(`{"param1": "20482048"}`))
|
||||
require.NoError(t, err)
|
||||
space.Get(ctx, key, ¶m)
|
||||
require.Equal(t, paramJSON{20482048, "helloworld"}, param)
|
||||
|
||||
space.Update(ctx, key, []byte(`{"param1": "40964096", "param2": "goodbyeworld"}`))
|
||||
err = space.Update(ctx, key, []byte(`{"param1": "40964096", "param2": "goodbyeworld"}`))
|
||||
require.NoError(t, err)
|
||||
space.Get(ctx, key, ¶m)
|
||||
require.Equal(t, paramJSON{40964096, "goodbyeworld"}, param)
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ func (suite *SubspaceTestSuite) TestModified() {
|
|||
|
||||
func (suite *SubspaceTestSuite) TestUpdate() {
|
||||
suite.Require().Panics(func() {
|
||||
suite.ss.Update(suite.ctx, []byte("invalid_key"), nil)
|
||||
suite.ss.Update(suite.ctx, []byte("invalid_key"), nil) // nolint:errcheck
|
||||
})
|
||||
|
||||
t := time.Hour * 48
|
||||
|
|
|
@ -64,7 +64,8 @@ func TestSlashingMsgs(t *testing.T) {
|
|||
)
|
||||
|
||||
header := abci.Header{Height: app.LastBlockHeight() + 1}
|
||||
simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1)
|
||||
_, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1)
|
||||
require.NoError(t, err)
|
||||
simapp.CheckBalance(t, app, addr1, sdk.Coins{genCoin.Sub(bondCoin)})
|
||||
|
||||
header = abci.Header{Height: app.LastBlockHeight() + 1}
|
||||
|
|
|
@ -70,7 +70,8 @@ func TestStakingMsgs(t *testing.T) {
|
|||
)
|
||||
|
||||
header := abci.Header{Height: app.LastBlockHeight() + 1}
|
||||
simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1)
|
||||
_, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1)
|
||||
require.NoError(t, err)
|
||||
simapp.CheckBalance(t, app, addr1, sdk.Coins{genCoin.Sub(bondCoin)})
|
||||
|
||||
header = abci.Header{Height: app.LastBlockHeight() + 1}
|
||||
|
@ -89,7 +90,8 @@ func TestStakingMsgs(t *testing.T) {
|
|||
editValidatorMsg := staking.NewMsgEditValidator(sdk.ValAddress(addr1), description, nil, nil)
|
||||
|
||||
header = abci.Header{Height: app.LastBlockHeight() + 1}
|
||||
simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{editValidatorMsg}, []uint64{0}, []uint64{1}, true, true, priv1)
|
||||
_, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{editValidatorMsg}, []uint64{0}, []uint64{1}, true, true, priv1)
|
||||
require.NoError(t, err)
|
||||
|
||||
validator = checkValidator(t, app, sdk.ValAddress(addr1), true)
|
||||
require.Equal(t, description, validator.Description)
|
||||
|
@ -99,14 +101,17 @@ func TestStakingMsgs(t *testing.T) {
|
|||
delegateMsg := staking.NewMsgDelegate(addr2, sdk.ValAddress(addr1), bondCoin)
|
||||
|
||||
header = abci.Header{Height: app.LastBlockHeight() + 1}
|
||||
simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{delegateMsg}, []uint64{1}, []uint64{0}, true, true, priv2)
|
||||
_, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{delegateMsg}, []uint64{1}, []uint64{0}, true, true, priv2)
|
||||
require.NoError(t, err)
|
||||
|
||||
simapp.CheckBalance(t, app, addr2, sdk.Coins{genCoin.Sub(bondCoin)})
|
||||
checkDelegation(t, app, addr2, sdk.ValAddress(addr1), true, bondTokens.ToDec())
|
||||
|
||||
// begin unbonding
|
||||
beginUnbondingMsg := staking.NewMsgUndelegate(addr2, sdk.ValAddress(addr1), bondCoin)
|
||||
header = abci.Header{Height: app.LastBlockHeight() + 1}
|
||||
simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{beginUnbondingMsg}, []uint64{1}, []uint64{1}, true, true, priv2)
|
||||
_, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{beginUnbondingMsg}, []uint64{1}, []uint64{1}, true, true, priv2)
|
||||
require.NoError(t, err)
|
||||
|
||||
// delegation should exist anymore
|
||||
checkDelegation(t, app, addr2, sdk.ValAddress(addr1), false, sdk.Dec{})
|
||||
|
|
|
@ -439,11 +439,13 @@ func TestQueryRedelegations(t *testing.T) {
|
|||
app.StakingKeeper.SetValidator(ctx, val2)
|
||||
|
||||
delAmount := sdk.TokensFromConsensusPower(100)
|
||||
app.StakingKeeper.Delegate(ctx, addrAcc2, delAmount, sdk.Unbonded, val1, true)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrAcc2, delAmount, sdk.Unbonded, val1, true)
|
||||
require.NoError(t, err)
|
||||
_ = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
|
||||
rdAmount := sdk.TokensFromConsensusPower(20)
|
||||
app.StakingKeeper.BeginRedelegation(ctx, addrAcc2, val1.GetOperator(), val2.GetOperator(), rdAmount.ToDec())
|
||||
_, err = app.StakingKeeper.BeginRedelegation(ctx, addrAcc2, val1.GetOperator(), val2.GetOperator(), rdAmount.ToDec())
|
||||
require.NoError(t, err)
|
||||
app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
|
||||
redel, found := app.StakingKeeper.GetRedelegation(ctx, addrAcc2, val1.OperatorAddress, val2.OperatorAddress)
|
||||
|
|
|
@ -93,8 +93,10 @@ func TestUpdateValidatorByPowerIndex(t *testing.T) {
|
|||
|
||||
bondedPool := app.StakingKeeper.GetBondedPool(ctx)
|
||||
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
|
||||
app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(1234))))
|
||||
app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(10000))))
|
||||
err := app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(1234))))
|
||||
require.NoError(t, err)
|
||||
err = app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(10000))))
|
||||
require.NoError(t, err)
|
||||
app.SupplyKeeper.SetModuleAccount(ctx, bondedPool)
|
||||
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
|
||||
|
||||
|
@ -141,8 +143,10 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
|
|||
app.StakingKeeper.SetParams(ctx, params)
|
||||
|
||||
// create a random pool
|
||||
app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(1234))))
|
||||
app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(10000))))
|
||||
err := app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(1234))))
|
||||
require.NoError(t, err)
|
||||
err = app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(10000))))
|
||||
require.NoError(t, err)
|
||||
app.SupplyKeeper.SetModuleAccount(ctx, bondedPool)
|
||||
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
|
||||
|
||||
|
@ -397,8 +401,10 @@ func TestGetValidatorSortingMixed(t *testing.T) {
|
|||
bondedPool := app.StakingKeeper.GetBondedPool(ctx)
|
||||
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
|
||||
|
||||
app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(501))))
|
||||
app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(0))))
|
||||
err := app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(501))))
|
||||
require.NoError(t, err)
|
||||
err = app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(0))))
|
||||
require.NoError(t, err)
|
||||
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
|
||||
app.SupplyKeeper.SetModuleAccount(ctx, bondedPool)
|
||||
|
||||
|
|
|
@ -71,15 +71,15 @@ func TestSendCoins(t *testing.T) {
|
|||
ak.SetAccount(ctx, baseAcc)
|
||||
|
||||
require.Panics(t, func() {
|
||||
keeper.SendCoinsFromModuleToModule(ctx, "", holderAcc.GetName(), initCoins)
|
||||
keeper.SendCoinsFromModuleToModule(ctx, "", holderAcc.GetName(), initCoins) // nolint:errcheck
|
||||
})
|
||||
|
||||
require.Panics(t, func() {
|
||||
keeper.SendCoinsFromModuleToModule(ctx, types.Burner, "", initCoins)
|
||||
keeper.SendCoinsFromModuleToModule(ctx, types.Burner, "", initCoins) // nolint:errcheck
|
||||
})
|
||||
|
||||
require.Panics(t, func() {
|
||||
keeper.SendCoinsFromModuleToAccount(ctx, "", baseAcc.GetAddress(), initCoins)
|
||||
keeper.SendCoinsFromModuleToAccount(ctx, "", baseAcc.GetAddress(), initCoins) // nolint:errcheck
|
||||
})
|
||||
|
||||
require.Error(
|
||||
|
@ -129,12 +129,12 @@ func TestMintCoins(t *testing.T) {
|
|||
|
||||
initialSupply := keeper.GetSupply(ctx)
|
||||
|
||||
require.Panics(t, func() { keeper.MintCoins(ctx, "", initCoins) }, "no module account")
|
||||
require.Panics(t, func() { keeper.MintCoins(ctx, types.Burner, initCoins) }, "invalid permission")
|
||||
require.Panics(t, func() { keeper.MintCoins(ctx, "", initCoins) }, "no module account") // nolint:errcheck
|
||||
require.Panics(t, func() { keeper.MintCoins(ctx, types.Burner, initCoins) }, "invalid permission") // nolint:errcheck
|
||||
err := keeper.MintCoins(ctx, types.Minter, sdk.Coins{sdk.Coin{Denom: "denom", Amount: sdk.NewInt(-10)}})
|
||||
require.Error(t, err, "insufficient coins")
|
||||
|
||||
require.Panics(t, func() { keeper.MintCoins(ctx, randomPerm, initCoins) })
|
||||
require.Panics(t, func() { keeper.MintCoins(ctx, randomPerm, initCoins) }) // nolint:errcheck
|
||||
|
||||
err = keeper.MintCoins(ctx, types.Minter, initCoins)
|
||||
require.NoError(t, err)
|
||||
|
@ -149,7 +149,7 @@ func TestMintCoins(t *testing.T) {
|
|||
require.Equal(t, initCoins, getCoinsByName(ctx, keeper, ak, bk, multiPermAcc.GetName()))
|
||||
require.Equal(t, initialSupply.GetTotal().Add(initCoins...), keeper.GetSupply(ctx).GetTotal())
|
||||
|
||||
require.Panics(t, func() { keeper.MintCoins(ctx, types.Burner, initCoins) })
|
||||
require.Panics(t, func() { keeper.MintCoins(ctx, types.Burner, initCoins) }) // nolint:errcheck
|
||||
}
|
||||
|
||||
func TestBurnCoins(t *testing.T) {
|
||||
|
@ -178,9 +178,9 @@ func TestBurnCoins(t *testing.T) {
|
|||
initialSupply.Inflate(initCoins)
|
||||
keeper.SetSupply(ctx, initialSupply)
|
||||
|
||||
require.Panics(t, func() { keeper.BurnCoins(ctx, "", initCoins) }, "no module account")
|
||||
require.Panics(t, func() { keeper.BurnCoins(ctx, types.Minter, initCoins) }, "invalid permission")
|
||||
require.Panics(t, func() { keeper.BurnCoins(ctx, randomPerm, initialSupply.GetTotal()) }, "random permission")
|
||||
require.Panics(t, func() { keeper.BurnCoins(ctx, "", initCoins) }, "no module account") // nolint:errcheck
|
||||
require.Panics(t, func() { keeper.BurnCoins(ctx, types.Minter, initCoins) }, "invalid permission") // nolint:errcheck
|
||||
require.Panics(t, func() { keeper.BurnCoins(ctx, randomPerm, initialSupply.GetTotal()) }, "random permission") // nolint:errcheck
|
||||
err := keeper.BurnCoins(ctx, types.Burner, initialSupply.GetTotal())
|
||||
require.Error(t, err, "insufficient coins")
|
||||
|
||||
|
|
Loading…
Reference in New Issue