Skip to content

Commit d46e1d9

Browse files
satawatnacksatawatnackRogerKSI
authored
init refactor testapp (#330)
* init refactor testdata * move back * move package * remove print * add comment * fix test * fix test * fix test * fix --------- Co-authored-by: satawatnack <satawat@bandprotocol.com> Co-authored-by: Kitipong Sirirueangsakul <kitipong.sirir@gmail.com>
1 parent 9b1d4da commit d46e1d9

28 files changed

+1444
-1149
lines changed

benchmark/app_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ import (
44
"testing"
55

66
abci "github.com/cometbft/cometbft/abci/types"
7-
"github.com/cometbft/cometbft/libs/log"
87
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
98
"github.com/cosmos/cosmos-sdk/client"
109
sdk "github.com/cosmos/cosmos-sdk/types"
1110
"github.com/stretchr/testify/require"
1211

13-
testapp "github.com/bandprotocol/chain/v2/testing/testapp"
12+
bandtesting "github.com/bandprotocol/chain/v2/testing"
1413
"github.com/bandprotocol/chain/v2/x/oracle/keeper"
1514
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
1615
)
1716

1817
type BenchmarkApp struct {
19-
*testapp.TestingApp
18+
*bandtesting.TestingApp
2019
Sender *Account
2120
Validator *Account
2221
Oid uint64
@@ -29,15 +28,16 @@ type BenchmarkApp struct {
2928
}
3029

3130
func InitializeBenchmarkApp(tb testing.TB, maxGasPerBlock int64) *BenchmarkApp {
31+
app, _ := bandtesting.CreateTestApp(&testing.T{}, false)
3232
ba := &BenchmarkApp{
33-
TestingApp: testapp.NewTestApp("", log.NewNopLogger()),
33+
TestingApp: app,
3434
Sender: &Account{
35-
Account: testapp.Owner,
35+
Account: bandtesting.Owner,
3636
Num: 0,
3737
Seq: 0,
3838
},
3939
Validator: &Account{
40-
Account: testapp.Validators[0],
40+
Account: bandtesting.Validators[0],
4141
Num: 5,
4242
Seq: 0,
4343
},

benchmark/helper_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import (
1818
"github.com/stretchr/testify/require"
1919

2020
"github.com/bandprotocol/chain/v2/pkg/obi"
21-
"github.com/bandprotocol/chain/v2/testing/testapp"
21+
bandtesting "github.com/bandprotocol/chain/v2/testing"
2222
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
2323
)
2424

2525
type Account struct {
26-
testapp.Account
26+
bandtesting.Account
2727
Num uint64
2828
Seq uint64
2929
}
@@ -128,7 +128,7 @@ func GenSequenceOfTxs(
128128
txs := make([]sdk.Tx, numTxs)
129129

130130
for i := 0; i < numTxs; i++ {
131-
txs[i], _ = testapp.GenTx(
131+
txs[i], _ = bandtesting.GenTx(
132132
txConfig,
133133
msgs,
134134
sdk.Coins{sdk.NewInt64Coin("uband", 1)},

testing/chain.go renamed to testing/ibctesting/chain.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"github.com/stretchr/testify/require"
3434

3535
bandapp "github.com/bandprotocol/chain/v2/app"
36-
"github.com/bandprotocol/chain/v2/testing/testapp"
36+
bandtesting "github.com/bandprotocol/chain/v2/testing"
3737
"github.com/bandprotocol/chain/v2/x/oracle/types"
3838
)
3939

@@ -48,7 +48,7 @@ type TestChain struct {
4848
t *testing.T
4949

5050
Coordinator *Coordinator
51-
App *testapp.TestingApp
51+
App *bandtesting.TestingApp
5252
ChainID string
5353
LastHeader *ibctmtypes.Header // header for last block height committed
5454
CurrentHeader tmproto.Header // header for current block height
@@ -83,22 +83,22 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {
8383

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

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

9393
signers[i] = privVal
9494

95-
senders[testapp.Validators[i].Address.String()] = authtypes.NewBaseAccount(
96-
testapp.Validators[i].PubKey.Address().Bytes(),
97-
testapp.Validators[i].PubKey,
95+
senders[bandtesting.Validators[i].Address.String()] = authtypes.NewBaseAccount(
96+
bandtesting.Validators[i].PubKey.Address().Bytes(),
97+
bandtesting.Validators[i].PubKey,
9898
i,
9999
0,
100100
)
101-
genesisAccount[i] = senders[testapp.Validators[i].Address.String()]
101+
genesisAccount[i] = senders[bandtesting.Validators[i].Address.String()]
102102
balances[i] = banktypes.Balance{
103103
Address: genesisAccount[i].GetAddress().String(),
104104
Coins: sdk.NewCoins(sdk.NewCoin("uband", sdk.NewInt(10000000))),
@@ -107,7 +107,7 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {
107107

108108
valSet := tmtypes.NewValidatorSet(validators)
109109

110-
app := testapp.SetupWithGenesisValSet(t, valSet, genesisAccount, chainID, balances...)
110+
app := bandtesting.SetupWithGenesisValSet(t, valSet, genesisAccount, chainID, balances...)
111111
ctx := app.NewContext(false, tmproto.Header{Height: app.LastBlockHeight()})
112112
vals := app.StakingKeeper.GetAllValidators(ctx)
113113
for _, v := range vals {
@@ -136,9 +136,9 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain {
136136
Codec: app.AppCodec(),
137137
Vals: valSet,
138138
Signers: signers,
139-
SenderPrivKey: testapp.Validators[0].PrivKey,
139+
SenderPrivKey: bandtesting.Validators[0].PrivKey,
140140
SenderAccount: genesisAccount[0],
141-
Treasury: testapp.Treasury.Address,
141+
Treasury: bandtesting.Treasury.Address,
142142
senders: senders,
143143
}
144144

@@ -254,7 +254,7 @@ func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
254254
// ensure the chain has the latest time
255255
chain.Coordinator.UpdateTimeForChain(chain)
256256

257-
_, r, err := testapp.SignAndDeliver(
257+
_, r, err := bandtesting.SignAndDeliver(
258258
chain.t,
259259
chain.TxConfig,
260260
chain.App.GetBaseApp(),
@@ -287,14 +287,14 @@ func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
287287
func (chain *TestChain) SendReport(
288288
rid types.RequestID,
289289
rawReps []types.RawReport,
290-
sender testapp.Account,
290+
sender bandtesting.Account,
291291
) (*sdk.Result, error) {
292292
senderAccount := chain.senders[sender.Address.String()]
293293

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

297-
_, r, err := testapp.SignAndDeliver(
297+
_, r, err := bandtesting.SignAndDeliver(
298298
chain.t,
299299
chain.TxConfig,
300300
chain.App.GetBaseApp(),
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)