diff --git a/vms/platformvm/block/builder/builder_test.go b/vms/platformvm/block/builder/builder_test.go index 4088ccaee7a1..eeddc5bc7f9b 100644 --- a/vms/platformvm/block/builder/builder_test.go +++ b/vms/platformvm/block/builder/builder_test.go @@ -16,7 +16,6 @@ import ( "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/platformvm/block" @@ -29,6 +28,7 @@ import ( blockexecutor "github.com/ava-labs/avalanchego/vms/platformvm/block/executor" txexecutor "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) func TestBuildBlockBasic(t *testing.T) { @@ -39,15 +39,17 @@ func TestBuildBlockBasic(t *testing.T) { defer env.ctx.Lock.Unlock() // Create a valid transaction - tx, err := env.txBuilder.NewCreateChainTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, constants.AVMID, nil, "chain name", - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) txID := tx.ID() // Issue the transaction @@ -109,7 +111,8 @@ func TestBuildBlockShouldReward(t *testing.T) { require.NoError(err) // Create a valid [AddPermissionlessValidatorTx] - tx, err := env.txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -130,13 +133,14 @@ func TestBuildBlockShouldReward(t *testing.T) { Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0]}, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) txID := tx.ID() // Issue the transaction @@ -247,15 +251,17 @@ func TestBuildBlockForceAdvanceTime(t *testing.T) { defer env.ctx.Lock.Unlock() // Create a valid transaction - tx, err := env.txBuilder.NewCreateChainTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, constants.AVMID, nil, "chain name", - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) txID := tx.ID() // Issue the transaction @@ -314,7 +320,8 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - tx1, err := env.txBuilder.NewAddPermissionlessValidatorTx( + builder1, signer1 := env.factory.NewWallet(preFundedKeys[0]) + utx1, err := builder1.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -335,13 +342,14 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0]}, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) + tx1, err := walletsigner.SignUnsigned(context.Background(), signer1, utx1) + require.NoError(err) require.NoError(env.mempool.Add(tx1)) tx1ID := tx1.ID() _, ok := env.mempool.Get(tx1ID) @@ -353,7 +361,8 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { sk, err = bls.NewSecretKey() require.NoError(err) - tx2, err := env.txBuilder.NewAddPermissionlessValidatorTx( + builder2, signer2 := env.factory.NewWallet(preFundedKeys[2]) + utx2, err := builder2.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -374,13 +383,14 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { Addrs: []ids.ShortID{preFundedKeys[2].PublicKey().Address()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[2]}, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{preFundedKeys[2].PublicKey().Address()}, }), ) require.NoError(err) + tx2, err := walletsigner.SignUnsigned(context.Background(), signer2, utx2) + require.NoError(err) require.NoError(env.mempool.Add(tx2)) tx2ID := tx2.ID() _, ok = env.mempool.Get(tx2ID) @@ -416,15 +426,17 @@ func TestPreviouslyDroppedTxsCannotBeReAddedToMempool(t *testing.T) { defer env.ctx.Lock.Unlock() // Create a valid transaction - tx, err := env.txBuilder.NewCreateChainTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, constants.AVMID, nil, "chain name", - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) txID := tx.ID() // Transaction should not be marked as dropped before being added to the diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 909d7adefe5e..eb80a9ffc4d3 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -53,6 +53,7 @@ import ( blockexecutor "github.com/ava-labs/avalanchego/vms/platformvm/block/executor" txexecutor "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" pvalidators "github.com/ava-labs/avalanchego/vms/platformvm/validators" + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" walletcommon "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" ) @@ -118,7 +119,7 @@ type environment struct { state state.State uptimes uptime.Manager utxosVerifier utxo.Verifier - txBuilder *txstest.Builder + factory *txstest.WalletFactory backend txexecutor.Backend } @@ -152,12 +153,7 @@ func newEnvironment(t *testing.T, f fork) *environment { //nolint:unparam res.uptimes = uptime.NewManager(res.state, res.clk) res.utxosVerifier = utxo.NewVerifier(res.ctx, res.clk, res.fx) - - res.txBuilder = txstest.NewBuilder( - res.ctx, - res.config, - res.state, - ) + res.factory = txstest.NewWalletFactory(res.ctx, res.config, res.state) genesisID := res.state.GetLastAccepted() res.backend = txexecutor.Backend{ @@ -240,9 +236,8 @@ func newEnvironment(t *testing.T, f fork) *environment { //nolint:unparam func addSubnet(t *testing.T, env *environment) { require := require.New(t) - // Create a subnet - var err error - testSubnet1, err = env.txBuilder.NewCreateSubnetTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ @@ -251,15 +246,15 @@ func addSubnet(t *testing.T, env *environment) { preFundedKeys[2].PublicKey().Address(), }, }, - []*secp256k1.PrivateKey{preFundedKeys[0]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) + testSubnet1, err = walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) - // store it genesisID := env.state.GetLastAccepted() stateDiff, err := state.NewDiff(genesisID, env.blkManager) require.NoError(err) diff --git a/vms/platformvm/block/builder/standard_block_test.go b/vms/platformvm/block/builder/standard_block_test.go index 8606163990eb..18ca5bdb3582 100644 --- a/vms/platformvm/block/builder/standard_block_test.go +++ b/vms/platformvm/block/builder/standard_block_test.go @@ -12,11 +12,12 @@ import ( "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) func TestAtomicTxImports(t *testing.T) { @@ -62,15 +63,17 @@ func TestAtomicTxImports(t *testing.T) { }}}, })) - tx, err := env.txBuilder.NewImportTx( + builder, signer := env.factory.NewWallet(recipientKey) + utx, err := builder.NewImportTx( env.ctx.XChainID, &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{recipientKey.PublicKey().Address()}, }, - []*secp256k1.PrivateKey{recipientKey}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) require.NoError(env.Builder.Add(tx)) b, err := env.Builder.BuildBlock(context.Background()) diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index d87b67c76d25..a8c276579c08 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -4,6 +4,7 @@ package executor import ( + "context" "fmt" "testing" "time" @@ -52,6 +53,7 @@ import ( "github.com/ava-labs/avalanchego/vms/secp256k1fx" pvalidators "github.com/ava-labs/avalanchego/vms/platformvm/validators" + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" walletcommon "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" ) @@ -130,7 +132,7 @@ type environment struct { mockedState *state.MockState uptimes uptime.Manager utxosVerifier utxo.Verifier - txBuilder *txstest.Builder + factory *txstest.WalletFactory backend *executor.Backend } @@ -158,7 +160,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f fork) *environment res.state = defaultState(res.config, res.ctx, res.baseDB, rewardsCalc) res.uptimes = uptime.NewManager(res.state, res.clk) res.utxosVerifier = utxo.NewVerifier(res.ctx, res.clk, res.fx) - res.txBuilder = txstest.NewBuilder( + res.factory = txstest.NewWalletFactory( res.ctx, res.config, res.state, @@ -168,8 +170,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f fork) *environment res.mockedState = state.NewMockState(ctrl) res.uptimes = uptime.NewManager(res.mockedState, res.clk) res.utxosVerifier = utxo.NewVerifier(res.ctx, res.clk, res.fx) - - res.txBuilder = txstest.NewBuilder( + res.factory = txstest.NewWalletFactory( res.ctx, res.config, res.mockedState, @@ -251,9 +252,8 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f fork) *environment } func addSubnet(env *environment) { - // Create a subnet - var err error - testSubnet1, err = env.txBuilder.NewCreateSubnetTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ @@ -262,7 +262,6 @@ func addSubnet(env *environment) { preFundedKeys[2].PublicKey().Address(), }, }, - []*secp256k1.PrivateKey{preFundedKeys[0]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, @@ -271,8 +270,11 @@ func addSubnet(env *environment) { if err != nil { panic(err) } + testSubnet1, err = walletsigner.SignUnsigned(context.Background(), signer, utx) + if err != nil { + panic(err) + } - // store it genesisID := env.state.GetLastAccepted() stateDiff, err := state.NewDiff(genesisID, env.blkManager) if err != nil { @@ -495,7 +497,8 @@ func addPendingValidator( rewardAddress ids.ShortID, keys []*secp256k1.PrivateKey, ) (*txs.Tx, error) { - addPendingValidatorTx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(keys...) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -507,11 +510,14 @@ func addPendingValidator( Addrs: []ids.ShortID{rewardAddress}, }, reward.PercentDenominator, - keys, ) if err != nil { return nil, err } + addPendingValidatorTx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + if err != nil { + return nil, err + } staker, err := state.NewPendingStaker( addPendingValidatorTx.ID(), diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 0436251e9993..3a3f45fd7c0d 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -29,6 +29,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" walletcommon "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" ) @@ -537,7 +538,8 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { env.config.TrackedSubnets.Add(subnetID) for _, staker := range test.stakers { - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: staker.nodeID, Start: uint64(staker.startTime.Unix()), @@ -549,13 +551,14 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { Addrs: []ids.ShortID{staker.rewardAddress}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }), ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) staker, err := state.NewPendingStaker( tx.ID(), @@ -569,7 +572,8 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { } for _, subStaker := range test.subnetStakers { - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subStaker.nodeID, @@ -579,13 +583,14 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }), ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) subnetStaker, err := state.NewPendingStaker( tx.ID(), @@ -604,7 +609,8 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0.endTime = newTime - addStaker0, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: staker0.nodeID, Start: uint64(staker0.startTime.Unix()), @@ -616,13 +622,14 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { Addrs: []ids.ShortID{staker0.rewardAddress}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }), ) require.NoError(err) + addStaker0, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) // store Staker0 to state addValTx := addStaker0.Unsigned.(*txs.AddValidatorTx) @@ -712,7 +719,8 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { subnetValidatorNodeID := genesisNodeIDs[0] subnetVdr1StartTime := defaultValidateStartTime subnetVdr1EndTime := defaultValidateStartTime.Add(defaultMinStakingDuration) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, @@ -722,9 +730,10 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) addSubnetValTx := tx.Unsigned.(*txs.AddSubnetValidatorTx) staker, err := state.NewCurrentStaker( @@ -743,7 +752,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { // Queue a staker that joins the staker set after the above validator leaves subnetVdr2NodeID := genesisNodeIDs[1] - tx, err = env.txBuilder.NewAddSubnetValidatorTx( + utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetVdr2NodeID, @@ -753,9 +762,10 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + tx, err = walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) staker, err = state.NewPendingStaker( tx.ID(), @@ -776,7 +786,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { // so to allow proposalBlk issuance staker0StartTime := defaultValidateStartTime staker0EndTime := subnetVdr1EndTime - addStaker0, err := env.txBuilder.NewAddValidatorTx( + uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), Start: uint64(staker0StartTime.Unix()), @@ -788,13 +798,14 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }), ) require.NoError(err) + addStaker0, err := walletsigner.SignUnsigned(context.Background(), signer, uVdrTx) + require.NoError(err) // store Staker0 to state addValTx := addStaker0.Unsigned.(*txs.AddValidatorTx) @@ -867,7 +878,9 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { subnetValidatorNodeID := genesisNodeIDs[0] subnetVdr1StartTime := defaultGenesisTime.Add(1 * time.Minute) subnetVdr1EndTime := defaultGenesisTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, @@ -877,9 +890,10 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) staker, err := state.NewPendingStaker( tx.ID(), @@ -898,7 +912,8 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { // so to allow proposalBlk issuance staker0StartTime := defaultGenesisTime staker0EndTime := subnetVdr1StartTime - addStaker0, err := env.txBuilder.NewAddValidatorTx( + + uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), Start: uint64(staker0StartTime.Unix()), @@ -910,9 +925,10 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + addStaker0, err := walletsigner.SignUnsigned(context.Background(), signer, uVdrTx) + require.NoError(err) // store Staker0 to state addValTx := addStaker0.Unsigned.(*txs.AddValidatorTx) @@ -987,7 +1003,8 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // just to allow proposalBlk issuance (with a reward Tx) staker0StartTime := defaultGenesisTime staker0EndTime := pendingValidatorStartTime - addStaker0, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), Start: uint64(staker0StartTime.Unix()), @@ -999,9 +1016,10 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + addStaker0, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) // store Staker0 to state addValTx := addStaker0.Unsigned.(*txs.AddValidatorTx) @@ -1056,7 +1074,8 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - addDelegatorTx, err := env.txBuilder.NewAddDelegatorTx( + builder, signer = env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(pendingDelegatorStartTime.Unix()), @@ -1067,13 +1086,10 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, }, - []*secp256k1.PrivateKey{ - preFundedKeys[0], - preFundedKeys[1], - preFundedKeys[4], - }, ) require.NoError(err) + addDelegatorTx, err := walletsigner.SignUnsigned(context.Background(), signer, uDelTx) + require.NoError(err) staker, err = state.NewPendingStaker( addDelegatorTx.ID(), @@ -1089,7 +1105,8 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0EndTime = pendingDelegatorStartTime - addStaker0, err = env.txBuilder.NewAddValidatorTx( + builder, signer = env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err = builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), Start: uint64(staker0StartTime.Unix()), @@ -1101,9 +1118,10 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + addStaker0, err = walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) // store Staker0 to state addValTx = addStaker0.Unsigned.(*txs.AddValidatorTx) @@ -1182,7 +1200,8 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // so to allow proposalBlk issuance staker0StartTime := defaultGenesisTime staker0EndTime := pendingValidatorStartTime - addStaker0, err := env.txBuilder.NewAddValidatorTx( + builder, txSigner := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), Start: uint64(staker0StartTime.Unix()), @@ -1194,9 +1213,10 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + addStaker0, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // store Staker0 to state addValTx := addStaker0.Unsigned.(*txs.AddValidatorTx) @@ -1250,7 +1270,8 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // Add delegator pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(defaultMinStakingDuration) - addDelegatorTx, err := env.txBuilder.NewAddDelegatorTx( + builder, txSigner = env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(pendingDelegatorStartTime.Unix()), @@ -1261,13 +1282,10 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, }, - []*secp256k1.PrivateKey{ - preFundedKeys[0], - preFundedKeys[1], - preFundedKeys[4], - }, ) require.NoError(err) + addDelegatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uDelTx) + require.NoError(err) staker, err = state.NewPendingStaker( addDelegatorTx.ID(), @@ -1283,7 +1301,8 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0EndTime = pendingDelegatorStartTime - addStaker0, err = env.txBuilder.NewAddValidatorTx( + builder, txSigner = env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err = builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), Start: uint64(staker0StartTime.Unix()), @@ -1295,9 +1314,10 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + addStaker0, err = walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // store Staker0 to state addValTx = addStaker0.Unsigned.(*txs.AddValidatorTx) @@ -1365,7 +1385,8 @@ func TestAddValidatorProposalBlock(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - addValidatorTx, err := env.txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -1386,13 +1407,10 @@ func TestAddValidatorProposalBlock(t *testing.T) { Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, }, 10000, - []*secp256k1.PrivateKey{ - preFundedKeys[0], - preFundedKeys[1], - preFundedKeys[4], - }, ) require.NoError(err) + addValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // Add validator through a [StandardBlock] preferredID := env.blkManager.Preferred() @@ -1452,7 +1470,7 @@ func TestAddValidatorProposalBlock(t *testing.T) { sk, err = bls.NewSecretKey() require.NoError(err) - addValidatorTx2, err := env.txBuilder.NewAddPermissionlessValidatorTx( + utx2, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -1473,13 +1491,10 @@ func TestAddValidatorProposalBlock(t *testing.T) { Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, }, 10000, - []*secp256k1.PrivateKey{ - preFundedKeys[0], - preFundedKeys[1], - preFundedKeys[4], - }, ) require.NoError(err) + addValidatorTx2, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx2) + require.NoError(err) // Add validator through a [ProposalBlock] and reward the last one preferredID = env.blkManager.Preferred() diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index b8c9257a2915..af8d469c48c3 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -23,6 +23,8 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) func TestApricotStandardBlockTimeVerification(t *testing.T) { @@ -508,7 +510,8 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { } for _, staker := range test.subnetStakers { - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: staker.nodeID, @@ -518,9 +521,10 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) staker, err := state.NewPendingStaker( tx.ID(), @@ -600,7 +604,8 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { subnetValidatorNodeID := genesisNodeIDs[0] subnetVdr1StartTime := defaultValidateStartTime subnetVdr1EndTime := defaultValidateStartTime.Add(defaultMinStakingDuration) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, @@ -610,9 +615,10 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) addSubnetValTx := tx.Unsigned.(*txs.AddSubnetValidatorTx) staker, err := state.NewCurrentStaker( @@ -631,7 +637,7 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { // Queue a staker that joins the staker set after the above validator leaves subnetVdr2NodeID := genesisNodeIDs[1] - tx, err = env.txBuilder.NewAddSubnetValidatorTx( + utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetVdr2NodeID, @@ -641,9 +647,10 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + tx, err = walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) staker, err = state.NewPendingStaker( tx.ID(), @@ -703,7 +710,8 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { subnetValidatorNodeID := genesisNodeIDs[0] subnetVdr1StartTime := defaultGenesisTime.Add(1 * time.Minute) subnetVdr1EndTime := defaultGenesisTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, @@ -713,9 +721,10 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) staker, err := state.NewPendingStaker( tx.ID(), @@ -796,7 +805,8 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - addDelegatorTx, err := env.txBuilder.NewAddDelegatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(pendingDelegatorStartTime.Unix()), @@ -807,13 +817,10 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, }, - []*secp256k1.PrivateKey{ - preFundedKeys[0], - preFundedKeys[1], - preFundedKeys[4], - }, ) require.NoError(err) + addDelegatorTx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) staker, err := state.NewPendingStaker( addDelegatorTx.ID(), diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index d72e11f6379c..3d4aac61770e 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -34,7 +34,6 @@ import ( "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/block" - "github.com/ava-labs/avalanchego/vms/platformvm/block/builder" "github.com/ava-labs/avalanchego/vms/platformvm/signer" "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/status" @@ -47,8 +46,10 @@ import ( avajson "github.com/ava-labs/avalanchego/utils/json" vmkeystore "github.com/ava-labs/avalanchego/vms/components/keystore" pchainapi "github.com/ava-labs/avalanchego/vms/platformvm/api" + blockbuilder "github.com/ava-labs/avalanchego/vms/platformvm/block/builder" blockexecutor "github.com/ava-labs/avalanchego/vms/platformvm/block/executor" txexecutor "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) var ( @@ -75,8 +76,8 @@ var ( } ) -func defaultService(t *testing.T) (*Service, *mutableSharedMemory, *txstest.Builder) { - vm, txBuilder, _, mutableSharedMemory := defaultVM(t, latestFork) +func defaultService(t *testing.T) (*Service, *mutableSharedMemory, *txstest.WalletFactory) { + vm, factory, _, mutableSharedMemory := defaultVM(t, latestFork) return &Service{ vm: vm, @@ -84,7 +85,7 @@ func defaultService(t *testing.T) (*Service, *mutableSharedMemory, *txstest.Buil stakerAttributesCache: &cache.LRU[ids.ID, *stakerAttributes]{ Size: stakerAttributesCacheSize, }, - }, mutableSharedMemory, txBuilder + }, mutableSharedMemory, factory } func TestExportKey(t *testing.T) { @@ -120,7 +121,7 @@ func TestExportKey(t *testing.T) { // Test issuing a tx and accepted func TestGetTxStatus(t *testing.T) { require := require.New(t) - service, mutableSharedMemory, txBuilder := defaultService(t) + service, mutableSharedMemory, factory := defaultService(t) service.vm.ctx.Lock.Lock() recipientKey, err := secp256k1.NewPrivateKey() @@ -168,15 +169,17 @@ func TestGetTxStatus(t *testing.T) { mutableSharedMemory.SharedMemory = sm - tx, err := txBuilder.NewImportTx( + builder, signer := factory.NewWallet(recipientKey) + utx, err := builder.NewImportTx( service.vm.ctx.XChainID, &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }, - []*secp256k1.PrivateKey{recipientKey}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) service.vm.ctx.Lock.Unlock() @@ -212,30 +215,32 @@ func TestGetTxStatus(t *testing.T) { func TestGetTx(t *testing.T) { type test struct { description string - createTx func(service *Service, builder *txstest.Builder) (*txs.Tx, error) + createTx func(service *Service, factory *txstest.WalletFactory) (*txs.Tx, error) } tests := []test{ { "standard block", - func(_ *Service, builder *txstest.Builder) (*txs.Tx, error) { - return builder.NewCreateChainTx( // Test GetTx works for standard blocks + func(_ *Service, factory *txstest.WalletFactory) (*txs.Tx, error) { + builder, signer := factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewCreateChainTx( testSubnet1.ID(), []byte{}, constants.AVMID, []ids.ID{}, "chain name", - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }), ) + require.NoError(t, err) + return walletsigner.SignUnsigned(context.Background(), signer, utx) }, }, { "proposal block", - func(service *Service, builder *txstest.Builder) (*txs.Tx, error) { + func(service *Service, factory *txstest.WalletFactory) (*txs.Tx, error) { sk, err := bls.NewSecretKey() require.NoError(t, err) @@ -244,7 +249,8 @@ func TestGetTx(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, } - return builder.NewAddPermissionlessValidatorTx( // Test GetTx works for proposal blocks + builder, txSigner := factory.NewWallet(keys[0]) + utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -259,18 +265,20 @@ func TestGetTx(t *testing.T) { rewardsOwner, rewardsOwner, 0, - []*secp256k1.PrivateKey{keys[0]}, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }), ) + require.NoError(t, err) + return walletsigner.SignUnsigned(context.Background(), txSigner, utx) }, }, { "atomic block", - func(service *Service, builder *txstest.Builder) (*txs.Tx, error) { - return builder.NewExportTx( // Test GetTx works for proposal blocks + func(service *Service, factory *txstest.WalletFactory) (*txs.Tx, error) { + builder, signer := factory.NewWallet(keys[0]) + utx, err := builder.NewExportTx( service.vm.ctx.XChainID, []*avax.TransferableOutput{{ Asset: avax.Asset{ID: service.vm.ctx.AVAXAssetID}, @@ -283,12 +291,13 @@ func TestGetTx(t *testing.T) { }, }, }}, - []*secp256k1.PrivateKey{keys[0]}, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }), ) + require.NoError(t, err) + return walletsigner.SignUnsigned(context.Background(), signer, utx) }, }, } @@ -398,7 +407,7 @@ func TestGetBalance(t *testing.T) { func TestGetStake(t *testing.T) { require := require.New(t) - service, _, txBuilder := defaultService(t) + service, _, factory := defaultService(t) // Ensure GetStake is correct for each of the genesis validators genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID) @@ -470,7 +479,8 @@ func TestGetStake(t *testing.T) { delegatorNodeID := genesisNodeIDs[0] delegatorStartTime := defaultValidateStartTime delegatorEndTime := defaultGenesisTime.Add(defaultMinStakingDuration) - tx, err := txBuilder.NewAddDelegatorTx( + builder, signer := factory.NewWallet(keys[0]) + utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: delegatorNodeID, Start: uint64(delegatorStartTime.Unix()), @@ -481,13 +491,14 @@ func TestGetStake(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, - []*secp256k1.PrivateKey{keys[0]}, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }), ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) addDelTx := tx.Unsigned.(*txs.AddDelegatorTx) staker, err := state.NewCurrentStaker( @@ -532,7 +543,7 @@ func TestGetStake(t *testing.T) { stakeAmount = service.vm.MinValidatorStake + 54321 pendingStakerNodeID := ids.GenerateTestNodeID() pendingStakerEndTime := uint64(defaultGenesisTime.Add(defaultMinStakingDuration).Unix()) - tx, err = txBuilder.NewAddValidatorTx( + utx2, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingStakerNodeID, Start: uint64(defaultGenesisTime.Unix()), @@ -544,13 +555,14 @@ func TestGetStake(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, 0, - []*secp256k1.PrivateKey{keys[0]}, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }), ) require.NoError(err) + tx, err = walletsigner.SignUnsigned(context.Background(), signer, utx2) + require.NoError(err) staker, err = state.NewPendingStaker( tx.ID(), @@ -584,7 +596,7 @@ func TestGetStake(t *testing.T) { func TestGetCurrentValidators(t *testing.T) { require := require.New(t) - service, _, txBuilder := defaultService(t) + service, _, factory := defaultService(t) genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID) @@ -618,7 +630,8 @@ func TestGetCurrentValidators(t *testing.T) { service.vm.ctx.Lock.Lock() - delTx, err := txBuilder.NewAddDelegatorTx( + builder, signer := factory.NewWallet(keys[0]) + utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: validatorNodeID, Start: uint64(delegatorStartTime.Unix()), @@ -629,13 +642,14 @@ func TestGetCurrentValidators(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, - []*secp256k1.PrivateKey{keys[0]}, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }), ) require.NoError(err) + delTx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) addDelTx := delTx.Unsigned.(*txs.AddDelegatorTx) staker, err := state.NewCurrentStaker( @@ -692,7 +706,7 @@ func TestGetCurrentValidators(t *testing.T) { service.vm.ctx.Lock.Lock() // Reward the delegator - tx, err := builder.NewRewardValidatorTx(service.vm.ctx, delTx.ID()) + tx, err := blockbuilder.NewRewardValidatorTx(service.vm.ctx, delTx.ID()) require.NoError(err) service.vm.state.AddTx(tx, status.Committed) service.vm.state.DeleteCurrentDelegator(staker) @@ -753,25 +767,26 @@ func TestGetBlock(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { require := require.New(t) - service, _, txBuilder := defaultService(t) + service, _, factory := defaultService(t) service.vm.ctx.Lock.Lock() service.vm.StaticFeeConfig.CreateAssetTxFee = 100 * defaultTxFee - // Make a block an accept it, then check we can get it. - tx, err := txBuilder.NewCreateChainTx( // Test GetTx works for standard blocks + builder, signer := factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewCreateChainTx( testSubnet1.ID(), []byte{}, constants.AVMID, []ids.ID{}, "chain name", - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }), ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) preferredID := service.vm.manager.Preferred() preferred, err := service.vm.manager.GetBlock(preferredID) diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index 755cbb3b2beb..48f4426276b2 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -4,6 +4,7 @@ package executor import ( + "context" "fmt" "testing" "time" @@ -20,6 +21,8 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) func newAdvanceTimeTx(t testing.TB, timestamp time.Time) (*txs.Tx, error) { @@ -376,7 +379,8 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { } for _, staker := range test.subnetStakers { - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: staker.nodeID, @@ -386,9 +390,10 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) staker, err := state.NewPendingStaker( tx.ID(), @@ -473,7 +478,9 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { subnetValidatorNodeID := genesisNodeIDs[0] subnetVdr1StartTime := defaultValidateStartTime subnetVdr1EndTime := defaultValidateStartTime.Add(defaultMinStakingDuration) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, @@ -483,9 +490,10 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) addSubnetValTx := tx.Unsigned.(*txs.AddSubnetValidatorTx) staker, err := state.NewCurrentStaker( @@ -505,7 +513,7 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { // Queue a staker that joins the staker set after the above validator leaves subnetVdr2NodeID := genesisNodeIDs[1] - tx, err = env.txBuilder.NewAddSubnetValidatorTx( + utx, err = builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetVdr2NodeID, @@ -515,9 +523,10 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + tx, err = walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) staker, err = state.NewPendingStaker( tx.ID(), @@ -584,7 +593,8 @@ func TestTrackedSubnet(t *testing.T) { subnetVdr1StartTime := defaultValidateStartTime.Add(1 * time.Minute) subnetVdr1EndTime := defaultValidateStartTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, @@ -594,9 +604,10 @@ func TestTrackedSubnet(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) staker, err := state.NewPendingStaker( tx.ID(), @@ -689,7 +700,8 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - addDelegatorTx, err := env.txBuilder.NewAddDelegatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(pendingDelegatorStartTime.Unix()), @@ -700,13 +712,10 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, }, - []*secp256k1.PrivateKey{ - preFundedKeys[0], - preFundedKeys[1], - preFundedKeys[4], - }, ) require.NoError(err) + addDelegatorTx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) staker, err := state.NewPendingStaker( addDelegatorTx.ID(), @@ -791,7 +800,8 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { // Add delegator pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(defaultMinStakingDuration) - addDelegatorTx, err := env.txBuilder.NewAddDelegatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(pendingDelegatorStartTime.Unix()), @@ -802,9 +812,10 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, }, - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]}, ) require.NoError(err) + addDelegatorTx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) staker, err := state.NewPendingStaker( addDelegatorTx.ID(), @@ -907,7 +918,8 @@ func addPendingValidator( nodeID ids.NodeID, keys []*secp256k1.PrivateKey, ) (*txs.Tx, error) { - addPendingValidatorTx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(keys...) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -919,11 +931,14 @@ func addPendingValidator( Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - keys, ) if err != nil { return nil, err } + addPendingValidatorTx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + if err != nil { + return nil, err + } staker, err := state.NewPendingStaker( addPendingValidatorTx.ID(), diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index 346c8ab1468a..4d52432ab8fa 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -4,6 +4,7 @@ package executor import ( + "context" "testing" "time" @@ -21,6 +22,8 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest" "github.com/ava-labs/avalanchego/vms/platformvm/utxo" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) // Ensure Execute fails when there are not enough control sigs @@ -30,15 +33,17 @@ func TestCreateChainTxInsufficientControlSigs(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - tx, err := env.txBuilder.NewCreateChainTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, constants.AVMID, nil, "chain name", - []*secp256k1.PrivateKey{preFundedKeys[0], preFundedKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) // Remove a signature tx.Creds[0].(*secp256k1fx.Credential).Sigs = tx.Creds[0].(*secp256k1fx.Credential).Sigs[1:] @@ -62,15 +67,17 @@ func TestCreateChainTxWrongControlSig(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - tx, err := env.txBuilder.NewCreateChainTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, constants.AVMID, nil, "chain name", - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) // Generate new, random key to sign tx with key, err := secp256k1.NewPrivateKey() @@ -101,15 +108,17 @@ func TestCreateChainTxNoSuchSubnet(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - tx, err := env.txBuilder.NewCreateChainTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, constants.AVMID, nil, "chain name", - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) tx.Unsigned.(*txs.CreateChainTx).SubnetID = ids.GenerateTestID() @@ -132,15 +141,17 @@ func TestCreateChainTxValid(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - tx, err := env.txBuilder.NewCreateChainTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, constants.AVMID, nil, "chain name", - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) stateDiff, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -195,17 +206,20 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { env.state.SetTimestamp(test.time) // to duly set fee cfg := *env.config + cfg.StaticFeeConfig.CreateBlockchainTxFee = test.fee - builder := txstest.NewBuilder(env.ctx, &cfg, env.state) - tx, err := builder.NewCreateChainTx( + factory := txstest.NewWalletFactory(env.ctx, &cfg, env.state) + builder, signer := factory.NewWallet(preFundedKeys...) + utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, ids.GenerateTestID(), nil, "", - preFundedKeys, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) stateDiff, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) diff --git a/vms/platformvm/txs/executor/create_subnet_test.go b/vms/platformvm/txs/executor/create_subnet_test.go index c1902dd56625..8ba9b529d565 100644 --- a/vms/platformvm/txs/executor/create_subnet_test.go +++ b/vms/platformvm/txs/executor/create_subnet_test.go @@ -4,6 +4,7 @@ package executor import ( + "context" "testing" "time" @@ -16,6 +17,8 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest" "github.com/ava-labs/avalanchego/vms/platformvm/utxo" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) func TestCreateSubnetTxAP3FeeChange(t *testing.T) { @@ -63,12 +66,14 @@ func TestCreateSubnetTxAP3FeeChange(t *testing.T) { cfg := *env.config cfg.StaticFeeConfig.CreateSubnetTxFee = test.fee - builder := txstest.NewBuilder(env.ctx, &cfg, env.state) - tx, err := builder.NewCreateSubnetTx( + factory := txstest.NewWalletFactory(env.ctx, &cfg, env.state) + builder, signer := factory.NewWallet(preFundedKeys...) + utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{}, - preFundedKeys, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) stateDiff, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) diff --git a/vms/platformvm/txs/executor/export_test.go b/vms/platformvm/txs/executor/export_test.go index 7959791187db..f962c1af8814 100644 --- a/vms/platformvm/txs/executor/export_test.go +++ b/vms/platformvm/txs/executor/export_test.go @@ -4,6 +4,7 @@ package executor import ( + "context" "testing" "time" @@ -14,6 +15,8 @@ import ( "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) func TestNewExportTx(t *testing.T) { @@ -50,7 +53,8 @@ func TestNewExportTx(t *testing.T) { t.Run(tt.description, func(t *testing.T) { require := require.New(t) - tx, err := env.txBuilder.NewExportTx( + builder, signer := env.factory.NewWallet(tt.sourceKeys...) + utx, err := builder.NewExportTx( tt.destinationChainID, []*avax.TransferableOutput{{ Asset: avax.Asset{ID: env.ctx.AVAXAssetID}, @@ -63,9 +67,10 @@ func TestNewExportTx(t *testing.T) { }, }, }}, - tt.sourceKeys, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) stateDiff, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 74c706227fea..557fb691417c 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -4,6 +4,7 @@ package executor import ( + "context" "fmt" "math" "testing" @@ -47,6 +48,8 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/utxo" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" + + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) const ( @@ -105,7 +108,7 @@ type environment struct { states map[ids.ID]state.Chain uptimes uptime.Manager utxosHandler utxo.Verifier - txBuilder *txstest.Builder + factory *txstest.WalletFactory backend Backend } @@ -144,11 +147,7 @@ func newEnvironment(t *testing.T, f fork) *environment { uptimes := uptime.NewManager(baseState, clk) utxosVerifier := utxo.NewVerifier(ctx, clk, fx) - txBuilder := txstest.NewBuilder( - ctx, - config, - baseState, - ) + factory := txstest.NewWalletFactory(ctx, config, baseState) backend := Backend{ Config: config, @@ -173,7 +172,7 @@ func newEnvironment(t *testing.T, f fork) *environment { states: make(map[ids.ID]state.Chain), uptimes: uptimes, utxosHandler: utxosVerifier, - txBuilder: txBuilder, + factory: factory, backend: backend, } @@ -209,9 +208,8 @@ func newEnvironment(t *testing.T, f fork) *environment { func addSubnet(t *testing.T, env *environment) { require := require.New(t) - // Create a subnet - var err error - testSubnet1, err = env.txBuilder.NewCreateSubnetTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ @@ -220,15 +218,15 @@ func addSubnet(t *testing.T, env *environment) { preFundedKeys[2].PublicKey().Address(), }, }, - []*secp256k1.PrivateKey{preFundedKeys[0]}, common.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{preFundedKeys[0].PublicKey().Address()}, }), ) require.NoError(err) + testSubnet1, err = walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) - // store it stateDiff, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) diff --git a/vms/platformvm/txs/executor/import_test.go b/vms/platformvm/txs/executor/import_test.go index 7bb0be9afcc1..7e8db3da48f0 100644 --- a/vms/platformvm/txs/executor/import_test.go +++ b/vms/platformvm/txs/executor/import_test.go @@ -4,6 +4,7 @@ package executor import ( + "context" "math/rand" "testing" "time" @@ -19,6 +20,8 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/chain/p/builder" + + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) var fundedSharedMemoryCalls byte @@ -120,15 +123,17 @@ func TestNewImportTx(t *testing.T) { require := require.New(t) env.msm.SharedMemory = tt.sharedMemory - tx, err := env.txBuilder.NewImportTx( + + builder, signer := env.factory.NewWallet(tt.sourceKeys...) + utx, err := builder.NewImportTx( tt.sourceChainID, to, - tt.sourceKeys, ) require.ErrorIs(err, tt.expectedErr) if tt.expectedErr != nil { return } + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) require.NoError(err) unsignedTx := tx.Unsigned.(*txs.ImportTx) diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index 87caaca7d7c1..cb547d4d589d 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -4,6 +4,7 @@ package executor import ( + "context" "math" "testing" "time" @@ -19,6 +20,8 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) func TestProposalTxExecuteAddDelegator(t *testing.T) { @@ -35,7 +38,8 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { addMinStakeValidator := func(env *environment) { require := require.New(t) - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, Start: newValidatorStartTime, @@ -46,10 +50,11 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{rewardAddress}, }, - reward.PercentDenominator, // Shares - []*secp256k1.PrivateKey{preFundedKeys[0]}, + reward.PercentDenominator, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) addValTx := tx.Unsigned.(*txs.AddValidatorTx) staker, err := state.NewCurrentStaker( @@ -71,7 +76,8 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { addMaxStakeValidator := func(env *environment) { require := require.New(t) - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, Start: newValidatorStartTime, @@ -83,9 +89,10 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { Addrs: []ids.ShortID{rewardAddress}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) addValTx := tx.Unsigned.(*txs.AddValidatorTx) staker, err := state.NewCurrentStaker( @@ -237,7 +244,8 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { env := newEnvironment(t, apricotPhase5) env.config.UpgradeConfig.ApricotPhase3Time = tt.AP3Time - tx, err := env.txBuilder.NewAddDelegatorTx( + builder, signer := env.factory.NewWallet(tt.feeKeys...) + utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: tt.nodeID, Start: tt.startTime, @@ -248,9 +256,10 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{rewardAddress}, }, - tt.feeKeys, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) if tt.setup != nil { tt.setup(env) @@ -285,7 +294,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { // Case: Proposed validator currently validating primary network // but stops validating subnet after stops validating primary network // (note that keys[0] is a genesis validator) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -295,9 +305,10 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onCommitState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -320,7 +331,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { // and proposed subnet validation period is subset of // primary network validation period // (note that keys[0] is a genesis validator) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -330,9 +342,10 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onCommitState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -355,7 +368,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { dsStartTime := defaultValidateStartTime.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) - addDSTx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), @@ -366,14 +380,16 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, - reward.PercentDenominator, // shares - []*secp256k1.PrivateKey{preFundedKeys[0]}, + reward.PercentDenominator, ) require.NoError(err) + addDSTx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) { // Case: Proposed validator isn't in pending or current validator sets - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -383,9 +399,10 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onCommitState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -423,7 +440,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Proposed validator is pending validator of primary network // but starts validating subnet before primary network - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -433,9 +451,10 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onCommitState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -456,7 +475,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Proposed validator is pending validator of primary network // but stops validating subnet after primary network - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -466,9 +486,10 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onCommitState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -489,7 +510,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Proposed validator is pending validator of primary network and // period validating subnet is subset of time validating primary network - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -499,9 +521,10 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onCommitState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -524,7 +547,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { env.state.SetTimestamp(newTimestamp) { - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -534,9 +558,10 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onCommitState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -559,7 +584,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { // Case: Proposed validator already validating the subnet // First, add validator as validator of subnet - subnetTx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer = env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + uSubnetTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -569,9 +595,10 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + subnetTx, err := walletsigner.SignUnsigned(context.Background(), signer, uSubnetTx) + require.NoError(err) addSubnetValTx := subnetTx.Unsigned.(*txs.AddSubnetValidatorTx) staker, err = state.NewCurrentStaker( @@ -589,7 +616,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Node with ID nodeIDKey.PublicKey().Address() now validating subnet with ID testSubnet1.ID - duplicateSubnetTx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -599,9 +627,10 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + duplicateSubnetTx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onCommitState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -625,7 +654,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Too few signatures - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -635,9 +665,10 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[2]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) // Remove a signature addSubnetValidatorTx := tx.Unsigned.(*txs.AddSubnetValidatorTx) @@ -664,7 +695,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Control Signature from invalid key (keys[3] is not a control key) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -674,9 +706,10 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], preFundedKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) // Replace a valid signature with one from keys[3] sig, err := preFundedKeys[3].SignHash(hashing.ComputeHash256(tx.Unsigned.Bytes())) @@ -702,7 +735,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Proposed validator in pending validator set for subnet // First, add validator to pending validator set of subnet - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -712,9 +746,10 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) addSubnetValTx := subnetTx.Unsigned.(*txs.AddSubnetValidatorTx) staker, err = state.NewCurrentStaker( @@ -758,7 +793,8 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator's start time too early - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(chainTime.Unix()), @@ -770,9 +806,10 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onCommitState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -794,7 +831,8 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { nodeID := genesisNodeIDs[0] // Case: Validator already validating primary network - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(defaultValidateStartTime.Unix()) + 1, @@ -806,9 +844,10 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onCommitState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -829,7 +868,8 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator in pending validator set of primary network startTime := defaultValidateStartTime.Add(1 * time.Second) - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -840,10 +880,11 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, - reward.PercentDenominator, // shares - []*secp256k1.PrivateKey{preFundedKeys[0]}, + reward.PercentDenominator, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) addValTx := tx.Unsigned.(*txs.AddValidatorTx) staker, err := state.NewCurrentStaker( @@ -878,7 +919,8 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator doesn't have enough tokens to cover stake amount - tx, err := env.txBuilder.NewAddValidatorTx( // create the tx + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, @@ -890,9 +932,10 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) // Remove all UTXOs owned by preFundedKeys[0] utxoIDs, err := env.state.UTXOIDs(preFundedKeys[0].PublicKey().Address().Bytes(), ids.Empty, math.MaxInt32) diff --git a/vms/platformvm/txs/executor/reward_validator_test.go b/vms/platformvm/txs/executor/reward_validator_test.go index 215e9a6f729a..88b7b0b8a368 100644 --- a/vms/platformvm/txs/executor/reward_validator_test.go +++ b/vms/platformvm/txs/executor/reward_validator_test.go @@ -4,6 +4,7 @@ package executor import ( + "context" "testing" "time" @@ -13,7 +14,6 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/math" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/components/avax" @@ -22,6 +22,8 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) func newRewardValidatorTx(t testing.TB, txID ids.ID) (*txs.Tx, error) { @@ -239,7 +241,8 @@ func TestRewardDelegatorTxExecuteOnCommitPreDelegateeDeferral(t *testing.T) { vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - vdrTx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, Start: vdrStartTime, @@ -251,14 +254,15 @@ func TestRewardDelegatorTxExecuteOnCommitPreDelegateeDeferral(t *testing.T) { Addrs: []ids.ShortID{vdrRewardAddress}, }, reward.PercentDenominator/4, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + vdrTx, err := walletsigner.SignUnsigned(context.Background(), signer, uVdrTx) + require.NoError(err) delStartTime := vdrStartTime delEndTime := vdrEndTime - delTx, err := env.txBuilder.NewAddDelegatorTx( + uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: vdrNodeID, Start: delStartTime, @@ -269,9 +273,10 @@ func TestRewardDelegatorTxExecuteOnCommitPreDelegateeDeferral(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{delRewardAddress}, }, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + delTx, err := walletsigner.SignUnsigned(context.Background(), signer, uDelTx) + require.NoError(err) addValTx := vdrTx.Unsigned.(*txs.AddValidatorTx) vdrStaker, err := state.NewCurrentStaker( @@ -368,7 +373,8 @@ func TestRewardDelegatorTxExecuteOnCommitPostDelegateeDeferral(t *testing.T) { vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - vdrTx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, Start: vdrStartTime, @@ -380,14 +386,15 @@ func TestRewardDelegatorTxExecuteOnCommitPostDelegateeDeferral(t *testing.T) { Addrs: []ids.ShortID{vdrRewardAddress}, }, reward.PercentDenominator/4, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + vdrTx, err := walletsigner.SignUnsigned(context.Background(), signer, uVdrTx) + require.NoError(err) delStartTime := vdrStartTime delEndTime := vdrEndTime - delTx, err := env.txBuilder.NewAddDelegatorTx( + uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: vdrNodeID, Start: delStartTime, @@ -398,9 +405,10 @@ func TestRewardDelegatorTxExecuteOnCommitPostDelegateeDeferral(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{delRewardAddress}, }, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + delTx, err := walletsigner.SignUnsigned(context.Background(), signer, uDelTx) + require.NoError(err) addValTx := vdrTx.Unsigned.(*txs.AddValidatorTx) vdrRewardAmt := uint64(2000000) @@ -592,7 +600,8 @@ func TestRewardDelegatorTxAndValidatorTxExecuteOnCommitPostDelegateeDeferral(t * vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - vdrTx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, Start: vdrStartTime, @@ -604,14 +613,15 @@ func TestRewardDelegatorTxAndValidatorTxExecuteOnCommitPostDelegateeDeferral(t * Addrs: []ids.ShortID{vdrRewardAddress}, }, reward.PercentDenominator/4, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + vdrTx, err := walletsigner.SignUnsigned(context.Background(), signer, uVdrTx) + require.NoError(err) delStartTime := vdrStartTime delEndTime := vdrEndTime - delTx, err := env.txBuilder.NewAddDelegatorTx( + uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: vdrNodeID, Start: delStartTime, @@ -622,9 +632,10 @@ func TestRewardDelegatorTxAndValidatorTxExecuteOnCommitPostDelegateeDeferral(t * Threshold: 1, Addrs: []ids.ShortID{delRewardAddress}, }, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + delTx, err := walletsigner.SignUnsigned(context.Background(), signer, uDelTx) + require.NoError(err) addValTx := vdrTx.Unsigned.(*txs.AddValidatorTx) vdrRewardAmt := uint64(2000000) @@ -762,7 +773,8 @@ func TestRewardDelegatorTxExecuteOnAbort(t *testing.T) { vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - vdrTx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, Start: vdrStartTime, @@ -774,13 +786,15 @@ func TestRewardDelegatorTxExecuteOnAbort(t *testing.T) { Addrs: []ids.ShortID{vdrRewardAddress}, }, reward.PercentDenominator/4, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + vdrTx, err := walletsigner.SignUnsigned(context.Background(), signer, uVdrTx) + require.NoError(err) delStartTime := vdrStartTime delEndTime := vdrEndTime - delTx, err := env.txBuilder.NewAddDelegatorTx( + + uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: vdrNodeID, Start: delStartTime, @@ -791,9 +805,10 @@ func TestRewardDelegatorTxExecuteOnAbort(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{delRewardAddress}, }, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + delTx, err := walletsigner.SignUnsigned(context.Background(), signer, uDelTx) + require.NoError(err) addValTx := vdrTx.Unsigned.(*txs.AddValidatorTx) vdrStaker, err := state.NewCurrentStaker( diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index de69b0ff5a8c..1de00365723f 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -4,6 +4,7 @@ package executor import ( + "context" "errors" "math" "math/rand" @@ -36,6 +37,8 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/utxo" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" + + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) // This tests that the math performed during TransformSubnetTx execution can @@ -74,7 +77,8 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { // Case: Empty validator node ID after banff env.config.UpgradeConfig.BanffTime = test.banffTime - tx, err := env.txBuilder.NewAddValidatorTx( // create the tx + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.EmptyNodeID, Start: uint64(startTime.Unix()), @@ -86,9 +90,10 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) stateDiff, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -117,7 +122,8 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { addMinStakeValidator := func(env *environment) { require := require.New(t) - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, Start: uint64(newValidatorStartTime.Unix()), @@ -128,10 +134,11 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{rewardAddress}, }, - reward.PercentDenominator, // Shares - []*secp256k1.PrivateKey{preFundedKeys[0]}, + reward.PercentDenominator, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) addValTx := tx.Unsigned.(*txs.AddValidatorTx) staker, err := state.NewCurrentStaker( @@ -153,7 +160,8 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { addMaxStakeValidator := func(env *environment) { require := require.New(t) - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, Start: uint64(newValidatorStartTime.Unix()), @@ -164,10 +172,11 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{rewardAddress}, }, - reward.PercentDenominator, // Shared - []*secp256k1.PrivateKey{preFundedKeys[0]}, + reward.PercentDenominator, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) addValTx := tx.Unsigned.(*txs.AddValidatorTx) staker, err := state.NewCurrentStaker( @@ -319,7 +328,8 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { env := newEnvironment(t, apricotPhase5) env.config.UpgradeConfig.ApricotPhase3Time = tt.AP3Time - tx, err := env.txBuilder.NewAddDelegatorTx( + builder, signer := env.factory.NewWallet(tt.feeKeys...) + utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: tt.nodeID, Start: uint64(tt.startTime.Unix()), @@ -330,9 +340,10 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{rewardAddress}, }, - tt.feeKeys, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) if tt.setup != nil { tt.setup(env) @@ -367,7 +378,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // but stops validating subnet after stops validating primary network // (note that keys[0] is a genesis validator) startTime := defaultValidateStartTime.Add(time.Second) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -377,9 +389,10 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onAcceptState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -398,7 +411,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // and proposed subnet validation period is subset of // primary network validation period // (note that keys[0] is a genesis validator) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -408,9 +422,10 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onAcceptState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -429,7 +444,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { dsStartTime := defaultGenesisTime.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) - addDSTx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), @@ -440,14 +456,16 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, - reward.PercentDenominator, // shares - []*secp256k1.PrivateKey{preFundedKeys[0]}, + reward.PercentDenominator, ) require.NoError(err) + addDSTx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) { // Case: Proposed validator isn't in pending or current validator sets - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -457,9 +475,10 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onAcceptState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -493,7 +512,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Proposed validator is pending validator of primary network // but starts validating subnet before primary network - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -503,9 +523,10 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onAcceptState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -522,7 +543,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Proposed validator is pending validator of primary network // but stops validating subnet after primary network - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -532,9 +554,10 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onAcceptState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -551,7 +574,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Proposed validator is pending validator of primary network and // period validating subnet is subset of time validating primary network - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -561,9 +585,10 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onAcceptState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -581,7 +606,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { env.state.SetTimestamp(newTimestamp) { - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -591,9 +617,10 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onAcceptState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -612,7 +639,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // Case: Proposed validator already validating the subnet // First, add validator as validator of subnet - subnetTx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer = env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + uSubnetTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -622,9 +650,10 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + subnetTx, err := walletsigner.SignUnsigned(context.Background(), signer, uSubnetTx) + require.NoError(err) addSubnetValTx := subnetTx.Unsigned.(*txs.AddSubnetValidatorTx) staker, err = state.NewCurrentStaker( @@ -643,7 +672,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Node with ID nodeIDKey.PublicKey().Address() now validating subnet with ID testSubnet1.ID startTime := defaultValidateStartTime.Add(time.Second) - duplicateSubnetTx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -653,9 +683,10 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onAcceptState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -663,9 +694,9 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { executor := StandardTxExecutor{ Backend: &env.backend, State: onAcceptState, - Tx: duplicateSubnetTx, + Tx: tx, } - err = duplicateSubnetTx.Unsigned.Visit(&executor) + err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrDuplicateValidator) } @@ -676,7 +707,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Duplicate signatures startTime := defaultValidateStartTime.Add(time.Second) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -686,9 +718,10 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) // Duplicate a signature addSubnetValidatorTx := tx.Unsigned.(*txs.AddSubnetValidatorTx) @@ -712,7 +745,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Too few signatures startTime := defaultValidateStartTime.Add(time.Second) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[2]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -722,9 +756,10 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[2]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) // Remove a signature addSubnetValidatorTx := tx.Unsigned.(*txs.AddSubnetValidatorTx) @@ -748,7 +783,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Control Signature from invalid key (keys[3] is not a control key) startTime := defaultValidateStartTime.Add(time.Second) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -758,9 +794,10 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], preFundedKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) // Replace a valid signature with one from keys[3] sig, err := preFundedKeys[3].SignHash(hashing.ComputeHash256(tx.Unsigned.Bytes())) @@ -783,7 +820,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // Case: Proposed validator in pending validator set for subnet // First, add validator to pending validator set of subnet startTime := defaultValidateStartTime.Add(time.Second) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -793,9 +831,10 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) addSubnetValTx := subnetTx.Unsigned.(*txs.AddSubnetValidatorTx) staker, err = state.NewCurrentStaker( @@ -834,7 +873,8 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator's start time too early - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(defaultValidateStartTime.Unix()) - 1, @@ -846,9 +886,10 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { Addrs: []ids.ShortID{ids.ShortEmpty}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) onAcceptState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) @@ -865,7 +906,8 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator in current validator set of primary network startTime := defaultValidateStartTime.Add(1 * time.Second) - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -876,10 +918,11 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }, - reward.PercentDenominator, // shares - []*secp256k1.PrivateKey{preFundedKeys[0]}, + reward.PercentDenominator, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) addValTx := tx.Unsigned.(*txs.AddValidatorTx) staker, err := state.NewCurrentStaker( @@ -908,7 +951,8 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator in pending validator set of primary network startTime := defaultValidateStartTime.Add(1 * time.Second) - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -919,10 +963,11 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }, - reward.PercentDenominator, // shares - []*secp256k1.PrivateKey{preFundedKeys[0]}, + reward.PercentDenominator, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) staker, err := state.NewPendingStaker( tx.ID(), @@ -948,7 +993,8 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator doesn't have enough tokens to cover stake amount startTime := defaultValidateStartTime.Add(1 * time.Second) - tx, err := env.txBuilder.NewAddValidatorTx( // create the tx + builder, signer := env.factory.NewWallet(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -960,9 +1006,10 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { Addrs: []ids.ShortID{ids.ShortEmpty}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{preFundedKeys[0]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) // Remove all UTXOs owned by preFundedKeys[0] utxoIDs, err := env.state.UTXOIDs(preFundedKeys[0].PublicKey().Address().Bytes(), ids.Empty, math.MaxInt32) @@ -1003,7 +1050,8 @@ func TestDurangoDisabledTransactions(t *testing.T) { endTime = chainTime.Add(defaultMaxStakingDuration) ) - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys...) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: 0, @@ -1014,10 +1062,11 @@ func TestDurangoDisabledTransactions(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }, - reward.PercentDenominator, // shares - preFundedKeys, + reward.PercentDenominator, ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) return tx }, @@ -1039,7 +1088,8 @@ func TestDurangoDisabledTransactions(t *testing.T) { } it.Release() - tx, err := env.txBuilder.NewAddDelegatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys...) + utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: primaryValidator.NodeID, Start: 0, @@ -1050,9 +1100,10 @@ func TestDurangoDisabledTransactions(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }, - preFundedKeys, ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) return tx }, @@ -1107,7 +1158,8 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys...) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: primaryValidator.NodeID, @@ -1117,10 +1169,11 @@ func TestDurangoMemoField(t *testing.T) { }, Subnet: testSubnet1.TxID, }, - preFundedKeys, common.WithMemo(memoField), ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) @@ -1130,16 +1183,18 @@ func TestDurangoMemoField(t *testing.T) { { name: "CreateChainTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - tx, err := env.txBuilder.NewCreateChainTx( + builder, signer := env.factory.NewWallet(preFundedKeys...) + utx, err := builder.NewCreateChainTx( testSubnet1.TxID, - []byte{}, // genesisData - ids.GenerateTestID(), // vmID - []ids.ID{}, // fxIDs - "aaa", // chain name - preFundedKeys, + []byte{}, + ids.GenerateTestID(), + []ids.ID{}, + "aaa", common.WithMemo(memoField), ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) @@ -1150,15 +1205,17 @@ func TestDurangoMemoField(t *testing.T) { { name: "CreateSubnetTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - tx, err := env.txBuilder.NewCreateSubnetTx( + builder, signer := env.factory.NewWallet(preFundedKeys...) + utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, - preFundedKeys, common.WithMemo(memoField), ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) @@ -1190,17 +1247,19 @@ func TestDurangoMemoField(t *testing.T) { ) env.msm.SharedMemory = sharedMemory - tx, err := env.txBuilder.NewImportTx( + builder, signer := env.factory.NewWallet(preFundedKeys...) + utx, err := builder.NewImportTx( sourceChain, &secp256k1fx.OutputOwners{ Locktime: 0, Threshold: 1, Addrs: []ids.ShortID{sourceKey.PublicKey().Address()}, }, - preFundedKeys, common.WithMemo(memoField), ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) @@ -1211,7 +1270,8 @@ func TestDurangoMemoField(t *testing.T) { { name: "ExportTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - tx, err := env.txBuilder.NewExportTx( + builder, signer := env.factory.NewWallet(preFundedKeys...) + utx, err := builder.NewExportTx( env.ctx.XChainID, []*avax.TransferableOutput{{ Asset: avax.Asset{ID: env.ctx.AVAXAssetID}, @@ -1224,10 +1284,11 @@ func TestDurangoMemoField(t *testing.T) { }, }, }}, - preFundedKeys, common.WithMemo(memoField), ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) @@ -1252,7 +1313,8 @@ func TestDurangoMemoField(t *testing.T) { it.Release() endTime := primaryValidator.EndTime - subnetValTx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: primaryValidator.NodeID, @@ -1262,9 +1324,10 @@ func TestDurangoMemoField(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(t, err) + subnetValTx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) @@ -1275,13 +1338,15 @@ func TestDurangoMemoField(t *testing.T) { Tx: subnetValTx, })) - tx, err := env.txBuilder.NewRemoveSubnetValidatorTx( + builder, signer = env.factory.NewWallet(preFundedKeys...) + utx2, err := builder.NewRemoveSubnetValidatorTx( primaryValidator.NodeID, testSubnet1.ID(), - preFundedKeys, common.WithMemo(memoField), ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx2) + require.NoError(t, err) return tx, onAcceptState }, @@ -1289,7 +1354,8 @@ func TestDurangoMemoField(t *testing.T) { { name: "TransformSubnetTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - tx, err := env.txBuilder.NewTransformSubnetTx( + builder, signer := env.factory.NewWallet(preFundedKeys...) + utx, err := builder.NewTransformSubnetTx( testSubnet1.TxID, // subnetID ids.GenerateTestID(), // assetID 10, // initial supply @@ -1304,10 +1370,11 @@ func TestDurangoMemoField(t *testing.T) { 10, // min delegator stake 1, // max validator weight factor 80, // uptime requirement - preFundedKeys, common.WithMemo(memoField), ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) @@ -1326,7 +1393,8 @@ func TestDurangoMemoField(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(t, err) - tx, err := env.txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := env.factory.NewWallet(preFundedKeys...) + utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -1347,10 +1415,11 @@ func TestDurangoMemoField(t *testing.T) { Addrs: []ids.ShortID{ids.ShortEmpty}, }, reward.PercentDenominator, - preFundedKeys, common.WithMemo(memoField), ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(t, err) onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) @@ -1374,7 +1443,8 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() - tx, err := env.txBuilder.NewAddPermissionlessDelegatorTx( + builder, signer := env.factory.NewWallet(preFundedKeys...) + utx, err := builder.NewAddPermissionlessDelegatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: primaryValidator.NodeID, @@ -1389,10 +1459,11 @@ func TestDurangoMemoField(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }, - preFundedKeys, common.WithMemo(memoField), ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) @@ -1403,16 +1474,18 @@ func TestDurangoMemoField(t *testing.T) { { name: "TransferSubnetOwnershipTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - tx, err := env.txBuilder.NewTransferSubnetOwnershipTx( + builder, signer := env.factory.NewWallet(preFundedKeys...) + utx, err := builder.NewTransferSubnetOwnershipTx( testSubnet1.TxID, &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }, - preFundedKeys, common.WithMemo(memoField), ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) @@ -1423,7 +1496,8 @@ func TestDurangoMemoField(t *testing.T) { { name: "BaseTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - tx, err := env.txBuilder.NewBaseTx( + builder, signer := env.factory.NewWallet(preFundedKeys...) + utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { Asset: avax.Asset{ID: env.ctx.AVAXAssetID}, @@ -1436,10 +1510,11 @@ func TestDurangoMemoField(t *testing.T) { }, }, }, - preFundedKeys, common.WithMemo(memoField), ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) diff --git a/vms/platformvm/txs/txstest/builder.go b/vms/platformvm/txs/txstest/builder.go index e9d9c8d40061..532720be981f 100644 --- a/vms/platformvm/txs/txstest/builder.go +++ b/vms/platformvm/txs/txstest/builder.go @@ -4,348 +4,40 @@ package txstest import ( - "context" - "fmt" - "time" - - "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" - "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/config" "github.com/ava-labs/avalanchego/vms/platformvm/state" - "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/chain/p/builder" - "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" - - vmsigner "github.com/ava-labs/avalanchego/vms/platformvm/signer" - walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" + "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) -func NewBuilder( +func NewWalletFactory( ctx *snow.Context, cfg *config.Config, state state.State, -) *Builder { - return &Builder{ +) *WalletFactory { + return &WalletFactory{ ctx: ctx, cfg: cfg, state: state, } } -type Builder struct { +type WalletFactory struct { ctx *snow.Context cfg *config.Config state state.State } -func (b *Builder) NewImportTx( - chainID ids.ID, - to *secp256k1fx.OutputOwners, - keys []*secp256k1.PrivateKey, - options ...common.Option, -) (*txs.Tx, error) { - pBuilder, pSigner := b.builders(keys) - - utx, err := pBuilder.NewImportTx( - chainID, - to, - options..., - ) - if err != nil { - return nil, fmt.Errorf("failed building import tx: %w", err) - } - - return walletsigner.SignUnsigned(context.Background(), pSigner, utx) -} - -func (b *Builder) NewExportTx( - chainID ids.ID, - outputs []*avax.TransferableOutput, - keys []*secp256k1.PrivateKey, - options ...common.Option, -) (*txs.Tx, error) { - pBuilder, pSigner := b.builders(keys) - - utx, err := pBuilder.NewExportTx( - chainID, - outputs, - options..., - ) - if err != nil { - return nil, fmt.Errorf("failed building export tx: %w", err) - } - - return walletsigner.SignUnsigned(context.Background(), pSigner, utx) -} - -func (b *Builder) NewCreateChainTx( - subnetID ids.ID, - genesis []byte, - vmID ids.ID, - fxIDs []ids.ID, - chainName string, - keys []*secp256k1.PrivateKey, - options ...common.Option, -) (*txs.Tx, error) { - pBuilder, pSigner := b.builders(keys) - - utx, err := pBuilder.NewCreateChainTx( - subnetID, - genesis, - vmID, - fxIDs, - chainName, - options..., - ) - if err != nil { - return nil, fmt.Errorf("failed building create chain tx: %w", err) - } - - return walletsigner.SignUnsigned(context.Background(), pSigner, utx) -} - -func (b *Builder) NewCreateSubnetTx( - owner *secp256k1fx.OutputOwners, - keys []*secp256k1.PrivateKey, - options ...common.Option, -) (*txs.Tx, error) { - pBuilder, pSigner := b.builders(keys) - - utx, err := pBuilder.NewCreateSubnetTx( - owner, - options..., - ) - if err != nil { - return nil, fmt.Errorf("failed building create subnet tx: %w", err) - } - - return walletsigner.SignUnsigned(context.Background(), pSigner, utx) -} - -func (b *Builder) NewTransformSubnetTx( - subnetID ids.ID, - assetID ids.ID, - initialSupply uint64, - maxSupply uint64, - minConsumptionRate uint64, - maxConsumptionRate uint64, - minValidatorStake uint64, - maxValidatorStake uint64, - minStakeDuration time.Duration, - maxStakeDuration time.Duration, - minDelegationFee uint32, - minDelegatorStake uint64, - maxValidatorWeightFactor byte, - uptimeRequirement uint32, - keys []*secp256k1.PrivateKey, - options ...common.Option, -) (*txs.Tx, error) { - pBuilder, pSigner := b.builders(keys) - - utx, err := pBuilder.NewTransformSubnetTx( - subnetID, - assetID, - initialSupply, - maxSupply, - minConsumptionRate, - maxConsumptionRate, - minValidatorStake, - maxValidatorStake, - minStakeDuration, - maxStakeDuration, - minDelegationFee, - minDelegatorStake, - maxValidatorWeightFactor, - uptimeRequirement, - options..., - ) - if err != nil { - return nil, fmt.Errorf("failed building transform subnet tx: %w", err) - } - - return walletsigner.SignUnsigned(context.Background(), pSigner, utx) -} - -func (b *Builder) NewAddValidatorTx( - vdr *txs.Validator, - rewardsOwner *secp256k1fx.OutputOwners, - shares uint32, - keys []*secp256k1.PrivateKey, - options ...common.Option, -) (*txs.Tx, error) { - pBuilder, pSigner := b.builders(keys) - - utx, err := pBuilder.NewAddValidatorTx( - vdr, - rewardsOwner, - shares, - options..., - ) - if err != nil { - return nil, fmt.Errorf("failed building add validator tx: %w", err) - } - - return walletsigner.SignUnsigned(context.Background(), pSigner, utx) -} - -func (b *Builder) NewAddPermissionlessValidatorTx( - vdr *txs.SubnetValidator, - signer vmsigner.Signer, - assetID ids.ID, - validationRewardsOwner *secp256k1fx.OutputOwners, - delegationRewardsOwner *secp256k1fx.OutputOwners, - shares uint32, - keys []*secp256k1.PrivateKey, - options ...common.Option, -) (*txs.Tx, error) { - pBuilder, pSigner := b.builders(keys) - - utx, err := pBuilder.NewAddPermissionlessValidatorTx( - vdr, - signer, - assetID, - validationRewardsOwner, - delegationRewardsOwner, - shares, - options..., - ) - if err != nil { - return nil, fmt.Errorf("failed building add permissionless validator tx: %w", err) - } - - return walletsigner.SignUnsigned(context.Background(), pSigner, utx) -} - -func (b *Builder) NewAddDelegatorTx( - vdr *txs.Validator, - rewardsOwner *secp256k1fx.OutputOwners, - keys []*secp256k1.PrivateKey, - options ...common.Option, -) (*txs.Tx, error) { - pBuilder, pSigner := b.builders(keys) - - utx, err := pBuilder.NewAddDelegatorTx( - vdr, - rewardsOwner, - options..., - ) - if err != nil { - return nil, fmt.Errorf("failed building add delegator tx: %w", err) - } - - return walletsigner.SignUnsigned(context.Background(), pSigner, utx) -} - -func (b *Builder) NewAddPermissionlessDelegatorTx( - vdr *txs.SubnetValidator, - assetID ids.ID, - rewardsOwner *secp256k1fx.OutputOwners, - keys []*secp256k1.PrivateKey, - options ...common.Option, -) (*txs.Tx, error) { - pBuilder, pSigner := b.builders(keys) - - utx, err := pBuilder.NewAddPermissionlessDelegatorTx( - vdr, - assetID, - rewardsOwner, - options..., - ) - if err != nil { - return nil, fmt.Errorf("failed building add permissionless delegator tx: %w", err) - } - - return walletsigner.SignUnsigned(context.Background(), pSigner, utx) -} - -func (b *Builder) NewAddSubnetValidatorTx( - vdr *txs.SubnetValidator, - keys []*secp256k1.PrivateKey, - options ...common.Option, -) (*txs.Tx, error) { - pBuilder, pSigner := b.builders(keys) - - utx, err := pBuilder.NewAddSubnetValidatorTx( - vdr, - options..., - ) - if err != nil { - return nil, fmt.Errorf("failed building add subnet validator tx: %w", err) - } - - return walletsigner.SignUnsigned(context.Background(), pSigner, utx) -} - -func (b *Builder) NewRemoveSubnetValidatorTx( - nodeID ids.NodeID, - subnetID ids.ID, - keys []*secp256k1.PrivateKey, - options ...common.Option, -) (*txs.Tx, error) { - pBuilder, pSigner := b.builders(keys) - - utx, err := pBuilder.NewRemoveSubnetValidatorTx( - nodeID, - subnetID, - options..., - ) - if err != nil { - return nil, fmt.Errorf("failed building remove subnet validator tx: %w", err) - } - - return walletsigner.SignUnsigned(context.Background(), pSigner, utx) -} - -func (b *Builder) NewTransferSubnetOwnershipTx( - subnetID ids.ID, - owner *secp256k1fx.OutputOwners, - keys []*secp256k1.PrivateKey, - options ...common.Option, -) (*txs.Tx, error) { - pBuilder, pSigner := b.builders(keys) - - utx, err := pBuilder.NewTransferSubnetOwnershipTx( - subnetID, - owner, - options..., - ) - if err != nil { - return nil, fmt.Errorf("failed building transfer subnet ownership tx: %w", err) - } - - return walletsigner.SignUnsigned(context.Background(), pSigner, utx) -} - -func (b *Builder) NewBaseTx( - outputs []*avax.TransferableOutput, - keys []*secp256k1.PrivateKey, - options ...common.Option, -) (*txs.Tx, error) { - pBuilder, pSigner := b.builders(keys) - - utx, err := pBuilder.NewBaseTx( - outputs, - options..., - ) - if err != nil { - return nil, fmt.Errorf("failed building base tx: %w", err) - } - - return walletsigner.SignUnsigned(context.Background(), pSigner, utx) -} - -func (b *Builder) builders(keys []*secp256k1.PrivateKey) (builder.Builder, walletsigner.Signer) { +func (w *WalletFactory) NewWallet(keys ...*secp256k1.PrivateKey) (builder.Builder, signer.Signer) { var ( kc = secp256k1fx.NewKeychain(keys...) addrs = kc.Addresses() - backend = newBackend(addrs, b.state, b.ctx.SharedMemory) - context = newContext(b.ctx, b.cfg, b.state.GetTimestamp()) - builder = builder.New(addrs, context, backend) - signer = walletsigner.New(kc, backend) + backend = newBackend(addrs, w.state, w.ctx.SharedMemory) + context = newContext(w.ctx, w.cfg, w.state.GetTimestamp()) ) - return builder, signer + return builder.New(addrs, context, backend), signer.New(kc, backend) } diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index faf5eb810d51..9ed3dc7cbd4d 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -30,7 +30,6 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/formatting" "github.com/ava-labs/avalanchego/utils/formatting/address" "github.com/ava-labs/avalanchego/utils/json" @@ -50,6 +49,7 @@ import ( blockexecutor "github.com/ava-labs/avalanchego/vms/platformvm/block/executor" txexecutor "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" walletcommon "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" ) @@ -258,14 +258,9 @@ func takeValidatorsSnapshotAtCurrentHeight(vm *VM, validatorsSetByHeightAndSubne } func addSubnetValidator(vm *VM, data *validatorInputData, subnetID ids.ID) (*state.Staker, error) { - txBuilder := txstest.NewBuilder( - vm.ctx, - &vm.Config, - vm.state, - ) - - addr := keys[0].PublicKey().Address() - signedTx, err := txBuilder.NewAddSubnetValidatorTx( + factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) + builder, signer := factory.NewWallet(keys[0], keys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: data.nodeID, @@ -275,16 +270,19 @@ func addSubnetValidator(vm *VM, data *validatorInputData, subnetID ids.ID) (*sta }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, - Addrs: []ids.ShortID{addr}, + Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }), ) if err != nil { - return nil, fmt.Errorf("could not create AddSubnetValidatorTx: %w", err) + return nil, fmt.Errorf("could not build AddSubnetValidatorTx: %w", err) + } + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + if err != nil { + return nil, fmt.Errorf("could not sign AddSubnetValidatorTx: %w", err) } - return internalAddValidator(vm, signedTx) + return internalAddValidator(vm, tx) } func addPrimaryValidatorWithBLSKey(vm *VM, data *validatorInputData) (*state.Staker, error) { @@ -295,13 +293,9 @@ func addPrimaryValidatorWithBLSKey(vm *VM, data *validatorInputData) (*state.Sta return nil, fmt.Errorf("failed to generate BLS key: %w", err) } - txBuilder := txstest.NewBuilder( - vm.ctx, - &vm.Config, - vm.state, - ) - - signedTx, err := txBuilder.NewAddPermissionlessValidatorTx( + factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) + builder, txSigner := factory.NewWallet(keys[0], keys[1]) + utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: data.nodeID, @@ -322,16 +316,19 @@ func addPrimaryValidatorWithBLSKey(vm *VM, data *validatorInputData) (*state.Sta Addrs: []ids.ShortID{addr}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr}, }), ) if err != nil { - return nil, fmt.Errorf("could not create AddPermissionlessValidatorTx: %w", err) + return nil, fmt.Errorf("could not build AddPermissionlessValidatorTx: %w", err) + } + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + if err != nil { + return nil, fmt.Errorf("could not sign AddPermissionlessValidatorTx: %w", err) } - return internalAddValidator(vm, signedTx) + return internalAddValidator(vm, tx) } func internalAddValidator(vm *VM, signedTx *txs.Tx) (*state.Staker, error) { @@ -718,21 +715,16 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { return nil, ids.Empty, err } - txBuilder := txstest.NewBuilder( - vm.ctx, - &vm.Config, - vm.state, - ) - // Create a subnet and store it in testSubnet1 // Note: following Banff activation, block acceptance will move // chain time ahead - testSubnet1, err = txBuilder.NewCreateSubnetTx( + factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) + builder, signer := factory.NewWallet(keys[len(keys)-1]) + utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }, - []*secp256k1.PrivateKey{keys[len(keys)-1]}, // pays tx fee walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, @@ -741,6 +733,10 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { if err != nil { return nil, ids.Empty, err } + testSubnet1, err = walletsigner.SignUnsigned(context.Background(), signer, utx) + if err != nil { + return nil, ids.Empty, err + } vm.ctx.Lock.Unlock() err = vm.issueTxFromRPC(testSubnet1) vm.ctx.Lock.Lock() diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index d29b2b0af1fa..629be17fe1ba 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -49,12 +49,13 @@ import ( "github.com/ava-labs/avalanchego/vms/secp256k1fx" blockexecutor "github.com/ava-labs/avalanchego/vms/platformvm/block/executor" + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" walletcommon "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" ) func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, cortina) + vm, factory, _, _ := defaultVM(t, cortina) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -65,7 +66,8 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { changeAddr := keys[0].PublicKey().Address() // create valid tx - addValidatorTx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := factory.NewWallet(keys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(validatorStartTime.Unix()), @@ -77,13 +79,14 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { Addrs: []ids.ShortID{changeAddr}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // trigger block creation vm.ctx.Lock.Unlock() @@ -108,7 +111,8 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { firstDelegatorEndTime := firstDelegatorStartTime.Add(vm.MinStakeDuration) // create valid tx - addFirstDelegatorTx, err := txBuilder.NewAddDelegatorTx( + builder, txSigner = factory.NewWallet(keys[0], keys[1]) + uDelTx1, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(firstDelegatorStartTime.Unix()), @@ -119,13 +123,14 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addFirstDelegatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uDelTx1) + require.NoError(err) // trigger block creation vm.ctx.Lock.Unlock() @@ -152,7 +157,8 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { vm.clock.Set(secondDelegatorStartTime.Add(-10 * executor.SyncBound)) // create valid tx - addSecondDelegatorTx, err := txBuilder.NewAddDelegatorTx( + builder, txSigner = factory.NewWallet(keys[0], keys[1], keys[3]) + uDelTx2, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(secondDelegatorStartTime.Unix()), @@ -163,13 +169,14 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }, - []*secp256k1.PrivateKey{keys[0], keys[1], keys[3]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addSecondDelegatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uDelTx2) + require.NoError(err) // trigger block creation vm.ctx.Lock.Unlock() @@ -186,7 +193,8 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { thirdDelegatorEndTime := thirdDelegatorStartTime.Add(vm.MinStakeDuration) // create valid tx - addThirdDelegatorTx, err := txBuilder.NewAddDelegatorTx( + builder, txSigner = factory.NewWallet(keys[0], keys[1], keys[4]) + uDelTx3, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(thirdDelegatorStartTime.Unix()), @@ -197,13 +205,14 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }, - []*secp256k1.PrivateKey{keys[0], keys[1], keys[4]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addThirdDelegatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uDelTx3) + require.NoError(err) // trigger block creation vm.ctx.Lock.Unlock() @@ -251,7 +260,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { t.Run(test.name, func(t *testing.T) { require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, apricotPhase3) + vm, factory, _, _ := defaultVM(t, apricotPhase3) vm.UpgradeConfig.ApricotPhase3Time = test.ap3Time vm.ctx.Lock.Lock() @@ -265,7 +274,8 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { changeAddr := keys[0].PublicKey().Address() // create valid tx - addValidatorTx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := factory.NewWallet(keys[0], keys[1]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(validatorStartTime.Unix()), @@ -277,13 +287,14 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { Addrs: []ids.ShortID{id}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // issue the add validator tx vm.ctx.Lock.Unlock() @@ -298,7 +309,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) // create valid tx - addFirstDelegatorTx, err := txBuilder.NewAddDelegatorTx( + uDelTx1, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(delegator1StartTime.Unix()), @@ -309,13 +320,14 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addFirstDelegatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uDelTx1) + require.NoError(err) // issue the first add delegator tx vm.ctx.Lock.Unlock() @@ -330,7 +342,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) // create valid tx - addSecondDelegatorTx, err := txBuilder.NewAddDelegatorTx( + uDelTx2, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(delegator2StartTime.Unix()), @@ -341,13 +353,14 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addSecondDelegatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uDelTx2) + require.NoError(err) // issue the second add delegator tx vm.ctx.Lock.Unlock() @@ -362,7 +375,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) // create valid tx - addThirdDelegatorTx, err := txBuilder.NewAddDelegatorTx( + uDelTx3, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(delegator3StartTime.Unix()), @@ -373,13 +386,14 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addThirdDelegatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uDelTx3) + require.NoError(err) // issue the third add delegator tx vm.ctx.Lock.Unlock() @@ -394,7 +408,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) // create valid tx - addFourthDelegatorTx, err := txBuilder.NewAddDelegatorTx( + uDelTx4, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(delegator4StartTime.Unix()), @@ -405,13 +419,14 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addFourthDelegatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uDelTx4) + require.NoError(err) // issue the fourth add delegator tx vm.ctx.Lock.Unlock() @@ -485,50 +500,55 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { addr0 := key0.PublicKey().Address() addr1 := key1.PublicKey().Address() - txBuilder := txstest.NewBuilder( + factory := txstest.NewWalletFactory( vm.ctx, &vm.Config, vm.state, ) - addSubnetTx0, err := txBuilder.NewCreateSubnetTx( + builder, txSigner := factory.NewWallet(key0) + utx0, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr0}, }, - []*secp256k1.PrivateKey{key0}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr0}, }), ) require.NoError(err) + addSubnetTx0, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx0) + require.NoError(err) - addSubnetTx1, err := txBuilder.NewCreateSubnetTx( + builder, txSigner = factory.NewWallet(key1) + utx1, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr1}, }, - []*secp256k1.PrivateKey{key1}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr1}, }), ) require.NoError(err) + addSubnetTx1, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx1) + require.NoError(err) - addSubnetTx2, err := txBuilder.NewCreateSubnetTx( + utx2, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr1}, }, - []*secp256k1.PrivateKey{key1}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr0}, }), ) require.NoError(err) + addSubnetTx2, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx2) + require.NoError(err) preferredID := vm.manager.Preferred() preferred, err := vm.manager.GetBlock(preferredID) @@ -582,7 +602,7 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { require := require.New(t) - vm, txBuilder, baseDB, mutableSharedMemory := defaultVM(t, cortina) + vm, factory, baseDB, mutableSharedMemory := defaultVM(t, cortina) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -591,7 +611,8 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { newValidatorEndTime := newValidatorStartTime.Add(defaultMinStakingDuration) // Create the tx to add a new validator - addValidatorTx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := factory.NewWallet(keys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(newValidatorStartTime.Unix()), @@ -603,9 +624,10 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0]}, ) require.NoError(err) + addValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // Create the standard block to add the new validator preferredID := vm.manager.Preferred() @@ -791,7 +813,7 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { require := require.New(t) - vm, txBuilder, baseDB, mutableSharedMemory := defaultVM(t, cortina) + vm, factory, baseDB, mutableSharedMemory := defaultVM(t, cortina) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -803,7 +825,8 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { nodeID0 := ids.GenerateTestNodeID() // Create the tx to add the first new validator - addValidatorTx0, err := txBuilder.NewAddValidatorTx( + builder, txSigner := factory.NewWallet(keys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID0, Start: uint64(newValidatorStartTime0.Unix()), @@ -815,9 +838,10 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0]}, ) require.NoError(err) + addValidatorTx0, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // Create the standard block to add the first new validator preferredID := vm.manager.Preferred() @@ -979,7 +1003,8 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { nodeID1 := ids.GenerateTestNodeID() // Create the tx to add the second new validator - addValidatorTx1, err := txBuilder.NewAddValidatorTx( + builder, txSigner = factory.NewWallet(keys[1]) + utx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID1, Start: uint64(newValidatorStartTime1.Unix()), @@ -991,9 +1016,10 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[1]}, ) require.NoError(err) + addValidatorTx1, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx1) + require.NoError(err) // Create the standard block to add the second new validator preferredChainTime = importBlk.Timestamp() @@ -1111,7 +1137,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, cortina) + vm, factory, _, _ := defaultVM(t, cortina) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -1138,7 +1164,8 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { extraNodeID := ids.GenerateTestNodeID() // Create the tx to add the first new validator - addValidatorTx0, err := txBuilder.NewAddValidatorTx( + builder, txSigner := factory.NewWallet(keys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: extraNodeID, Start: uint64(newValidatorStartTime0.Unix()), @@ -1150,9 +1177,10 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0]}, ) require.NoError(err) + addValidatorTx0, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // Create the standard block to add the first new validator preferredID := vm.manager.Preferred() @@ -1251,7 +1279,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { delegator2EndTime := delegator2StartTime.Add(3 * defaultMinStakingDuration) delegator2Stake := defaultMaxValidatorStake - validatorStake - vm, txBuilder, _, _ := defaultVM(t, cortina) + vm, factory, _, _ := defaultVM(t, cortina) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -1263,7 +1291,8 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { changeAddr := keys[0].PublicKey().Address() // create valid tx - addValidatorTx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := factory.NewWallet(keys[0], keys[1]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(validatorStartTime.Unix()), @@ -1275,13 +1304,14 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { Addrs: []ids.ShortID{id}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // issue the add validator tx vm.ctx.Lock.Unlock() @@ -1296,7 +1326,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) // create valid tx - addFirstDelegatorTx, err := txBuilder.NewAddDelegatorTx( + uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(delegator1StartTime.Unix()), @@ -1307,13 +1337,14 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addFirstDelegatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uDelTx) + require.NoError(err) // issue the first add delegator tx vm.ctx.Lock.Unlock() @@ -1328,7 +1359,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) // create valid tx - addSecondDelegatorTx, err := txBuilder.NewAddDelegatorTx( + uDelTx, err = builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(delegator2StartTime.Unix()), @@ -1339,13 +1370,14 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addSecondDelegatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uDelTx) + require.NoError(err) // attempting to issue the second add delegator tx should fail because the // total stake weight would go over the limit. @@ -1361,7 +1393,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t validatorStartTime := latestForkTime.Add(executor.SyncBound).Add(1 * time.Second) validatorEndTime := validatorStartTime.Add(360 * 24 * time.Hour) - vm, txBuilder, _, _ := defaultVM(t, cortina) + vm, factory, _, _ := defaultVM(t, cortina) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -1372,7 +1404,8 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t nodeID := ids.GenerateTestNodeID() changeAddr := keys[0].PublicKey().Address() - addValidatorTx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := factory.NewWallet(keys[0], keys[1]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(validatorStartTime.Unix()), @@ -1384,13 +1417,14 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t Addrs: []ids.ShortID{id}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(addValidatorTx)) @@ -1403,18 +1437,19 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t require.NoError(addValidatorBlock.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - createSubnetTx, err := txBuilder.NewCreateSubnetTx( + uSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + createSubnetTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uSubnetTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(createSubnetTx)) @@ -1427,7 +1462,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t require.NoError(createSubnetBlock.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - addSubnetValidatorTx, err := txBuilder.NewAddSubnetValidatorTx( + uSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -1437,13 +1472,14 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t }, Subnet: createSubnetTx.ID(), }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addSubnetValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uSubnetValTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(addSubnetValidatorTx)) @@ -1464,16 +1500,17 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t require.NoError(err) require.Empty(emptyValidatorSet) - removeSubnetValidatorTx, err := txBuilder.NewRemoveSubnetValidatorTx( + uRemoveSubnetValTx, err := builder.NewRemoveSubnetValidatorTx( nodeID, createSubnetTx.ID(), - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + removeSubnetValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uRemoveSubnetValTx) + require.NoError(err) // Set the clock so that the validator will be moved from the pending // validator set into the current validator set. @@ -1505,7 +1542,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t validatorStartTime := latestForkTime.Add(executor.SyncBound).Add(1 * time.Second) validatorEndTime := validatorStartTime.Add(360 * 24 * time.Hour) - vm, txBuilder, _, _ := defaultVM(t, cortina) + vm, factory, _, _ := defaultVM(t, cortina) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -1516,7 +1553,8 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t nodeID := ids.GenerateTestNodeID() changeAddr := keys[0].PublicKey().Address() - addValidatorTx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := factory.NewWallet(keys[0], keys[1]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(validatorStartTime.Unix()), @@ -1528,13 +1566,14 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t Addrs: []ids.ShortID{id}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(addValidatorTx)) @@ -1547,18 +1586,19 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t require.NoError(addValidatorBlock.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - createSubnetTx, err := txBuilder.NewCreateSubnetTx( + uCreateSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + createSubnetTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uCreateSubnetTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(createSubnetTx)) @@ -1571,7 +1611,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t require.NoError(createSubnetBlock.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - addSubnetValidatorTx, err := txBuilder.NewAddSubnetValidatorTx( + uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -1581,13 +1621,14 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t }, Subnet: createSubnetTx.ID(), }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + addSubnetValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddSubnetValTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(addSubnetValidatorTx)) @@ -1600,16 +1641,17 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t require.NoError(addSubnetValidatorBlock.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - removeSubnetValidatorTx, err := txBuilder.NewRemoveSubnetValidatorTx( + uRemoveSubnetValTx, err := builder.NewRemoveSubnetValidatorTx( nodeID, createSubnetTx.ID(), - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + removeSubnetValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uRemoveSubnetValTx) + require.NoError(err) // Set the clock so that the validator will be moved from the pending // validator set into the current validator set. @@ -1632,7 +1674,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { // setup require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, cortina) + vm, factory, _, _ := defaultVM(t, cortina) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -1662,7 +1704,8 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) // build primary network validator with BLS key - primaryTx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := factory.NewWallet(keys...) + uPrimaryTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -1683,14 +1726,14 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { Addrs: []ids.ShortID{addr}, }, reward.PercentDenominator, - keys, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr}, }), ) require.NoError(err) - uPrimaryTx := primaryTx.Unsigned.(*txs.AddPermissionlessValidatorTx) + primaryTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uPrimaryTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(primaryTx)) @@ -1710,7 +1753,8 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) // insert the subnet validator - subnetTx, err := txBuilder.NewAddSubnetValidatorTx( + builder, txSigner = factory.NewWallet(keys[0], keys[1]) + uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -1720,13 +1764,14 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr}, }), ) require.NoError(err) + subnetTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddSubnetValTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(subnetTx)) @@ -1789,7 +1834,8 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) require.NotEqual(sk1, sk2) - primaryRestartTx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner = factory.NewWallet(keys...) + uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -1810,14 +1856,14 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { Addrs: []ids.ShortID{addr}, }, reward.PercentDenominator, - keys, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr}, }), ) require.NoError(err) - uPrimaryRestartTx := primaryRestartTx.Unsigned.(*txs.AddPermissionlessValidatorTx) + primaryRestartTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uPrimaryRestartTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(primaryRestartTx)) @@ -1893,7 +1939,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { // setup require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, cortina) + vm, factory, _, _ := defaultVM(t, cortina) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -1913,7 +1959,9 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { // Add a primary network validator with no BLS key nodeID := ids.GenerateTestNodeID() addr := keys[0].PublicKey().Address() - primaryTx1, err := txBuilder.NewAddValidatorTx( + + builder, txSigner := factory.NewWallet(keys[0]) + uAddValTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(primaryStartTime1.Unix()), @@ -1925,13 +1973,14 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { Addrs: []ids.ShortID{addr}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr}, }), ) require.NoError(err) + primaryTx1, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddValTx1) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(primaryTx1)) @@ -1981,7 +2030,8 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { sk2, err := bls.NewSecretKey() require.NoError(err) - primaryRestartTx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner = factory.NewWallet(keys...) + uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -2002,13 +2052,14 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { Addrs: []ids.ShortID{addr}, }, reward.PercentDenominator, - keys, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr}, }), ) require.NoError(err) + primaryRestartTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uPrimaryRestartTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(primaryRestartTx)) @@ -2044,7 +2095,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { // setup require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, cortina) + vm, factory, _, _ := defaultVM(t, cortina) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -2068,7 +2119,9 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { // Add a primary network validator with no BLS key nodeID := ids.GenerateTestNodeID() addr := keys[0].PublicKey().Address() - primaryTx1, err := txBuilder.NewAddValidatorTx( + + builder, txSigner := factory.NewWallet(keys[0]) + uPrimaryTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(primaryStartTime1.Unix()), @@ -2080,13 +2133,14 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { Addrs: []ids.ShortID{addr}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr}, }), ) require.NoError(err) + primaryTx1, err := walletsigner.SignUnsigned(context.Background(), txSigner, uPrimaryTx1) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(primaryTx1)) @@ -2106,7 +2160,8 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { require.NoError(err) // insert the subnet validator - subnetTx, err := txBuilder.NewAddSubnetValidatorTx( + builder, txSigner = factory.NewWallet(keys[0], keys[1]) + uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -2116,13 +2171,14 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr}, }), ) require.NoError(err) + subnetTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddSubnetValTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(subnetTx)) @@ -2184,7 +2240,8 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { sk2, err := bls.NewSecretKey() require.NoError(err) - primaryRestartTx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner = factory.NewWallet(keys...) + uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -2205,13 +2262,14 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { Addrs: []ids.ShortID{addr}, }, reward.PercentDenominator, - keys, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr}, }), ) require.NoError(err) + primaryRestartTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uPrimaryRestartTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(primaryRestartTx)) @@ -2256,7 +2314,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { // setup require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, cortina) + vm, factory, _, _ := defaultVM(t, cortina) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -2278,7 +2336,9 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { // Add a primary network validator with no BLS key nodeID := ids.GenerateTestNodeID() addr := keys[0].PublicKey().Address() - primaryTx1, err := txBuilder.NewAddValidatorTx( + + builder, txSigner := factory.NewWallet(keys[0]) + uPrimaryTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(primaryStartTime1.Unix()), @@ -2290,13 +2350,14 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { Addrs: []ids.ShortID{addr}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr}, }), ) require.NoError(err) + primaryTx1, err := walletsigner.SignUnsigned(context.Background(), txSigner, uPrimaryTx1) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(primaryTx1)) @@ -2313,7 +2374,8 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { require.NoError(err) // insert the subnet validator - subnetTx, err := txBuilder.NewAddSubnetValidatorTx( + builder, txSigner = factory.NewWallet(keys[0], keys[1]) + uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -2323,13 +2385,14 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{keys[0], keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{addr}, }), ) require.NoError(err) + subnetTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddSubnetValTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(subnetTx)) diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 50c677688713..e6e645d74242 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -71,6 +71,7 @@ import ( blockexecutor "github.com/ava-labs/avalanchego/vms/platformvm/block/executor" txexecutor "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" walletbuilder "github.com/ava-labs/avalanchego/wallet/chain/p/builder" + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" walletcommon "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" ) @@ -205,7 +206,7 @@ func defaultGenesis(t *testing.T, avaxAssetID ids.ID) (*api.BuildGenesisArgs, [] return &buildGenesisArgs, genesisBytes } -func defaultVM(t *testing.T, f fork) (*VM, *txstest.Builder, database.Database, *mutableSharedMemory) { +func defaultVM(t *testing.T, f fork) (*VM, *txstest.WalletFactory, database.Database, *mutableSharedMemory) { require := require.New(t) var ( apricotPhase3Time = mockable.MaxTime @@ -309,7 +310,7 @@ func defaultVM(t *testing.T, f fork) (*VM, *txstest.Builder, database.Database, require.NoError(vm.SetState(context.Background(), snow.NormalOp)) - builder := txstest.NewBuilder( + factory := txstest.NewWalletFactory( ctx, &vm.Config, vm.state, @@ -318,8 +319,8 @@ func defaultVM(t *testing.T, f fork) (*VM, *txstest.Builder, database.Database, // Create a subnet and store it in testSubnet1 // Note: following Banff activation, block acceptance will move // chain time ahead - var err error - testSubnet1, err = builder.NewCreateSubnetTx( + builder, signer := factory.NewWallet(keys[0]) + utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ @@ -328,13 +329,15 @@ func defaultVM(t *testing.T, f fork) (*VM, *txstest.Builder, database.Database, keys[2].PublicKey().Address(), }, }, - []*secp256k1.PrivateKey{keys[0]}, // pays tx fee walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }), ) require.NoError(err) + testSubnet1, err = walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) + vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(testSubnet1)) vm.ctx.Lock.Lock() @@ -351,7 +354,7 @@ func defaultVM(t *testing.T, f fork) (*VM, *txstest.Builder, database.Database, require.NoError(vm.Shutdown(context.Background())) }) - return vm, builder, db, msm + return vm, factory, db, msm } // Ensure genesis state is parsed from bytes and stored correctly @@ -410,7 +413,7 @@ func TestGenesis(t *testing.T) { // accept proposal to add validator to primary network func TestAddValidatorCommit(t *testing.T) { require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, latestFork) + vm, factory, _, _ := defaultVM(t, latestFork) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -425,7 +428,8 @@ func TestAddValidatorCommit(t *testing.T) { require.NoError(err) // create valid tx - tx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := factory.NewWallet(keys[0]) + utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -446,9 +450,10 @@ func TestAddValidatorCommit(t *testing.T) { Addrs: []ids.ShortID{rewardAddress}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // trigger block creation vm.ctx.Lock.Unlock() @@ -473,7 +478,7 @@ func TestAddValidatorCommit(t *testing.T) { // verify invalid attempt to add validator to primary network func TestInvalidAddValidatorCommit(t *testing.T) { require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, cortina) + vm, factory, _, _ := defaultVM(t, cortina) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -482,7 +487,8 @@ func TestInvalidAddValidatorCommit(t *testing.T) { endTime := startTime.Add(defaultMinStakingDuration) // create invalid tx - tx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := factory.NewWallet(keys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -494,9 +500,10 @@ func TestInvalidAddValidatorCommit(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) preferredID := vm.manager.Preferred() preferred, err := vm.manager.GetBlock(preferredID) @@ -527,7 +534,7 @@ func TestInvalidAddValidatorCommit(t *testing.T) { // Reject attempt to add validator to primary network func TestAddValidatorReject(t *testing.T) { require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, cortina) + vm, factory, _, _ := defaultVM(t, cortina) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -539,7 +546,8 @@ func TestAddValidatorReject(t *testing.T) { ) // create valid tx - tx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := factory.NewWallet(keys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -551,9 +559,10 @@ func TestAddValidatorReject(t *testing.T) { Addrs: []ids.ShortID{rewardAddress}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // trigger block creation vm.ctx.Lock.Unlock() @@ -576,7 +585,7 @@ func TestAddValidatorReject(t *testing.T) { // Reject proposal to add validator to primary network func TestAddValidatorInvalidNotReissued(t *testing.T) { require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, latestFork) + vm, factory, _, _ := defaultVM(t, latestFork) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -590,7 +599,8 @@ func TestAddValidatorInvalidNotReissued(t *testing.T) { require.NoError(err) // create valid tx - tx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := factory.NewWallet(keys[0]) + utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: repeatNodeID, @@ -611,9 +621,10 @@ func TestAddValidatorInvalidNotReissued(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // trigger block creation vm.ctx.Lock.Unlock() @@ -625,7 +636,7 @@ func TestAddValidatorInvalidNotReissued(t *testing.T) { // Accept proposal to add validator to subnet func TestAddSubnetValidatorAccept(t *testing.T) { require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, latestFork) + vm, factory, _, _ := defaultVM(t, latestFork) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -638,7 +649,8 @@ func TestAddSubnetValidatorAccept(t *testing.T) { // create valid tx // note that [startTime, endTime] is a subset of time that keys[0] // validates primary network ([defaultValidateStartTime, defaultValidateEndTime]) - tx, err := txBuilder.NewAddSubnetValidatorTx( + builder, txSigner := factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -648,9 +660,10 @@ func TestAddSubnetValidatorAccept(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // trigger block creation vm.ctx.Lock.Unlock() @@ -675,7 +688,7 @@ func TestAddSubnetValidatorAccept(t *testing.T) { // Reject proposal to add validator to subnet func TestAddSubnetValidatorReject(t *testing.T) { require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, latestFork) + vm, factory, _, _ := defaultVM(t, latestFork) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -688,7 +701,8 @@ func TestAddSubnetValidatorReject(t *testing.T) { // create valid tx // note that [startTime, endTime] is a subset of time that keys[0] // validates primary network ([defaultValidateStartTime, defaultValidateEndTime]) - tx, err := txBuilder.NewAddSubnetValidatorTx( + builder, txSigner := factory.NewWallet(testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -698,9 +712,10 @@ func TestAddSubnetValidatorReject(t *testing.T) { }, Subnet: testSubnet1.ID(), }, - []*secp256k1.PrivateKey{testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // trigger block creation vm.ctx.Lock.Unlock() @@ -873,19 +888,21 @@ func TestUnneededBuildBlock(t *testing.T) { // test acceptance of proposal to create a new chain func TestCreateChain(t *testing.T) { require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, latestFork) + vm, factory, _, _ := defaultVM(t, latestFork) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - tx, err := txBuilder.NewCreateChainTx( + builder, txSigner := factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, ids.ID{'t', 'e', 's', 't', 'v', 'm'}, nil, "name", - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(tx)) @@ -921,12 +938,12 @@ func TestCreateChain(t *testing.T) { // 3) Advance timestamp to validator's end time (removing validator from current) func TestCreateSubnet(t *testing.T) { require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, latestFork) + vm, factory, _, _ := defaultVM(t, latestFork) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - nodeID := genesisNodeIDs[0] - createSubnetTx, err := txBuilder.NewCreateSubnetTx( + builder, txSigner := factory.NewWallet(keys[0]) + uCreateSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ @@ -934,13 +951,14 @@ func TestCreateSubnet(t *testing.T) { keys[1].PublicKey().Address(), }, }, - []*secp256k1.PrivateKey{keys[0]}, // payer walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }), ) require.NoError(err) + createSubnetTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uCreateSubnetTx) + require.NoError(err) subnetID := createSubnetTx.ID() vm.ctx.Lock.Unlock() @@ -964,10 +982,11 @@ func TestCreateSubnet(t *testing.T) { require.Contains(subnetIDs, subnetID) // Now that we've created a new subnet, add a validator to that subnet + nodeID := genesisNodeIDs[0] startTime := vm.clock.Time().Add(txexecutor.SyncBound).Add(1 * time.Second) endTime := startTime.Add(defaultMinStakingDuration) // [startTime, endTime] is subset of time keys[0] validates default subnet so tx is valid - addValidatorTx, err := txBuilder.NewAddSubnetValidatorTx( + uAddValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -977,9 +996,10 @@ func TestCreateSubnet(t *testing.T) { }, Subnet: subnetID, }, - []*secp256k1.PrivateKey{keys[0]}, ) require.NoError(err) + addValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddValTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(addValidatorTx)) @@ -1020,7 +1040,7 @@ func TestCreateSubnet(t *testing.T) { // test asset import func TestAtomicImport(t *testing.T) { require := require.New(t) - vm, txBuilder, baseDB, mutableSharedMemory := defaultVM(t, latestFork) + vm, factory, baseDB, mutableSharedMemory := defaultVM(t, latestFork) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -1036,13 +1056,13 @@ func TestAtomicImport(t *testing.T) { mutableSharedMemory.SharedMemory = m.NewSharedMemory(vm.ctx.ChainID) peerSharedMemory := m.NewSharedMemory(vm.ctx.XChainID) - _, err := txBuilder.NewImportTx( + builder, _ := factory.NewWallet(keys[0]) + _, err := builder.NewImportTx( vm.ctx.XChainID, &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{recipientKey.PublicKey().Address()}, }, - []*secp256k1.PrivateKey{keys[0]}, ) require.ErrorIs(err, walletbuilder.ErrInsufficientFunds) @@ -1077,15 +1097,17 @@ func TestAtomicImport(t *testing.T) { }, })) - tx, err := txBuilder.NewImportTx( + builder, txSigner := factory.NewWallet(recipientKey) + utx, err := builder.NewImportTx( vm.ctx.XChainID, &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{recipientKey.PublicKey().Address()}, }, - []*secp256k1.PrivateKey{recipientKey}, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(tx)) @@ -2085,7 +2107,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { validatorStartTime := latestForkTime.Add(txexecutor.SyncBound).Add(1 * time.Second) validatorEndTime := validatorStartTime.Add(360 * 24 * time.Hour) - vm, txBuilder, _, _ := defaultVM(t, latestFork) + vm, factory, _, _ := defaultVM(t, latestFork) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -2097,7 +2119,8 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - addValidatorTx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := factory.NewWallet(keys[0]) + uAddValTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -2118,13 +2141,14 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { Addrs: []ids.ShortID{id}, }, reward.PercentDenominator, - []*secp256k1.PrivateKey{keys[0]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }), ) require.NoError(err) + addValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddValTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(addValidatorTx)) @@ -2137,18 +2161,19 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { require.NoError(addValidatorBlock.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - createSubnetTx, err := txBuilder.NewCreateSubnetTx( + uCreateSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{id}, }, - []*secp256k1.PrivateKey{keys[0]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }), ) require.NoError(err) + createSubnetTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uCreateSubnetTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(createSubnetTx)) @@ -2161,7 +2186,8 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { require.NoError(createSubnetBlock.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - addSubnetValidatorTx, err := txBuilder.NewAddSubnetValidatorTx( + builder, txSigner = factory.NewWallet(key, keys[1]) + uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -2171,24 +2197,27 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { }, Subnet: createSubnetTx.ID(), }, - []*secp256k1.PrivateKey{key, keys[1]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[1].PublicKey().Address()}, }), ) require.NoError(err) + addSubnetValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddSubnetValTx) + require.NoError(err) - removeSubnetValidatorTx, err := txBuilder.NewRemoveSubnetValidatorTx( + builder, txSigner = factory.NewWallet(key, keys[2]) + uRemoveSubnetValTx, err := builder.NewRemoveSubnetValidatorTx( nodeID, createSubnetTx.ID(), - []*secp256k1.PrivateKey{key, keys[2]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[2].PublicKey().Address()}, }), ) require.NoError(err) + removeSubnetValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uRemoveSubnetValTx) + require.NoError(err) statelessBlock, err := block.NewBanffStandardBlock( vm.state.GetTimestamp(), @@ -2214,23 +2243,25 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { func TestTransferSubnetOwnershipTx(t *testing.T) { require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, latestFork) + vm, factory, _, _ := defaultVM(t, latestFork) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - // Create a subnet - createSubnetTx, err := txBuilder.NewCreateSubnetTx( + builder, txSigner := factory.NewWallet(keys[0]) + uCreateSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }, - []*secp256k1.PrivateKey{keys[0]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[0].PublicKey().Address()}, }), ) require.NoError(err) + createSubnetTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uCreateSubnetTx) + require.NoError(err) + subnetID := createSubnetTx.ID() vm.ctx.Lock.Unlock() @@ -2261,15 +2292,16 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { expectedOwner.InitCtx(ctx) require.Equal(expectedOwner, subnetOwner) - transferSubnetOwnershipTx, err := txBuilder.NewTransferSubnetOwnershipTx( + uTransferSubnetOwnershipTx, err := builder.NewTransferSubnetOwnershipTx( subnetID, &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{keys[1].PublicKey().Address()}, }, - []*secp256k1.PrivateKey{keys[0]}, ) require.NoError(err) + transferSubnetOwnershipTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uTransferSubnetOwnershipTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(transferSubnetOwnershipTx)) @@ -2300,14 +2332,15 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { func TestBaseTx(t *testing.T) { require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, latestFork) + vm, factory, _, _ := defaultVM(t, latestFork) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() sendAmt := uint64(100000) changeAddr := ids.ShortEmpty - baseTx, err := txBuilder.NewBaseTx( + builder, txSigner := factory.NewWallet(keys[0]) + utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { Asset: avax.Asset{ID: vm.ctx.AVAXAssetID}, @@ -2322,13 +2355,14 @@ func TestBaseTx(t *testing.T) { }, }, }, - []*secp256k1.PrivateKey{keys[0]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + baseTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) totalInputAmt := uint64(0) key0InputAmt := uint64(0) @@ -2384,7 +2418,7 @@ func TestBaseTx(t *testing.T) { func TestPruneMempool(t *testing.T) { require := require.New(t) - vm, txBuilder, _, _ := defaultVM(t, latestFork) + vm, factory, _, _ := defaultVM(t, latestFork) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() @@ -2392,7 +2426,8 @@ func TestPruneMempool(t *testing.T) { sendAmt := uint64(100000) changeAddr := ids.ShortEmpty - baseTx, err := txBuilder.NewBaseTx( + builder, txSigner := factory.NewWallet(keys[0]) + utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { Asset: avax.Asset{ID: vm.ctx.AVAXAssetID}, @@ -2407,13 +2442,14 @@ func TestPruneMempool(t *testing.T) { }, }, }, - []*secp256k1.PrivateKey{keys[0]}, walletcommon.WithChangeOwner(&secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{changeAddr}, }), ) require.NoError(err) + baseTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(baseTx)) @@ -2433,7 +2469,8 @@ func TestPruneMempool(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - addValidatorTx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner = factory.NewWallet(keys[1]) + uAddValTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -2454,9 +2491,10 @@ func TestPruneMempool(t *testing.T) { Addrs: []ids.ShortID{keys[2].Address()}, }, 20000, - []*secp256k1.PrivateKey{keys[1]}, ) require.NoError(err) + addValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddValTx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(addValidatorTx))