-
Notifications
You must be signed in to change notification settings - Fork 902
[ENG-128] Fee distribution - types tests #464
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4e62b56
x/fees - add unit tests for params & msg
loredanacirstea 3ebf4d3
x/fees - add genesis unit tests
loredanacirstea 8c6159b
x/fees - add unit tests for types/fee
loredanacirstea f95cdbf
x/fees - 0 address unit test
loredanacirstea 2d6e8ad
x/fees - testing setup changes (PR review)
loredanacirstea 8ee39ee
Merge branch 'main' into loredana/ENG-128-fee-distribution-types-tests
loredanacirstea 79deb43
Apply suggestions from code review
fedekunze 1f091fd
x/fees tests - fix imports
loredanacirstea 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,149 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/tharsis/ethermint/tests" | ||
) | ||
|
||
type FeeTestSuite struct { | ||
suite.Suite | ||
address1 sdk.AccAddress | ||
address2 sdk.AccAddress | ||
} | ||
|
||
func TestFeeSuite(t *testing.T) { | ||
suite.Run(t, new(FeeTestSuite)) | ||
} | ||
|
||
func (suite *FeeTestSuite) SetupTest() { | ||
suite.address1 = sdk.AccAddress(tests.GenerateAddress().Bytes()) | ||
suite.address2 = sdk.AccAddress(tests.GenerateAddress().Bytes()) | ||
} | ||
|
||
func (suite *FeeTestSuite) TestDevFeeInfoNew() { | ||
testCases := []struct { | ||
name string | ||
contract common.Address | ||
deployer sdk.AccAddress | ||
withdraw sdk.AccAddress | ||
expectPass bool | ||
}{ | ||
{ | ||
"Create fee info - pass", | ||
tests.GenerateAddress(), | ||
suite.address1, | ||
suite.address2, | ||
true, | ||
}, | ||
{ | ||
"Create fee info, omit withdraw - pass", | ||
tests.GenerateAddress(), | ||
suite.address1, | ||
nil, | ||
true, | ||
}, | ||
{ | ||
"Create fee info - invalid contract address", | ||
common.Address{}, | ||
suite.address1, | ||
suite.address2, | ||
false, | ||
}, | ||
{ | ||
"Create fee info - invalid deployer address", | ||
tests.GenerateAddress(), | ||
sdk.AccAddress{}, | ||
suite.address2, | ||
false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
i := NewDevFeeInfo(tc.contract, tc.deployer, tc.withdraw) | ||
err := i.Validate() | ||
|
||
if tc.expectPass { | ||
suite.Require().NoError(err, tc.name) | ||
} else { | ||
suite.Require().Error(err, tc.name) | ||
} | ||
} | ||
} | ||
|
||
func (suite *FeeTestSuite) TestFee() { | ||
testCases := []struct { | ||
msg string | ||
feeInfo DevFeeInfo | ||
expectPass bool | ||
}{ | ||
{ | ||
"Create fee info - pass", | ||
DevFeeInfo{ | ||
tests.GenerateAddress().String(), | ||
suite.address1.String(), | ||
suite.address2.String(), | ||
}, | ||
true, | ||
}, | ||
{ | ||
"Create fee info - invalid contract address (not hex)", | ||
DevFeeInfo{ | ||
"0x5dCA2483280D9727c80b5518faC4556617fb19ZZ", | ||
suite.address1.String(), | ||
suite.address2.String(), | ||
}, | ||
false, | ||
}, | ||
{ | ||
"Create fee info - invalid contract address (invalid length 1)", | ||
DevFeeInfo{ | ||
"0x5dCA2483280D9727c80b5518faC4556617fb19", | ||
suite.address1.String(), | ||
suite.address2.String(), | ||
}, | ||
false, | ||
}, | ||
{ | ||
"Create fee info - invalid contract address (invalid length 2)", | ||
DevFeeInfo{ | ||
"0x5dCA2483280D9727c80b5518faC4556617fb194FFF", | ||
suite.address1.String(), | ||
suite.address2.String(), | ||
}, | ||
false, | ||
}, | ||
{ | ||
"Create fee info - invalid deployer address", | ||
DevFeeInfo{ | ||
tests.GenerateAddress().String(), | ||
"evmos14mq5c8yn9jx295ahaxye2f0xw3tlell0lt542Z", | ||
suite.address2.String(), | ||
}, | ||
false, | ||
}, | ||
{ | ||
"Create fee info - invalid withdraw address", | ||
DevFeeInfo{ | ||
tests.GenerateAddress().String(), | ||
suite.address1.String(), | ||
"evmos14mq5c8yn9jx295ahaxye2f0xw3tlell0lt542Z", | ||
}, | ||
false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
err := tc.feeInfo.Validate() | ||
|
||
if tc.expectPass { | ||
suite.Require().NoError(err, tc.msg) | ||
} else { | ||
suite.Require().Error(err, tc.msg) | ||
} | ||
} | ||
} |
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,172 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/suite" | ||
"github.com/tharsis/ethermint/tests" | ||
) | ||
|
||
type GenesisTestSuite struct { | ||
suite.Suite | ||
address1 string | ||
address2 string | ||
} | ||
|
||
func TestGenesisTestSuite(t *testing.T) { | ||
suite.Run(t, new(GenesisTestSuite)) | ||
} | ||
|
||
func (suite *GenesisTestSuite) SetupTest() { | ||
suite.address1 = sdk.AccAddress(tests.GenerateAddress().Bytes()).String() | ||
suite.address2 = sdk.AccAddress(tests.GenerateAddress().Bytes()).String() | ||
} | ||
|
||
func (suite *GenesisTestSuite) TestValidateGenesis() { | ||
newGen := NewGenesisState(DefaultParams(), []DevFeeInfo{}) | ||
testCases := []struct { | ||
name string | ||
genState *GenesisState | ||
expPass bool | ||
}{ | ||
{ | ||
name: "valid genesis constructor", | ||
genState: &newGen, | ||
expPass: true, | ||
}, | ||
{ | ||
name: "default", | ||
genState: DefaultGenesisState(), | ||
expPass: true, | ||
}, | ||
{ | ||
name: "valid genesis", | ||
genState: &GenesisState{ | ||
Params: DefaultParams(), | ||
DevFeeInfos: []DevFeeInfo{}, | ||
}, | ||
expPass: true, | ||
}, | ||
{ | ||
name: "valid genesis - with fee information", | ||
genState: &GenesisState{ | ||
Params: DefaultParams(), | ||
DevFeeInfos: []DevFeeInfo{ | ||
{ | ||
ContractAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7", | ||
DeployerAddress: suite.address1, | ||
}, | ||
{ | ||
ContractAddress: "0xdac17f958d2ee523a2206206994597c13d831ec8", | ||
DeployerAddress: suite.address2, | ||
WithdrawAddress: suite.address2, | ||
}, | ||
}, | ||
}, | ||
expPass: true, | ||
}, | ||
{ | ||
name: "empty genesis", | ||
genState: &GenesisState{}, | ||
expPass: false, | ||
}, | ||
{ | ||
name: "invalid genesis - duplicated fee info", | ||
genState: &GenesisState{ | ||
Params: DefaultParams(), | ||
DevFeeInfos: []DevFeeInfo{ | ||
{ | ||
ContractAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7", | ||
DeployerAddress: suite.address1, | ||
}, | ||
{ | ||
ContractAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7", | ||
DeployerAddress: suite.address1, | ||
}, | ||
}, | ||
}, | ||
expPass: false, | ||
}, | ||
{ | ||
name: "invalid genesis - duplicated fee info 2", | ||
genState: &GenesisState{ | ||
Params: DefaultParams(), | ||
DevFeeInfos: []DevFeeInfo{ | ||
{ | ||
AE8F | ContractAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7", | |
DeployerAddress: suite.address1, | ||
}, | ||
{ | ||
ContractAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7", | ||
DeployerAddress: suite.address2, | ||
}, | ||
}, | ||
}, | ||
expPass: false, | ||
}, | ||
{ | ||
name: "invalid genesis - invalid contract address", | ||
genState: &GenesisState{ | ||
Params: DefaultParams(), | ||
DevFeeInfos: []DevFeeInfo{ | ||
{ | ||
ContractAddress: suite.address1, | ||
DeployerAddress: suite.address1, | ||
}, | ||
}, | ||
}, | ||
expPass: false, | ||
}, | ||
{ | ||
name: "invalid genesis - invalid deployer address", | ||
genState: &GenesisState{ | ||
Params: DefaultParams(), | ||
DevFeeInfos: []DevFeeInfo{ | ||
{ | ||
ContractAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7", | ||
DeployerAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7", | ||
}, | ||
}, | ||
}, | ||
expPass: false, | ||
}, | ||
{ | ||
name: "invalid genesis - invalid withdraw address", | ||
genState: &GenesisState{ | ||
Params: DefaultParams(), | ||
DevFeeInfos: []DevFeeInfo{ | ||
{ | ||
ContractAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7", | ||
DeployerAddress: suite.address1, | ||
WithdrawAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7", | ||
}, | ||
}, | ||
}, | ||
expPass: false, | ||
}, | ||
{ | ||
name: "invalid genesis - invalid params", | ||
genState: &GenesisState{ | ||
Params: DefaultParams(), | ||
DevFeeInfos: []DevFeeInfo{ | ||
{ | ||
ContractAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7", | ||
DeployerAddress: suite.address1, | ||
WithdrawAddress: "withdraw", | ||
}, | ||
}, | ||
}, | ||
expPass: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
err := tc.genState.Validate() | ||
if tc.expPass { | ||
suite.Require().NoError(err, tc.name) | ||
} else { | ||
suite.Require().Error(err, tc.name) | ||
} | ||
} | ||
} |
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.