This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
forked from 0xPolygon/polygon-edge
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make stake token address as mandatory in certain use cases (0xPolygon…
…#1914) * Stake token address is mandatory if not run in test mode * Mandatory stake token in rootchain fund command (in case those are minted) * Add unit tests
- Loading branch information
1 parent
38efd92
commit 4fbe4ba
Showing
7 changed files
with
189 additions
and
8 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,105 @@ | ||
package fund | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
rootHelper "github.com/0xPolygon/polygon-edge/command/rootchain/helper" | ||
"github.com/0xPolygon/polygon-edge/types" | ||
) | ||
|
||
func Test_validateFlags(t *testing.T) { | ||
t.Parallel() | ||
|
||
cases := []struct { | ||
buildParamsFn func() *fundParams | ||
err string | ||
}{ | ||
{ | ||
// no addresses provided | ||
buildParamsFn: func() *fundParams { | ||
return &fundParams{} | ||
}, | ||
err: errNoAddressesProvided.Error(), | ||
}, | ||
{ | ||
// inconsistent length (addresses vs amounts) | ||
buildParamsFn: func() *fundParams { | ||
return &fundParams{ | ||
addresses: []string{"0x1", "0x2"}, | ||
amounts: []string{"10"}, | ||
} | ||
}, | ||
err: errInconsistentLength.Error(), | ||
}, | ||
{ | ||
// address contains invalid characters | ||
buildParamsFn: func() *fundParams { | ||
return &fundParams{ | ||
addresses: []string{"0x10", "0x20"}, | ||
amounts: []string{"10", "20"}, | ||
} | ||
}, | ||
err: "address \x10 has invalid length", | ||
}, | ||
{ | ||
// stake token address omitted | ||
buildParamsFn: func() *fundParams { | ||
return &fundParams{ | ||
mintStakeToken: true, | ||
addresses: []string{ | ||
types.StringToAddress("0x10").String(), | ||
types.StringToAddress("0x20").String()}, | ||
amounts: []string{"10", "20"}, | ||
} | ||
}, | ||
err: rootHelper.ErrMandatoryStakeToken.Error(), | ||
}, | ||
{ | ||
// stake token address omitted | ||
buildParamsFn: func() *fundParams { | ||
return &fundParams{ | ||
mintStakeToken: true, | ||
stakeTokenAddr: "0xA", | ||
addresses: []string{ | ||
types.StringToAddress("0x10").String(), | ||
types.StringToAddress("0x20").String()}, | ||
amounts: []string{"10", "20"}, | ||
} | ||
}, | ||
err: "invalid stake token address is provided", | ||
}, | ||
{ | ||
// valid scenario | ||
buildParamsFn: func() *fundParams { | ||
return &fundParams{ | ||
addresses: []string{ | ||
types.StringToAddress("0x10").String(), | ||
types.StringToAddress("0x20").String()}, | ||
amounts: []string{"10", "20"}, | ||
} | ||
}, | ||
err: "", | ||
}, | ||
} | ||
|
||
for i, c := range cases { | ||
c := c | ||
i := i | ||
|
||
t.Run(fmt.Sprintf("case#%d", i+1), func(t *testing.T) { | ||
t.Parallel() | ||
|
||
fp := c.buildParamsFn() | ||
|
||
err := fp.validateFlags() | ||
if c.err != "" { | ||
require.ErrorContains(t, err, c.err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
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
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,48 @@ | ||
package stakemanager | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
rootHelper "github.com/0xPolygon/polygon-edge/command/rootchain/helper" | ||
) | ||
|
||
func TestValidateFlags(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := []struct { | ||
params *stakeManagerDeployParams | ||
errMsg string | ||
}{ | ||
{ | ||
params: &stakeManagerDeployParams{ | ||
isTestMode: false, | ||
privateKey: rootHelper.TestAccountPrivKey, | ||
stakeTokenAddress: "", | ||
}, | ||
errMsg: rootHelper.ErrMandatoryStakeToken.Error(), | ||
}, | ||
{ | ||
params: &stakeManagerDeployParams{ | ||
isTestMode: false, | ||
privateKey: rootHelper.TestAccountPrivKey, | ||
stakeTokenAddress: "0x1B", | ||
}, | ||
errMsg: "invalid stake token address is provided", | ||
}, | ||
} | ||
|
||
for i, tc := range testCases { | ||
i := i | ||
tc := tc | ||
|
||
t.Run(fmt.Sprintf("case#%d", i+1), func(t *testing.T) { | ||
t.Parallel() | ||
|
||
err := tc.params.validateFlags() | ||
require.ErrorContains(t, err, tc.errMsg) | ||
}) | ||
} | ||
} |
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