Skip to content
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

[staking] refactor to split staking abi into separate version #4272

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix test
envestcc committed May 21, 2024
commit fcece9ed85ec24c53f5dbedf06a476cc3aa4efe8
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

"github.com/iotexproject/iotex-core/action/protocol"
"github.com/iotexproject/iotex-core/action/protocol/staking/ethabi/common"
)

@@ -57,7 +58,11 @@ func TestCandidateByAddressToEth(t *testing.T) {
Data: candidateBytes,
}

ctx := &common.CandidateByAddressStateContext{}
ctx := &common.CandidateByAddressStateContext{
BaseStateContext: &protocol.BaseStateContext{
Method: &_candidateByAddressMethod,
},
}
data, err := ctx.EncodeToEth(resp)
r.Nil(err)
r.EqualValues("000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000008ac7230489e8000000000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000004563918244f40000000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000", data)
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

"github.com/iotexproject/iotex-core/action/protocol"
"github.com/iotexproject/iotex-core/action/protocol/staking/ethabi/common"
)

@@ -57,7 +58,11 @@ func TestCandidateByNameToEth(t *testing.T) {
Data: candidateBytes,
}

ctx := &common.CandidateByNameStateContext{}
ctx := &common.CandidateByNameStateContext{
BaseStateContext: &protocol.BaseStateContext{
Method: &_candidateByNameMethod,
},
}
data, err := ctx.EncodeToEth(resp)
r.Nil(err)
r.EqualValues("000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000008ac7230489e8000000000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000004563918244f40000000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000", data)
13 changes: 11 additions & 2 deletions action/protocol/staking/ethabi/v1/stakecandidates_test.go
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

"github.com/iotexproject/iotex-core/action/protocol"
"github.com/iotexproject/iotex-core/action/protocol/staking/ethabi/common"
)

@@ -71,7 +72,11 @@ func TestCandidatesToEth(t *testing.T) {
Data: candidatesBytes,
}

ctx := &common.CandidatesStateContext{}
ctx := &common.CandidatesStateContext{
BaseStateContext: &protocol.BaseStateContext{
Method: &_candidatesMethod,
},
}
data, err := ctx.EncodeToEth(resp)
r.Nil(err)
r.EqualValues("000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000008ac7230489e8000000000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000004563918244f40000000000000000000000000000000000000000000000000000000000000000000568656c6c6f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000098a7d9b8314c0000000000000000000000000000000000000000000000000000000000000000006500000000000000000000000000000000000000000000000053444835ec5800000000000000000000000000000000000000000000000000000000000000000005776f726c64000000000000000000000000000000000000000000000000000000", data)
@@ -88,7 +93,11 @@ func TestCandidatesToEthEmptyCandidates(t *testing.T) {
Data: candidatesBytes,
}

ctx := &common.CandidatesStateContext{}
ctx := &common.CandidatesStateContext{
BaseStateContext: &protocol.BaseStateContext{
Method: &_candidatesMethod,
},
}
data, err := ctx.EncodeToEth(resp)
r.Nil(err)
r.EqualValues("00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000", data)
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

"github.com/iotexproject/iotex-core/action/protocol"
"github.com/iotexproject/iotex-core/action/protocol/staking/ethabi/common"
)

@@ -49,7 +50,11 @@ func TestEncodeTotalStakingAmountToEth(t *testing.T) {
Data: metaBytes,
}

ctx := &common.TotalStakingAmountStateContext{}
ctx := &common.TotalStakingAmountStateContext{
BaseStateContext: &protocol.BaseStateContext{
Method: &_totalStakingAmountMethod,
},
}
data, err := ctx.EncodeToEth(resp)
r.Nil(err)
r.EqualValues("0000000000000000000000000000000000000000000000056bc75e2d63100000", data)
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

"github.com/iotexproject/iotex-core/action/protocol"
"github.com/iotexproject/iotex-core/action/protocol/staking/ethabi/common"
)

@@ -20,7 +21,7 @@ func TestBuildReadStateRequestCompositeTotalStakingAmount(t *testing.T) {
req, err := BuildReadStateRequest(data)

r.Nil(err)
r.EqualValues("*common.CompositeTotalStakingAmountStateContext", reflect.TypeOf(req).String())
r.EqualValues("*common.TotalStakingAmountStateContext", reflect.TypeOf(req).String())

method := &iotexapi.ReadStakingDataMethod{
Method: iotexapi.ReadStakingDataMethod_COMPOSITE_TOTAL_STAKING_AMOUNT,
@@ -49,7 +50,11 @@ func TestEncodeCompositeTotalStakingAmountToEth(t *testing.T) {
Data: metaBytes,
}

ctx := &common.TotalStakingAmountStateContext{}
ctx := &common.TotalStakingAmountStateContext{
BaseStateContext: &protocol.BaseStateContext{
Method: &_compositeTotalStakingAmountMethod,
},
}
data, err := ctx.EncodeToEth(resp)
r.Nil(err)
r.EqualValues("0000000000000000000000000000000000000000000000056bc75e2d63100000", data)
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ func TestBuildReadStateRequestContractBucketTypes(t *testing.T) {
r.NoError(err)
req, err := BuildReadStateRequest(data)
r.NoError(err)
r.EqualValues("*common.ContractBucketTypesStateContext", reflect.TypeOf(req).String())
r.EqualValues("*v2.ContractBucketTypesStateContext", reflect.TypeOf(req).String())

method := &iotexapi.ReadStakingDataMethod{
Method: iotexapi.ReadStakingDataMethod_CONTRACT_STAKING_BUCKET_TYPES,