-
Notifications
You must be signed in to change notification settings - Fork 7
test(evm): Add tests for feemarket wrapper #66
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
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7156f44
add bank mock
0xstepit bdbcb81
replace deprecated golang mock with uber mock
0xstepit 362dbbe
refactor bank mock to use uber mock
0xstepit a214b0e
add mint tests
0xstepit ef7f695
add tests for burn coins
0xstepit 1aa44e9
add get balance tests
0xstepit 069c5e6
add tests for send coins
0xstepit 08051bb
add contract doc to scaling
0xstepit 00caa02
add changelog
0xstepit c60628d
use correct mock
0xstepit 6acee28
fix linter
0xstepit 7976319
linter
0xstepit c080628
add tests get base fee
0xstepit 016175e
add tests for calculate base fee
0xstepit 900a82d
add get params tests
0xstepit 4ad475d
Merge branch 'main' into stepit/feemarket-wrapper-test
0xstepit d4ac2cd
add changelog entry
0xstepit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,269 @@ | ||
package wrappers_test | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
evmtypes "github.com/evmos/os/x/evm/types" | ||
"github.com/evmos/os/x/evm/wrappers" | ||
"github.com/evmos/os/x/evm/wrappers/testutil" | ||
feemarkettypes "github.com/evmos/os/x/feemarket/types" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
func TestGetBaseFee(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
evmDecimals uint8 | ||
expResult *big.Int | ||
mockSetup func(*testutil.MockFeeMarketKeeper) | ||
}{ | ||
{ | ||
name: "success - does not convert 18 decimals", | ||
evmDecimals: 18, | ||
expResult: big.NewInt(1e18), // 1 token in 18 decimals | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
GetBaseFee(gomock.Any()). | ||
Return(sdkmath.LegacyNewDec(1e18)) | ||
}, | ||
}, | ||
{ | ||
name: "success - convert 6 decimals to 18 decimals", | ||
evmDecimals: 6, | ||
expResult: big.NewInt(1e18), // 1 token in 18 decimals | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
GetBaseFee(gomock.Any()). | ||
Return(sdkmath.LegacyNewDec(1_000_000)) | ||
}, | ||
}, | ||
{ | ||
name: "success - nil base fee", | ||
evmDecimals: 6, | ||
expResult: nil, | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
GetBaseFee(gomock.Any()). | ||
Return(sdkmath.LegacyDec{}) | ||
}, | ||
}, | ||
{ | ||
name: "success - small amount 18 decimals", | ||
evmDecimals: 6, | ||
expResult: big.NewInt(1e12), // 0.000001 token in 18 decimals | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
GetBaseFee(gomock.Any()). | ||
Return(sdkmath.LegacyNewDec(1)) | ||
}, | ||
}, | ||
{ | ||
name: "success - base fee is zero", | ||
evmDecimals: 6, | ||
expResult: big.NewInt(0), | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
GetBaseFee(gomock.Any()). | ||
Return(sdkmath.LegacyNewDec(0)) | ||
}, | ||
}, | ||
{ | ||
name: "success - truncate decimals with number less than 1", | ||
evmDecimals: 6, | ||
expResult: big.NewInt(0), // 0.000001 token in 18 decimals | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
GetBaseFee(gomock.Any()). | ||
Return(sdkmath.LegacyNewDecWithPrec(1, 13)) // multiplied by 1e12 is still less than 1 | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
// Setup EVM configurator to have access to the EVM coin info. | ||
configurator := evmtypes.NewEVMConfigurator() | ||
configurator.ResetTestConfig() | ||
err := configurator.WithEVMCoinInfo("token", tc.evmDecimals).Configure() | ||
require.NoError(t, err, "failed to configure EVMConfigurator") | ||
|
||
ctrl := gomock.NewController(t) | ||
mockFeeMarketKeeper := testutil.NewMockFeeMarketKeeper(ctrl) | ||
tc.mockSetup(mockFeeMarketKeeper) | ||
|
||
feeMarketWrapper := wrappers.NewFeeMarketWrapper(mockFeeMarketKeeper) | ||
result := feeMarketWrapper.GetBaseFee(sdk.Context{}) | ||
|
||
require.Equal(t, tc.expResult, result) | ||
}) | ||
} | ||
} | ||
|
||
func TestCalculateBaseFee(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
evmDecimals uint8 | ||
baseFee sdkmath.LegacyDec | ||
expResult *big.Int | ||
mockSetup func(*testutil.MockFeeMarketKeeper) | ||
}{ | ||
{ | ||
name: "success - does not convert 18 decimals", | ||
evmDecimals: 18, | ||
expResult: big.NewInt(1e18), // 1 token in 18 decimals | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
CalculateBaseFee(gomock.Any()). | ||
Return(sdkmath.LegacyNewDec(1e18)) | ||
}, | ||
}, | ||
{ | ||
name: "success - convert 6 decimals to 18 decimals", | ||
evmDecimals: 6, | ||
expResult: big.NewInt(1e18), // 1 token in 18 decimals | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
CalculateBaseFee(gomock.Any()). | ||
Return(sdkmath.LegacyNewDec(1_000_000)) | ||
}, | ||
}, | ||
{ | ||
name: "success - nil base fee", | ||
evmDecimals: 6, | ||
expResult: nil, | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
CalculateBaseFee(gomock.Any()). | ||
Return(sdkmath.LegacyDec{}) | ||
}, | ||
}, | ||
{ | ||
name: "success - small amount 18 decimals", | ||
evmDecimals: 6, | ||
expResult: big.NewInt(1e12), // 0.000001 token in 18 decimals | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
CalculateBaseFee(gomock.Any()). | ||
Return(sdkmath.LegacyNewDec(1)) | ||
}, | ||
}, | ||
{ | ||
name: "success - base fee is zero", | ||
evmDecimals: 6, | ||
expResult: big.NewInt(0), | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
CalculateBaseFee(gomock.Any()). | ||
Return(sdkmath.LegacyNewDec(0)) | ||
}, | ||
}, | ||
{ | ||
name: "success - truncate decimals with number less than 1", | ||
evmDecimals: 6, | ||
expResult: big.NewInt(0), // 0.000001 token in 18 decimals | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
CalculateBaseFee(gomock.Any()). | ||
Return(sdkmath.LegacyNewDecWithPrec(1, 13)) // multiplied by 1e12 is still less than 1 | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
// Setup EVM configurator to have access to the EVM coin info. | ||
configurator := evmtypes.NewEVMConfigurator() | ||
configurator.ResetTestConfig() | ||
err := configurator.WithEVMCoinInfo("token", tc.evmDecimals).Configure() | ||
require.NoError(t, err, "failed to configure EVMConfigurator") | ||
|
||
ctrl := gomock.NewController(t) | ||
mockFeeMarketKeeper := testutil.NewMockFeeMarketKeeper(ctrl) | ||
tc.mockSetup(mockFeeMarketKeeper) | ||
|
||
feeMarketWrapper := wrappers.NewFeeMarketWrapper(mockFeeMarketKeeper) | ||
result := feeMarketWrapper.CalculateBaseFee(sdk.Context{}) | ||
|
||
require.Equal(t, tc.expResult, result) | ||
}) | ||
} | ||
} | ||
|
||
func TestGetParams(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
evmDecimals uint8 | ||
expParams feemarkettypes.Params | ||
mockSetup func(*testutil.MockFeeMarketKeeper) | ||
}{ | ||
{ | ||
name: "success - convert 6 decimals to 18 decimals", | ||
evmDecimals: 6, | ||
expParams: feemarkettypes.Params{ | ||
BaseFee: sdkmath.LegacyNewDec(1e18), | ||
MinGasPrice: sdkmath.LegacyNewDec(1e18), | ||
}, | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
GetParams(gomock.Any()). | ||
Return(feemarkettypes.Params{ | ||
BaseFee: sdkmath.LegacyNewDec(1_000_000), | ||
MinGasPrice: sdkmath.LegacyNewDec(1_000_000), | ||
}) | ||
}, | ||
}, | ||
{ | ||
name: "success - does not convert 18 decimals", | ||
evmDecimals: 18, | ||
expParams: feemarkettypes.Params{ | ||
BaseFee: sdkmath.LegacyNewDec(1e18), | ||
MinGasPrice: sdkmath.LegacyNewDec(1e18), | ||
}, | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
GetParams(gomock.Any()). | ||
Return(feemarkettypes.Params{ | ||
BaseFee: sdkmath.LegacyNewDec(1e18), | ||
MinGasPrice: sdkmath.LegacyNewDec(1e18), | ||
}) | ||
}, | ||
}, | ||
{ | ||
name: "success - nil base fee", | ||
evmDecimals: 18, | ||
expParams: feemarkettypes.Params{ | ||
MinGasPrice: sdkmath.LegacyNewDec(1e18), | ||
}, | ||
mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { | ||
mfk.EXPECT(). | ||
GetParams(gomock.Any()). | ||
Return(feemarkettypes.Params{ | ||
MinGasPrice: sdkmath.LegacyNewDec(1e18), | ||
}) | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
// Setup EVM configurator to have access to the EVM coin info. | ||
configurator := evmtypes.NewEVMConfigurator() | ||
configurator.ResetTestConfig() | ||
err := configurator.WithEVMCoinInfo("token", tc.evmDecimals).Configure() | ||
require.NoError(t, err, "failed to configure EVMConfigurator") | ||
|
||
ctrl := gomock.NewController(t) | ||
mockFeeMarketKeeper := testutil.NewMockFeeMarketKeeper(ctrl) | ||
tc.mockSetup(mockFeeMarketKeeper) | ||
|
||
feeMarketWrapper := wrappers.NewFeeMarketWrapper(mockFeeMarketKeeper) | ||
result := feeMarketWrapper.GetParams(sdk.Context{}) | ||
|
||
require.Equal(t, tc.expParams, result) | ||
}) | ||
} | ||
} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.