Skip to content

Commit

Permalink
init refactor testdata
Browse files Browse the repository at this point in the history
  • Loading branch information
satawatnack committed Sep 19, 2023
1 parent ef868be commit ebf53d3
Show file tree
Hide file tree
Showing 36 changed files with 1,511 additions and 1,199 deletions.
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
7 changes: 4 additions & 3 deletions benchmark/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"time"

"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"
owasm "github.com/bandprotocol/go-owasm/api"
types "github.com/cometbft/cometbft/abci/types"
Expand All @@ -22,7 +23,7 @@ import (
)

type Account struct {
testapp.Account
bandtesting.Account
Num uint64
Seq uint64
}
Expand Down Expand Up @@ -127,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
31 changes: 16 additions & 15 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 @@ -35,7 +36,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 @@ -52,7 +53,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 Down Expand Up @@ -88,22 +89,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 @@ -112,7 +113,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 @@ -140,9 +141,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 @@ -258,7 +259,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 @@ -290,14 +291,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

0 comments on commit ebf53d3

Please sign in to comment.