Skip to content

Commit 8f88057

Browse files
mergify[bot]Alex Johnson
andauthored
test: make extendable (#112) (#113)
* wip * ok * ok * configurable * async (cherry picked from commit daca8c8) # Conflicts: # tests/e2e/e2e_test.go # tests/e2e/suite.go Co-authored-by: Alex Johnson <[email protected]>
1 parent a2469bc commit 8f88057

File tree

2 files changed

+185
-9
lines changed

2 files changed

+185
-9
lines changed

tests/e2e/e2e_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ import (
99
"github.com/cosmos/cosmos-sdk/x/auth"
1010
"github.com/cosmos/cosmos-sdk/x/bank"
1111
"github.com/cosmos/cosmos-sdk/x/gov"
12+
<<<<<<< HEAD
1213
interchaintest "github.com/strangelove-ventures/interchaintest/v7"
1314
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
1415
"github.com/strangelove-ventures/interchaintest/v7/ibc"
1516
ictestutil "github.com/strangelove-ventures/interchaintest/v7/testutil"
17+
=======
18+
interchaintest "github.com/strangelove-ventures/interchaintest/v8"
19+
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
20+
"github.com/strangelove-ventures/interchaintest/v8/ibc"
21+
>>>>>>> daca8c8 (test: make extendable (#112))
1622
"github.com/stretchr/testify/suite"
1723

1824
"github.com/skip-mev/feemarket/tests/e2e"
@@ -104,11 +110,22 @@ var (
104110
ConfigFileOverrides: map[string]any{"config/config.toml": ictestutil.Toml{"consensus": consensusParams}},
105111
},
106112
}
113+
114+
txCfg = e2e.TestTxConfig{
115+
SmallSendsNum: 1,
116+
LargeSendsNum: 400,
117+
TargetIncreaseGasPrice: sdkmath.LegacyMustNewDecFromStr("0.1"),
118+
}
107119
)
108120

109121
func TestE2ETestSuite(t *testing.T) {
110122
s := e2e.NewIntegrationSuite(
111123
spec,
124+
<<<<<<< HEAD
125+
=======
126+
oracleImage,
127+
txCfg,
128+
>>>>>>> daca8c8 (test: make extendable (#112))
112129
)
113130

114131
suite.Run(t, s)

tests/e2e/suite.go

Lines changed: 168 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package e2e
22

33
import (
44
"context"
5+
"fmt"
56
"math/rand"
67
"os"
78
"os/signal"
@@ -36,6 +37,83 @@ func init() {
3637
r = rand.New(s)
3738
}
3839

40+
<<<<<<< HEAD
41+
=======
42+
func DefaultOracleSidecar(image ibc.DockerImage) ibc.SidecarConfig {
43+
return ibc.SidecarConfig{
44+
ProcessName: "oracle",
45+
Image: image,
46+
HomeDir: "/oracle",
47+
Ports: []string{"8080", "8081"},
48+
StartCmd: []string{
49+
"slinky",
50+
"--oracle-config", "/oracle/oracle.json",
51+
},
52+
ValidatorProcess: true,
53+
PreStart: true,
54+
}
55+
}
56+
57+
func DefaultOracleConfig(url string) oracleconfig.OracleConfig {
58+
cfg := marketmap.DefaultAPIConfig
59+
cfg.Endpoints = []oracleconfig.Endpoint{
60+
{
61+
URL: url,
62+
},
63+
}
64+
65+
// Create the oracle config
66+
oracleConfig := oracleconfig.OracleConfig{
67+
UpdateInterval: 500 * time.Millisecond,
68+
MaxPriceAge: 1 * time.Minute,
69+
Host: "0.0.0.0",
70+
Port: "8080",
71+
Providers: map[string]oracleconfig.ProviderConfig{
72+
marketmap.Name: {
73+
Name: marketmap.Name,
74+
API: cfg,
75+
Type: "market_map_provider",
76+
},
77+
},
78+
}
79+
80+
return oracleConfig
81+
}
82+
83+
func DefaultMarketMap() mmtypes.MarketMap {
84+
return mmtypes.MarketMap{}
85+
}
86+
87+
func GetOracleSideCar(node *cosmos.ChainNode) *cosmos.SidecarProcess {
88+
if len(node.Sidecars) == 0 {
89+
panic("no sidecars found")
90+
}
91+
return node.Sidecars[0]
92+
}
93+
94+
type TestTxConfig struct {
95+
SmallSendsNum int
96+
LargeSendsNum int
97+
TargetIncreaseGasPrice math.LegacyDec
98+
}
99+
100+
func (tx *TestTxConfig) Validate() error {
101+
if tx.SmallSendsNum < 1 || tx.LargeSendsNum < 1 {
102+
return fmt.Errorf("sends num should be greater than 1")
103+
}
104+
105+
if tx.TargetIncreaseGasPrice.IsNil() {
106+
return fmt.Errorf("target increase gas price is nil")
107+
}
108+
109+
if tx.TargetIncreaseGasPrice.LTE(math.LegacyZeroDec()) {
110+
return fmt.Errorf("target increase gas price is less than or equal to 0")
111+
}
112+
113+
return nil
114+
}
115+
116+
>>>>>>> daca8c8 (test: make extendable (#112))
39117
// TestSuite runs the feemarket e2e test-suite against a given interchaintest specification
40118
type TestSuite struct {
41119
suite.Suite
@@ -71,6 +149,8 @@ type TestSuite struct {
71149

72150
// chain constructor
73151
cc ChainConstructor
152+
153+
txConfig TestTxConfig
74154
}
75155

76156
// Option is a function that modifies the TestSuite
@@ -111,13 +191,30 @@ func WithChainConstructor(cc ChainConstructor) Option {
111191
}
112192
}
113193

194+
<<<<<<< HEAD
114195
func NewIntegrationSuite(spec *interchaintest.ChainSpec, opts ...Option) *TestSuite {
115196
suite := &TestSuite{
116197
spec: spec,
117198
denom: defaultDenom,
118199
authority: authtypes.NewModuleAddress(govtypes.ModuleName),
119200
icc: DefaultInterchainConstructor,
120201
cc: DefaultChainConstructor,
202+
=======
203+
func NewIntegrationSuite(spec *interchaintest.ChainSpec, oracleImage ibc.DockerImage, txCfg TestTxConfig, opts ...Option) *TestSuite {
204+
if err := txCfg.Validate(); err != nil {
205+
panic(err)
206+
}
207+
208+
suite := &TestSuite{
209+
spec: spec,
210+
oracleConfig: DefaultOracleSidecar(oracleImage),
211+
denom: defaultDenom,
212+
gasPrices: "",
213+
authority: authtypes.NewModuleAddress(govtypes.ModuleName),
214+
icc: DefaultInterchainConstructor,
215+
cc: DefaultChainConstructor,
216+
txConfig: txCfg,
217+
>>>>>>> daca8c8 (test: make extendable (#112))
121218
}
122219

123220
for _, opt := range opts {
@@ -252,15 +349,42 @@ func (s *TestSuite) TestSendTxDecrease() {
252349
gas := int64(200000)
253350
minBaseFee := sdk.NewDecCoinFromDec(defaultGasPrice.Denom, defaultGasPrice.Amount.Mul(math.LegacyNewDec(gas)))
254351
minBaseFeeCoins := sdk.NewCoins(sdk.NewCoin(minBaseFee.Denom, minBaseFee.Amount.TruncateInt()))
255-
sendAmt := int64(100000)
352+
sendAmt := int64(100)
256353

257354
s.Run("expect fee market state to decrease", func() {
258355
s.T().Log("performing sends...")
356+
<<<<<<< HEAD
259357
for {
260358
// send with the exact expected fee
261359
height, err := s.chain.(*cosmos.CosmosChain).Height(context.Background())
262360
s.Require().NoError(err)
263361
// send with the exact expected defaultGasPrice
362+
=======
363+
sig := make(chan struct{})
364+
quit := make(chan struct{})
365+
defer close(quit)
366+
367+
checkPrice := func(c, quit chan struct{}) {
368+
select {
369+
case <-time.After(500 * time.Millisecond):
370+
gasPrice := s.QueryDefaultGasPrice()
371+
s.T().Log("gas price", gasPrice.String())
372+
373+
if gasPrice.Amount.Equal(params.MinBaseGasPrice) {
374+
c <- struct{}{}
375+
}
376+
case <-quit:
377+
return
378+
}
379+
}
380+
go checkPrice(sig, quit)
381+
382+
select {
383+
case <-sig:
384+
break
385+
386+
case <-time.After(100 * time.Millisecond):
387+
>>>>>>> daca8c8 (test: make extendable (#112))
264388
wg := sync.WaitGroup{}
265389
wg.Add(3)
266390

@@ -273,7 +397,7 @@ func (s *TestSuite) TestSendTxDecrease() {
273397
sdk.NewCoins(sdk.NewCoin(cosmosChain.Config().Denom, math.NewInt(sendAmt))),
274398
minBaseFeeCoins,
275399
gas,
276-
1,
400+
s.txConfig.SmallSendsNum,
277401
)
278402
s.Require().NoError(err, txResp)
279403
s.Require().Equal(uint32(0), txResp.CheckTx.Code, txResp.CheckTx)
@@ -289,7 +413,7 @@ func (s *TestSuite) TestSendTxDecrease() {
289413
sdk.NewCoins(sdk.NewCoin(cosmosChain.Config().Denom, math.NewInt(sendAmt))),
290414
minBaseFeeCoins,
291415
gas,
292-
1,
416+
s.txConfig.SmallSendsNum,
293417
)
294418
s.Require().NoError(err, txResp)
295419
s.Require().Equal(uint32(0), txResp.CheckTx.Code, txResp.CheckTx)
@@ -305,13 +429,14 @@ func (s *TestSuite) TestSendTxDecrease() {
305429
sdk.NewCoins(sdk.NewCoin(cosmosChain.Config().Denom, math.NewInt(sendAmt))),
306430
minBaseFeeCoins,
307431
gas,
308-
1,
432+
s.txConfig.SmallSendsNum,
309433
)
310434
s.Require().NoError(err, txResp)
311435
s.Require().Equal(uint32(0), txResp.CheckTx.Code, txResp.CheckTx)
312436
s.Require().Equal(uint32(0), txResp.DeliverTx.Code, txResp.DeliverTx)
313437
}()
314438
wg.Wait()
439+
<<<<<<< HEAD
315440
s.WaitForHeight(s.chain.(*cosmos.CosmosChain), height+1)
316441

317442
gasPrice := s.QueryDefaultGasPrice()
@@ -320,6 +445,8 @@ func (s *TestSuite) TestSendTxDecrease() {
320445
if gasPrice.Amount.Equal(params.MinBaseGasPrice) {
321446
break
322447
}
448+
=======
449+
>>>>>>> daca8c8 (test: make extendable (#112))
323450
}
324451

325452
// wait for 5 blocks
@@ -348,17 +475,46 @@ func (s *TestSuite) TestSendTxIncrease() {
348475
nodes := cosmosChain.Nodes()
349476
s.Require().True(len(nodes) > 0)
350477

478+
<<<<<<< HEAD
351479
baseGasPrice := s.QueryDefaultGasPrice()
352480
gas := int64(20000100)
353481
sendAmt := int64(100)
354482

483+
=======
484+
>>>>>>> daca8c8 (test: make extendable (#112))
355485
params := s.QueryParams()
356486

487+
gas := int64(params.MaxBlockUtilization)
488+
sendAmt := int64(100)
489+
357490
s.Run("expect fee market gas price to increase", func() {
358491
s.T().Log("performing sends...")
359-
for {
492+
sig := make(chan struct{})
493+
quit := make(chan struct{})
494+
defer close(quit)
495+
496+
checkPrice := func(c, quit chan struct{}) {
497+
select {
498+
case <-time.After(500 * time.Millisecond):
499+
gasPrice := s.QueryDefaultGasPrice()
500+
s.T().Log("gas price", gasPrice.String())
501+
502+
if gasPrice.Amount.GT(s.txConfig.TargetIncreaseGasPrice) {
503+
c <- struct{}{}
504+
}
505+
case <-quit:
506+
return
507+
}
508+
}
509+
go checkPrice(sig, quit)
510+
511+
select {
512+
case <-sig:
513+
break
514+
515+
case <-time.After(100 * time.Millisecond):
360516
// send with the exact expected baseGasPrice
361-
baseGasPrice = s.QueryDefaultGasPrice()
517+
baseGasPrice := s.QueryDefaultGasPrice()
362518
minBaseFee := sdk.NewDecCoinFromDec(baseGasPrice.Denom, baseGasPrice.Amount.Mul(math.LegacyNewDec(gas)))
363519
// add headroom
364520
minBaseFeeCoins := sdk.NewCoins(sdk.NewCoin(minBaseFee.Denom, minBaseFee.Amount.Add(math.LegacyNewDec(10)).TruncateInt()))
@@ -377,7 +533,7 @@ func (s *TestSuite) TestSendTxIncrease() {
377533
sdk.NewCoins(sdk.NewCoin(cosmosChain.Config().Denom, math.NewInt(sendAmt))),
378534
minBaseFeeCoins,
379535
gas,
380-
400,
536+
s.txConfig.LargeSendsNum,
381537
)
382538
s.Require().NoError(err, txResp)
383539
s.Require().Equal(uint32(0), txResp.CheckTx.Code, txResp.CheckTx)
@@ -393,7 +549,7 @@ func (s *TestSuite) TestSendTxIncrease() {
393549
sdk.NewCoins(sdk.NewCoin(cosmosChain.Config().Denom, math.NewInt(sendAmt))),
394550
minBaseFeeCoins,
395551
gas,
396-
400,
552+
s.txConfig.LargeSendsNum,
397553
)
398554
s.Require().NoError(err, txResp)
399555
s.Require().Equal(uint32(0), txResp.CheckTx.Code, txResp.CheckTx)
@@ -409,13 +565,14 @@ func (s *TestSuite) TestSendTxIncrease() {
409565
sdk.NewCoins(sdk.NewCoin(cosmosChain.Config().Denom, math.NewInt(sendAmt))),
410566
minBaseFeeCoins,
411567
gas,
412-
400,
568+
s.txConfig.LargeSendsNum,
413569
)
414570
s.Require().NoError(err, txResp)
415571
s.Require().Equal(uint32(0), txResp.CheckTx.Code, txResp.CheckTx)
416572
s.Require().Equal(uint32(0), txResp.DeliverTx.Code, txResp.DeliverTx)
417573
}()
418574
wg.Wait()
575+
<<<<<<< HEAD
419576
s.WaitForHeight(s.chain.(*cosmos.CosmosChain), height+1)
420577

421578
baseGasPrice = s.QueryDefaultGasPrice()
@@ -424,6 +581,8 @@ func (s *TestSuite) TestSendTxIncrease() {
424581
if baseGasPrice.Amount.GT(params.MinBaseGasPrice.Mul(math.LegacyNewDec(10))) {
425582
break
426583
}
584+
=======
585+
>>>>>>> daca8c8 (test: make extendable (#112))
427586
}
428587

429588
// wait for 5 blocks

0 commit comments

Comments
 (0)