-
Notifications
You must be signed in to change notification settings - Fork 324
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
[api] web3 rewarding action #3691
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
21659f0
add rewarding execute action
ququzone d55f02d
add rewarding execute test
ququzone d9c8c07
add commmet for public type
ququzone 6bcbc3d
add builder test
ququzone 4393705
complete web3 rewarding read
ququzone ecee446
complete web3 rewarding read test
ququzone 48d23e5
remove read api and receive create rewarding action enterance
ququzone 8dd263f
add test to rlp tx test
ququzone f7295d8
change name
ququzone f2681fc
revert fix amount bug for deposit cost bug
ququzone f221032
change check error style
ququzone 3a0a688
Merge branch 'master' into web3_rewarding
dustinxie ebafd6c
add entrance for web3 rewarding
ququzone 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 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
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,146 @@ | ||
package action | ||
|
||
import ( | ||
"encoding/hex" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/iotexproject/iotex-address/address" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
_defaultGasPrice = big.NewInt(1000000000000) | ||
_errNegativeNumberMsg = "negative value" | ||
) | ||
|
||
func TestClaimRewardSerialize(t *testing.T) { | ||
r := require.New(t) | ||
|
||
rc := &ClaimFromRewardingFund{} | ||
data := rc.Serialize() | ||
r.NotNil(data) | ||
|
||
rc.amount = big.NewInt(100) | ||
rc.data = []byte{1} | ||
data = rc.Serialize() | ||
r.NotNil(data) | ||
r.EqualValues("0a03313030120101", hex.EncodeToString(data)) | ||
} | ||
|
||
func TestClaimRewardIntrinsicGas(t *testing.T) { | ||
r := require.New(t) | ||
|
||
rc := &ClaimFromRewardingFund{} | ||
gas, err := rc.IntrinsicGas() | ||
r.Nil(err) | ||
ququzone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
r.EqualValues(10000, gas) | ||
|
||
rc.amount = big.NewInt(100000000) | ||
gas, err = rc.IntrinsicGas() | ||
r.Nil(err) | ||
r.EqualValues(10000, gas) | ||
|
||
rc.data = []byte{1} | ||
gas, err = rc.IntrinsicGas() | ||
r.Nil(err) | ||
r.EqualValues(10100, gas) | ||
} | ||
|
||
func TestClaimRewardSanityCheck(t *testing.T) { | ||
r := require.New(t) | ||
|
||
rc := &ClaimFromRewardingFund{} | ||
|
||
rc.amount = big.NewInt(1) | ||
err := rc.SanityCheck() | ||
r.Nil(err) | ||
|
||
rc.amount = big.NewInt(-1) | ||
err = rc.SanityCheck() | ||
r.NotNil(err) | ||
r.EqualValues(_errNegativeNumberMsg, err.Error()) | ||
} | ||
|
||
func TestClaimRewardCost(t *testing.T) { | ||
r := require.New(t) | ||
|
||
rc := &ClaimFromRewardingFund{} | ||
rc.gasPrice = _defaultGasPrice | ||
cost, err := rc.Cost() | ||
r.Nil(err) | ||
r.EqualValues("10000000000000000", cost.String()) | ||
|
||
rc.amount = big.NewInt(100) | ||
cost, err = rc.Cost() | ||
r.Nil(err) | ||
r.EqualValues("10000000000000000", cost.String()) | ||
|
||
rc.data = []byte{1} | ||
cost, err = rc.Cost() | ||
r.Nil(err) | ||
r.EqualValues("10100000000000000", cost.String()) | ||
} | ||
|
||
func TestClaimRewardEncodeABIBinary(t *testing.T) { | ||
r := require.New(t) | ||
|
||
rc := &ClaimFromRewardingFund{} | ||
rc.amount = big.NewInt(101) | ||
data, err := rc.encodeABIBinary() | ||
r.Nil(err) | ||
r.EqualValues( | ||
"2df163ef000000000000000000000000000000000000000000000000000000000000006500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000", | ||
hex.EncodeToString(data), | ||
) | ||
|
||
rc.data = []byte{1, 2, 3} | ||
data, err = rc.encodeABIBinary() | ||
r.Nil(err) | ||
r.EqualValues( | ||
"2df163ef000000000000000000000000000000000000000000000000000000000000006500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003", | ||
hex.EncodeToString(data), | ||
) | ||
} | ||
|
||
func TestClaimRewardToEthTx(t *testing.T) { | ||
r := require.New(t) | ||
|
||
rewardingPool, _ := address.FromString(address.RewardingProtocol) | ||
rewardEthAddr := common.BytesToAddress(rewardingPool.Bytes()) | ||
|
||
rc := &ClaimFromRewardingFund{} | ||
|
||
rc.amount = big.NewInt(101) | ||
tx, err := rc.ToEthTx() | ||
r.Nil(err) | ||
r.EqualValues(rewardEthAddr, *tx.To()) | ||
r.EqualValues( | ||
"2df163ef000000000000000000000000000000000000000000000000000000000000006500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000", | ||
hex.EncodeToString(tx.Data()), | ||
) | ||
r.EqualValues("0", tx.Value().String()) | ||
|
||
rc.data = []byte{1, 2, 3} | ||
tx, err = rc.ToEthTx() | ||
r.Nil(err) | ||
r.EqualValues(rewardEthAddr, *tx.To()) | ||
r.EqualValues( | ||
"2df163ef000000000000000000000000000000000000000000000000000000000000006500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003", | ||
hex.EncodeToString(tx.Data()), | ||
) | ||
r.EqualValues("0", tx.Value().String()) | ||
} | ||
|
||
func TestNewRewardingClaimFromABIBinary(t *testing.T) { | ||
r := require.New(t) | ||
|
||
data, _ := hex.DecodeString("2df163ef000000000000000000000000000000000000000000000000000000000000006500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003") | ||
|
||
rc, err := NewClaimFromRewardingFundFromABIBinary(data) | ||
r.Nil(err) | ||
r.IsType(&ClaimFromRewardingFund{}, rc) | ||
r.EqualValues("101", rc.Amount().String()) | ||
r.EqualValues([]byte{1, 2, 3}, rc.Data()) | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defined but not used?
need to use it in
web3server_utils.go
similar to howBuildStakingAction
is usedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is prepared for another PR and that PR will use this function as similar
BuildStakingAction
, because accord the meeting discussed, this feature should split two PRs, one is this envelope actions and another is invoking API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after discussing with haixiang, better do it in one PR altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, have added it.