-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests for feemarket gas prices query
- Loading branch information
1 parent
76b2d18
commit e7378fb
Showing
6 changed files
with
2,166 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package submit | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
cosmossdk_io_math "cosmossdk.io/math" | ||
abci "github.com/cometbft/cometbft/abci/types" | ||
coretypes "github.com/cometbft/cometbft/rpc/core/types" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/types" | ||
authtxtypes "github.com/cosmos/cosmos-sdk/x/auth/tx" | ||
"github.com/golang/mock/gomock" | ||
submit_mock "github.com/neutron-org/neutron-query-relayer/testutil/mocks/submit" | ||
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func setupTest(t *testing.T, gasMultiplier float64, maxGas float64, gasPrices string, mockClient *submit_mock.MockClient) *TxSender { | ||
logger, _ := zap.NewDevelopment() | ||
txConfig := authtxtypes.NewTxConfig(codec.NewProtoCodec(nil), authtxtypes.DefaultSignModes) | ||
return &TxSender{ | ||
rpcClient: mockClient, | ||
txConfig: txConfig, | ||
logger: logger, | ||
denom: "testdenom", | ||
gasMultiplier: gasMultiplier, | ||
maxGas: maxGas, | ||
gasPrices: gasPrices, | ||
} | ||
} | ||
|
||
func TestQueryDynamicPrice(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
gasMultiplier float64 | ||
maxGas float64 | ||
gasPrices string | ||
mockResponse *coretypes.ResultABCIQuery | ||
expectedPrice string | ||
expectError bool | ||
}{ | ||
{ | ||
name: "Basic", | ||
gasMultiplier: 1.0, | ||
maxGas: 100000000, | ||
mockResponse: &coretypes.ResultABCIQuery{ | ||
Response: abci.ResponseQuery{ | ||
Code: 0, | ||
Value: func() []byte { | ||
gasPrice := feemarkettypes.GasPriceResponse{ | ||
Price: types.DecCoin{ | ||
Denom: "testdenom", | ||
Amount: cosmossdk_io_math.LegacyNewDec(123), | ||
}, | ||
} | ||
rawGasPrice, _ := gasPrice.Marshal() | ||
return rawGasPrice | ||
}(), | ||
}, | ||
}, | ||
expectedPrice: "123testdenom", | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Multiply", | ||
gasMultiplier: 1.1, | ||
maxGas: 100000000, | ||
mockResponse: &coretypes.ResultABCIQuery{ | ||
Response: abci.ResponseQuery{ | ||
Code: 0, | ||
Value: func() []byte { | ||
gasPrice := feemarkettypes.GasPriceResponse{ | ||
Price: types.DecCoin{ | ||
Denom: "testdenom", | ||
Amount: cosmossdk_io_math.LegacyNewDec(123), | ||
}, | ||
} | ||
rawGasPrice, _ := gasPrice.Marshal() | ||
return rawGasPrice | ||
}(), | ||
}, | ||
}, | ||
expectedPrice: "135.3testdenom", | ||
expectError: false, | ||
}, | ||
{ | ||
name: "DefaultGasPrice", | ||
gasMultiplier: 1.0, | ||
maxGas: 100.0, | ||
gasPrices: "99.0testdenom", | ||
mockResponse: &coretypes.ResultABCIQuery{ | ||
Response: abci.ResponseQuery{ | ||
Code: 1, | ||
}, | ||
}, | ||
expectedPrice: "99.0testdenom", | ||
expectError: false, | ||
}, | ||
{ | ||
name: "MaxGas", | ||
gasMultiplier: 1.5, | ||
maxGas: 111.1, | ||
gasPrices: "99.0testdenom", | ||
mockResponse: &coretypes.ResultABCIQuery{ | ||
Response: abci.ResponseQuery{ | ||
Code: 0, | ||
Value: func() []byte { | ||
gasPrice := feemarkettypes.GasPriceResponse{ | ||
Price: types.DecCoin{ | ||
Denom: "testdenom", | ||
Amount: cosmossdk_io_math.LegacyNewDec(123), | ||
}, | ||
} | ||
rawGasPrice, _ := gasPrice.Marshal() | ||
return rawGasPrice | ||
}(), | ||
}, | ||
}, | ||
expectedPrice: "111.1testdenom", | ||
expectError: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockClient := submit_mock.NewMockClient(ctrl) | ||
txs := setupTest(t, tt.gasMultiplier, tt.maxGas, tt.gasPrices, mockClient) | ||
|
||
if tt.mockResponse != nil { | ||
mockClient.EXPECT(). | ||
ABCIQueryWithOptions(gomock.Any(), getPricesQueryPath, gomock.Any(), gomock.Any()). | ||
Return(tt.mockResponse, nil) | ||
} else { | ||
mockClient.EXPECT(). | ||
ABCIQueryWithOptions(gomock.Any(), getPricesQueryPath, gomock.Any(), gomock.Any()). | ||
Return(nil, nil) | ||
} | ||
|
||
price, err := txs.getGasPrice(context.Background()) | ||
if tt.expectError { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
require.Equal(t, tt.expectedPrice, price) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
package mocks | ||
|
||
//go:generate mockgen -source=./../../internal/subscriber/clients.go -destination ./subscriber/expected_clients.go | ||
//go:generate mockgen -source=$GOPATH/pkg/mod/github.com/cometbft/cometbft@v0.38.7/rpc/client/interface.go -destination ./submit/mock_client.go |
Oops, something went wrong.