From 2beadc9ab5459c3b71d140509648aeb2cebba116 Mon Sep 17 00:00:00 2001 From: envestcc Date: Wed, 3 Jul 2024 17:44:21 +0800 Subject: [PATCH 1/3] fix api --- action/protocol/staking/candidate.go | 1 + action/protocol/staking/candidate_buckets_indexer.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/action/protocol/staking/candidate.go b/action/protocol/staking/candidate.go index d5dfcf35ce..915b7fcf54 100644 --- a/action/protocol/staking/candidate.go +++ b/action/protocol/staking/candidate.go @@ -267,6 +267,7 @@ func (d *Candidate) toIoTeXTypes() *iotextypes.CandidateV2 { TotalWeightedVotes: d.Votes.String(), SelfStakeBucketIdx: d.SelfStakeBucketIdx, SelfStakingTokens: d.SelfStake.String(), + Id: d.GetIdentifier().String(), } } diff --git a/action/protocol/staking/candidate_buckets_indexer.go b/action/protocol/staking/candidate_buckets_indexer.go index 17d6e18b60..26abf14cea 100644 --- a/action/protocol/staking/candidate_buckets_indexer.go +++ b/action/protocol/staking/candidate_buckets_indexer.go @@ -146,6 +146,12 @@ func (cbi *CandidatesBucketsIndexer) GetCandidates(height uint64, offset, limit end = uint32(len(candidateList.Candidates)) } candidateList.Candidates = candidateList.Candidates[offset:end] + // fill id if it's empty for backward compatibility + for i := range candidateList.Candidates { + if candidateList.Candidates[i].Id == "" { + candidateList.Candidates[i].Id = candidateList.Candidates[i].OwnerAddress + } + } return candidateList, height, nil } From c146b09b4ba8018e69b28038bc38e3f64951c5f6 Mon Sep 17 00:00:00 2001 From: envestcc Date: Wed, 3 Jul 2024 23:12:46 +0800 Subject: [PATCH 2/3] fix test --- .../staking/candidate_buckets_indexer_test.go | 3 ++ e2etest/native_staking_test.go | 28 +++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/action/protocol/staking/candidate_buckets_indexer_test.go b/action/protocol/staking/candidate_buckets_indexer_test.go index 40a00c7fed..f6ee7a09b8 100644 --- a/action/protocol/staking/candidate_buckets_indexer_test.go +++ b/action/protocol/staking/candidate_buckets_indexer_test.go @@ -43,6 +43,7 @@ func TestCandidatesBucketsIndexer_PutGetCandidates(t *testing.T) { OwnerAddress: "owner1", Name: "abc", SelfStakeBucketIdx: 123, + Id: "owner1", }, } cand2 := &iotextypes.CandidateListV2{ @@ -53,6 +54,7 @@ func TestCandidatesBucketsIndexer_PutGetCandidates(t *testing.T) { OwnerAddress: "owner2", Name: "xyz", SelfStakeBucketIdx: 456, + Id: "owner2", }), } @@ -126,6 +128,7 @@ func TestCandidatesBucketsIndexer_PutGetCandidates(t *testing.T) { OwnerAddress: "ownermax", Name: "alphabeta", SelfStakeBucketIdx: 789, + Id: "ownermax", }), } require.NoError(cbi.PutCandidates(height, candMax)) diff --git a/e2etest/native_staking_test.go b/e2etest/native_staking_test.go index f66fb53c9b..1a1afd1190 100644 --- a/e2etest/native_staking_test.go +++ b/e2etest/native_staking_test.go @@ -611,7 +611,7 @@ func TestCandidateTransferOwnership(t *testing.T) { {mustNoErr(action.SignedCandidateRegister(test.nonceMgr.pop(identityset.Address(oldOwnerID).String()), "cand1", identityset.Address(1).String(), identityset.Address(1).String(), identityset.Address(oldOwnerID).String(), registerAmount.String(), 1, true, nil, gasLimit, gasPrice, identityset.PrivateKey(oldOwnerID), action.WithChainID(chainID))), time.Now()}, }, act: &actionWithTime{mustNoErr(action.SignedCandidateTransferOwnership(test.nonceMgr.pop(identityset.Address(oldOwnerID).String()), identityset.Address(newOwnerID).String(), nil, gasLimit, gasPrice, identityset.PrivateKey(oldOwnerID), action.WithChainID(chainID))), time.Now()}, - expect: []actionExpect{successExpect, &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1245621408203087110422302", SelfStakingTokens: "0", OwnerAddress: identityset.Address(newOwnerID).String(), SelfStakeBucketIdx: math.MaxUint64}}}, + expect: []actionExpect{successExpect, &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", Id: identityset.Address(oldOwnerID).String(), OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1245621408203087110422302", SelfStakingTokens: "0", OwnerAddress: identityset.Address(newOwnerID).String(), SelfStakeBucketIdx: math.MaxUint64}}}, }, { name: "cannot transfer from non-owner", @@ -630,7 +630,7 @@ func TestCandidateTransferOwnership(t *testing.T) { { name: "transfer back to old owner", act: &actionWithTime{mustNoErr(action.SignedCandidateTransferOwnership(test.nonceMgr.pop(identityset.Address(newOwnerID).String()), identityset.Address(oldOwnerID).String(), nil, gasLimit, gasPrice, identityset.PrivateKey(newOwnerID), action.WithChainID(chainID))), time.Now()}, - expect: []actionExpect{successExpect, &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1245621408203087110422302", SelfStakingTokens: "0", OwnerAddress: identityset.Address(oldOwnerID).String(), SelfStakeBucketIdx: math.MaxUint64}}}, + expect: []actionExpect{successExpect, &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", Id: identityset.Address(oldOwnerID).String(), OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1245621408203087110422302", SelfStakingTokens: "0", OwnerAddress: identityset.Address(oldOwnerID).String(), SelfStakeBucketIdx: math.MaxUint64}}}, }, }) }) @@ -680,7 +680,7 @@ func TestCandidateTransferOwnership(t *testing.T) { {mustNoErr(action.SignedCreateStake(test.nonceMgr.pop(identityset.Address(newOwnerID).String()), "cand1", registerAmount.String(), 1, true, nil, gasLimit, gasPrice, identityset.PrivateKey(newOwnerID), action.WithChainID(chainID))), time.Now()}, }, act: &actionWithTime{mustNoErr(action.SignedCandidateActivate(test.nonceMgr.pop(identityset.Address(newOwnerID).String()), 2, gasLimit, gasPrice, identityset.PrivateKey(newOwnerID), action.WithChainID(chainID))), time.Now()}, - expect: []actionExpect{successExpect, &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "3736864224609261331266906", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(newOwnerID).String(), SelfStakeBucketIdx: 2}}}, + expect: []actionExpect{successExpect, &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", Id: identityset.Address(oldOwnerID).String(), OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "3736864224609261331266906", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(newOwnerID).String(), SelfStakeBucketIdx: 2}}}, }, }) }) @@ -734,12 +734,12 @@ func TestCandidateTransferOwnership(t *testing.T) { { name: "transfer ownership to another new owner", act: &actionWithTime{mustNoErr(action.SignedCandidateTransferOwnership(test.nonceMgr.pop(identityset.Address(newOwnerID).String()), identityset.Address(newOwnerID2).String(), nil, gasLimit, gasPrice, identityset.PrivateKey(newOwnerID), action.WithChainID(chainID))), time.Now()}, - expect: []actionExpect{successExpect, &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1245621408203087110422302", SelfStakingTokens: "0", OwnerAddress: identityset.Address(newOwnerID2).String(), SelfStakeBucketIdx: math.MaxUint64}}}, + expect: []actionExpect{successExpect, &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", Id: identityset.Address(oldOwnerID).String(), OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1245621408203087110422302", SelfStakingTokens: "0", OwnerAddress: identityset.Address(newOwnerID2).String(), SelfStakeBucketIdx: math.MaxUint64}}}, }, { name: "new owner can register again", act: &actionWithTime{mustNoErr(action.SignedCandidateRegister(test.nonceMgr.pop(identityset.Address(newOwnerID).String()), "cand3", identityset.Address(3).String(), identityset.Address(1).String(), identityset.Address(newOwnerID).String(), registerAmount.String(), 1, true, nil, gasLimit, gasPrice, identityset.PrivateKey(newOwnerID), action.WithChainID(chainID))), time.Now()}, - expect: []actionExpect{successExpect, &candidateExpect{"cand3", &iotextypes.CandidateV2{Name: "cand3", OperatorAddress: identityset.Address(3).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1245621408203087110422302", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(newOwnerID).String(), SelfStakeBucketIdx: 1}}}, + expect: []actionExpect{successExpect, &candidateExpect{"cand3", &iotextypes.CandidateV2{Name: "cand3", Id: identityset.Address(newOwnerID).String(), OperatorAddress: identityset.Address(3).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1245621408203087110422302", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(newOwnerID).String(), SelfStakeBucketIdx: 1}}}, }, }) }) @@ -764,7 +764,7 @@ func TestCandidateTransferOwnership(t *testing.T) { { name: "new owner can update", act: &actionWithTime{mustNoErr(action.SignedCandidateUpdate(test.nonceMgr.pop(identityset.Address(newOwnerID).String()), "cand2", identityset.Address(2).String(), identityset.Address(1).String(), gasLimit, gasPrice, identityset.PrivateKey(newOwnerID), action.WithChainID(chainID))), time.Now()}, - expect: []actionExpect{successExpect, &candidateExpect{"cand2", &iotextypes.CandidateV2{Name: "cand2", OperatorAddress: identityset.Address(2).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1245621408203087110422302", SelfStakingTokens: "0", OwnerAddress: identityset.Address(newOwnerID).String(), SelfStakeBucketIdx: math.MaxUint64}}}, + expect: []actionExpect{successExpect, &candidateExpect{"cand2", &iotextypes.CandidateV2{Name: "cand2", Id: identityset.Address(oldOwnerID).String(), OperatorAddress: identityset.Address(2).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1245621408203087110422302", SelfStakingTokens: "0", OwnerAddress: identityset.Address(newOwnerID).String(), SelfStakeBucketIdx: math.MaxUint64}}}, }, }) }) @@ -791,8 +791,8 @@ func TestCandidateTransferOwnership(t *testing.T) { expect: []actionExpect{ successExpect, &bucketExpect{&iotextypes.VoteBucket{Index: 2, CandidateAddress: identityset.Address(oldOwnerID).String(), StakedAmount: registerAmount.String(), AutoStake: true, StakedDuration: 1, CreateTime: timestamppb.New(stakeTime), StakeStartTime: timestamppb.New(stakeTime), UnstakeStartTime: ×tamppb.Timestamp{}, Owner: identityset.Address(stakerID).String(), ContractAddress: "", EndorsementExpireBlockHeight: 0}}, - &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "2491242816406174220844604", SelfStakingTokens: "0", OwnerAddress: identityset.Address(newOwnerID).String(), SelfStakeBucketIdx: math.MaxUint64}}, - &candidateExpect{"cand2", &iotextypes.CandidateV2{Name: "cand2", OperatorAddress: identityset.Address(2).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1245621408203087110422302", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(stakerID).String(), SelfStakeBucketIdx: 1}}, + &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", Id: identityset.Address(oldOwnerID).String(), OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "2491242816406174220844604", SelfStakingTokens: "0", OwnerAddress: identityset.Address(newOwnerID).String(), SelfStakeBucketIdx: math.MaxUint64}}, + &candidateExpect{"cand2", &iotextypes.CandidateV2{Name: "cand2", Id: identityset.Address(stakerID).String(), OperatorAddress: identityset.Address(2).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1245621408203087110422302", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(stakerID).String(), SelfStakeBucketIdx: 1}}, }, }, }) @@ -868,7 +868,7 @@ func TestCandidateTransferOwnership(t *testing.T) { &basicActionExpect{nil, uint64(iotextypes.ReceiptStatus_ErrUnauthorizedOperator), ""}, &bucketExpect{&iotextypes.VoteBucket{Index: 1, CandidateAddress: identityset.Address(candOwnerID).String(), StakedAmount: stakeAmount.String(), AutoStake: true, StakedDuration: stakeDurationDays, Owner: identityset.Address(stakerID).String(), CreateTime: timestamppb.New(stakeTime), StakeStartTime: timestamppb.New(stakeTime), UnstakeStartTime: ×tamppb.Timestamp{}}}, &accountExpect{identityset.Address(stakerID), "99989999999999999996377414", test.nonceMgr[identityset.Address(stakerID).String()]}, - &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1256001586604779503009155", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(candOwnerID).String(), SelfStakeBucketIdx: 0}}, + &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", Id: identityset.Address(candOwnerID).String(), OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1256001586604779503009155", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(candOwnerID).String(), SelfStakeBucketIdx: 0}}, }, }, { @@ -918,7 +918,7 @@ func TestCandidateTransferOwnership(t *testing.T) { &bucketExpect{&iotextypes.VoteBucket{Index: 1, CandidateAddress: identityset.Address(candOwnerID).String(), StakedAmount: stakeAmount.String(), AutoStake: true, StakedDuration: stakeDurationDays, StakedDurationBlockNumber: uint64(stakeDurationDays) * uint64(blocksPerDay), CreateBlockHeight: 5, StakeStartBlockHeight: 5, UnstakeStartBlockHeight: math.MaxUint64, Owner: identityset.Address(stakerID).String(), ContractAddress: contractAddress, CreateTime: timestamppb.New(time.Time{}), StakeStartTime: timestamppb.New(time.Time{}), UnstakeStartTime: timestamppb.New(time.Time{})}}, &noBucketExpect{1, ""}, &accountExpect{identityset.Address(stakerID), "99989999999999999996165380", test.nonceMgr[identityset.Address(stakerID).String()]}, - &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1256001586604779503009155", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(candOwnerID).String(), SelfStakeBucketIdx: 0}}, + &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", Id: identityset.Address(candOwnerID).String(), OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "1256001586604779503009155", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(candOwnerID).String(), SelfStakeBucketIdx: 0}}, &functionExpect{func(test *e2etest, act *action.SealedEnvelope, receipt *action.Receipt, err error) { resp, err := test.api.GetAccount(context.Background(), &iotexapi.GetAccountRequest{ Address: identityset.Address(stakerID).String(), @@ -1114,7 +1114,7 @@ func TestCandidateTransferOwnership(t *testing.T) { expect: []actionExpect{ successExpect, &bucketExpect{&iotextypes.VoteBucket{Index: 1, EndorsementExpireBlockHeight: 22, CandidateAddress: identityset.Address(candOwnerID2).String(), StakedAmount: registerAmount.String(), AutoStake: true, StakedDuration: 91, Owner: identityset.Address(stakerID).String(), CreateTime: timestamppb.New(stakeTime), StakeStartTime: timestamppb.New(stakeTime), UnstakeStartTime: ×tamppb.Timestamp{}}}, - &candidateExpect{"cand2", &iotextypes.CandidateV2{Name: "cand2", OperatorAddress: identityset.Address(3).String(), RewardAddress: identityset.Address(3).String(), TotalWeightedVotes: "1635067133824581908640994", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(candOwnerID2).String(), SelfStakeBucketIdx: 1}}, + &candidateExpect{"cand2", &iotextypes.CandidateV2{Name: "cand2", Id: identityset.Address(candOwnerID2).String(), OperatorAddress: identityset.Address(3).String(), RewardAddress: identityset.Address(3).String(), TotalWeightedVotes: "1635067133824581908640994", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(candOwnerID2).String(), SelfStakeBucketIdx: 1}}, }, }, { @@ -1131,7 +1131,7 @@ func TestCandidateTransferOwnership(t *testing.T) { }, act: &actionWithTime{mustNoErr(action.SignedTransfer(identityset.Address(1).String(), identityset.PrivateKey(2), test.nonceMgr.pop(identityset.Address(2).String()), unit.ConvertIotxToRau(1), nil, gasLimit, gasPrice, action.WithChainID(chainID))), time.Now()}, expect: []actionExpect{successExpect, - &candidateExpect{"cand2", &iotextypes.CandidateV2{Name: "cand2", OperatorAddress: identityset.Address(3).String(), RewardAddress: identityset.Address(3).String(), TotalWeightedVotes: "1635067133824581908640994", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(candOwnerID2).String(), SelfStakeBucketIdx: 1}}, + &candidateExpect{"cand2", &iotextypes.CandidateV2{Name: "cand2", Id: identityset.Address(candOwnerID2).String(), OperatorAddress: identityset.Address(3).String(), RewardAddress: identityset.Address(3).String(), TotalWeightedVotes: "1635067133824581908640994", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(candOwnerID2).String(), SelfStakeBucketIdx: 1}}, }, }, { @@ -1140,7 +1140,7 @@ func TestCandidateTransferOwnership(t *testing.T) { expect: []actionExpect{ successExpect, &bucketExpect{&iotextypes.VoteBucket{Index: 1, EndorsementExpireBlockHeight: 0, CandidateAddress: identityset.Address(candOwnerID2).String(), StakedAmount: registerAmount.String(), AutoStake: true, StakedDuration: 91, Owner: identityset.Address(stakerID).String(), CreateTime: timestamppb.New(stakeTime), StakeStartTime: timestamppb.New(stakeTime), UnstakeStartTime: ×tamppb.Timestamp{}}}, - &candidateExpect{"cand2", &iotextypes.CandidateV2{Name: "cand2", OperatorAddress: identityset.Address(3).String(), RewardAddress: identityset.Address(3).String(), TotalWeightedVotes: "1542516163985454635820816", SelfStakingTokens: "0", OwnerAddress: identityset.Address(candOwnerID2).String(), SelfStakeBucketIdx: math.MaxUint64}}, + &candidateExpect{"cand2", &iotextypes.CandidateV2{Name: "cand2", Id: identityset.Address(candOwnerID2).String(), OperatorAddress: identityset.Address(3).String(), RewardAddress: identityset.Address(3).String(), TotalWeightedVotes: "1542516163985454635820816", SelfStakingTokens: "0", OwnerAddress: identityset.Address(candOwnerID2).String(), SelfStakeBucketIdx: math.MaxUint64}}, }, }, { @@ -1158,7 +1158,7 @@ func TestCandidateTransferOwnership(t *testing.T) { }, act: &actionWithTime{mustNoErr(action.SignedCandidateEndorsement(test.nonceMgr.pop(identityset.Address(candOwnerID2).String()), 1, action.CandidateEndorsementOpRevoke, gasLimit, gasPrice, identityset.PrivateKey(candOwnerID2), action.WithChainID(chainID))), time.Now()}, expect: []actionExpect{successExpect, - &candidateExpect{"cand2", &iotextypes.CandidateV2{Name: "cand2", OperatorAddress: identityset.Address(3).String(), RewardAddress: identityset.Address(3).String(), TotalWeightedVotes: "1542516163985454635820816", SelfStakingTokens: "0", OwnerAddress: identityset.Address(candOwnerID2).String(), SelfStakeBucketIdx: math.MaxUint64}}, + &candidateExpect{"cand2", &iotextypes.CandidateV2{Name: "cand2", Id: identityset.Address(candOwnerID2).String(), OperatorAddress: identityset.Address(3).String(), RewardAddress: identityset.Address(3).String(), TotalWeightedVotes: "1542516163985454635820816", SelfStakingTokens: "0", OwnerAddress: identityset.Address(candOwnerID2).String(), SelfStakeBucketIdx: math.MaxUint64}}, }, }, }) From 0afcdb0dbde64a7b2c2e0ae09a9e5a62a76c6961 Mon Sep 17 00:00:00 2001 From: envestcc Date: Thu, 4 Jul 2024 22:31:26 +0800 Subject: [PATCH 3/3] fix test --- e2etest/contract_staking_v2_test.go | 2 +- e2etest/native_staking_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/e2etest/contract_staking_v2_test.go b/e2etest/contract_staking_v2_test.go index dc6b690ec9..e507f82ead 100644 --- a/e2etest/contract_staking_v2_test.go +++ b/e2etest/contract_staking_v2_test.go @@ -97,7 +97,7 @@ func TestContractStakingV2(t *testing.T) { act: &actionWithTime{mustNoErr(action.SignedExecution(contractAddress, identityset.PrivateKey(stakerID), test.nonceMgr.pop(identityset.Address(stakerID).String()), stakeAmount, gasLimit, gasPrice, mustCallData("stake(uint256,address)", stakeDurationBlocks, common.BytesToAddress(identityset.Address(candOwnerID).Bytes())), action.WithChainID(chainID))), stakeTime}, expect: []actionExpect{successExpect, &bucketExpect{&iotextypes.VoteBucket{Index: 1, ContractAddress: contractAddress, Owner: identityset.Address(stakerID).String(), CandidateAddress: identityset.Address(candOwnerID).String(), StakedDuration: uint32(stakeDurationBlocks.Uint64() / uint64(blocksPerDay)), StakedDurationBlockNumber: stakeDurationBlocks.Uint64(), CreateTime: timestamppb.New(time.Time{}), StakeStartTime: timestamppb.New(time.Time{}), StakeStartBlockHeight: 3, CreateBlockHeight: 3, UnstakeStartTime: timestamppb.New(time.Time{}), UnstakeStartBlockHeight: uint64(math.MaxUint64), StakedAmount: stakeAmount.String(), AutoStake: true}}, - &candidateExpect{"cand1", &iotextypes.CandidateV2{OwnerAddress: identityset.Address(candOwnerID).String(), OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), Name: "cand1", TotalWeightedVotes: "1256001586604779503009155", SelfStakingTokens: registerAmount.String(), SelfStakeBucketIdx: 0}}, + &candidateExpect{"cand1", &iotextypes.CandidateV2{OwnerAddress: identityset.Address(candOwnerID).String(), Id: identityset.Address(candOwnerID).String(), OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), Name: "cand1", TotalWeightedVotes: "1256001586604779503009155", SelfStakingTokens: registerAmount.String(), SelfStakeBucketIdx: 0}}, &functionExpect{func(test *e2etest, act *action.SealedEnvelope, receipt *action.Receipt, err error) { candidate, err := test.getCandidateByName("cand1") require.NoError(err) diff --git a/e2etest/native_staking_test.go b/e2etest/native_staking_test.go index 1a1afd1190..a92d76cc25 100644 --- a/e2etest/native_staking_test.go +++ b/e2etest/native_staking_test.go @@ -651,7 +651,7 @@ func TestCandidateTransferOwnership(t *testing.T) { {mustNoErr(action.SignedCandidateActivate(test.nonceMgr.pop(identityset.Address(oldOwnerID).String()), 1, gasLimit, gasPrice, identityset.PrivateKey(oldOwnerID), action.WithChainID(chainID))), time.Now()}, }, act: &actionWithTime{mustNoErr(action.SignedCandidateTransferOwnership(test.nonceMgr.pop(identityset.Address(oldOwnerID).String()), identityset.Address(newOwnerID).String(), nil, gasLimit, gasPrice, identityset.PrivateKey(oldOwnerID), action.WithChainID(chainID))), time.Now()}, - expect: []actionExpect{successExpect, &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "2491242816406174220844604", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(newOwnerID).String(), SelfStakeBucketIdx: 1}}}, + expect: []actionExpect{successExpect, &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", Id: identityset.Address(oldOwnerID).String(), OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "2491242816406174220844604", SelfStakingTokens: registerAmount.String(), OwnerAddress: identityset.Address(newOwnerID).String(), SelfStakeBucketIdx: 1}}}, }, }) }) @@ -1195,7 +1195,7 @@ func TestCandidateTransferOwnership(t *testing.T) { }, act: &actionWithTime{mustNoErr(action.SignedDepositToStake(test.nonceMgr.pop(identityset.Address(stakerID).String()), 1, unit.ConvertIotxToRau(10000000).String(), nil, gasLimit, gasPrice, identityset.PrivateKey(stakerID), action.WithChainID(chainID))), time.Now()}, expect: []actionExpect{successExpect, - &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "15734989908573124317570090", SelfStakingTokens: "0", OwnerAddress: identityset.Address(candOwnerID).String(), SelfStakeBucketIdx: math.MaxUint64}}, + &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", Id: identityset.Address(candOwnerID).String(), OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "15734989908573124317570090", SelfStakingTokens: "0", OwnerAddress: identityset.Address(candOwnerID).String(), SelfStakeBucketIdx: math.MaxUint64}}, &bucketExpect{&iotextypes.VoteBucket{Index: 1, EndorsementExpireBlockHeight: 10, CandidateAddress: identityset.Address(candOwnerID).String(), StakedAmount: "11200000000000000000000000", AutoStake: true, StakedDuration: 91, Owner: identityset.Address(stakerID).String(), CreateTime: timestamppb.New(stakeTime), StakeStartTime: timestamppb.New(stakeTime), UnstakeStartTime: ×tamppb.Timestamp{}}}, }, }, @@ -1207,7 +1207,7 @@ func TestCandidateTransferOwnership(t *testing.T) { }, act: &actionWithTime{mustNoErr(action.SignedChangeCandidate(test.nonceMgr.pop(identityset.Address(stakerID).String()), "cand2", 1, nil, gasLimit, gasPrice, identityset.PrivateKey(stakerID), action.WithChainID(chainID))), time.Now()}, expect: []actionExpect{successExpect, - &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "92550969839127272820178", SelfStakingTokens: "0", OwnerAddress: identityset.Address(candOwnerID).String(), SelfStakeBucketIdx: math.MaxUint64}}, + &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", Id: identityset.Address(candOwnerID).String(), OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "92550969839127272820178", SelfStakingTokens: "0", OwnerAddress: identityset.Address(candOwnerID).String(), SelfStakeBucketIdx: math.MaxUint64}}, }, }, { @@ -1225,7 +1225,7 @@ func TestCandidateTransferOwnership(t *testing.T) { }, act: &actionWithTime{mustNoErr(action.SignedTransfer(identityset.Address(1).String(), identityset.PrivateKey(2), test.nonceMgr.pop(identityset.Address(2).String()), unit.ConvertIotxToRau(1), nil, gasLimit, gasPrice, action.WithChainID(chainID))), time.Now()}, expect: []actionExpect{successExpect, - &candidateExpect{"cand3", &iotextypes.CandidateV2{Name: "cand3", OperatorAddress: identityset.Address(4).String(), RewardAddress: identityset.Address(4).String(), TotalWeightedVotes: "2880688542027669019063296", SelfStakingTokens: "0", OwnerAddress: identityset.Address(candOwnerID3).String(), SelfStakeBucketIdx: math.MaxUint64}}, + &candidateExpect{"cand3", &iotextypes.CandidateV2{Name: "cand3", Id: identityset.Address(candOwnerID3).String(), OperatorAddress: identityset.Address(4).String(), RewardAddress: identityset.Address(4).String(), TotalWeightedVotes: "2880688542027669019063296", SelfStakingTokens: "0", OwnerAddress: identityset.Address(candOwnerID3).String(), SelfStakeBucketIdx: math.MaxUint64}}, &bucketExpect{&iotextypes.VoteBucket{Index: 4, EndorsementExpireBlockHeight: 24, CandidateAddress: identityset.Address(candOwnerID3).String(), StakedAmount: "1200000000000000000000000", AutoStake: true, StakedDuration: 91, Owner: identityset.Address(stakerID).String(), CreateTime: timestamppb.New(stakeTime), StakeStartTime: timestamppb.New(stakeTime), UnstakeStartTime: ×tamppb.Timestamp{}}}, }, }, @@ -1235,7 +1235,7 @@ func TestCandidateTransferOwnership(t *testing.T) { expect: []actionExpect{successExpect, &bucketExpect{&iotextypes.VoteBucket{Index: 1, EndorsementExpireBlockHeight: 10, CandidateAddress: identityset.Address(candOwnerID2).String(), StakedAmount: "11200000000000000000000000", AutoStake: true, StakedDuration: 91, Owner: identityset.Address(stakerID).String(), CreateTime: timestamppb.New(stakeTime), StakeStartTime: timestamppb.New(stakeTime), UnstakeStartTime: ×tamppb.Timestamp{}}}, &bucketExpect{&iotextypes.VoteBucket{Index: 4, EndorsementExpireBlockHeight: 0, CandidateAddress: identityset.Address(candOwnerID3).String(), StakedAmount: "1200000000000000000000000", AutoStake: true, StakedDuration: 91, Owner: identityset.Address(stakerID).String(), CreateTime: timestamppb.New(stakeTime), StakeStartTime: timestamppb.New(stakeTime), UnstakeStartTime: ×tamppb.Timestamp{}}}, - &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "0", SelfStakingTokens: "0", OwnerAddress: identityset.Address(candOwnerID).String(), SelfStakeBucketIdx: math.MaxUint64}}, + &candidateExpect{"cand1", &iotextypes.CandidateV2{Name: "cand1", Id: identityset.Address(candOwnerID).String(), OperatorAddress: identityset.Address(1).String(), RewardAddress: identityset.Address(1).String(), TotalWeightedVotes: "0", SelfStakingTokens: "0", OwnerAddress: identityset.Address(candOwnerID).String(), SelfStakeBucketIdx: math.MaxUint64}}, }, }, })