@@ -1581,6 +1581,8 @@ func TestCandidateBLSPublicKey(t *testing.T) {
15811581 cfg := initCfg (require )
15821582 cfg .Genesis .WakeBlockHeight = 1
15831583 cfg .Genesis .XinguBlockHeight = 10 // enable CandidateBLSPublicKey feature
1584+ cfg .Genesis .XinguBetaBlockHeight = 11
1585+ cfg .Genesis .ToBeEnabledBlockHeight = 20 // enable candidate BLS key update by operator feature
15841586 cfg .Genesis .SystemStakingContractAddress = ""
15851587 cfg .Genesis .SystemStakingContractV2Address = ""
15861588 cfg .Genesis .SystemStakingContractV3Address = ""
@@ -1592,10 +1594,12 @@ func TestCandidateBLSPublicKey(t *testing.T) {
15921594 test := newE2ETest (t , cfg )
15931595
15941596 var (
1595- chainID = test .cfg .Chain .ID
1596- registerAmount = unit .ConvertIotxToRau (1200000 )
1597- candOwnerID = 3
1598- candOwnerID2 = 4
1597+ chainID = test .cfg .Chain .ID
1598+ registerAmount = unit .ConvertIotxToRau (1200000 )
1599+ candOwnerID = 3
1600+ candOperatorID = 1
1601+ candOwnerID2 = 4
1602+ candOperatorID2 = 2
15991603 )
16001604 genTransferActionsWithPrice := func (n int , price * big.Int ) []* actionWithTime {
16011605 acts := make ([]* actionWithTime , n )
@@ -1611,7 +1615,7 @@ func TestCandidateBLSPublicKey(t *testing.T) {
16111615 {
16121616 name : "register without bls key" ,
16131617 acts : []* actionWithTime {
1614- {mustNoErr (action .SignedCandidateRegister (test .nonceMgr .pop (identityset .Address (candOwnerID ).String ()), "cand1" , identityset .Address (1 ).String (), identityset .Address (1 ).String (), identityset .Address (candOwnerID ).String (), registerAmount .String (), 1 , true , nil , gasLimit , gasPrice1559 , identityset .PrivateKey (candOwnerID ), action .WithChainID (chainID ))), time .Now ()},
1618+ {mustNoErr (action .SignedCandidateRegister (test .nonceMgr .pop (identityset .Address (candOwnerID ).String ()), "cand1" , identityset .Address (candOperatorID ).String (), identityset .Address (1 ).String (), identityset .Address (candOwnerID ).String (), registerAmount .String (), 1 , true , nil , gasLimit , gasPrice1559 , identityset .PrivateKey (candOwnerID ), action .WithChainID (chainID ))), time .Now ()},
16151619 },
16161620 blockExpect : func (test * e2etest , blk * block.Block , err error ) {
16171621 require .NoError (err )
@@ -1627,7 +1631,7 @@ func TestCandidateBLSPublicKey(t *testing.T) {
16271631 name : "register with bls key" ,
16281632 preActs : genTransferActionsWithPrice (int (cfg .Genesis .XinguBlockHeight ), gasPrice1559 ),
16291633 acts : []* actionWithTime {
1630- {mustNoErr (action .SignedCandidateRegisterWithBLS (test .nonceMgr .pop (identityset .Address (candOwnerID2 ).String ()), "cand2" , identityset .Address (2 ).String (), identityset .Address (2 ).String (), identityset .Address (candOwnerID2 ).String (), registerAmount .String (), 1 , true , blsPubKey , []byte {1 , 2 , 3 }, gasLimit , gasPrice , identityset .PrivateKey (candOwnerID2 ), action .WithChainID (chainID ))), time .Now ()},
1634+ {mustNoErr (action .SignedCandidateRegisterWithBLS (test .nonceMgr .pop (identityset .Address (candOwnerID2 ).String ()), "cand2" , identityset .Address (candOperatorID2 ).String (), identityset .Address (2 ).String (), identityset .Address (candOwnerID2 ).String (), registerAmount .String (), 1 , true , blsPubKey , []byte {1 , 2 , 3 }, gasLimit , gasPrice , identityset .PrivateKey (candOwnerID2 ), action .WithChainID (chainID ))), time .Now ()},
16311635 },
16321636 blockExpect : func (test * e2etest , blk * block.Block , err error ) {
16331637 require .NoError (err )
@@ -1640,6 +1644,31 @@ func TestCandidateBLSPublicKey(t *testing.T) {
16401644 },
16411645 },
16421646 })
1647+ height , err := test .cs .BlockDAO ().Height ()
1648+ require .NoError (err )
1649+ jumps := int (cfg .Genesis .ToBeEnabledBlockHeight - height )
1650+ if jumps <= 0 {
1651+ jumps = 1
1652+ }
1653+ blsPrivKey2 , err := crypto .GenerateBLS12381PrivateKey (identityset .PrivateKey (candOperatorID ).Bytes ())
1654+ require .NoError (err )
1655+ test .run ([]* testcase {
1656+ {
1657+ name : "update bls key by operator" ,
1658+ preActs : genTransferActionsWithPrice (jumps , gasPrice1559 ),
1659+ acts : []* actionWithTime {
1660+ {mustNoErr (action .SignedCandidateUpdateWithBLS (test .nonceMgr .pop (identityset .Address (candOperatorID ).String ()), "cand1" , identityset .Address (candOperatorID ).String (), "" , blsPrivKey2 .PublicKey ().Bytes (), gasLimit , gasPrice , identityset .PrivateKey (candOperatorID ), action .WithChainID (chainID ))), time .Now ()},
1661+ },
1662+ blockExpect : func (test * e2etest , blk * block.Block , err error ) {
1663+ require .NoError (err )
1664+ require .EqualValues (2 , len (blk .Receipts ))
1665+ require .EqualValues (iotextypes .ReceiptStatus_Success , blk .Receipts [0 ].Status )
1666+ cand , err := test .getCandidateByName ("cand1" )
1667+ require .NoError (err )
1668+ require .EqualValues (blsPrivKey2 .PublicKey ().Bytes (), cand .BlsPubKey )
1669+ },
1670+ },
1671+ })
16431672}
16441673
16451674func parseNativeStakedBucketIndex (receipt * action.Receipt ) []uint64 {
0 commit comments