Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADR 004 Implementation II (Unit Tests & Misc.) #5580

Merged
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3ed12f8
Update bank keeper tests
alexanderbez Jan 28, 2020
960dfa1
Update testing utils/cmn
alexanderbez Jan 28, 2020
c131ebe
Test updates
alexanderbez Jan 28, 2020
cf48a79
Fix supply unit tests
alexanderbez Jan 28, 2020
3a611c0
Update staking tests
alexanderbez Jan 28, 2020
cd48b0f
Fix slashing tests
alexanderbez Jan 28, 2020
aef0378
Fix more tests
alexanderbez Jan 28, 2020
70d3b92
Updating delegation tests
alexanderbez Jan 28, 2020
3571b8a
Fix vesting genesis
alexanderbez Jan 28, 2020
1df9f9d
Update slashing unit tests
alexanderbez Jan 28, 2020
1ffc952
Update evidence unit tests
alexanderbez Jan 28, 2020
79e71b9
Update distribution tests
alexanderbez Jan 28, 2020
3160686
Update distribution unit tests
alexanderbez Jan 28, 2020
ae7c900
Fix auth tests
jackzampolin Jan 28, 2020
ad9db69
Fix gov unit tests
alexanderbez Jan 28, 2020
0fcc9a9
Update gov keeper tests
alexanderbez Jan 28, 2020
6715384
Fix TestSimGenesisAccountValidate
alexanderbez Jan 28, 2020
4ea5fe6
Fix sim
alexanderbez Jan 28, 2020
29dd752
Fix sendMsgMultiSend
alexanderbez Jan 28, 2020
72fd685
Fix AddressFromBalancesKey
alexanderbez Jan 28, 2020
c7e2349
Add panic in AddressFromBalancesKey
alexanderbez Jan 28, 2020
5c1c21e
Fix key check
alexanderbez Jan 28, 2020
4d6bbe3
Fix AddressFromBalancesStore
alexanderbez Jan 28, 2020
10f2a3b
Update alias
alexanderbez Jan 28, 2020
8320489
Fix bank abci tests
alexanderbez Jan 28, 2020
3b883ab
Fix crisis tests
alexanderbez Jan 28, 2020
3bb7c77
x/gov linting
alexanderbez Jan 28, 2020
6ca678c
x/gov linting
alexanderbez Jan 28, 2020
8e3c423
More linting
alexanderbez Jan 28, 2020
4cde7db
Fix bank export genesis address conversion
alexanderbez Jan 29, 2020
a25de11
Wrap error in panic
alexanderbez Jan 29, 2020
69a3808
Use suite.Require()
alexanderbez Jan 29, 2020
59592cf
Merge PR #5589: ADR 004 Geneis Migration
alexanderbez Jan 30, 2020
ac3df34
Implement and use SpendableCoins
alexanderbez Jan 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions simapp/genesis_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ func TestSimGenesisAccountValidate(t *testing.T) {
vestingStart := time.Now().UTC()

coins := sdk.NewCoins(sdk.NewInt64Coin("test", 1000))
baseAcc := authtypes.NewBaseAccount(addr, nil, pubkey, 0, 0)
require.NoError(t, baseAcc.SetCoins(coins))
baseAcc := authtypes.NewBaseAccount(addr, pubkey, 0, 0)

testCases := []struct {
name string
Expand All @@ -38,14 +37,14 @@ func TestSimGenesisAccountValidate(t *testing.T) {
{
"invalid basic account with mismatching address/pubkey",
simapp.SimGenesisAccount{
BaseAccount: authtypes.NewBaseAccount(addr, nil, secp256k1.GenPrivKey().PubKey(), 0, 0),
BaseAccount: authtypes.NewBaseAccount(addr, secp256k1.GenPrivKey().PubKey(), 0, 0),
},
true,
},
{
"valid basic account with module name",
simapp.SimGenesisAccount{
BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(crypto.AddressHash([]byte("testmod"))), nil, nil, 0, 0),
BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(crypto.AddressHash([]byte("testmod"))), nil, 0, 0),
ModuleName: "testmod",
},
false,
Expand Down Expand Up @@ -78,16 +77,6 @@ func TestSimGenesisAccountValidate(t *testing.T) {
},
true,
},
{
"valid basic account with invalid original vesting coins",
simapp.SimGenesisAccount{
BaseAccount: baseAcc,
OriginalVesting: coins.Add(coins...),
StartTime: vestingStart.Unix(),
EndTime: vestingStart.Add(1 * time.Hour).Unix(),
},
true,
},
}

for _, tc := range testCases {
Expand Down
3 changes: 1 addition & 2 deletions simapp/test_helpers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package simapp

import (
"os"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -48,7 +47,7 @@ func Setup(isCheckTx bool) *SimApp {
// genesis accounts.
func SetupWithGenesisAccounts(genAccs []authexported.GenesisAccount) *SimApp {
db := dbm.NewMemDB()
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, 0)
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, 0)

// initialize the chain with the passed in genesis accounts
genesisState := NewDefaultGenesisState()
Expand Down
4 changes: 1 addition & 3 deletions store/prefix/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import (

// copied from iavl/store_test.go
var (
cacheSize = 100
numRecent int64 = 5
storeEvery int64 = 3
cacheSize = 100
)

func bz(s string) []byte { return []byte(s) }
Expand Down
61 changes: 32 additions & 29 deletions x/auth/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ func TestSimulateGasCost(t *testing.T) {

// set the accounts
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
acc1.SetCoins(types.NewTestCoins())
require.NoError(t, acc1.SetAccountNumber(0))
app.AccountKeeper.SetAccount(ctx, acc1)
app.BankKeeper.SetBalances(ctx, acc1.GetAddress(), types.NewTestCoins())
acc2 := app.AccountKeeper.NewAccountWithAddress(ctx, addr2)
acc2.SetCoins(types.NewTestCoins())
require.NoError(t, acc2.SetAccountNumber(1))
app.AccountKeeper.SetAccount(ctx, acc2)
app.BankKeeper.SetBalances(ctx, acc2.GetAddress(), types.NewTestCoins())
acc3 := app.AccountKeeper.NewAccountWithAddress(ctx, addr3)
acc3.SetCoins(types.NewTestCoins())
require.NoError(t, acc3.SetAccountNumber(2))
app.AccountKeeper.SetAccount(ctx, acc3)
app.BankKeeper.SetBalances(ctx, acc3.GetAddress(), types.NewTestCoins())

// set up msgs and fee
var tx sdk.Tx
Expand Down Expand Up @@ -128,8 +128,8 @@ func TestAnteHandlerSigErrors(t *testing.T) {

// save the first account, but second is still unrecognized
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
acc1.SetCoins(fee.Amount)
app.AccountKeeper.SetAccount(ctx, acc1)
app.BankKeeper.SetBalances(ctx, addr1, fee.Amount)
checkInvalidTx(t, anteHandler, ctx, tx, false, sdkerrors.ErrUnknownAddress)
}

Expand All @@ -146,13 +146,13 @@ func TestAnteHandlerAccountNumbers(t *testing.T) {

// set the accounts
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
acc1.SetCoins(types.NewTestCoins())
require.NoError(t, acc1.SetAccountNumber(0))
app.AccountKeeper.SetAccount(ctx, acc1)
app.BankKeeper.SetBalances(ctx, addr1, types.NewTestCoins())
acc2 := app.AccountKeeper.NewAccountWithAddress(ctx, addr2)
acc2.SetCoins(types.NewTestCoins())
require.NoError(t, acc2.SetAccountNumber(1))
app.AccountKeeper.SetAccount(ctx, acc2)
app.BankKeeper.SetBalances(ctx, addr2, types.NewTestCoins())

// msg and signatures
var tx sdk.Tx
Expand Down Expand Up @@ -203,12 +203,12 @@ 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)
acc1.SetCoins(types.NewTestCoins())
app.AccountKeeper.SetAccount(ctx, acc1)
app.BankKeeper.SetBalances(ctx, addr1, types.NewTestCoins())
acc2 := app.AccountKeeper.NewAccountWithAddress(ctx, addr2)
acc2.SetCoins(types.NewTestCoins())
require.NoError(t, acc2.SetAccountNumber(1))
app.AccountKeeper.SetAccount(ctx, acc2)
app.BankKeeper.SetBalances(ctx, addr2, types.NewTestCoins())

// msg and signatures
var tx sdk.Tx
Expand Down Expand Up @@ -260,17 +260,17 @@ func TestAnteHandlerSequences(t *testing.T) {

// set the accounts
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
acc1.SetCoins(types.NewTestCoins())
require.NoError(t, acc1.SetAccountNumber(0))
app.AccountKeeper.SetAccount(ctx, acc1)
app.BankKeeper.SetBalances(ctx, addr1, types.NewTestCoins())
acc2 := app.AccountKeeper.NewAccountWithAddress(ctx, addr2)
acc2.SetCoins(types.NewTestCoins())
require.NoError(t, acc2.SetAccountNumber(1))
app.AccountKeeper.SetAccount(ctx, acc2)
app.BankKeeper.SetBalances(ctx, addr2, types.NewTestCoins())
acc3 := app.AccountKeeper.NewAccountWithAddress(ctx, addr3)
acc3.SetCoins(types.NewTestCoins())
require.NoError(t, acc3.SetAccountNumber(2))
app.AccountKeeper.SetAccount(ctx, acc3)
app.BankKeeper.SetBalances(ctx, addr3, types.NewTestCoins())

// msg and signatures
var tx sdk.Tx
Expand Down Expand Up @@ -347,19 +347,21 @@ func TestAnteHandlerFees(t *testing.T) {
tx = types.NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
checkInvalidTx(t, anteHandler, ctx, tx, false, sdkerrors.ErrInsufficientFunds)

acc1.SetCoins(sdk.NewCoins(sdk.NewInt64Coin("atom", 149)))
app.AccountKeeper.SetAccount(ctx, acc1)
app.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("atom", 149)))
checkInvalidTx(t, anteHandler, ctx, tx, false, sdkerrors.ErrInsufficientFunds)

require.True(t, app.SupplyKeeper.GetModuleAccount(ctx, types.FeeCollectorName).GetCoins().Empty())
require.True(sdk.IntEq(t, app.AccountKeeper.GetAccount(ctx, addr1).GetCoins().AmountOf("atom"), sdk.NewInt(149)))
modAcc := app.SupplyKeeper.GetModuleAccount(ctx, types.FeeCollectorName)

require.True(t, app.BankKeeper.GetAllBalances(ctx, modAcc.GetAddress()).Empty())
require.True(sdk.IntEq(t, app.BankKeeper.GetAllBalances(ctx, addr1).AmountOf("atom"), sdk.NewInt(149)))

acc1.SetCoins(sdk.NewCoins(sdk.NewInt64Coin("atom", 150)))
app.AccountKeeper.SetAccount(ctx, acc1)
app.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("atom", 150)))
checkValidTx(t, anteHandler, ctx, tx, false)

require.True(sdk.IntEq(t, app.SupplyKeeper.GetModuleAccount(ctx, types.FeeCollectorName).GetCoins().AmountOf("atom"), sdk.NewInt(150)))
require.True(sdk.IntEq(t, app.AccountKeeper.GetAccount(ctx, addr1).GetCoins().AmountOf("atom"), sdk.NewInt(0)))
require.True(sdk.IntEq(t, app.BankKeeper.GetAllBalances(ctx, modAcc.GetAddress()).AmountOf("atom"), sdk.NewInt(150)))
require.True(sdk.IntEq(t, app.BankKeeper.GetAllBalances(ctx, addr1).AmountOf("atom"), sdk.NewInt(0)))
}

// Test logic around memo gas consumption.
Expand Down Expand Up @@ -416,17 +418,17 @@ func TestAnteHandlerMultiSigner(t *testing.T) {

// set the accounts
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
acc1.SetCoins(types.NewTestCoins())
require.NoError(t, acc1.SetAccountNumber(0))
app.AccountKeeper.SetAccount(ctx, acc1)
app.BankKeeper.SetBalances(ctx, addr1, types.NewTestCoins())
acc2 := app.AccountKeeper.NewAccountWithAddress(ctx, addr2)
acc2.SetCoins(types.NewTestCoins())
require.NoError(t, acc2.SetAccountNumber(1))
app.AccountKeeper.SetAccount(ctx, acc2)
app.BankKeeper.SetBalances(ctx, addr2, types.NewTestCoins())
acc3 := app.AccountKeeper.NewAccountWithAddress(ctx, addr3)
acc3.SetCoins(types.NewTestCoins())
require.NoError(t, acc3.SetAccountNumber(2))
app.AccountKeeper.SetAccount(ctx, acc3)
app.BankKeeper.SetBalances(ctx, addr3, types.NewTestCoins())

// set up msgs and fee
var tx sdk.Tx
Expand Down Expand Up @@ -465,13 +467,13 @@ func TestAnteHandlerBadSignBytes(t *testing.T) {

// set the accounts
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
acc1.SetCoins(types.NewTestCoins())
require.NoError(t, acc1.SetAccountNumber(0))
app.AccountKeeper.SetAccount(ctx, acc1)
app.BankKeeper.SetBalances(ctx, addr1, types.NewTestCoins())
acc2 := app.AccountKeeper.NewAccountWithAddress(ctx, addr2)
acc2.SetCoins(types.NewTestCoins())
require.NoError(t, acc2.SetAccountNumber(1))
app.AccountKeeper.SetAccount(ctx, acc2)
app.BankKeeper.SetBalances(ctx, addr2, types.NewTestCoins())

var tx sdk.Tx
msg := types.NewTestMsg(addr1)
Expand Down Expand Up @@ -542,13 +544,13 @@ func TestAnteHandlerSetPubKey(t *testing.T) {

// set the accounts
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
acc1.SetCoins(types.NewTestCoins())
require.NoError(t, acc1.SetAccountNumber(0))
app.AccountKeeper.SetAccount(ctx, acc1)
app.BankKeeper.SetBalances(ctx, addr1, types.NewTestCoins())
acc2 := app.AccountKeeper.NewAccountWithAddress(ctx, addr2)
acc2.SetCoins(types.NewTestCoins())
require.NoError(t, acc2.SetAccountNumber(1))
app.AccountKeeper.SetAccount(ctx, acc2)
app.BankKeeper.SetBalances(ctx, addr2, types.NewTestCoins())

var tx sdk.Tx

Expand Down Expand Up @@ -669,9 +671,9 @@ func TestAnteHandlerSigLimitExceeded(t *testing.T) {
// set the accounts
for i, addr := range addrs {
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
acc.SetCoins(types.NewTestCoins())
acc.SetAccountNumber(uint64(i))
app.AccountKeeper.SetAccount(ctx, acc)
app.BankKeeper.SetBalances(ctx, addr, types.NewTestCoins())
}

var tx sdk.Tx
Expand Down Expand Up @@ -705,8 +707,8 @@ func TestCustomSignatureVerificationGasConsumer(t *testing.T) {
// verify that an secp256k1 account gets rejected
priv1, _, addr1 := types.KeyTestPubAddr()
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
_ = acc1.SetCoins(sdk.NewCoins(sdk.NewInt64Coin("atom", 150)))
app.AccountKeeper.SetAccount(ctx, acc1)
app.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("atom", 150)))

var tx sdk.Tx
msg := types.NewTestMsg(addr1)
Expand All @@ -721,7 +723,8 @@ func TestCustomSignatureVerificationGasConsumer(t *testing.T) {
pub2 := priv2.PubKey()
addr2 := sdk.AccAddress(pub2.Address())
acc2 := app.AccountKeeper.NewAccountWithAddress(ctx, addr2)
require.NoError(t, acc2.SetCoins(sdk.NewCoins(sdk.NewInt64Coin("atom", 150))))

require.NoError(t, app.BankKeeper.SetBalances(ctx, addr2, sdk.NewCoins(sdk.NewInt64Coin("atom", 150))))
require.NoError(t, acc2.SetAccountNumber(1))
app.AccountKeeper.SetAccount(ctx, acc2)
msg = types.NewTestMsg(addr2)
Expand All @@ -745,9 +748,9 @@ func TestAnteHandlerReCheck(t *testing.T) {

// set the accounts
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
acc1.SetCoins(types.NewTestCoins())
require.NoError(t, acc1.SetAccountNumber(0))
app.AccountKeeper.SetAccount(ctx, acc1)
app.BankKeeper.SetBalances(ctx, addr1, types.NewTestCoins())

antehandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, ante.DefaultSigVerificationGasConsumer)

Expand Down Expand Up @@ -806,8 +809,8 @@ func TestAnteHandlerReCheck(t *testing.T) {
ctx = ctx.WithMinGasPrices(sdk.DecCoins{})

// remove funds for account so antehandler fails on recheck
acc1.SetCoins(sdk.Coins{})
app.AccountKeeper.SetAccount(ctx, acc1)
app.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins())

_, err = antehandler(ctx, tx, false)
require.NotNil(t, err, "antehandler on recheck did not fail once feePayer no longer has sufficient funds")
Expand Down
4 changes: 2 additions & 2 deletions x/auth/ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func TestDeductFees(t *testing.T) {

// Set account with insufficient funds
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
acc.SetCoins([]sdk.Coin{sdk.NewCoin("atom", sdk.NewInt(10))})
app.AccountKeeper.SetAccount(ctx, acc)
app.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(10))))

dfd := ante.NewDeductFeeDecorator(app.AccountKeeper, app.SupplyKeeper)
antehandler := sdk.ChainAnteDecorators(dfd)
Expand All @@ -89,8 +89,8 @@ func TestDeductFees(t *testing.T) {
require.NotNil(t, err, "Tx did not error when fee payer had insufficient funds")

// Set account with sufficient funds
acc.SetCoins([]sdk.Coin{sdk.NewCoin("atom", sdk.NewInt(200))})
app.AccountKeeper.SetAccount(ctx, acc)
app.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(200))))

_, err = antehandler(ctx, tx, false)

Expand Down
2 changes: 1 addition & 1 deletion x/auth/exported/exported_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestGenesisAccountsContains(t *testing.T) {
pubkey := secp256k1.GenPrivKey().PubKey()
addr := sdk.AccAddress(pubkey.Address())
acc := authtypes.NewBaseAccount(addr, nil, secp256k1.GenPrivKey().PubKey(), 0, 0)
acc := authtypes.NewBaseAccount(addr, secp256k1.GenPrivKey().PubKey(), 0, 0)

genAccounts := exported.GenesisAccounts{}
require.False(t, genAccounts.Contains(acc.GetAddress()))
Expand Down
52 changes: 0 additions & 52 deletions x/auth/keeper/keeper_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,6 @@ func BenchmarkAccountMapperGetAccountFound(b *testing.B) {
}
}

func BenchmarkAccountMapperGetAccountFoundWithCoins(b *testing.B) {
app, ctx := createTestApp(false)

coins := sdk.Coins{
sdk.NewCoin("ltc", sdk.NewInt(1000)),
sdk.NewCoin("btc", sdk.NewInt(1000)),
sdk.NewCoin("eth", sdk.NewInt(1000)),
sdk.NewCoin("xrp", sdk.NewInt(1000)),
sdk.NewCoin("bch", sdk.NewInt(1000)),
sdk.NewCoin("eos", sdk.NewInt(1000)),
}

// assumes b.N < 2**24
for i := 0; i < b.N; i++ {
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
addr := sdk.AccAddress(arr)
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
acc.SetCoins(coins)
app.AccountKeeper.SetAccount(ctx, acc)
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
app.AccountKeeper.GetAccount(ctx, sdk.AccAddress(arr))
}
}

func BenchmarkAccountMapperSetAccount(b *testing.B) {
app, ctx := createTestApp(false)

Expand All @@ -65,27 +37,3 @@ func BenchmarkAccountMapperSetAccount(b *testing.B) {
app.AccountKeeper.SetAccount(ctx, acc)
}
}

func BenchmarkAccountMapperSetAccountWithCoins(b *testing.B) {
app, ctx := createTestApp(false)

coins := sdk.Coins{
sdk.NewCoin("ltc", sdk.NewInt(1000)),
sdk.NewCoin("btc", sdk.NewInt(1000)),
sdk.NewCoin("eth", sdk.NewInt(1000)),
sdk.NewCoin("xrp", sdk.NewInt(1000)),
sdk.NewCoin("bch", sdk.NewInt(1000)),
sdk.NewCoin("eos", sdk.NewInt(1000)),
}

b.ResetTimer()

// assumes b.N < 2**24
for i := 0; i < b.N; i++ {
arr := []byte{byte((i & 0xFF0000) >> 16), byte((i & 0xFF00) >> 8), byte(i & 0xFF)}
addr := sdk.AccAddress(arr)
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
acc.SetCoins(coins)
app.AccountKeeper.SetAccount(ctx, acc)
}
}
Loading