Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slandymani committed May 8, 2024
1 parent 16db336 commit 5277cac
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 33 deletions.
55 changes: 33 additions & 22 deletions benchmark/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package benchmark
import (
"testing"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
"cosmossdk.io/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -50,10 +49,13 @@ func InitializeBenchmarkApp(b testing.TB, maxGasPerBlock int64) *BenchmarkApp {
ba.TxConfig = ba.GetTxConfig()
ba.TxEncoder = ba.TxConfig.TxEncoder()

ba.Commit()
ba.CallBeginBlock()
_, err := ba.Commit()
require.NoError(ba.TB, err)
_, err = ba.CallBeginBlock()
require.NoError(ba.TB, err)

ba.StoreConsensusParams(ba.Ctx, GetConsensusParams(maxGasPerBlock))
err = ba.StoreConsensusParams(ba.Ctx, *GetConsensusParams(maxGasPerBlock))
require.NoError(ba.TB, err)

// create oracle script
oCode, err := GetBenchmarkWasm()
Expand All @@ -75,8 +77,10 @@ func InitializeBenchmarkApp(b testing.TB, maxGasPerBlock int64) *BenchmarkApp {
// activate oracle
_, _, _ = ba.DeliverMsg(ba.Validator, GenMsgActivate(ba.Validator))

ba.CallEndBlock()
ba.Commit()
_, err = ba.CallEndBlock()
require.NoError(ba.TB, err)
_, err = ba.Commit()
require.NoError(ba.TB, err)

return ba
}
Expand All @@ -87,27 +91,27 @@ func (ba *BenchmarkApp) DeliverMsg(account *Account, msgs []sdk.Msg) (sdk.GasInf
return gas, res, err
}

func (ba *BenchmarkApp) CallBeginBlock() abci.ResponseBeginBlock {
return ba.BeginBlock(
abci.RequestBeginBlock{
Header: tmproto.Header{Height: ba.LastBlockHeight() + 1},
Hash: ba.LastCommitID().Hash,
},
)
func (ba *BenchmarkApp) CallBeginBlock() (sdk.BeginBlock, error) {
ctx := ba.Ctx.WithBlockHeight(ba.LastBlockHeight() + 1).WithHeaderHash(ba.LastCommitID().Hash)
return ba.BeginBlocker(ctx)
}

func (ba *BenchmarkApp) CallEndBlock() abci.ResponseEndBlock {
return ba.EndBlock(abci.RequestEndBlock{Height: ba.LastBlockHeight() + 1})
func (ba *BenchmarkApp) CallEndBlock() (sdk.EndBlock, error) {
ctx := ba.Ctx.WithBlockHeight(ba.LastBlockHeight() + 1)
return ba.EndBlocker(ctx)
}

func (ba *BenchmarkApp) CallDeliver(tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) {
return ba.SimDeliver(ba.TxEncoder, tx)
}

func (ba *BenchmarkApp) AddMaxMsgRequests(msg []sdk.Msg) {
func (ba *BenchmarkApp) AddMaxMsgRequests(msg []sdk.Msg) error {
// maximum of request blocks is only 20 because after that it will become report only block because of ante
for block := 0; block < 10; block++ {
ba.CallBeginBlock()
_, err := ba.CallBeginBlock()
if err != nil {
return err
}

var totalGas uint64 = 0
for {
Expand All @@ -126,14 +130,21 @@ func (ba *BenchmarkApp) AddMaxMsgRequests(msg []sdk.Msg) {
}
}

ba.CallEndBlock()
ba.Commit()
_, err = ba.CallEndBlock()
if err != nil {
return err
}
_, err = ba.Commit()
if err != nil {
return err
}
}
return nil
}

func (ba *BenchmarkApp) GetAllPendingRequests(account *Account) *oracletypes.QueryPendingRequestsResponse {
res, err := ba.Querier.PendingRequests(
sdk.WrapSDKContext(ba.Ctx),
ba.Ctx,
&oracletypes.QueryPendingRequestsRequest{
ValidatorAddress: account.ValAddress.String(),
},
Expand All @@ -158,13 +169,13 @@ func (ba *BenchmarkApp) GenMsgReportData(account *Account, rids []uint64) []sdk.

for _, rid := range rids {
request, err := ba.OracleKeeper.GetRequest(ba.Ctx, oracletypes.RequestID(rid))
require.NoError(ba.TB, err)

// find all external ids of the request
eids := []int64{}
for _, raw := range request.RawRequests {
eids = append(eids, int64(raw.ExternalID))
}
require.NoError(ba.TB, err)

rawReports := []oracletypes.RawReport{}

Expand Down
21 changes: 12 additions & 9 deletions benchmark/helper_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package benchmark

import (
"io/ioutil"
"math"
"math/rand"
"os"
"strconv"
"strings"
"testing"
"time"

types "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/client"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
owasm "github.com/odin-protocol/go-owasm/api"
Expand All @@ -36,7 +38,7 @@ type BenchmarkCalldata struct {
}

func GetBenchmarkWasm() ([]byte, error) {
oCode, err := ioutil.ReadFile("./testdata/benchmark-oracle-script.wasm")
oCode, err := os.ReadFile("./testdata/benchmark-oracle-script.wasm")
return oCode, err
}

Expand Down Expand Up @@ -128,7 +130,8 @@ func GenSequenceOfTxs(
txs := make([]sdk.Tx, numTxs)

for i := 0; i < numTxs; i++ {
txs[i], _ = testapp.GenTx(
txs[i], _ = simtestutil.GenSignedMockTx(
rand.New(rand.NewSource(time.Now().UnixNano())),
txConfig,
msgs,
sdk.Coins{sdk.NewInt64Coin("loki", 1)},
Expand Down Expand Up @@ -215,17 +218,17 @@ func InitOwasmTestEnv(
return owasmVM, compiledCode, req
}

func GetConsensusParams(maxGas int64) *tmproto.ConsensusParams {
return &tmproto.ConsensusParams{
Block: &tmproto.BlockParams{
func GetConsensusParams(maxGas int64) *cmtproto.ConsensusParams {
return &cmtproto.ConsensusParams{
Block: &cmtproto.BlockParams{
MaxBytes: 200000,
MaxGas: maxGas,
},
Evidence: &tmproto.EvidenceParams{
Evidence: &cmtproto.EvidenceParams{
MaxAgeNumBlocks: 302400,
MaxAgeDuration: 504 * time.Hour,
},
Validator: &tmproto.ValidatorParams{
Validator: &cmtproto.ValidatorParams{
PubKeyTypes: []string{
tmtypes.ABCIPubKeyTypeSecp256k1,
},
Expand Down
2 changes: 1 addition & 1 deletion client/grpc/oracle/proof/iavl_proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

storetypes "cosmossdk.io/store/types"
"github.com/cometbft/cometbft/crypto/tmhash"
ics23 "github.com/confio/ics23/go"
ics23 "github.com/cosmos/ics23/go"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion client/grpc/oracle/proof/multi_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

storetypes "cosmossdk.io/store/types"
"github.com/cometbft/cometbft/crypto/tmhash"
ics23 "github.com/confio/ics23/go"
ics23 "github.com/cosmos/ics23/go"
"github.com/stretchr/testify/require"
)

Expand Down

0 comments on commit 5277cac

Please sign in to comment.