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

P-chain - Tx builder cleanup #2718

Merged
merged 5 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
9 changes: 9 additions & 0 deletions vms/platformvm/block/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestBuildBlockBasic(t *testing.T) {
"chain name",
[]*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)
txID := tx.ID()
Expand Down Expand Up @@ -119,6 +120,7 @@ func TestBuildBlockShouldReward(t *testing.T) {
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[0]},
preFundedKeys[0].PublicKey().Address(),
nil,
)
require.NoError(err)
txID := tx.ID()
Expand Down Expand Up @@ -239,6 +241,7 @@ func TestBuildBlockForceAdvanceTime(t *testing.T) {
"chain name",
[]*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)
txID := tx.ID()
Expand Down Expand Up @@ -306,6 +309,7 @@ func TestBuildBlockDropExpiredStakerTxs(t *testing.T) {
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[0]},
preFundedKeys[0].PublicKey().Address(),
nil,
)
require.NoError(err)
require.NoError(env.mempool.Add(tx1))
Expand All @@ -326,6 +330,7 @@ func TestBuildBlockDropExpiredStakerTxs(t *testing.T) {
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[1]},
preFundedKeys[1].PublicKey().Address(),
nil,
)
require.NoError(err)
require.NoError(env.mempool.Add(tx2))
Expand All @@ -346,6 +351,7 @@ func TestBuildBlockDropExpiredStakerTxs(t *testing.T) {
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[2]},
preFundedKeys[2].PublicKey().Address(),
nil,
)
require.NoError(err)
require.NoError(env.mempool.Add(tx3))
Expand Down Expand Up @@ -412,6 +418,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) {
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[0]},
preFundedKeys[0].PublicKey().Address(),
nil,
)
require.NoError(err)
require.NoError(env.mempool.Add(tx1))
Expand All @@ -435,6 +442,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) {
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[2]},
preFundedKeys[2].PublicKey().Address(),
nil,
)
require.NoError(err)
require.NoError(env.mempool.Add(tx2))
Expand Down Expand Up @@ -480,6 +488,7 @@ func TestPreviouslyDroppedTxsCannotBeReAddedToMempool(t *testing.T) {
"chain name",
[]*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)
txID := tx.ID()
Expand Down
1 change: 1 addition & 0 deletions vms/platformvm/block/builder/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func addSubnet(t *testing.T, env *environment) {
},
[]*secp256k1.PrivateKey{preFundedKeys[0]},
preFundedKeys[0].PublicKey().Address(),
nil,
)
require.NoError(err)

Expand Down
1 change: 1 addition & 0 deletions vms/platformvm/block/builder/standard_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func TestAtomicTxImports(t *testing.T) {
recipientKey.PublicKey().Address(),
[]*secp256k1.PrivateKey{recipientKey},
ids.ShortEmpty, // change addr
nil,
)
require.NoError(err)

Expand Down
2 changes: 2 additions & 0 deletions vms/platformvm/block/executor/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func addSubnet(env *environment) {
},
[]*secp256k1.PrivateKey{preFundedKeys[0]},
preFundedKeys[0].PublicKey().Address(),
nil,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -468,6 +469,7 @@ func addPendingValidator(
reward.PercentDenominator,
keys,
ids.ShortEmpty,
nil,
)
if err != nil {
return nil, err
Expand Down
16 changes: 16 additions & 0 deletions vms/platformvm/block/executor/proposal_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) {
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[0]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand All @@ -589,6 +590,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) {
subnetID, // Subnet ID
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -618,6 +620,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) {
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -718,6 +721,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) {
subnetID, // Subnet ID
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -746,6 +750,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) {
subnetID, // Subnet ID
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -777,6 +782,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) {
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -860,6 +866,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) {
subnetID, // Subnet ID
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -889,6 +896,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) {
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -975,6 +983,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) {
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -1043,6 +1052,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) {
preFundedKeys[4],
},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand All @@ -1069,6 +1079,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) {
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -1159,6 +1170,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) {
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -1226,6 +1238,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) {
preFundedKeys[4],
},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand All @@ -1252,6 +1265,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) {
reward.PercentDenominator,
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -1337,6 +1351,7 @@ func TestAddValidatorProposalBlock(t *testing.T) {
preFundedKeys[4],
},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -1412,6 +1427,7 @@ func TestAddValidatorProposalBlock(t *testing.T) {
preFundedKeys[4],
},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down
5 changes: 5 additions & 0 deletions vms/platformvm/block/executor/standard_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) {
subnetID, // Subnet ID
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -610,6 +611,7 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) {
subnetID, // Subnet ID
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -638,6 +640,7 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) {
subnetID, // Subnet ID
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -708,6 +711,7 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) {
subnetID, // Subnet ID
[]*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -803,6 +807,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) {
preFundedKeys[4],
},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down
7 changes: 7 additions & 0 deletions vms/platformvm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,7 @@ func (s *Service) buildAddValidatorTx(args *AddValidatorArgs) (*txs.Tx, ids.Shor
uint32(10000*args.DelegationFeeRate), // Shares
privKeys.Keys, // Keys providing the staked tokens
changeAddr,
nil,
)
if err != nil {
return nil, ids.ShortEmpty, err
Expand Down Expand Up @@ -1406,6 +1407,7 @@ func (s *Service) buildAddDelegatorTx(args *AddDelegatorArgs) (*txs.Tx, ids.Shor
rewardAddress, // Reward Address
privKeys.Keys, // Private keys
changeAddr, // Change address
nil, // Memo
)
if err != nil {
return nil, ids.ShortEmpty, err
Expand Down Expand Up @@ -1520,6 +1522,7 @@ func (s *Service) buildAddSubnetValidatorTx(args *AddSubnetValidatorArgs) (*txs.
subnetID, // Subnet ID
keys.Keys,
changeAddr,
nil,
)
if err != nil {
return nil, ids.ShortEmpty, err
Expand Down Expand Up @@ -1604,6 +1607,7 @@ func (s *Service) buildCreateSubnetTx(args *CreateSubnetArgs) (*txs.Tx, ids.Shor
controlKeys.List(), // Control Addresses
privKeys.Keys, // Private keys
changeAddr,
nil,
)
if err != nil {
return nil, ids.ShortEmpty, err
Expand Down Expand Up @@ -1708,6 +1712,7 @@ func (s *Service) buildExportAVAX(args *ExportAVAXArgs) (*txs.Tx, ids.ShortID, e
to, // Address
privKeys.Keys, // Private keys
changeAddr, // Change address
nil,
)
if err != nil {
return nil, ids.ShortEmpty, err
Expand Down Expand Up @@ -1801,6 +1806,7 @@ func (s *Service) buildImportAVAXTx(args *ImportAVAXArgs) (*txs.Tx, ids.ShortID,
to,
privKeys.Keys,
changeAddr,
nil,
)
if err != nil {
return nil, ids.ShortEmpty, err
Expand Down Expand Up @@ -1933,6 +1939,7 @@ func (s *Service) buildCreateBlockchainTx(args *CreateBlockchainArgs) (*txs.Tx,
args.Name,
keys.Keys,
changeAddr, // Change address
nil,
)
if err != nil {
return nil, ids.ShortEmpty, err
Expand Down
8 changes: 8 additions & 0 deletions vms/platformvm/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func TestGetTxStatus(t *testing.T) {
ids.ShortEmpty,
[]*secp256k1.PrivateKey{recipientKey},
ids.ShortEmpty,
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -263,6 +264,7 @@ func TestGetTx(t *testing.T) {
"chain name",
[]*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
keys[0].PublicKey().Address(), // change addr
nil,
)
},
},
Expand All @@ -282,6 +284,7 @@ func TestGetTx(t *testing.T) {
0,
[]*secp256k1.PrivateKey{keys[0]},
keys[0].PublicKey().Address(), // change addr
nil,
)
},
},
Expand All @@ -294,6 +297,7 @@ func TestGetTx(t *testing.T) {
ids.GenerateTestShortID(),
[]*secp256k1.PrivateKey{keys[0]},
keys[0].PublicKey().Address(), // change addr
nil,
)
},
},
Expand Down Expand Up @@ -482,6 +486,7 @@ func TestGetStake(t *testing.T) {
ids.GenerateTestShortID(),
[]*secp256k1.PrivateKey{keys[0]},
keys[0].PublicKey().Address(), // change addr
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -537,6 +542,7 @@ func TestGetStake(t *testing.T) {
0,
[]*secp256k1.PrivateKey{keys[0]},
keys[0].PublicKey().Address(), // change addr
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -615,6 +621,7 @@ func TestGetCurrentValidators(t *testing.T) {
ids.GenerateTestShortID(),
[]*secp256k1.PrivateKey{keys[0]},
keys[0].PublicKey().Address(), // change addr
nil,
)
require.NoError(err)

Expand Down Expand Up @@ -748,6 +755,7 @@ func TestGetBlock(t *testing.T) {
"chain name",
[]*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
keys[0].PublicKey().Address(), // change addr
nil,
)
require.NoError(err)

Expand Down
Loading
Loading