Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Jan 18, 2024
1 parent 7549e81 commit 7ab6ddf
Showing 1 changed file with 43 additions and 11 deletions.
54 changes: 43 additions & 11 deletions action/protocol/staking/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/golang/mock/gomock"
"github.com/mohae/deepcopy"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -531,6 +532,27 @@ func TestProtocol_HandleCandidateRegister(t *testing.T) {
nil,
iotextypes.ReceiptStatus_ErrCandidateConflict,
},
// register without self-stake
{
1201000,
identityset.Address(27),
1,
"test",
identityset.Address(28).String(),
identityset.Address(29).String(),
identityset.Address(30).String(),
"0",
"0",
uint32(10000),
false,
nil,
uint64(1000000),
uint64(1000000),
big.NewInt(1),
true,
nil,
iotextypes.ReceiptStatus_Success,
},
}

for _, test := range tests {
Expand All @@ -553,7 +575,9 @@ func TestProtocol_HandleCandidateRegister(t *testing.T) {
BlockTimeStamp: time.Now(),
GasLimit: test.blkGasLimit,
})
ctx = genesis.WithGenesisContext(ctx, genesis.Default)
g := deepcopy.Copy(genesis.Default).(genesis.Genesis)
g.ToBeEnabledBlockHeight = 0
ctx = genesis.WithGenesisContext(ctx, g)
ctx = protocol.WithFeatureCtx(protocol.WithFeatureWithHeightCtx(ctx))
require.Equal(test.err, errors.Cause(p.Validate(ctx, act, sm)))
if test.err != nil {
Expand All @@ -570,16 +594,24 @@ func TestProtocol_HandleCandidateRegister(t *testing.T) {
if test.err == nil && test.status == iotextypes.ReceiptStatus_Success {
// check the special create bucket and candidate register log
tLogs := r.TransactionLogs()
require.Equal(2, len(tLogs))
cLog := tLogs[0]
require.Equal(test.caller.String(), cLog.Sender)
require.Equal(address.StakingBucketPoolAddr, cLog.Recipient)
require.Equal(test.amountStr, cLog.Amount.String())

cLog = tLogs[1]
require.Equal(test.caller.String(), cLog.Sender)
require.Equal(address.RewardingPoolAddr, cLog.Recipient)
require.Equal(p.config.RegistrationConsts.Fee.String(), cLog.Amount.String())
if test.amountStr == "0" {
require.Equal(1, len(tLogs))
cLog := tLogs[0]
require.Equal(test.caller.String(), cLog.Sender)
require.Equal(address.RewardingPoolAddr, cLog.Recipient)
require.Equal(p.config.RegistrationConsts.Fee.String(), cLog.Amount.String())
} else {
require.Equal(2, len(tLogs))
cLog := tLogs[0]
require.Equal(test.caller.String(), cLog.Sender)
require.Equal(address.StakingBucketPoolAddr, cLog.Recipient)
require.Equal(test.amountStr, cLog.Amount.String())

cLog = tLogs[1]
require.Equal(test.caller.String(), cLog.Sender)
require.Equal(address.RewardingPoolAddr, cLog.Recipient)
require.Equal(p.config.RegistrationConsts.Fee.String(), cLog.Amount.String())
}

// test candidate
candidate, _, err := csr.getCandidate(act.OwnerAddress())
Expand Down

0 comments on commit 7ab6ddf

Please sign in to comment.