Skip to content

init refactor testapp #330

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

Merged
merged 13 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
12 changes: 6 additions & 6 deletions benchmark/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ import (
"testing"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

testapp "github.com/bandprotocol/chain/v2/testing/testapp"
bandtesting "github.com/bandprotocol/chain/v2/testing"
"github.com/bandprotocol/chain/v2/x/oracle/keeper"
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
)

type BenchmarkApp struct {
*testapp.TestingApp
*bandtesting.TestingApp
Sender *Account
Validator *Account
Oid uint64
Expand All @@ -29,15 +28,16 @@ type BenchmarkApp struct {
}

func InitializeBenchmarkApp(b testing.TB, maxGasPerBlock int64) *BenchmarkApp {
app, _ := bandtesting.CreateTestApp(&testing.T{}, false)
ba := &BenchmarkApp{
TestingApp: testapp.NewTestApp("", log.NewNopLogger()),
TestingApp: app,
Sender: &Account{
Account: testapp.Owner,
Account: bandtesting.Owner,
Num: 0,
Seq: 0,
},
Validator: &Account{
Account: testapp.Validators[0],
Account: bandtesting.Validators[0],
Num: 5,
Seq: 0,
},
Expand Down
6 changes: 3 additions & 3 deletions benchmark/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
"github.com/stretchr/testify/require"

"github.com/bandprotocol/chain/v2/pkg/obi"
"github.com/bandprotocol/chain/v2/testing/testapp"
bandtesting "github.com/bandprotocol/chain/v2/testing"
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
)

type Account struct {
testapp.Account
bandtesting.Account
Num uint64
Seq uint64
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func GenSequenceOfTxs(
txs := make([]sdk.Tx, numTxs)

for i := 0; i < numTxs; i++ {
txs[i], _ = testapp.GenTx(
txs[i], _ = bandtesting.GenTx(
txConfig,
msgs,
sdk.Coins{sdk.NewInt64Coin("uband", 1)},
Expand Down
32 changes: 16 additions & 16 deletions testing/chain.go → testing/ibctesting/chain.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 0.47 TODO: consider importing directly from ibc instead of forking
package ibctesting

// 0.47 TODO: consider importing directly from ibc instead of forking

import (
"bytes"
"fmt"
Expand Down Expand Up @@ -34,7 +35,7 @@ import (
"github.com/stretchr/testify/require"

bandapp "github.com/bandprotocol/chain/v2/app"
"github.com/bandprotocol/chain/v2/testing/testapp"
bandtesting "github.com/bandprotocol/chain/v2/testing"
"github.com/bandprotocol/chain/v2/x/oracle/types"
)

Expand All @@ -51,7 +52,7 @@ type TestChain struct {
t *testing.T

Coordinator *Coordinator
App *testapp.TestingApp
App *bandtesting.TestingApp
ChainID string
LastHeader *ibctmtypes.Header // header for last block height committed
CurrentHeader tmproto.Header // header for current block height
Expand All @@ -78,7 +79,6 @@ type TestChain struct {
// Time management is handled by the Coordinator in order to ensure synchrony between chains.
// Each update of any chain increments the block header time for all chains by 5 seconds.
func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {
// TODO: change sender
signers := make([]tmtypes.PrivValidator, valSize)
validators := make([]*tmtypes.Validator, valSize)
genesisAccount := make([]authtypes.GenesisAccount, valSize)
Expand All @@ -87,22 +87,22 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {

for i := uint64(0); i < valSize; i++ {
// generate validator private/public key
privVal := mock.PV{PrivKey: testapp.Validators[i].PrivKey}
tmPub, err := cryptocodec.ToTmPubKeyInterface(testapp.Validators[i].PubKey)
privVal := mock.PV{PrivKey: bandtesting.Validators[i].PrivKey}
tmPub, err := cryptocodec.ToTmPubKeyInterface(bandtesting.Validators[i].PubKey)
require.NoError(t, err)

// create validator set with two validators
validators[i] = tmtypes.NewValidator(tmPub, 1)

signers[i] = privVal

senders[testapp.Validators[i].Address.String()] = authtypes.NewBaseAccount(
testapp.Validators[i].PubKey.Address().Bytes(),
testapp.Validators[i].PubKey,
senders[bandtesting.Validators[i].Address.String()] = authtypes.NewBaseAccount(
bandtesting.Validators[i].PubKey.Address().Bytes(),
bandtesting.Validators[i].PubKey,
i,
0,
)
genesisAccount[i] = senders[testapp.Validators[i].Address.String()]
genesisAccount[i] = senders[bandtesting.Validators[i].Address.String()]
balances[i] = banktypes.Balance{
Address: genesisAccount[i].GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin("uband", sdk.NewInt(10000000))),
Expand All @@ -111,7 +111,7 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {

valSet := tmtypes.NewValidatorSet(validators)

app := testapp.SetupWithGenesisValSet(t, valSet, genesisAccount, chainID, balances...)
app := bandtesting.SetupWithGenesisValSet(t, valSet, genesisAccount, chainID, balances...)
ctx := app.NewContext(false, tmproto.Header{Height: app.LastBlockHeight()})
vals := app.StakingKeeper.GetAllValidators(ctx)
for _, v := range vals {
Expand Down Expand Up @@ -139,9 +139,9 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {
Codec: app.AppCodec(),
Vals: valSet,
Signers: signers,
SenderPrivKey: testapp.Validators[0].PrivKey,
SenderPrivKey: bandtesting.Validators[0].PrivKey,
SenderAccount: genesisAccount[0],
Treasury: testapp.Treasury.Address,
Treasury: bandtesting.Treasury.Address,
senders: senders,
}

Expand Down Expand Up @@ -257,7 +257,7 @@ func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
// ensure the chain has the latest time
chain.Coordinator.UpdateTimeForChain(chain)

_, r, err := testapp.SignAndDeliver(
_, r, err := bandtesting.SignAndDeliver(
chain.t,
chain.TxConfig,
chain.App.GetBaseApp(),
Expand Down Expand Up @@ -289,14 +289,14 @@ func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
func (chain *TestChain) SendReport(
rid types.RequestID,
rawReps []types.RawReport,
sender testapp.Account,
sender bandtesting.Account,
) (*sdk.Result, error) {
senderAccount := chain.senders[sender.Address.String()]

// ensure the chain has the latest time
chain.Coordinator.UpdateTimeForChain(chain)

_, r, err := testapp.SignAndDeliver(
_, r, err := bandtesting.SignAndDeliver(
chain.t,
chain.TxConfig,
chain.App.GetBaseApp(),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading