Skip to content

Commit

Permalink
Move benchmark into module
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon committed Jun 22, 2018
1 parent f41ad63 commit 22d63f7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 47 deletions.
2 changes: 1 addition & 1 deletion baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package baseapp
import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/x/bank"
"os"
"testing"

Expand All @@ -20,6 +19,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
)

func defaultLogger() log.Logger {
Expand Down
18 changes: 8 additions & 10 deletions x/auth/mock/simulate_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,18 @@ func GenTx(msgs []sdk.Msg, accnums []int64, seq []int64, priv ...crypto.PrivKeyE

// generate a set of signed transactions a msg, that differ only by having the
// sequence numbers incremented between every transaction.
func GenSequenceOfTxs(msgs []sdk.Msg, accnums []int64, init_seq_nums []int64, num_to_generate int, priv ...crypto.PrivKeyEd25519) []auth.StdTx {
copy_of_init_seq_nums := make([]int64, len(init_seq_nums), len(init_seq_nums))
copy(copy_of_init_seq_nums, init_seq_nums)
txs := make([]auth.StdTx, num_to_generate, num_to_generate)
for i := 0; i < num_to_generate; i++ {
txs[i] = GenTx(msgs, accnums, copy_of_init_seq_nums, priv...)
incrementAllSequenceNumbers(copy_of_init_seq_nums)
func GenSequenceOfTxs(msgs []sdk.Msg, accnums []int64, initSeqNums []int64, numToGenerate int, priv ...crypto.PrivKeyEd25519) []auth.StdTx {
txs := make([]auth.StdTx, numToGenerate, numToGenerate)
for i := 0; i < numToGenerate; i++ {
txs[i] = GenTx(msgs, accnums, initSeqNums, priv...)
incrementAllSequenceNumbers(initSeqNums)
}
return txs
}

func incrementAllSequenceNumbers(init_seq_nums []int64) {
for i := 0; i < len(init_seq_nums); i++ {
init_seq_nums[i] += 1
func incrementAllSequenceNumbers(initSeqNums []int64) {
for i := 0; i < len(initSeqNums); i++ {
initSeqNums[i]++
}
}

Expand Down
15 changes: 14 additions & 1 deletion x/bank/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,24 @@ var (

// initialize the mock application for this module
func getMockApp(t *testing.T) *mock.App {
mapp, err := GetBenchmarkMockApp()
mapp, err := getBenchmarkMockApp()
require.NoError(t, err)
return mapp
}

// getBenchmarkMockApp initializes a mock application for this module, for purposes of benchmarking
// Any long term API support commitments do not apply to this function.
func getBenchmarkMockApp() (*mock.App, error) {
mapp := mock.NewApp()

RegisterWire(mapp.Cdc)
coinKeeper := NewKeeper(mapp.AccountMapper)
mapp.Router().AddRoute("bank", NewHandler(coinKeeper))

err := mapp.CompleteSetup([]*sdk.KVStoreKey{})
return mapp, err
}

func TestMsgSendWithAccounts(t *testing.T) {
mapp := getMockApp(t)

Expand Down
19 changes: 3 additions & 16 deletions tests/bench/block_processing_time_test.go → x/bank/bench_test.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
package benchmarking
package bank

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/mock"
"github.com/cosmos/cosmos-sdk/x/bank"
abci "github.com/tendermint/abci/types"
crypto "github.com/tendermint/go-crypto"
)

var (
priv1 = crypto.GenPrivKeyEd25519()
addr1 = priv1.PubKey().Address()
priv2 = crypto.GenPrivKeyEd25519()
addr2 = priv2.PubKey().Address()
coins = sdk.Coins{sdk.NewCoin("foocoin", 10)}
sendMsg1 = bank.MsgSend{
Inputs: []bank.Input{bank.NewInput(addr1, coins)},
Outputs: []bank.Output{bank.NewOutput(addr2, coins)},
}
abci "github.com/tendermint/abci/types"
)

func BenchmarkOneBankSendTxPerBlock(b *testing.B) {
benchmarkApp, _ := bank.GetBenchmarkMockApp()
benchmarkApp, _ := getBenchmarkMockApp()

// Add an account at genesis
acc := &auth.BaseAccount{
Expand Down
19 changes: 0 additions & 19 deletions x/bank/test_helpers.go

This file was deleted.

0 comments on commit 22d63f7

Please sign in to comment.