From 8215e7ecd7c5dbdc11fd392cadef7b79591a0b4b Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 28 Mar 2024 21:08:20 -0400 Subject: [PATCH 01/14] [components/avax] Remove `AtomicUTXOManager` interface --- vms/avm/service.go | 14 ++++- vms/avm/vm.go | 2 - vms/components/avax/atomic_utxos.go | 52 ++++++------------- vms/platformvm/block/builder/helpers_test.go | 3 -- vms/platformvm/block/executor/helpers_test.go | 3 -- vms/platformvm/service.go | 5 +- vms/platformvm/service_test.go | 1 - vms/platformvm/txs/executor/helpers_test.go | 4 -- vms/platformvm/txs/txstest/backend.go | 11 +++- vms/platformvm/vm.go | 1 - 10 files changed, 39 insertions(+), 57 deletions(-) diff --git a/vms/avm/service.go b/vms/avm/service.go index 5392308480a1..bc6dadd8705f 100644 --- a/vms/avm/service.go +++ b/vms/avm/service.go @@ -433,7 +433,9 @@ func (s *Service) GetUTXOs(_ *http.Request, args *api.GetUTXOsArgs, reply *api.G limit, ) } else { - utxos, endAddr, endUTXOID, err = s.vm.GetAtomicUTXOs( + utxos, endAddr, endUTXOID, err = avax.GetAtomicUTXOs( + s.vm.ctx.SharedMemory, + s.vm.parser.Codec(), sourceChain, addrSet, startAddr, @@ -1782,7 +1784,15 @@ func (s *Service) buildImport(args *ImportArgs) (*txs.Tx, error) { return nil, err } - atomicUTXOs, _, _, err := s.vm.GetAtomicUTXOs(chainID, kc.Addrs, ids.ShortEmpty, ids.Empty, int(maxPageSize)) + atomicUTXOs, _, _, err := avax.GetAtomicUTXOs( + s.vm.ctx.SharedMemory, + s.vm.parser.Codec(), + chainID, + kc.Addrs, + ids.ShortEmpty, + ids.Empty, + int(maxPageSize), + ) if err != nil { return nil, fmt.Errorf("problem retrieving user's atomic UTXOs: %w", err) } diff --git a/vms/avm/vm.go b/vms/avm/vm.go index 82080d377344..672a1e158eba 100644 --- a/vms/avm/vm.go +++ b/vms/avm/vm.go @@ -68,7 +68,6 @@ type VM struct { metrics metrics.Metrics avax.AddressManager - avax.AtomicUTXOManager ids.Aliaser utxo.Spender @@ -227,7 +226,6 @@ func (vm *VM) Initialize( } codec := vm.parser.Codec() - vm.AtomicUTXOManager = avax.NewAtomicUTXOManager(ctx.SharedMemory, codec) vm.Spender = utxo.NewSpender(&vm.clock, codec) state, err := state.New( diff --git a/vms/components/avax/atomic_utxos.go b/vms/components/avax/atomic_utxos.go index 3ac9c166ea3c..f0a854284f22 100644 --- a/vms/components/avax/atomic_utxos.go +++ b/vms/components/avax/atomic_utxos.go @@ -12,41 +12,19 @@ import ( "github.com/ava-labs/avalanchego/utils/set" ) -var _ AtomicUTXOManager = (*atomicUTXOManager)(nil) - -type AtomicUTXOManager interface { - // GetAtomicUTXOs returns exported UTXOs such that at least one of the - // addresses in [addrs] is referenced. - // - // Returns at most [limit] UTXOs. - // - // Returns: - // * The fetched UTXOs - // * The address associated with the last UTXO fetched - // * The ID of the last UTXO fetched - // * Any error that may have occurred upstream. - GetAtomicUTXOs( - chainID ids.ID, - addrs set.Set[ids.ShortID], - startAddr ids.ShortID, - startUTXOID ids.ID, - limit int, - ) ([]*UTXO, ids.ShortID, ids.ID, error) -} - -type atomicUTXOManager struct { - sm atomic.SharedMemory - codec codec.Manager -} - -func NewAtomicUTXOManager(sm atomic.SharedMemory, codec codec.Manager) AtomicUTXOManager { - return &atomicUTXOManager{ - sm: sm, - codec: codec, - } -} - -func (a *atomicUTXOManager) GetAtomicUTXOs( +// GetAtomicUTXOs returns exported UTXOs such that at least one of the +// addresses in [addrs] is referenced. +// +// Returns at most [limit] UTXOs. +// +// Returns: +// * The fetched UTXOs +// * The address associated with the last UTXO fetched +// * The ID of the last UTXO fetched +// * Any error that may have occurred upstream. +func GetAtomicUTXOs( + sharedMemory atomic.SharedMemory, + codec codec.Manager, chainID ids.ID, addrs set.Set[ids.ShortID], startAddr ids.ShortID, @@ -61,7 +39,7 @@ func (a *atomicUTXOManager) GetAtomicUTXOs( i++ } - allUTXOBytes, lastAddr, lastUTXO, err := a.sm.Indexed( + allUTXOBytes, lastAddr, lastUTXO, err := sharedMemory.Indexed( chainID, addrsList, startAddr.Bytes(), @@ -84,7 +62,7 @@ func (a *atomicUTXOManager) GetAtomicUTXOs( utxos := make([]*UTXO, len(allUTXOBytes)) for i, utxoBytes := range allUTXOBytes { utxo := &UTXO{} - if _, err := a.codec.Unmarshal(utxoBytes, utxo); err != nil { + if _, err := codec.Unmarshal(utxoBytes, utxo); err != nil { return nil, ids.ShortID{}, ids.ID{}, fmt.Errorf("error parsing UTXO: %w", err) } utxos[i] = utxo diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index bdb23bdfef1b..958ef92ae5c2 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -34,7 +34,6 @@ import ( "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/api" "github.com/ava-labs/avalanchego/vms/platformvm/config" "github.com/ava-labs/avalanchego/vms/platformvm/fx" @@ -115,7 +114,6 @@ type environment struct { msm *mutableSharedMemory fx fx.Fx state state.State - atomicUTXOs avax.AtomicUTXOManager uptimes uptime.Manager utxosVerifier utxo.Verifier txBuilder *txstest.Builder @@ -150,7 +148,6 @@ func newEnvironment(t *testing.T, f fork) *environment { //nolint:unparam rewardsCalc := reward.NewCalculator(res.config.RewardConfig) res.state = defaultState(t, res.config, res.ctx, res.baseDB, rewardsCalc) - res.atomicUTXOs = avax.NewAtomicUTXOManager(res.ctx.SharedMemory, txs.Codec) res.uptimes = uptime.NewManager(res.state, res.clk) res.utxosVerifier = utxo.NewVerifier(res.ctx, res.clk, res.fx) diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 0a8b902ffc46..0849146afcf6 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -35,7 +35,6 @@ import ( "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/api" "github.com/ava-labs/avalanchego/vms/platformvm/config" "github.com/ava-labs/avalanchego/vms/platformvm/fx" @@ -127,7 +126,6 @@ type environment struct { fx fx.Fx state state.State mockedState *state.MockState - atomicUTXOs avax.AtomicUTXOManager uptimes uptime.Manager utxosVerifier utxo.Verifier txBuilder *txstest.Builder @@ -153,7 +151,6 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f fork) *environment res.fx = defaultFx(res.clk, res.ctx.Log, res.isBootstrapped.Get()) rewardsCalc := reward.NewCalculator(res.config.RewardConfig) - res.atomicUTXOs = avax.NewAtomicUTXOManager(res.ctx.SharedMemory, txs.Codec) if ctrl == nil { res.state = defaultState(res.config, res.ctx, res.baseDB, rewardsCalc) diff --git a/vms/platformvm/service.go b/vms/platformvm/service.go index 6c0004404b34..dfe970a88b0a 100644 --- a/vms/platformvm/service.go +++ b/vms/platformvm/service.go @@ -70,7 +70,6 @@ type Service struct { vm *VM addrManager avax.AddressManager stakerAttributesCache *cache.LRU[ids.ID, *stakerAttributes] - atomicUtxosManager avax.AtomicUTXOManager } // All attributes are optional and may not be filled for each stakerTx. @@ -384,7 +383,9 @@ func (s *Service) GetUTXOs(_ *http.Request, args *api.GetUTXOsArgs, response *ap limit, ) } else { - utxos, endAddr, endUTXOID, err = s.atomicUtxosManager.GetAtomicUTXOs( + utxos, endAddr, endUTXOID, err = avax.GetAtomicUTXOs( + s.vm.ctx.SharedMemory, + txs.Codec, sourceChain, addrSet, startAddr, diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 9d28576dc03d..8f39770548b8 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -83,7 +83,6 @@ func defaultService(t *testing.T) (*Service, *mutableSharedMemory, *txstest.Buil stakerAttributesCache: &cache.LRU[ids.ID, *stakerAttributes]{ Size: stakerAttributesCacheSize, }, - atomicUtxosManager: avax.NewAtomicUTXOManager(vm.ctx.SharedMemory, txs.Codec), }, mutableSharedMemory, txBuilder } diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 4d58a9aebf40..2a08a99ae650 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -33,7 +33,6 @@ import ( "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/api" "github.com/ava-labs/avalanchego/vms/platformvm/config" "github.com/ava-labs/avalanchego/vms/platformvm/fx" @@ -102,7 +101,6 @@ type environment struct { fx fx.Fx state state.State states map[ids.ID]state.Chain - atomicUTXOs avax.AtomicUTXOManager uptimes uptime.Manager utxosHandler utxo.Verifier txBuilder *txstest.Builder @@ -141,7 +139,6 @@ func newEnvironment(t *testing.T, f fork) *environment { rewards := reward.NewCalculator(config.RewardConfig) baseState := defaultState(config, ctx, baseDB, rewards) - atomicUTXOs := avax.NewAtomicUTXOManager(ctx.SharedMemory, txs.Codec) uptimes := uptime.NewManager(baseState, clk) utxosVerifier := utxo.NewVerifier(ctx, clk, fx) @@ -172,7 +169,6 @@ func newEnvironment(t *testing.T, f fork) *environment { fx: fx, state: baseState, states: make(map[ids.ID]state.Chain), - atomicUTXOs: atomicUTXOs, uptimes: uptimes, utxosHandler: utxosVerifier, txBuilder: txBuilder, diff --git a/vms/platformvm/txs/txstest/backend.go b/vms/platformvm/txs/txstest/backend.go index 6dd1e4ff6cf4..b442ab63a33c 100644 --- a/vms/platformvm/txs/txstest/backend.go +++ b/vms/platformvm/txs/txstest/backend.go @@ -47,8 +47,15 @@ func (b *Backend) UTXOs(_ context.Context, sourceChainID ids.ID) ([]*avax.UTXO, return avax.GetAllUTXOs(b.state, b.addrs) } - atomicUTXOManager := avax.NewAtomicUTXOManager(b.sharedMemory, txs.Codec) - utxos, _, _, err := atomicUTXOManager.GetAtomicUTXOs(sourceChainID, b.addrs, ids.ShortEmpty, ids.Empty, math.MaxInt) + utxos, _, _, err := avax.GetAtomicUTXOs( + b.sharedMemory, + txs.Codec, + sourceChainID, + b.addrs, + ids.ShortEmpty, + ids.Empty, + math.MaxInt, + ) return utxos, err } diff --git a/vms/platformvm/vm.go b/vms/platformvm/vm.go index 1fc8e6fb1366..214e7246ce37 100644 --- a/vms/platformvm/vm.go +++ b/vms/platformvm/vm.go @@ -464,7 +464,6 @@ func (vm *VM) CreateHandlers(context.Context) (map[string]http.Handler, error) { stakerAttributesCache: &cache.LRU[ids.ID, *stakerAttributes]{ Size: stakerAttributesCacheSize, }, - atomicUtxosManager: avax.NewAtomicUTXOManager(vm.ctx.SharedMemory, txs.Codec), } err := server.RegisterService(service, "platform") return map[string]http.Handler{ From 3b711a150665b422e0bd97c93a30891440ea6e92 Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 29 Mar 2024 00:49:40 -0400 Subject: [PATCH 02/14] wip --- vms/platformvm/block/builder/builder_test.go | 38 ++- vms/platformvm/block/builder/helpers_test.go | 10 +- .../block/builder/standard_block_test.go | 9 +- vms/platformvm/service_test.go | 36 +- .../txs/executor/advance_time_test.go | 51 ++- vms/platformvm/txs/executor/export_test.go | 8 +- vms/platformvm/txs/executor/helpers_test.go | 9 +- .../txs/executor/reward_validator_test.go | 49 ++- .../txs/executor/standard_tx_executor_test.go | 74 +++-- vms/platformvm/txs/txstest/builder.go | 314 +----------------- vms/platformvm/validator_set_property_test.go | 39 ++- 11 files changed, 215 insertions(+), 422 deletions(-) diff --git a/vms/platformvm/block/builder/builder_test.go b/vms/platformvm/block/builder/builder_test.go index 64abd8a46857..361e7fca83e5 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.txBuilder.Builders(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( + txBuilder, txSigner := env.txBuilder.Builders(preFundedKeys[0]) + utx, err := txBuilder.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.txBuilder.Builders(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.txBuilder.Builders(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.txBuilder.Builders(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.txBuilder.Builders(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 958ef92ae5c2..4e3ef64e5f9b 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -51,6 +51,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" ) @@ -238,9 +239,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.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ @@ -249,15 +249,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..6a93b81124e6 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.txBuilder.Builders(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/service_test.go b/vms/platformvm/service_test.go index 8f39770548b8..9cfb550e4f11 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -48,6 +48,7 @@ import ( pchainapi "github.com/ava-labs/avalanchego/vms/platformvm/api" 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 ( @@ -166,15 +167,17 @@ func TestGetTxStatus(t *testing.T) { mutableSharedMemory.SharedMemory = sm - tx, err := txBuilder.NewImportTx( + builder, signer := txBuilder.Builders(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() @@ -217,18 +220,20 @@ func TestGetTx(t *testing.T) { { "standard block", func(_ *Service, builder *txstest.Builder) (*txs.Tx, error) { - return builder.NewCreateChainTx( // Test GetTx works for standard blocks + txBuilder, signer := builder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := txBuilder.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) }, }, { @@ -242,7 +247,8 @@ func TestGetTx(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, } - return builder.NewAddPermissionlessValidatorTx( // Test GetTx works for proposal blocks + txBuilder, txSigner := builder.Builders(keys[0]) + utx, err := txBuilder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -257,18 +263,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 + txBuilder, txSigner := builder.Builders(keys[0]) + utx, err := txBuilder.NewExportTx( service.vm.ctx.XChainID, []*avax.TransferableOutput{{ Asset: avax.Asset{ID: service.vm.ctx.AVAXAssetID}, @@ -281,12 +289,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(), txSigner, utx) }, }, } @@ -463,7 +472,8 @@ func TestGetStake(t *testing.T) { delegatorNodeID := genesisNodeIDs[0] delegatorStartTime := defaultValidateStartTime delegatorEndTime := defaultGenesisTime.Add(defaultMinStakingDuration) - tx, err := txBuilder.NewAddDelegatorTx( + builder, signer := txBuilder.Builders(keys[0]) + utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: delegatorNodeID, Start: uint64(delegatorStartTime.Unix()), @@ -474,13 +484,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( @@ -525,7 +536,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()), @@ -537,13 +548,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(), diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index ea36af13e939..8f0313254d98 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.txBuilder.Builders(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.txBuilder.Builders(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.txBuilder.Builders(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.txBuilder.Builders(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.txBuilder.Builders(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.txBuilder.Builders(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/export_test.go b/vms/platformvm/txs/executor/export_test.go index d45a52b486d5..278105964c5b 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.txBuilder.Builders(tt.sourceKeys...) + utx, err := builder.NewExportTx( tt.destinationChainID, []*avax.TransferableOutput{{ Asset: avax.Asset{ID: env.ctx.AVAXAssetID}, @@ -63,9 +67,9 @@ func TestNewExportTx(t *testing.T) { }, }, }}, - tt.sourceKeys, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) 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 2a08a99ae650..0c8025616715 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" @@ -45,6 +46,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 ( @@ -213,7 +216,8 @@ func addSubnet( // Create a subnet var err error - testSubnet1, err = txBuilder.NewCreateSubnetTx( + builder, signer := env.txBuilder.Builders([]*secp256k1.PrivateKey{preFundedKeys[0]}) + utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ @@ -222,13 +226,14 @@ func addSubnet( 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) diff --git a/vms/platformvm/txs/executor/reward_validator_test.go b/vms/platformvm/txs/executor/reward_validator_test.go index 215e9a6f729a..478475ffb09c 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.txBuilder.Builders(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.txBuilder.Builders(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.txBuilder.Builders(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.txBuilder.Builders(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 66a4799eaf1e..bc0b988b41f2 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" "testing" @@ -34,6 +35,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 @@ -69,10 +72,10 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { }, } for _, test := range tests { - // Case: Empty validator node ID after banff env.config.BanffTime = test.banffTime - tx, err := env.txBuilder.NewAddValidatorTx( // create the tx + builder, signer := env.txBuilder.Builders([]*secp256k1.PrivateKey{preFundedKeys[0]}) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.EmptyNodeID, Start: uint64(startTime.Unix()), @@ -84,9 +87,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) @@ -113,7 +117,8 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { // [addMinStakeValidator] adds a new validator to the primary network's // pending validator set with the minimum staking amount addMinStakeValidator := func(target *environment) { - tx, err := target.txBuilder.NewAddValidatorTx( + builder, signer := target.txBuilder.Builders([]*secp256k1.PrivateKey{preFundedKeys[0]}) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, Start: uint64(newValidatorStartTime.Unix()), @@ -124,10 +129,11 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{rewardAddress}, }, - reward.PercentDenominator, // Shares - []*secp256k1.PrivateKey{preFundedKeys[0]}, + reward.PercentDenominator, ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) addValTx := tx.Unsigned.(*txs.AddValidatorTx) staker, err := state.NewCurrentStaker( @@ -147,7 +153,8 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { // [addMaxStakeValidator] adds a new validator to the primary network's // pending validator set with the maximum staking amount addMaxStakeValidator := func(target *environment) { - tx, err := target.txBuilder.NewAddValidatorTx( + builder, signer := target.txBuilder.Builders([]*secp256k1.PrivateKey{preFundedKeys[0]}) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, Start: uint64(newValidatorStartTime.Unix()), @@ -158,10 +165,11 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{rewardAddress}, }, - reward.PercentDenominator, // Shared - []*secp256k1.PrivateKey{preFundedKeys[0]}, + reward.PercentDenominator, ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) addValTx := tx.Unsigned.(*txs.AddValidatorTx) staker, err := state.NewCurrentStaker( @@ -320,10 +328,11 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { require := require.New(t) - freshTH := newEnvironment(t, apricotPhase5) - freshTH.config.ApricotPhase3Time = tt.AP3Time + env := newEnvironment(t, apricotPhase5) + env.config.ApricotPhase3Time = tt.AP3Time - tx, err := freshTH.txBuilder.NewAddDelegatorTx( + builder, signer := env.txBuilder.Builders(tt.feeKeys) + utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: tt.nodeID, Start: uint64(tt.startTime.Unix()), @@ -334,21 +343,22 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{tt.rewardAddress}, }, - tt.feeKeys, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) if tt.setup != nil { - tt.setup(freshTH) + tt.setup(env) } - onAcceptState, err := state.NewDiff(lastAcceptedID, freshTH) + onAcceptState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) - freshTH.config.BanffTime = onAcceptState.GetTimestamp() + env.config.BanffTime = onAcceptState.GetTimestamp() executor := StandardTxExecutor{ - Backend: &freshTH.backend, + Backend: &env.backend, State: onAcceptState, Tx: tx, } @@ -1255,7 +1265,8 @@ func TestDurangoMemoField(t *testing.T) { it.Release() endTime := primaryValidator.EndTime - subnetValTx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: primaryValidator.NodeID, @@ -1265,9 +1276,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) @@ -1278,13 +1290,15 @@ func TestDurangoMemoField(t *testing.T) { Tx: subnetValTx, })) - tx, err := env.txBuilder.NewRemoveSubnetValidatorTx( + builder, signer = env.txBuilder.Builders(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 }, @@ -1292,7 +1306,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.txBuilder.Builders(preFundedKeys) + utx, err := builder.NewTransformSubnetTx( testSubnet1.TxID, // subnetID ids.GenerateTestID(), // assetID 10, // initial supply @@ -1307,10 +1322,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) @@ -1329,7 +1345,8 @@ func TestDurangoMemoField(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(t, err) - tx, err := env.txBuilder.NewAddPermissionlessValidatorTx( + txBuilder, txSigner := env.txBuilder.Builders(preFundedKeys) + utx, err := txBuilder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -1350,10 +1367,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) @@ -1396,6 +1414,8 @@ func TestDurangoMemoField(t *testing.T) { 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) @@ -1416,6 +1436,8 @@ func TestDurangoMemoField(t *testing.T) { 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) @@ -1443,6 +1465,8 @@ func TestDurangoMemoField(t *testing.T) { 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 f310616bb197..3ab354ded214 100644 --- a/vms/platformvm/txs/txstest/builder.go +++ b/vms/platformvm/txs/txstest/builder.go @@ -4,23 +4,13 @@ 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( @@ -41,311 +31,13 @@ type Builder struct { 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 (b *Builder) Builders(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, backend.state.GetTimestamp()) - builder = builder.New(addrs, context, backend) - signer = walletsigner.New(kc, backend) ) - 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 9effc6fbeeb2..120cbbb6ff52 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" @@ -48,6 +47,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" ) @@ -262,8 +262,8 @@ func addSubnetValidator(vm *VM, data *validatorInputData, subnetID ids.ID) (*sta vm.state, ) - addr := keys[0].PublicKey().Address() - signedTx, err := txBuilder.NewAddSubnetValidatorTx( + builder, signer := txBuilder.Builders(keys[0], keys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: data.nodeID, @@ -273,16 +273,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) } - return internalAddValidator(vm, signedTx) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + if err != nil { + return nil, fmt.Errorf("could not sign AddSubnetValidatorTx: %w", err) + } + return internalAddValidator(vm, tx) } func addPrimaryValidatorWithBLSKey(vm *VM, data *validatorInputData) (*state.Staker, error) { @@ -293,13 +296,14 @@ func addPrimaryValidatorWithBLSKey(vm *VM, data *validatorInputData) (*state.Sta return nil, fmt.Errorf("failed to generate BLS key: %w", err) } - txBuilder := txstest.NewBuilder( + builder := txstest.NewBuilder( vm.ctx, &vm.Config, vm.state, ) - signedTx, err := txBuilder.NewAddPermissionlessValidatorTx( + txBuilder, txSigner := builder.Builders(keys[0], keys[1]) + utx, err := txBuilder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: data.nodeID, @@ -320,16 +324,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) } - return internalAddValidator(vm, signedTx) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + if err != nil { + return nil, fmt.Errorf("could not sign AddPermissionlessValidatorTx: %w", err) + } + return internalAddValidator(vm, tx) } func internalAddValidator(vm *VM, signedTx *txs.Tx) (*state.Staker, error) { @@ -721,12 +728,12 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { // Create a subnet and store it in testSubnet1 // Note: following Banff activation, block acceptance will move // chain time ahead - testSubnet1, err = txBuilder.NewCreateSubnetTx( + builder, signer := txBuilder.Builders(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()}, @@ -735,6 +742,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() From 9e79a2c22b2427afd010dee0820200f286b7321c Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 29 Mar 2024 01:05:32 -0400 Subject: [PATCH 03/14] wip --- vms/platformvm/block/executor/helpers_test.go | 18 +++++---- vms/platformvm/service_test.go | 20 +++++----- .../txs/executor/create_chain_test.go | 39 ++++++++++++------- vms/platformvm/txs/executor/helpers_test.go | 5 +-- vms/platformvm/vm_test.go | 1 - 5 files changed, 47 insertions(+), 36 deletions(-) diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 0849146afcf6..34a238c9a883 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" @@ -50,6 +51,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" ) @@ -249,9 +251,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.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ @@ -260,7 +261,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()}, @@ -269,8 +269,8 @@ func addSubnet(env *environment) { if err != nil { panic(err) } + testSubnet1, err = walletsigner.SignUnsigned(context.Background(), signer, utx) - // store it genesisID := env.state.GetLastAccepted() stateDiff, err := state.NewDiff(genesisID, env.blkManager) if err != nil { @@ -489,7 +489,8 @@ func addPendingValidator( rewardAddress ids.ShortID, keys []*secp256k1.PrivateKey, ) (*txs.Tx, error) { - addPendingValidatorTx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.txBuilder.Builders(keys...) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -501,11 +502,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/service_test.go b/vms/platformvm/service_test.go index 9cfb550e4f11..7cf7eb4dd4eb 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" @@ -46,6 +45,7 @@ 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" @@ -536,7 +536,7 @@ func TestGetStake(t *testing.T) { stakeAmount = service.vm.MinValidatorStake + 54321 pendingStakerNodeID := ids.GenerateTestNodeID() pendingStakerEndTime := uint64(defaultGenesisTime.Add(defaultMinStakingDuration).Unix()) - utx2, err = builder.NewAddValidatorTx( + utx2, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingStakerNodeID, Start: uint64(defaultGenesisTime.Unix()), @@ -623,7 +623,8 @@ func TestGetCurrentValidators(t *testing.T) { service.vm.ctx.Lock.Lock() - delTx, err := txBuilder.NewAddDelegatorTx( + builder, signer := txBuilder.Builders(keys[0]) + utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: validatorNodeID, Start: uint64(delegatorStartTime.Unix()), @@ -634,13 +635,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( @@ -697,7 +699,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) @@ -760,23 +762,23 @@ func TestGetBlock(t *testing.T) { require := require.New(t) service, _, txBuilder := defaultService(t) service.vm.ctx.Lock.Lock() - service.vm.Config.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 := txBuilder.Builders(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/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index 97f543ab6f0d..63bb08a212eb 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -23,7 +23,8 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/utxo" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/chain/p/builder" - "github.com/ava-labs/avalanchego/wallet/chain/p/signer" + + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) // Ensure Execute fails when there are not enough control sigs @@ -33,15 +34,17 @@ func TestCreateChainTxInsufficientControlSigs(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - tx, err := env.txBuilder.NewCreateChainTx( + builder, signer := env.txBuilder.Builders(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:] @@ -65,15 +68,17 @@ func TestCreateChainTxWrongControlSig(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - tx, err := env.txBuilder.NewCreateChainTx( + builder, signer := env.txBuilder.Builders(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() @@ -104,15 +109,17 @@ func TestCreateChainTxNoSuchSubnet(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - tx, err := env.txBuilder.NewCreateChainTx( + builder, signer := env.txBuilder.Builders(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() @@ -135,15 +142,17 @@ func TestCreateChainTxValid(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - tx, err := env.txBuilder.NewCreateChainTx( + builder, signer := env.txBuilder.Builders(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) @@ -200,10 +209,10 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { cfg := *env.config cfg.CreateBlockchainTxFee = test.fee builderContext := txstest.NewContext(env.ctx, &cfg, env.state.GetTimestamp()) - backend := txstest.NewBackend(addrs, env.state, env.msm) - pBuilder := builder.New(addrs, builderContext, backend) + backend := txstest.NewBackend(addrs, env.state, env.ctx.SharedMemory) + builder := builder.New(addrs, builderContext, backend) - utx, err := pBuilder.NewCreateChainTx( + utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, // genesisData ids.GenerateTestID(), // vmID @@ -212,9 +221,9 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { ) require.NoError(err) - kc := secp256k1fx.NewKeychain(preFundedKeys...) - s := signer.New(kc, backend) - tx, err := signer.SignUnsigned(context.Background(), s, utx) + keychain := secp256k1fx.NewKeychain(preFundedKeys...) + signer := walletsigner.New(keychain, backend) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) require.NoError(err) stateDiff, err := state.NewDiff(lastAcceptedID, env) diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 0c8025616715..81eaa8b4b339 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -214,9 +214,7 @@ func addSubnet( ) { require := require.New(t) - // Create a subnet - var err error - builder, signer := env.txBuilder.Builders([]*secp256k1.PrivateKey{preFundedKeys[0]}) + builder, signer := env.txBuilder.Builders(preFundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, @@ -235,7 +233,6 @@ func addSubnet( 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/vm_test.go b/vms/platformvm/vm_test.go index 1eb98a115da6..5ee91bea61dc 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -2195,7 +2195,6 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - // Create a subnet createSubnetTx, err := txBuilder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, From e675b810c7ba7d9f74a28d1e37de111bf4c5219b Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 29 Mar 2024 01:12:35 -0400 Subject: [PATCH 04/14] wip --- .../block/executor/standard_block_test.go | 35 +++++++++++-------- vms/platformvm/txs/executor/import_test.go | 10 ++++-- .../txs/executor/standard_tx_executor_test.go | 14 ++++---- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index 880b706884e1..f8d5550a004e 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.txBuilder.Builders(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.txBuilder.Builders(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.txBuilder.Builders(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.txBuilder.Builders(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/txs/executor/import_test.go b/vms/platformvm/txs/executor/import_test.go index 4ae35d80ae03..b63060db32a7 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 @@ -115,11 +118,14 @@ func TestNewImportTx(t *testing.T) { require := require.New(t) env.msm.SharedMemory = tt.sharedMemory - tx, err := env.txBuilder.NewImportTx( + + builder, signer := env.txBuilder.Builders(tt.sourceKeys...) + utx, err := builder.NewImportTx( tt.sourceChainID, to, - tt.sourceKeys, ) + require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) require.ErrorIs(err, tt.expectedErr) if tt.expectedErr != nil { return diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index bc0b988b41f2..354477682142 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -74,7 +74,7 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { for _, test := range tests { env.config.BanffTime = test.banffTime - builder, signer := env.txBuilder.Builders([]*secp256k1.PrivateKey{preFundedKeys[0]}) + builder, signer := env.txBuilder.Builders(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.EmptyNodeID, @@ -117,7 +117,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { // [addMinStakeValidator] adds a new validator to the primary network's // pending validator set with the minimum staking amount addMinStakeValidator := func(target *environment) { - builder, signer := target.txBuilder.Builders([]*secp256k1.PrivateKey{preFundedKeys[0]}) + builder, signer := target.txBuilder.Builders(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -153,7 +153,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { // [addMaxStakeValidator] adds a new validator to the primary network's // pending validator set with the maximum staking amount addMaxStakeValidator := func(target *environment) { - builder, signer := target.txBuilder.Builders([]*secp256k1.PrivateKey{preFundedKeys[0]}) + builder, signer := target.txBuilder.Builders(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -331,7 +331,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { env := newEnvironment(t, apricotPhase5) env.config.ApricotPhase3Time = tt.AP3Time - builder, signer := env.txBuilder.Builders(tt.feeKeys) + builder, signer := env.txBuilder.Builders(tt.feeKeys...) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: tt.nodeID, @@ -1290,7 +1290,7 @@ func TestDurangoMemoField(t *testing.T) { Tx: subnetValTx, })) - builder, signer = env.txBuilder.Builders(preFundedKeys) + builder, signer = env.txBuilder.Builders(preFundedKeys...) utx2, err := builder.NewRemoveSubnetValidatorTx( primaryValidator.NodeID, testSubnet1.ID(), @@ -1306,7 +1306,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "TransformSubnetTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.txBuilder.Builders(preFundedKeys) + builder, signer := env.txBuilder.Builders(preFundedKeys...) utx, err := builder.NewTransformSubnetTx( testSubnet1.TxID, // subnetID ids.GenerateTestID(), // assetID @@ -1345,7 +1345,7 @@ func TestDurangoMemoField(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(t, err) - txBuilder, txSigner := env.txBuilder.Builders(preFundedKeys) + txBuilder, txSigner := env.txBuilder.Builders(preFundedKeys...) utx, err := txBuilder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ From 31610992d4e64af51d7f74ed551801b75654bc57 Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 29 Mar 2024 01:18:11 -0400 Subject: [PATCH 05/14] wip --- .../block/executor/proposal_block_test.go | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 0436251e9993..6209190b0993 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" ) @@ -712,7 +713,8 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { subnetValidatorNodeID := genesisNodeIDs[0] subnetVdr1StartTime := defaultValidateStartTime subnetVdr1EndTime := defaultValidateStartTime.Add(defaultMinStakingDuration) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, @@ -722,9 +724,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 +746,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 +756,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 +780,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 +792,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 +872,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.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subnetValidatorNodeID, @@ -877,9 +884,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 +906,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 +919,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) From a997230740ce84dc82a7f060813000050904739c Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 29 Mar 2024 01:27:44 -0400 Subject: [PATCH 06/14] wip --- .../txs/executor/create_chain_test.go | 17 ++++------ .../txs/executor/create_subnet_test.go | 19 +++++------- vms/platformvm/txs/txstest/backend.go | 2 +- vms/platformvm/txs/txstest/builder.go | 17 ++++++++-- vms/platformvm/txs/txstest/context.go | 31 ------------------- 5 files changed, 29 insertions(+), 57 deletions(-) delete mode 100644 vms/platformvm/txs/txstest/context.go diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index 63bb08a212eb..eeb4ea74c535 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -22,7 +22,6 @@ 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" - "github.com/ava-labs/avalanchego/wallet/chain/p/builder" walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) @@ -208,21 +207,17 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { cfg := *env.config cfg.CreateBlockchainTxFee = test.fee - builderContext := txstest.NewContext(env.ctx, &cfg, env.state.GetTimestamp()) - backend := txstest.NewBackend(addrs, env.state, env.ctx.SharedMemory) - builder := builder.New(addrs, builderContext, backend) + builderBlah := txstest.NewBuilder(env.ctx, &cfg, env.state) + builder, signer := builderBlah.Builders(preFundedKeys...) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), - nil, // genesisData - ids.GenerateTestID(), // vmID - nil, // fxIDs - "", // chainName + nil, + ids.GenerateTestID(), + nil, + "", ) require.NoError(err) - - keychain := secp256k1fx.NewKeychain(preFundedKeys...) - signer := walletsigner.New(keychain, backend) tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) require.NoError(err) diff --git a/vms/platformvm/txs/executor/create_subnet_test.go b/vms/platformvm/txs/executor/create_subnet_test.go index 8f5fecbe5bc6..fd8bffa4d650 100644 --- a/vms/platformvm/txs/executor/create_subnet_test.go +++ b/vms/platformvm/txs/executor/create_subnet_test.go @@ -17,8 +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" - "github.com/ava-labs/avalanchego/wallet/chain/p/builder" - "github.com/ava-labs/avalanchego/wallet/chain/p/signer" + + walletsigner "github.com/ava-labs/avalanchego/wallet/chain/p/signer" ) func TestCreateSubnetTxAP3FeeChange(t *testing.T) { @@ -66,18 +66,13 @@ func TestCreateSubnetTxAP3FeeChange(t *testing.T) { cfg := *env.config cfg.CreateSubnetTxFee = test.fee - builderContext := txstest.NewContext(env.ctx, &cfg, env.state.GetTimestamp()) - backend := txstest.NewBackend(addrs, env.state, env.msm) - pBuilder := builder.New(addrs, builderContext, backend) - - utx, err := pBuilder.NewCreateSubnetTx( - &secp256k1fx.OutputOwners{}, // owner + builderBlah := txstest.NewBuilder(env.ctx, &cfg, env.state) + builder, signer := builderBlah.Builders(preFundedKeys...) + utx, err := builder.NewCreateSubnetTx( + &secp256k1fx.OutputOwners{}, ) require.NoError(err) - - kc := secp256k1fx.NewKeychain(preFundedKeys...) - s := signer.New(kc, backend) - tx, err := signer.SignUnsigned(context.Background(), s, utx) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) require.NoError(err) stateDiff, err := state.NewDiff(lastAcceptedID, env) diff --git a/vms/platformvm/txs/txstest/backend.go b/vms/platformvm/txs/txstest/backend.go index b442ab63a33c..3ef798c0b69d 100644 --- a/vms/platformvm/txs/txstest/backend.go +++ b/vms/platformvm/txs/txstest/backend.go @@ -24,7 +24,7 @@ var ( _ signer.Backend = (*Backend)(nil) ) -func NewBackend( +func newBackend( addrs set.Set[ids.ShortID], state state.State, sharedMemory atomic.SharedMemory, diff --git a/vms/platformvm/txs/txstest/builder.go b/vms/platformvm/txs/txstest/builder.go index 3ab354ded214..0c0ac8f9f500 100644 --- a/vms/platformvm/txs/txstest/builder.go +++ b/vms/platformvm/txs/txstest/builder.go @@ -35,8 +35,21 @@ func (b *Builder) Builders(keys ...*secp256k1.PrivateKey) (builder.Builder, sign var ( kc = secp256k1fx.NewKeychain(keys...) addrs = kc.Addresses() - backend = NewBackend(addrs, b.state, b.ctx.SharedMemory) - context = NewContext(b.ctx, b.cfg, backend.state.GetTimestamp()) + backend = newBackend(addrs, b.state, b.ctx.SharedMemory) + + timestamp = b.state.GetTimestamp() + context = &builder.Context{ + NetworkID: b.ctx.NetworkID, + AVAXAssetID: b.ctx.AVAXAssetID, + BaseTxFee: b.cfg.TxFee, + CreateSubnetTxFee: b.cfg.GetCreateSubnetTxFee(timestamp), + TransformSubnetTxFee: b.cfg.TransformSubnetTxFee, + CreateBlockchainTxFee: b.cfg.GetCreateBlockchainTxFee(timestamp), + AddPrimaryNetworkValidatorFee: b.cfg.AddPrimaryNetworkValidatorFee, + AddPrimaryNetworkDelegatorFee: b.cfg.AddPrimaryNetworkDelegatorFee, + AddSubnetValidatorFee: b.cfg.AddSubnetValidatorFee, + AddSubnetDelegatorFee: b.cfg.AddSubnetDelegatorFee, + } ) return builder.New(addrs, context, backend), signer.New(kc, backend) diff --git a/vms/platformvm/txs/txstest/context.go b/vms/platformvm/txs/txstest/context.go deleted file mode 100644 index c4379ddf115f..000000000000 --- a/vms/platformvm/txs/txstest/context.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package txstest - -import ( - "time" - - "github.com/ava-labs/avalanchego/snow" - "github.com/ava-labs/avalanchego/vms/platformvm/config" - "github.com/ava-labs/avalanchego/wallet/chain/p/builder" -) - -func NewContext( - ctx *snow.Context, - cfg *config.Config, - timestamp time.Time, -) *builder.Context { - return &builder.Context{ - NetworkID: ctx.NetworkID, - AVAXAssetID: ctx.AVAXAssetID, - BaseTxFee: cfg.TxFee, - CreateSubnetTxFee: cfg.GetCreateSubnetTxFee(timestamp), - TransformSubnetTxFee: cfg.TransformSubnetTxFee, - CreateBlockchainTxFee: cfg.GetCreateBlockchainTxFee(timestamp), - AddPrimaryNetworkValidatorFee: cfg.AddPrimaryNetworkValidatorFee, - AddPrimaryNetworkDelegatorFee: cfg.AddPrimaryNetworkDelegatorFee, - AddSubnetValidatorFee: cfg.AddSubnetValidatorFee, - AddSubnetDelegatorFee: cfg.AddSubnetDelegatorFee, - } -} From 2bcf9983a82fa9d0d26fe2c365f001426c9ddc4d Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 29 Mar 2024 12:32:52 -0400 Subject: [PATCH 07/14] wip --- .../txs/executor/standard_tx_executor_test.go | 182 +++++++++++------- 1 file changed, 116 insertions(+), 66 deletions(-) diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 354477682142..e2368a85834d 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -381,7 +381,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -391,9 +392,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) @@ -412,7 +414,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -422,9 +425,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) @@ -443,7 +447,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.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), @@ -454,14 +459,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -471,9 +478,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) @@ -507,7 +515,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -517,9 +526,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) @@ -536,7 +546,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -546,9 +557,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) @@ -565,7 +577,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -575,9 +588,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) @@ -595,7 +609,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { env.state.SetTimestamp(newTimestamp) { - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -605,9 +620,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) @@ -626,7 +642,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + uSubnetTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -636,9 +653,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( @@ -657,7 +675,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -667,9 +686,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) @@ -677,9 +697,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) } @@ -690,7 +710,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Duplicate signatures startTime := defaultValidateStartTime.Add(time.Second) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -700,9 +721,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) @@ -726,7 +748,8 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Too few signatures startTime := defaultValidateStartTime.Add(time.Second) - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[2]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -736,9 +759,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) @@ -762,7 +786,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.txBuilder.Builders(testSubnet1ControlKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -772,9 +797,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())) @@ -797,7 +823,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -807,9 +834,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( @@ -848,7 +876,8 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator's start time too early - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(defaultValidateStartTime.Unix()) - 1, @@ -860,9 +889,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) @@ -879,7 +909,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.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -890,10 +921,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( @@ -922,7 +954,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.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -933,10 +966,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(), @@ -962,7 +996,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.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -974,9 +1009,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) @@ -1017,7 +1053,8 @@ func TestDurangoDisabledTransactions(t *testing.T) { endTime = chainTime.Add(defaultMaxStakingDuration) ) - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.txBuilder.Builders(preFundedKeys...) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: 0, @@ -1028,10 +1065,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 }, @@ -1053,7 +1091,8 @@ func TestDurangoDisabledTransactions(t *testing.T) { } it.Release() - tx, err := env.txBuilder.NewAddDelegatorTx( + builder, signer := env.txBuilder.Builders(preFundedKeys...) + utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: primaryValidator.NodeID, Start: 0, @@ -1064,9 +1103,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 }, @@ -1121,7 +1161,8 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.txBuilder.Builders(preFundedKeys...) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: primaryValidator.NodeID, @@ -1131,10 +1172,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) @@ -1144,16 +1186,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.txBuilder.Builders(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) @@ -1164,15 +1208,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.txBuilder.Builders(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) @@ -1203,17 +1249,19 @@ func TestDurangoMemoField(t *testing.T) { ) env.msm.SharedMemory = sharedMemory - tx, err := env.txBuilder.NewImportTx( + builder, signer := env.txBuilder.Builders(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) @@ -1224,7 +1272,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.txBuilder.Builders(preFundedKeys...) + utx, err := builder.NewExportTx( env.ctx.XChainID, []*avax.TransferableOutput{{ Asset: avax.Asset{ID: env.ctx.AVAXAssetID}, @@ -1237,10 +1286,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) @@ -1395,7 +1445,8 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() - tx, err := env.txBuilder.NewAddPermissionlessDelegatorTx( + builder, signer := env.txBuilder.Builders(preFundedKeys...) + utx, err := builder.NewAddPermissionlessDelegatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: primaryValidator.NodeID, @@ -1410,7 +1461,6 @@ func TestDurangoMemoField(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }, - preFundedKeys, common.WithMemo(memoField), ) require.NoError(t, err) @@ -1426,13 +1476,13 @@ 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.txBuilder.Builders(preFundedKeys...) + utx, err := builder.NewTransferSubnetOwnershipTx( testSubnet1.TxID, &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }, - preFundedKeys, common.WithMemo(memoField), ) require.NoError(t, err) @@ -1448,7 +1498,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.txBuilder.Builders(preFundedKeys...) + utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { Asset: avax.Asset{ID: env.ctx.AVAXAssetID}, @@ -1461,7 +1512,6 @@ func TestDurangoMemoField(t *testing.T) { }, }, }, - preFundedKeys, common.WithMemo(memoField), ) require.NoError(t, err) From 2e9298b0de02db835d918ff3b3c87fdacd125f15 Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 29 Mar 2024 12:41:39 -0400 Subject: [PATCH 08/14] wip --- .../block/executor/proposal_block_test.go | 81 ++++++++++--------- .../txs/executor/proposal_tx_executor_test.go | 9 ++- 2 files changed, 50 insertions(+), 40 deletions(-) diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 6209190b0993..934f98777093 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -538,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.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: staker.nodeID, Start: uint64(staker.startTime.Unix()), @@ -550,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(), @@ -570,7 +572,8 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { } for _, subStaker := range test.subnetStakers { - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: subStaker.nodeID, @@ -580,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(), @@ -605,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.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: staker0.nodeID, Start: uint64(staker0.startTime.Unix()), @@ -617,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) @@ -997,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.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), Start: uint64(staker0StartTime.Unix()), @@ -1009,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) @@ -1066,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.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(pendingDelegatorStartTime.Unix()), @@ -1077,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(), @@ -1099,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.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + utx, err = builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), Start: uint64(staker0StartTime.Unix()), @@ -1111,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) @@ -1192,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.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), Start: uint64(staker0StartTime.Unix()), @@ -1204,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) @@ -1260,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.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(pendingDelegatorStartTime.Unix()), @@ -1271,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(), @@ -1293,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.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + utx, err = builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), Start: uint64(staker0StartTime.Unix()), @@ -1305,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) @@ -1375,7 +1385,8 @@ func TestAddValidatorProposalBlock(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - addValidatorTx, err := env.txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -1396,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() @@ -1462,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, @@ -1483,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/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index 582e622b2221..6d047d5acee7 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) { @@ -884,7 +887,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.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), Start: uint64(defaultValidateStartTime.Unix()) + 1, @@ -896,9 +900,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) From 12beac14fa33f842931c8058ce34958a8c887c63 Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:09:17 -0400 Subject: [PATCH 09/14] nits --- vms/platformvm/txs/executor/export_test.go | 1 + vms/platformvm/txs/executor/helpers_test.go | 3 +- .../txs/executor/proposal_tx_executor_test.go | 122 +++++++----- vms/platformvm/vm_regression_test.go | 175 ++++++++++++------ 4 files changed, 200 insertions(+), 101 deletions(-) diff --git a/vms/platformvm/txs/executor/export_test.go b/vms/platformvm/txs/executor/export_test.go index 278105964c5b..117834b6b63a 100644 --- a/vms/platformvm/txs/executor/export_test.go +++ b/vms/platformvm/txs/executor/export_test.go @@ -70,6 +70,7 @@ func TestNewExportTx(t *testing.T) { ) 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 81eaa8b4b339..5f5fe1160a51 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -178,7 +178,7 @@ func newEnvironment(t *testing.T, f fork) *environment { backend: backend, } - addSubnet(t, env, txBuilder) + addSubnet(t, env) t.Cleanup(func() { env.ctx.Lock.Lock() @@ -210,7 +210,6 @@ func newEnvironment(t *testing.T, f fork) *environment { func addSubnet( t *testing.T, env *environment, - txBuilder *txstest.Builder, ) { require := require.New(t) diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index 6d047d5acee7..4e779f84f867 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -36,7 +36,8 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { // [addMinStakeValidator] adds a new validator to the primary network's // pending validator set with the minimum staking amount addMinStakeValidator := func(target *environment) { - tx, err := target.txBuilder.NewAddValidatorTx( + builder, signer := target.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, Start: newValidatorStartTime, @@ -47,10 +48,11 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{rewardAddress}, }, - reward.PercentDenominator, // Shares - []*secp256k1.PrivateKey{preFundedKeys[0]}, + reward.PercentDenominator, ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) addValTx := tx.Unsigned.(*txs.AddValidatorTx) staker, err := state.NewCurrentStaker( @@ -70,7 +72,8 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { // [addMaxStakeValidator] adds a new validator to the primary network's // pending validator set with the maximum staking amount addMaxStakeValidator := func(target *environment) { - tx, err := target.txBuilder.NewAddValidatorTx( + builder, signer := target.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, Start: newValidatorStartTime, @@ -81,10 +84,11 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{rewardAddress}, }, - reward.PercentDenominator, // Shared - []*secp256k1.PrivateKey{preFundedKeys[0]}, + reward.PercentDenominator, ) require.NoError(t, err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(t, err) addValTx := tx.Unsigned.(*txs.AddValidatorTx) staker, err := state.NewCurrentStaker( @@ -246,7 +250,8 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { freshTH := newEnvironment(t, apricotPhase5) freshTH.config.ApricotPhase3Time = tt.AP3Time - tx, err := freshTH.txBuilder.NewAddDelegatorTx( + builder, signer := freshTH.txBuilder.Builders(tt.feeKeys...) + utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: tt.nodeID, Start: tt.startTime, @@ -257,9 +262,10 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{tt.rewardAddress}, }, - tt.feeKeys, ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + require.NoError(err) if tt.setup != nil { tt.setup(freshTH) @@ -294,7 +300,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -304,9 +311,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) @@ -329,7 +337,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -339,9 +348,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) @@ -364,7 +374,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.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingDSValidatorID, Start: uint64(dsStartTime.Unix()), @@ -375,14 +386,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -392,9 +405,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) @@ -432,7 +446,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -442,9 +457,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) @@ -465,7 +481,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -475,9 +492,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) @@ -498,7 +516,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: pendingDSValidatorID, @@ -508,9 +527,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) @@ -533,7 +553,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { env.state.SetTimestamp(newTimestamp) { - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -543,9 +564,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) @@ -568,7 +590,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + uSubnetTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -578,9 +601,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( @@ -598,7 +622,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -608,9 +633,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) @@ -634,7 +660,8 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Too few signatures - tx, err := env.txBuilder.NewAddSubnetValidatorTx( + builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -644,9 +671,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) @@ -673,7 +701,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.txBuilder.Builders(testSubnet1ControlKeys[0], preFundedKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -683,9 +712,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())) @@ -711,7 +741,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.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -721,9 +752,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( @@ -767,7 +799,8 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator's start time too early - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(chainTime.Unix()), @@ -779,9 +812,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) @@ -803,7 +837,8 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { nodeID := genesisNodeIDs[0] // Case: Validator already validating primary network - tx, err := env.txBuilder.NewAddValidatorTx( + builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(defaultValidateStartTime.Unix()) + 1, @@ -815,9 +850,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) @@ -838,7 +874,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.txBuilder.Builders(preFundedKeys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -849,10 +886,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( diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 0218e115521d..b752f3079897 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -48,6 +48,7 @@ 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" ) @@ -64,7 +65,8 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { changeAddr := keys[0].PublicKey().Address() // create valid tx - addValidatorTx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := txBuilder.Builders(keys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(validatorStartTime.Unix()), @@ -76,13 +78,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() @@ -107,7 +110,8 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { firstDelegatorEndTime := firstDelegatorStartTime.Add(vm.MinStakeDuration) // create valid tx - addFirstDelegatorTx, err := txBuilder.NewAddDelegatorTx( + builder, txSigner = txBuilder.Builders(keys[0], keys[1]) + uDelTx1, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(firstDelegatorStartTime.Unix()), @@ -118,13 +122,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() @@ -151,7 +156,8 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { vm.clock.Set(secondDelegatorStartTime.Add(-10 * executor.SyncBound)) // create valid tx - addSecondDelegatorTx, err := txBuilder.NewAddDelegatorTx( + builder, txSigner = txBuilder.Builders(keys[0], keys[1], keys[3]) + uDelTx2, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(secondDelegatorStartTime.Unix()), @@ -162,13 +168,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() @@ -185,7 +192,8 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { thirdDelegatorEndTime := thirdDelegatorStartTime.Add(vm.MinStakeDuration) // create valid tx - addThirdDelegatorTx, err := txBuilder.NewAddDelegatorTx( + builder, txSigner = txBuilder.Builders(keys[0], keys[1], keys[4]) + uDelTx3, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(thirdDelegatorStartTime.Unix()), @@ -196,13 +204,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() @@ -264,7 +273,8 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { changeAddr := keys[0].PublicKey().Address() // create valid tx - addValidatorTx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := txBuilder.Builders(keys[0], keys[1]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(validatorStartTime.Unix()), @@ -276,13 +286,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() @@ -297,7 +308,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()), @@ -308,13 +319,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() @@ -329,7 +341,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()), @@ -340,13 +352,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() @@ -361,7 +374,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()), @@ -372,13 +385,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() @@ -393,7 +407,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()), @@ -404,13 +418,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() @@ -488,44 +503,49 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { vm.state, ) - addSubnetTx0, err := txBuilder.NewCreateSubnetTx( + builder, txSigner := txBuilder.Builders(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 = txBuilder.Builders(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) @@ -588,7 +608,8 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { newValidatorEndTime := newValidatorStartTime.Add(defaultMinStakingDuration) // Create the tx to add a new validator - addValidatorTx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := txBuilder.Builders(keys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(newValidatorStartTime.Unix()), @@ -600,9 +621,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() @@ -800,7 +822,8 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { nodeID0 := ids.GenerateTestNodeID() // Create the tx to add the first new validator - addValidatorTx0, err := txBuilder.NewAddValidatorTx( + builder, txSigner := txBuilder.Builders(keys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID0, Start: uint64(newValidatorStartTime0.Unix()), @@ -812,9 +835,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() @@ -976,7 +1000,8 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { nodeID1 := ids.GenerateTestNodeID() // Create the tx to add the second new validator - addValidatorTx1, err := txBuilder.NewAddValidatorTx( + builder, txSigner = txBuilder.Builders(keys[1]) + utx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID1, Start: uint64(newValidatorStartTime1.Unix()), @@ -988,9 +1013,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() @@ -1135,7 +1161,8 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { extraNodeID := ids.GenerateTestNodeID() // Create the tx to add the first new validator - addValidatorTx0, err := txBuilder.NewAddValidatorTx( + builder, txSigner := txBuilder.Builders(keys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: extraNodeID, Start: uint64(newValidatorStartTime0.Unix()), @@ -1147,9 +1174,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() @@ -1260,7 +1288,8 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { changeAddr := keys[0].PublicKey().Address() // create valid tx - addValidatorTx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := txBuilder.Builders(keys[0], keys[1]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(validatorStartTime.Unix()), @@ -1272,13 +1301,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() @@ -1293,7 +1323,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()), @@ -1304,13 +1334,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() @@ -1325,7 +1356,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()), @@ -1336,13 +1367,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. @@ -1369,7 +1401,8 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t nodeID := ids.GenerateTestNodeID() changeAddr := keys[0].PublicKey().Address() - addValidatorTx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := txBuilder.Builders(keys[0], keys[1]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(validatorStartTime.Unix()), @@ -1381,13 +1414,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)) @@ -1400,18 +1434,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)) @@ -1424,7 +1459,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, @@ -1434,13 +1469,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)) @@ -1461,16 +1497,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. @@ -1513,7 +1550,8 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t nodeID := ids.GenerateTestNodeID() changeAddr := keys[0].PublicKey().Address() - addValidatorTx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := txBuilder.Builders(keys[0], keys[1]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(validatorStartTime.Unix()), @@ -1525,13 +1563,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)) @@ -1544,18 +1583,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)) @@ -1568,7 +1608,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, @@ -1578,13 +1618,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)) @@ -1597,16 +1638,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. @@ -1659,7 +1701,8 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) // build primary network validator with BLS key - primaryTx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := txBuilder.Builders(keys...) + uPrimaryTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -1680,14 +1723,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, utx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(primaryTx)) @@ -1724,6 +1767,8 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { }), ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(subnetTx)) @@ -1814,6 +1859,8 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { }), ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) uPrimaryRestartTx := primaryRestartTx.Unsigned.(*txs.AddPermissionlessValidatorTx) vm.ctx.Lock.Unlock() @@ -1929,6 +1976,8 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { }), ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(primaryTx1)) @@ -2006,6 +2055,8 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { }), ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(primaryRestartTx)) @@ -2084,6 +2135,8 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { }), ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(primaryTx1)) @@ -2120,6 +2173,8 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { }), ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(subnetTx)) @@ -2209,6 +2264,8 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { }), ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(primaryRestartTx)) @@ -2294,6 +2351,8 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { }), ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(primaryTx1)) @@ -2327,6 +2386,8 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { }), ) require.NoError(err) + tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(subnetTx)) From e1ea8a6704301ad3a879d165b36a0211036431c5 Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:43:39 -0400 Subject: [PATCH 10/14] wip --- vms/platformvm/block/executor/helpers_test.go | 3 + vms/platformvm/vm_regression_test.go | 60 ++++---- vms/platformvm/vm_test.go | 133 ++++++++++++------ 3 files changed, 121 insertions(+), 75 deletions(-) diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 34a238c9a883..6e661b0c4ac9 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -270,6 +270,9 @@ func addSubnet(env *environment) { panic(err) } testSubnet1, err = walletsigner.SignUnsigned(context.Background(), signer, utx) + if err != nil { + panic(err) + } genesisID := env.state.GetLastAccepted() stateDiff, err := state.NewDiff(genesisID, env.blkManager) diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index b752f3079897..a38da0e15c41 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -1729,7 +1729,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { }), ) require.NoError(err) - primaryTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + primaryTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uPrimaryTx) require.NoError(err) vm.ctx.Lock.Unlock() @@ -1750,7 +1750,8 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) // insert the subnet validator - subnetTx, err := txBuilder.NewAddSubnetValidatorTx( + builder, txSigner = txBuilder.Builders(keys[0], keys[1]) + uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -1760,14 +1761,13 @@ 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) - tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + subnetTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddSubnetValTx) require.NoError(err) vm.ctx.Lock.Unlock() @@ -1831,7 +1831,8 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) require.NotEqual(sk1, sk2) - primaryRestartTx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner = txBuilder.Builders(keys...) + uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -1852,16 +1853,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) - tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + primaryRestartTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uPrimaryRestartTx) require.NoError(err) - uPrimaryRestartTx := primaryRestartTx.Unsigned.(*txs.AddPermissionlessValidatorTx) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(primaryRestartTx)) @@ -1957,7 +1956,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 := txBuilder.Builders(keys[0]) + uAddValTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(primaryStartTime1.Unix()), @@ -1969,14 +1970,13 @@ 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) - tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + primaryTx1, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddValTx1) require.NoError(err) vm.ctx.Lock.Unlock() @@ -2027,7 +2027,8 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { sk2, err := bls.NewSecretKey() require.NoError(err) - primaryRestartTx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner = txBuilder.Builders(keys...) + uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -2048,14 +2049,13 @@ 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) - tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + primaryRestartTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uPrimaryRestartTx) require.NoError(err) vm.ctx.Lock.Unlock() @@ -2116,7 +2116,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 := txBuilder.Builders(keys[0]) + uPrimaryTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(primaryStartTime1.Unix()), @@ -2128,14 +2130,13 @@ 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) - tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + primaryTx1, err := walletsigner.SignUnsigned(context.Background(), txSigner, uPrimaryTx1) require.NoError(err) vm.ctx.Lock.Unlock() @@ -2156,7 +2157,8 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { require.NoError(err) // insert the subnet validator - subnetTx, err := txBuilder.NewAddSubnetValidatorTx( + builder, txSigner = txBuilder.Builders(keys[0], keys[1]) + uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -2166,14 +2168,13 @@ 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) - tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + subnetTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddSubnetValTx) require.NoError(err) vm.ctx.Lock.Unlock() @@ -2236,7 +2237,8 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { sk2, err := bls.NewSecretKey() require.NoError(err) - primaryRestartTx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner = txBuilder.Builders(keys...) + uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -2257,14 +2259,13 @@ 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) - tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + primaryRestartTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uPrimaryRestartTx) require.NoError(err) vm.ctx.Lock.Unlock() @@ -2332,7 +2333,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 := txBuilder.Builders(keys[0]) + uPrimaryTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(primaryStartTime1.Unix()), @@ -2344,14 +2347,13 @@ 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) - tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + primaryTx1, err := walletsigner.SignUnsigned(context.Background(), txSigner, uPrimaryTx1) require.NoError(err) vm.ctx.Lock.Unlock() @@ -2369,7 +2371,8 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { require.NoError(err) // insert the subnet validator - subnetTx, err := txBuilder.NewAddSubnetValidatorTx( + builder, txSigner = txBuilder.Builders(keys[0], keys[1]) + uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -2379,14 +2382,13 @@ 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) - tx, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx) + subnetTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddSubnetValTx) require.NoError(err) vm.ctx.Lock.Unlock() diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 5ee91bea61dc..415c20e2eb07 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -69,6 +69,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" ) @@ -303,7 +304,7 @@ func defaultVM(t *testing.T, f fork) (*VM, *txstest.Builder, database.Database, require.NoError(vm.SetState(context.Background(), snow.NormalOp)) - builder := txstest.NewBuilder( + txBuilder := txstest.NewBuilder( ctx, &vm.Config, vm.state, @@ -312,8 +313,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 := txBuilder.Builders(keys[0]) + utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, Addrs: []ids.ShortID{ @@ -322,13 +323,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() @@ -345,7 +348,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, txBuilder, db, msm } // Ensure genesis state is parsed from bytes and stored correctly @@ -419,7 +422,8 @@ func TestAddValidatorCommit(t *testing.T) { require.NoError(err) // create valid tx - tx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := txBuilder.Builders(keys[0]) + utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -440,9 +444,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() @@ -476,7 +481,8 @@ func TestInvalidAddValidatorCommit(t *testing.T) { endTime := startTime.Add(defaultMinStakingDuration) // create invalid tx - tx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := txBuilder.Builders(keys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -488,9 +494,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) @@ -533,7 +540,8 @@ func TestAddValidatorReject(t *testing.T) { ) // create valid tx - tx, err := txBuilder.NewAddValidatorTx( + builder, txSigner := txBuilder.Builders(keys[0]) + utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, Start: uint64(startTime.Unix()), @@ -545,9 +553,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() @@ -584,7 +593,8 @@ func TestAddValidatorInvalidNotReissued(t *testing.T) { require.NoError(err) // create valid tx - tx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := txBuilder.Builders(keys[0]) + utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: repeatNodeID, @@ -605,9 +615,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() @@ -632,7 +643,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 := txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -642,9 +654,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() @@ -682,7 +695,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 := txBuilder.Builders(testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) + utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -692,9 +706,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() @@ -871,15 +886,17 @@ func TestCreateChain(t *testing.T) { vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - tx, err := txBuilder.NewCreateChainTx( + builder, txSigner := txBuilder.Builders(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)) @@ -919,8 +936,8 @@ func TestCreateSubnet(t *testing.T) { vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - nodeID := genesisNodeIDs[0] - createSubnetTx, err := txBuilder.NewCreateSubnetTx( + builder, txSigner := txBuilder.Builders(keys[0]) + uCreateSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, Addrs: []ids.ShortID{ @@ -928,13 +945,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) vm.ctx.Lock.Unlock() require.NoError(vm.issueTxFromRPC(createSubnetTx)) @@ -965,10 +983,11 @@ func TestCreateSubnet(t *testing.T) { require.True(found) // 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, @@ -978,9 +997,10 @@ func TestCreateSubnet(t *testing.T) { }, Subnet: createSubnetTx.ID(), }, - []*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)) @@ -1037,15 +1057,17 @@ func TestAtomicImport(t *testing.T) { mutableSharedMemory.SharedMemory = m.NewSharedMemory(vm.ctx.ChainID) peerSharedMemory := m.NewSharedMemory(vm.ctx.XChainID) - _, err := txBuilder.NewImportTx( + builder, txSigner := txBuilder.Builders(keys[0]) + utx, 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) + _, err = walletsigner.SignUnsigned(context.Background(), txSigner, utx) + require.NoError(err) // Provide the avm UTXO @@ -1078,15 +1100,17 @@ func TestAtomicImport(t *testing.T) { }, })) - tx, err := txBuilder.NewImportTx( + builder, txSigner = txBuilder.Builders(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)) @@ -2074,7 +2098,8 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - addValidatorTx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := txBuilder.Builders(keys[0]) + uAddValTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -2095,13 +2120,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)) @@ -2114,18 +2140,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)) @@ -2138,7 +2165,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 = txBuilder.Builders(key, keys[1]) + uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -2148,24 +2176,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 = txBuilder.Builders(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(), @@ -2195,18 +2226,21 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - createSubnetTx, err := txBuilder.NewCreateSubnetTx( + builder, txSigner := txBuilder.Builders(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() @@ -2237,15 +2271,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)) @@ -2283,7 +2318,8 @@ func TestBaseTx(t *testing.T) { sendAmt := uint64(100000) changeAddr := ids.ShortEmpty - baseTx, err := txBuilder.NewBaseTx( + builder, txSigner := txBuilder.Builders(keys[0]) + utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { Asset: avax.Asset{ID: vm.ctx.AVAXAssetID}, @@ -2298,13 +2334,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) @@ -2368,7 +2405,8 @@ func TestPruneMempool(t *testing.T) { sendAmt := uint64(100000) changeAddr := ids.ShortEmpty - baseTx, err := txBuilder.NewBaseTx( + builder, txSigner := txBuilder.Builders(keys[0]) + utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { Asset: avax.Asset{ID: vm.ctx.AVAXAssetID}, @@ -2383,13 +2421,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)) @@ -2409,7 +2448,8 @@ func TestPruneMempool(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - addValidatorTx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner = txBuilder.Builders(keys[1]) + uAddValTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -2430,9 +2470,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)) From 76d57505a58f4c0c8b4773525448e66f2cd36ad3 Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:55:12 -0400 Subject: [PATCH 11/14] ci passing --- vms/platformvm/txs/executor/import_test.go | 3 +-- vms/platformvm/vm_test.go | 12 +++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/vms/platformvm/txs/executor/import_test.go b/vms/platformvm/txs/executor/import_test.go index b63060db32a7..ab67dca4bf23 100644 --- a/vms/platformvm/txs/executor/import_test.go +++ b/vms/platformvm/txs/executor/import_test.go @@ -124,12 +124,11 @@ func TestNewImportTx(t *testing.T) { tt.sourceChainID, to, ) - require.NoError(err) - tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) 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/vm_test.go b/vms/platformvm/vm_test.go index 415c20e2eb07..bcc157d9be48 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -329,7 +329,7 @@ func defaultVM(t *testing.T, f fork) (*VM, *txstest.Builder, database.Database, }), ) require.NoError(err) - testSubnet1, err := walletsigner.SignUnsigned(context.Background(), signer, utx) + testSubnet1, err = walletsigner.SignUnsigned(context.Background(), signer, utx) require.NoError(err) vm.ctx.Lock.Unlock() @@ -1057,8 +1057,8 @@ func TestAtomicImport(t *testing.T) { mutableSharedMemory.SharedMemory = m.NewSharedMemory(vm.ctx.ChainID) peerSharedMemory := m.NewSharedMemory(vm.ctx.XChainID) - builder, txSigner := txBuilder.Builders(keys[0]) - utx, err := builder.NewImportTx( + builder, _ := txBuilder.Builders(keys[0]) + _, err := builder.NewImportTx( vm.ctx.XChainID, &secp256k1fx.OutputOwners{ Threshold: 1, @@ -1066,8 +1066,6 @@ func TestAtomicImport(t *testing.T) { }, ) require.ErrorIs(err, walletbuilder.ErrInsufficientFunds) - _, err = walletsigner.SignUnsigned(context.Background(), txSigner, utx) - require.NoError(err) // Provide the avm UTXO @@ -1100,8 +1098,8 @@ func TestAtomicImport(t *testing.T) { }, })) - builder, txSigner = txBuilder.Builders(recipientKey) - utx, err = builder.NewImportTx( + builder, txSigner := txBuilder.Builders(recipientKey) + utx, err := builder.NewImportTx( vm.ctx.XChainID, &secp256k1fx.OutputOwners{ Threshold: 1, From dd9a29919b59ea391a0c23559482550cb13e8f70 Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:12:59 -0400 Subject: [PATCH 12/14] rename to walletfactory --- vms/platformvm/block/builder/builder_test.go | 14 +-- vms/platformvm/block/builder/helpers_test.go | 11 +-- .../block/builder/standard_block_test.go | 2 +- vms/platformvm/block/executor/helpers_test.go | 11 +-- .../block/executor/proposal_block_test.go | 24 ++--- .../block/executor/standard_block_test.go | 8 +- vms/platformvm/service_test.go | 44 ++++----- .../txs/executor/advance_time_test.go | 12 +-- .../txs/executor/create_chain_test.go | 12 +-- .../txs/executor/create_subnet_test.go | 4 +- vms/platformvm/txs/executor/export_test.go | 2 +- vms/platformvm/txs/executor/helpers_test.go | 12 +-- vms/platformvm/txs/executor/import_test.go | 2 +- .../txs/executor/proposal_tx_executor_test.go | 40 ++++---- .../txs/executor/reward_validator_test.go | 8 +- .../txs/executor/standard_tx_executor_test.go | 94 ++++++++++--------- vms/platformvm/txs/txstest/builder.go | 14 +-- vms/platformvm/validator_set_property_test.go | 29 ++---- vms/platformvm/vm_regression_test.go | 74 +++++++-------- vms/platformvm/vm_test.go | 68 +++++++------- 20 files changed, 231 insertions(+), 254 deletions(-) diff --git a/vms/platformvm/block/builder/builder_test.go b/vms/platformvm/block/builder/builder_test.go index 361e7fca83e5..0693a6752c26 100644 --- a/vms/platformvm/block/builder/builder_test.go +++ b/vms/platformvm/block/builder/builder_test.go @@ -39,7 +39,7 @@ func TestBuildBlockBasic(t *testing.T) { defer env.ctx.Lock.Unlock() // Create a valid transaction - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -111,8 +111,8 @@ func TestBuildBlockShouldReward(t *testing.T) { require.NoError(err) // Create a valid [AddPermissionlessValidatorTx] - txBuilder, txSigner := env.txBuilder.Builders(preFundedKeys[0]) - utx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := env.factory.MakeWallet(preFundedKeys[0]) + utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -251,7 +251,7 @@ func TestBuildBlockForceAdvanceTime(t *testing.T) { defer env.ctx.Lock.Unlock() // Create a valid transaction - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -320,7 +320,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder1, signer1 := env.txBuilder.Builders(preFundedKeys[0]) + builder1, signer1 := env.factory.MakeWallet(preFundedKeys[0]) utx1, err := builder1.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -361,7 +361,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { sk, err = bls.NewSecretKey() require.NoError(err) - builder2, signer2 := env.txBuilder.Builders(preFundedKeys[2]) + builder2, signer2 := env.factory.MakeWallet(preFundedKeys[2]) utx2, err := builder2.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -426,7 +426,7 @@ func TestPreviouslyDroppedTxsCannotBeReAddedToMempool(t *testing.T) { defer env.ctx.Lock.Unlock() // Create a valid transaction - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 4e3ef64e5f9b..5e0e8a7a0e8a 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -117,7 +117,7 @@ type environment struct { state state.State uptimes uptime.Manager utxosVerifier utxo.Verifier - txBuilder *txstest.Builder + factory *txstest.WalletFactory backend txexecutor.Backend } @@ -151,12 +151,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{ @@ -239,7 +234,7 @@ func newEnvironment(t *testing.T, f fork) *environment { //nolint:unparam func addSubnet(t *testing.T, env *environment) { require := require.New(t) - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, diff --git a/vms/platformvm/block/builder/standard_block_test.go b/vms/platformvm/block/builder/standard_block_test.go index 6a93b81124e6..36547342bed9 100644 --- a/vms/platformvm/block/builder/standard_block_test.go +++ b/vms/platformvm/block/builder/standard_block_test.go @@ -63,7 +63,7 @@ func TestAtomicTxImports(t *testing.T) { }}}, })) - builder, signer := env.txBuilder.Builders(recipientKey) + builder, signer := env.factory.MakeWallet(recipientKey) utx, err := builder.NewImportTx( env.ctx.XChainID, &secp256k1fx.OutputOwners{ diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 6e661b0c4ac9..c2420a03b51b 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -130,7 +130,7 @@ type environment struct { mockedState *state.MockState uptimes uptime.Manager utxosVerifier utxo.Verifier - txBuilder *txstest.Builder + factory *txstest.WalletFactory backend *executor.Backend } @@ -158,7 +158,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 +168,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,7 +250,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f fork) *environment } func addSubnet(env *environment) { - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, @@ -492,7 +491,7 @@ func addPendingValidator( rewardAddress ids.ShortID, keys []*secp256k1.PrivateKey, ) (*txs.Tx, error) { - builder, signer := env.txBuilder.Builders(keys...) + builder, signer := env.factory.MakeWallet(keys...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 934f98777093..d37f99fc6791 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -538,7 +538,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { env.config.TrackedSubnets.Add(subnetID) for _, staker := range test.stakers { - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: staker.nodeID, @@ -572,7 +572,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { } for _, subStaker := range test.subnetStakers { - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -609,7 +609,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0.endTime = newTime - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: staker0.nodeID, @@ -719,7 +719,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { subnetValidatorNodeID := genesisNodeIDs[0] subnetVdr1StartTime := defaultValidateStartTime subnetVdr1EndTime := defaultValidateStartTime.Add(defaultMinStakingDuration) - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -879,7 +879,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { subnetVdr1StartTime := defaultGenesisTime.Add(1 * time.Minute) subnetVdr1EndTime := defaultGenesisTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1003,7 +1003,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // just to allow proposalBlk issuance (with a reward Tx) staker0StartTime := defaultGenesisTime staker0EndTime := pendingValidatorStartTime - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1074,7 +1074,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - builder, signer = env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, signer = env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -1105,7 +1105,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0EndTime = pendingDelegatorStartTime - builder, signer = env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, signer = env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err = builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1200,7 +1200,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // so to allow proposalBlk issuance staker0StartTime := defaultGenesisTime staker0EndTime := pendingValidatorStartTime - builder, txSigner := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, txSigner := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1270,7 +1270,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // Add delegator pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(defaultMinStakingDuration) - builder, txSigner = env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, txSigner = env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -1301,7 +1301,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0EndTime = pendingDelegatorStartTime - builder, txSigner = env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, txSigner = env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err = builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1385,7 +1385,7 @@ func TestAddValidatorProposalBlock(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, txSigner := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index f8d5550a004e..03a96e286d24 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -510,7 +510,7 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { } for _, staker := range test.subnetStakers { - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -604,7 +604,7 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { subnetValidatorNodeID := genesisNodeIDs[0] subnetVdr1StartTime := defaultValidateStartTime subnetVdr1EndTime := defaultValidateStartTime.Add(defaultMinStakingDuration) - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -710,7 +710,7 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { subnetValidatorNodeID := genesisNodeIDs[0] subnetVdr1StartTime := defaultGenesisTime.Add(1 * time.Minute) subnetVdr1EndTime := defaultGenesisTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -805,7 +805,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 7cf7eb4dd4eb..a915b662835f 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -75,8 +75,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 +84,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 +120,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() @@ -167,7 +167,7 @@ func TestGetTxStatus(t *testing.T) { mutableSharedMemory.SharedMemory = sm - builder, signer := txBuilder.Builders(recipientKey) + builder, signer := factory.MakeWallet(recipientKey) utx, err := builder.NewImportTx( service.vm.ctx.XChainID, &secp256k1fx.OutputOwners{ @@ -213,15 +213,15 @@ 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) { - txBuilder, signer := builder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) - utx, err := txBuilder.NewCreateChainTx( + func(_ *Service, factory *txstest.WalletFactory) (*txs.Tx, error) { + builder, signer := factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + utx, err := builder.NewCreateChainTx( testSubnet1.ID(), []byte{}, constants.AVMID, @@ -238,7 +238,7 @@ func TestGetTx(t *testing.T) { }, { "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) @@ -247,8 +247,8 @@ func TestGetTx(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, } - txBuilder, txSigner := builder.Builders(keys[0]) - utx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := factory.MakeWallet(keys[0]) + utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -274,9 +274,9 @@ func TestGetTx(t *testing.T) { }, { "atomic block", - func(service *Service, builder *txstest.Builder) (*txs.Tx, error) { - txBuilder, txSigner := builder.Builders(keys[0]) - utx, err := txBuilder.NewExportTx( + func(service *Service, factory *txstest.WalletFactory) (*txs.Tx, error) { + builder, signer := factory.MakeWallet(keys[0]) + utx, err := builder.NewExportTx( service.vm.ctx.XChainID, []*avax.TransferableOutput{{ Asset: avax.Asset{ID: service.vm.ctx.AVAXAssetID}, @@ -295,7 +295,7 @@ func TestGetTx(t *testing.T) { }), ) require.NoError(t, err) - return walletsigner.SignUnsigned(context.Background(), txSigner, utx) + return walletsigner.SignUnsigned(context.Background(), signer, utx) }, }, } @@ -400,7 +400,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) @@ -472,7 +472,7 @@ func TestGetStake(t *testing.T) { delegatorNodeID := genesisNodeIDs[0] delegatorStartTime := defaultValidateStartTime delegatorEndTime := defaultGenesisTime.Add(defaultMinStakingDuration) - builder, signer := txBuilder.Builders(keys[0]) + builder, signer := factory.MakeWallet(keys[0]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: delegatorNodeID, @@ -589,7 +589,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) @@ -623,7 +623,7 @@ func TestGetCurrentValidators(t *testing.T) { service.vm.ctx.Lock.Lock() - builder, signer := txBuilder.Builders(keys[0]) + builder, signer := factory.MakeWallet(keys[0]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: validatorNodeID, @@ -760,11 +760,11 @@ 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.Config.CreateAssetTxFee = 100 * defaultTxFee - builder, signer := txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), []byte{}, diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index 8f0313254d98..e5699f65aa5b 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -379,7 +379,7 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { } for _, staker := range test.subnetStakers { - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -479,7 +479,7 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { subnetVdr1StartTime := defaultValidateStartTime subnetVdr1EndTime := defaultValidateStartTime.Add(defaultMinStakingDuration) - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -593,7 +593,7 @@ func TestTrackedSubnet(t *testing.T) { subnetVdr1StartTime := defaultValidateStartTime.Add(1 * time.Minute) subnetVdr1EndTime := defaultValidateStartTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -700,7 +700,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -800,7 +800,7 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { // Add delegator pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(defaultMinStakingDuration) - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -918,7 +918,7 @@ func addPendingValidator( nodeID ids.NodeID, keys []*secp256k1.PrivateKey, ) (*txs.Tx, error) { - builder, signer := env.txBuilder.Builders(keys...) + builder, signer := env.factory.MakeWallet(keys...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index eeb4ea74c535..ca677f45ed9e 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -33,7 +33,7 @@ func TestCreateChainTxInsufficientControlSigs(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - builder, signer := env.txBuilder.Builders(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -67,7 +67,7 @@ func TestCreateChainTxWrongControlSig(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -108,7 +108,7 @@ func TestCreateChainTxNoSuchSubnet(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -141,7 +141,7 @@ func TestCreateChainTxValid(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -208,8 +208,8 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { cfg := *env.config cfg.CreateBlockchainTxFee = test.fee - builderBlah := txstest.NewBuilder(env.ctx, &cfg, env.state) - builder, signer := builderBlah.Builders(preFundedKeys...) + factory := txstest.NewWalletFactory(env.ctx, &cfg, env.state) + builder, signer := factory.MakeWallet(preFundedKeys...) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, diff --git a/vms/platformvm/txs/executor/create_subnet_test.go b/vms/platformvm/txs/executor/create_subnet_test.go index fd8bffa4d650..7ae34e5cbf79 100644 --- a/vms/platformvm/txs/executor/create_subnet_test.go +++ b/vms/platformvm/txs/executor/create_subnet_test.go @@ -66,8 +66,8 @@ func TestCreateSubnetTxAP3FeeChange(t *testing.T) { cfg := *env.config cfg.CreateSubnetTxFee = test.fee - builderBlah := txstest.NewBuilder(env.ctx, &cfg, env.state) - builder, signer := builderBlah.Builders(preFundedKeys...) + factory := txstest.NewWalletFactory(env.ctx, &cfg, env.state) + builder, signer := factory.MakeWallet(preFundedKeys...) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{}, ) diff --git a/vms/platformvm/txs/executor/export_test.go b/vms/platformvm/txs/executor/export_test.go index 117834b6b63a..f886bf33eb11 100644 --- a/vms/platformvm/txs/executor/export_test.go +++ b/vms/platformvm/txs/executor/export_test.go @@ -53,7 +53,7 @@ func TestNewExportTx(t *testing.T) { t.Run(tt.description, func(t *testing.T) { require := require.New(t) - builder, signer := env.txBuilder.Builders(tt.sourceKeys...) + builder, signer := env.factory.MakeWallet(tt.sourceKeys...) utx, err := builder.NewExportTx( tt.destinationChainID, []*avax.TransferableOutput{{ diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 5f5fe1160a51..5263af849340 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -106,7 +106,7 @@ type environment struct { states map[ids.ID]state.Chain uptimes uptime.Manager utxosHandler utxo.Verifier - txBuilder *txstest.Builder + factory *txstest.WalletFactory backend Backend } @@ -145,11 +145,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, @@ -174,7 +170,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, } @@ -213,7 +209,7 @@ func addSubnet( ) { require := require.New(t) - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, diff --git a/vms/platformvm/txs/executor/import_test.go b/vms/platformvm/txs/executor/import_test.go index ab67dca4bf23..9704d0280665 100644 --- a/vms/platformvm/txs/executor/import_test.go +++ b/vms/platformvm/txs/executor/import_test.go @@ -119,7 +119,7 @@ func TestNewImportTx(t *testing.T) { env.msm.SharedMemory = tt.sharedMemory - builder, signer := env.txBuilder.Builders(tt.sourceKeys...) + builder, signer := env.factory.MakeWallet(tt.sourceKeys...) utx, err := builder.NewImportTx( tt.sourceChainID, to, diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index 4e779f84f867..fd6d25ffcb1a 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -36,7 +36,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { // [addMinStakeValidator] adds a new validator to the primary network's // pending validator set with the minimum staking amount addMinStakeValidator := func(target *environment) { - builder, signer := target.txBuilder.Builders(preFundedKeys[0]) + builder, signer := target.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -72,7 +72,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { // [addMaxStakeValidator] adds a new validator to the primary network's // pending validator set with the maximum staking amount addMaxStakeValidator := func(target *environment) { - builder, signer := target.txBuilder.Builders(preFundedKeys[0]) + builder, signer := target.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -250,7 +250,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { freshTH := newEnvironment(t, apricotPhase5) freshTH.config.ApricotPhase3Time = tt.AP3Time - builder, signer := freshTH.txBuilder.Builders(tt.feeKeys...) + builder, signer := freshTH.factory.MakeWallet(tt.feeKeys...) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: tt.nodeID, @@ -300,7 +300,7 @@ 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) - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -337,7 +337,7 @@ 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) - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -374,7 +374,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { dsStartTime := defaultValidateStartTime.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingDSValidatorID, @@ -394,7 +394,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Proposed validator isn't in pending or current validator sets - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -446,7 +446,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Proposed validator is pending validator of primary network // but starts validating subnet before primary network - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -481,7 +481,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Proposed validator is pending validator of primary network // but stops validating subnet after primary network - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -516,7 +516,7 @@ 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 - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -553,7 +553,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { env.state.SetTimestamp(newTimestamp) { - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -590,7 +590,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { // Case: Proposed validator already validating the subnet // First, add validator as validator of subnet - builder, signer = env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer = env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) uSubnetTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -622,7 +622,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Node with ID nodeIDKey.PublicKey().Address() now validating subnet with ID testSubnet1.ID - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -660,7 +660,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Too few signatures - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -701,7 +701,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Control Signature from invalid key (keys[3] is not a control key) - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], preFundedKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -741,7 +741,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Proposed validator in pending validator set for subnet // First, add validator to pending validator set of subnet - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -799,7 +799,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator's start time too early - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -837,7 +837,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { nodeID := genesisNodeIDs[0] // Case: Validator already validating primary network - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -874,7 +874,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator in pending validator set of primary network startTime := defaultValidateStartTime.Add(1 * time.Second) - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -925,7 +925,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator doesn't have enough tokens to cover stake amount - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), diff --git a/vms/platformvm/txs/executor/reward_validator_test.go b/vms/platformvm/txs/executor/reward_validator_test.go index 478475ffb09c..9c9a2d7a7344 100644 --- a/vms/platformvm/txs/executor/reward_validator_test.go +++ b/vms/platformvm/txs/executor/reward_validator_test.go @@ -241,7 +241,7 @@ func TestRewardDelegatorTxExecuteOnCommitPreDelegateeDeferral(t *testing.T) { vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, @@ -373,7 +373,7 @@ func TestRewardDelegatorTxExecuteOnCommitPostDelegateeDeferral(t *testing.T) { vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, @@ -600,7 +600,7 @@ func TestRewardDelegatorTxAndValidatorTxExecuteOnCommitPostDelegateeDeferral(t * vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, @@ -773,7 +773,7 @@ func TestRewardDelegatorTxExecuteOnAbort(t *testing.T) { vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index e2368a85834d..d203e5a00445 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -74,7 +74,7 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { for _, test := range tests { env.config.BanffTime = test.banffTime - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.EmptyNodeID, @@ -116,14 +116,16 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { // [addMinStakeValidator] adds a new validator to the primary network's // pending validator set with the minimum staking amount - addMinStakeValidator := func(target *environment) { - builder, signer := target.txBuilder.Builders(preFundedKeys[0]) + addMinStakeValidator := func(env *environment) { + require := require.New(t) + + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, Start: uint64(newValidatorStartTime.Unix()), End: uint64(newValidatorEndTime.Unix()), - Wght: target.config.MinValidatorStake, + Wght: env.config.MinValidatorStake, }, &secp256k1fx.OutputOwners{ Threshold: 1, @@ -131,9 +133,9 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { }, reward.PercentDenominator, ) - require.NoError(t, err) + require.NoError(err) tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) - require.NoError(t, err) + require.NoError(err) addValTx := tx.Unsigned.(*txs.AddValidatorTx) staker, err := state.NewCurrentStaker( @@ -142,18 +144,18 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { newValidatorStartTime, 0, ) - require.NoError(t, err) + require.NoError(err) - target.state.PutCurrentValidator(staker) - target.state.AddTx(tx, status.Committed) - target.state.SetHeight(dummyHeight) - require.NoError(t, target.state.Commit()) + env.state.PutCurrentValidator(staker) + env.state.AddTx(tx, status.Committed) + env.state.SetHeight(dummyHeight) + require.NoError(env.state.Commit()) } // [addMaxStakeValidator] adds a new validator to the primary network's // pending validator set with the maximum staking amount addMaxStakeValidator := func(target *environment) { - builder, signer := target.txBuilder.Builders(preFundedKeys[0]) + builder, signer := target.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -331,7 +333,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { env := newEnvironment(t, apricotPhase5) env.config.ApricotPhase3Time = tt.AP3Time - builder, signer := env.txBuilder.Builders(tt.feeKeys...) + builder, signer := env.factory.MakeWallet(tt.feeKeys...) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: tt.nodeID, @@ -381,7 +383,7 @@ 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) - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -414,7 +416,7 @@ 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) - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -447,7 +449,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { dsStartTime := defaultGenesisTime.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingDSValidatorID, @@ -467,7 +469,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Proposed validator isn't in pending or current validator sets - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -515,7 +517,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Proposed validator is pending validator of primary network // but starts validating subnet before primary network - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -546,7 +548,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Proposed validator is pending validator of primary network // but stops validating subnet after primary network - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -577,7 +579,7 @@ 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 - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -609,7 +611,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { env.state.SetTimestamp(newTimestamp) { - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -642,7 +644,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // Case: Proposed validator already validating the subnet // First, add validator as validator of subnet - builder, signer = env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer = env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) uSubnetTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -675,7 +677,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Node with ID nodeIDKey.PublicKey().Address() now validating subnet with ID testSubnet1.ID startTime := defaultValidateStartTime.Add(time.Second) - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -710,7 +712,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Duplicate signatures startTime := defaultValidateStartTime.Add(time.Second) - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -748,7 +750,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Too few signatures startTime := defaultValidateStartTime.Add(time.Second) - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[2]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[2]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -786,7 +788,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Control Signature from invalid key (keys[3] is not a control key) startTime := defaultValidateStartTime.Add(time.Second) - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], preFundedKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -823,7 +825,7 @@ 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) - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -876,7 +878,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator's start time too early - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -909,7 +911,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator in current validator set of primary network startTime := defaultValidateStartTime.Add(1 * time.Second) - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -954,7 +956,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator in pending validator set of primary network startTime := defaultValidateStartTime.Add(1 * time.Second) - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -996,7 +998,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator doesn't have enough tokens to cover stake amount startTime := defaultValidateStartTime.Add(1 * time.Second) - builder, signer := env.txBuilder.Builders(preFundedKeys[0]) + builder, signer := env.factory.MakeWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1053,7 +1055,7 @@ func TestDurangoDisabledTransactions(t *testing.T) { endTime = chainTime.Add(defaultMaxStakingDuration) ) - builder, signer := env.txBuilder.Builders(preFundedKeys...) + builder, signer := env.factory.MakeWallet(preFundedKeys...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1091,7 +1093,7 @@ func TestDurangoDisabledTransactions(t *testing.T) { } it.Release() - builder, signer := env.txBuilder.Builders(preFundedKeys...) + builder, signer := env.factory.MakeWallet(preFundedKeys...) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: primaryValidator.NodeID, @@ -1161,7 +1163,7 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() - builder, signer := env.txBuilder.Builders(preFundedKeys...) + builder, signer := env.factory.MakeWallet(preFundedKeys...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1186,7 +1188,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "CreateChainTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.txBuilder.Builders(preFundedKeys...) + builder, signer := env.factory.MakeWallet(preFundedKeys...) utx, err := builder.NewCreateChainTx( testSubnet1.TxID, []byte{}, @@ -1208,7 +1210,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "CreateSubnetTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.txBuilder.Builders(preFundedKeys...) + builder, signer := env.factory.MakeWallet(preFundedKeys...) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, @@ -1249,7 +1251,7 @@ func TestDurangoMemoField(t *testing.T) { ) env.msm.SharedMemory = sharedMemory - builder, signer := env.txBuilder.Builders(preFundedKeys...) + builder, signer := env.factory.MakeWallet(preFundedKeys...) utx, err := builder.NewImportTx( sourceChain, &secp256k1fx.OutputOwners{ @@ -1272,7 +1274,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "ExportTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.txBuilder.Builders(preFundedKeys...) + builder, signer := env.factory.MakeWallet(preFundedKeys...) utx, err := builder.NewExportTx( env.ctx.XChainID, []*avax.TransferableOutput{{ @@ -1315,7 +1317,7 @@ func TestDurangoMemoField(t *testing.T) { it.Release() endTime := primaryValidator.EndTime - builder, signer := env.txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1340,7 +1342,7 @@ func TestDurangoMemoField(t *testing.T) { Tx: subnetValTx, })) - builder, signer = env.txBuilder.Builders(preFundedKeys...) + builder, signer = env.factory.MakeWallet(preFundedKeys...) utx2, err := builder.NewRemoveSubnetValidatorTx( primaryValidator.NodeID, testSubnet1.ID(), @@ -1356,7 +1358,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "TransformSubnetTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.txBuilder.Builders(preFundedKeys...) + builder, signer := env.factory.MakeWallet(preFundedKeys...) utx, err := builder.NewTransformSubnetTx( testSubnet1.TxID, // subnetID ids.GenerateTestID(), // assetID @@ -1395,8 +1397,8 @@ func TestDurangoMemoField(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(t, err) - txBuilder, txSigner := env.txBuilder.Builders(preFundedKeys...) - utx, err := txBuilder.NewAddPermissionlessValidatorTx( + builder, txSigner := env.factory.MakeWallet(preFundedKeys...) + utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: nodeID, @@ -1445,7 +1447,7 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() - builder, signer := env.txBuilder.Builders(preFundedKeys...) + builder, signer := env.factory.MakeWallet(preFundedKeys...) utx, err := builder.NewAddPermissionlessDelegatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1476,7 +1478,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "TransferSubnetOwnershipTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.txBuilder.Builders(preFundedKeys...) + builder, signer := env.factory.MakeWallet(preFundedKeys...) utx, err := builder.NewTransferSubnetOwnershipTx( testSubnet1.TxID, &secp256k1fx.OutputOwners{ @@ -1498,7 +1500,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "BaseTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.txBuilder.Builders(preFundedKeys...) + builder, signer := env.factory.MakeWallet(preFundedKeys...) utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { diff --git a/vms/platformvm/txs/txstest/builder.go b/vms/platformvm/txs/txstest/builder.go index 4a5d04414ba8..86750ed3757b 100644 --- a/vms/platformvm/txs/txstest/builder.go +++ b/vms/platformvm/txs/txstest/builder.go @@ -13,30 +13,30 @@ import ( "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) Builders(keys ...*secp256k1.PrivateKey) (builder.Builder, signer.Signer) { +func (w *WalletFactory) MakeWallet(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()) + backend = newBackend(addrs, w.state, w.ctx.SharedMemory) + context = newContext(w.ctx, w.cfg, w.state.GetTimestamp()) ) 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 120cbbb6ff52..6c360af8ca5f 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -256,13 +256,8 @@ 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, - ) - - builder, signer := txBuilder.Builders(keys[0], keys[1]) + factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) + builder, signer := factory.MakeWallet(keys[0], keys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -296,14 +291,9 @@ func addPrimaryValidatorWithBLSKey(vm *VM, data *validatorInputData) (*state.Sta return nil, fmt.Errorf("failed to generate BLS key: %w", err) } - builder := txstest.NewBuilder( - vm.ctx, - &vm.Config, - vm.state, - ) - - txBuilder, txSigner := builder.Builders(keys[0], keys[1]) - utx, err := txBuilder.NewAddPermissionlessValidatorTx( + factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) + builder, txSigner := factory.MakeWallet(keys[0], keys[1]) + utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ NodeID: data.nodeID, @@ -719,16 +709,11 @@ 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 - builder, signer := txBuilder.Builders(keys[len(keys)-1]) + factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) + builder, signer := factory.MakeWallet(keys[len(keys)-1]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index a38da0e15c41..b19edc6b2b5e 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -54,7 +54,7 @@ import ( 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 +65,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { changeAddr := keys[0].PublicKey().Address() // create valid tx - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -110,7 +110,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { firstDelegatorEndTime := firstDelegatorStartTime.Add(vm.MinStakeDuration) // create valid tx - builder, txSigner = txBuilder.Builders(keys[0], keys[1]) + builder, txSigner = factory.MakeWallet(keys[0], keys[1]) uDelTx1, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -156,7 +156,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { vm.clock.Set(secondDelegatorStartTime.Add(-10 * executor.SyncBound)) // create valid tx - builder, txSigner = txBuilder.Builders(keys[0], keys[1], keys[3]) + builder, txSigner = factory.MakeWallet(keys[0], keys[1], keys[3]) uDelTx2, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -192,7 +192,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { thirdDelegatorEndTime := thirdDelegatorStartTime.Add(vm.MinStakeDuration) // create valid tx - builder, txSigner = txBuilder.Builders(keys[0], keys[1], keys[4]) + builder, txSigner = factory.MakeWallet(keys[0], keys[1], keys[4]) uDelTx3, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -259,7 +259,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.ApricotPhase3Time = test.ap3Time vm.ctx.Lock.Lock() @@ -273,7 +273,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { changeAddr := keys[0].PublicKey().Address() // create valid tx - builder, txSigner := txBuilder.Builders(keys[0], keys[1]) + builder, txSigner := factory.MakeWallet(keys[0], keys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -497,13 +497,13 @@ 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, ) - builder, txSigner := txBuilder.Builders(key0) + builder, txSigner := factory.MakeWallet(key0) utx0, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, @@ -518,7 +518,7 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { addSubnetTx0, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx0) require.NoError(err) - builder, txSigner = txBuilder.Builders(key1) + builder, txSigner = factory.MakeWallet(key1) utx1, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, @@ -599,7 +599,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() @@ -608,7 +608,7 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { newValidatorEndTime := newValidatorStartTime.Add(defaultMinStakingDuration) // Create the tx to add a new validator - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -810,7 +810,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() @@ -822,7 +822,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { nodeID0 := ids.GenerateTestNodeID() // Create the tx to add the first new validator - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID0, @@ -1000,7 +1000,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { nodeID1 := ids.GenerateTestNodeID() // Create the tx to add the second new validator - builder, txSigner = txBuilder.Builders(keys[1]) + builder, txSigner = factory.MakeWallet(keys[1]) utx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID1, @@ -1134,7 +1134,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() @@ -1161,7 +1161,7 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { extraNodeID := ids.GenerateTestNodeID() // Create the tx to add the first new validator - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: extraNodeID, @@ -1276,7 +1276,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() @@ -1288,7 +1288,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { changeAddr := keys[0].PublicKey().Address() // create valid tx - builder, txSigner := txBuilder.Builders(keys[0], keys[1]) + builder, txSigner := factory.MakeWallet(keys[0], keys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1390,7 +1390,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() @@ -1401,7 +1401,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t nodeID := ids.GenerateTestNodeID() changeAddr := keys[0].PublicKey().Address() - builder, txSigner := txBuilder.Builders(keys[0], keys[1]) + builder, txSigner := factory.MakeWallet(keys[0], keys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1539,7 +1539,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() @@ -1550,7 +1550,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t nodeID := ids.GenerateTestNodeID() changeAddr := keys[0].PublicKey().Address() - builder, txSigner := txBuilder.Builders(keys[0], keys[1]) + builder, txSigner := factory.MakeWallet(keys[0], keys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1671,7 +1671,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() @@ -1701,7 +1701,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) // build primary network validator with BLS key - builder, txSigner := txBuilder.Builders(keys...) + builder, txSigner := factory.MakeWallet(keys...) uPrimaryTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1750,7 +1750,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = txBuilder.Builders(keys[0], keys[1]) + builder, txSigner = factory.MakeWallet(keys[0], keys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1831,7 +1831,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) require.NotEqual(sk1, sk2) - builder, txSigner = txBuilder.Builders(keys...) + builder, txSigner = factory.MakeWallet(keys...) uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1936,7 +1936,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() @@ -1957,7 +1957,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { nodeID := ids.GenerateTestNodeID() addr := keys[0].PublicKey().Address() - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) uAddValTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -2027,7 +2027,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { sk2, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner = txBuilder.Builders(keys...) + builder, txSigner = factory.MakeWallet(keys...) uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2092,7 +2092,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() @@ -2117,7 +2117,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { nodeID := ids.GenerateTestNodeID() addr := keys[0].PublicKey().Address() - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) uPrimaryTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -2157,7 +2157,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = txBuilder.Builders(keys[0], keys[1]) + builder, txSigner = factory.MakeWallet(keys[0], keys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2237,7 +2237,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { sk2, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner = txBuilder.Builders(keys...) + builder, txSigner = factory.MakeWallet(keys...) uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2311,7 +2311,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() @@ -2334,7 +2334,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { nodeID := ids.GenerateTestNodeID() addr := keys[0].PublicKey().Address() - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) uPrimaryTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -2371,7 +2371,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = txBuilder.Builders(keys[0], keys[1]) + builder, txSigner = factory.MakeWallet(keys[0], keys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index bcc157d9be48..78b055914847 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -204,7 +204,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 @@ -304,7 +304,7 @@ func defaultVM(t *testing.T, f fork) (*VM, *txstest.Builder, database.Database, require.NoError(vm.SetState(context.Background(), snow.NormalOp)) - txBuilder := txstest.NewBuilder( + factory := txstest.NewWalletFactory( ctx, &vm.Config, vm.state, @@ -313,7 +313,7 @@ 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 - builder, signer := txBuilder.Builders(keys[0]) + builder, signer := factory.MakeWallet(keys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, @@ -348,7 +348,7 @@ func defaultVM(t *testing.T, f fork) (*VM, *txstest.Builder, database.Database, require.NoError(vm.Shutdown(context.Background())) }) - return vm, txBuilder, db, msm + return vm, factory, db, msm } // Ensure genesis state is parsed from bytes and stored correctly @@ -407,7 +407,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() @@ -422,7 +422,7 @@ func TestAddValidatorCommit(t *testing.T) { require.NoError(err) // create valid tx - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -472,7 +472,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() @@ -481,7 +481,7 @@ func TestInvalidAddValidatorCommit(t *testing.T) { endTime := startTime.Add(defaultMinStakingDuration) // create invalid tx - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -528,7 +528,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() @@ -540,7 +540,7 @@ func TestAddValidatorReject(t *testing.T) { ) // create valid tx - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -579,7 +579,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() @@ -593,7 +593,7 @@ func TestAddValidatorInvalidNotReissued(t *testing.T) { require.NoError(err) // create valid tx - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -630,7 +630,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() @@ -643,7 +643,7 @@ 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]) - builder, txSigner := txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, txSigner := factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -682,7 +682,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() @@ -695,7 +695,7 @@ 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]) - builder, txSigner := txBuilder.Builders(testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) + builder, txSigner := factory.MakeWallet(testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -882,11 +882,11 @@ 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() - builder, txSigner := txBuilder.Builders(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, txSigner := factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -932,11 +932,11 @@ 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() - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) uCreateSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, @@ -1041,7 +1041,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() @@ -1057,7 +1057,7 @@ func TestAtomicImport(t *testing.T) { mutableSharedMemory.SharedMemory = m.NewSharedMemory(vm.ctx.ChainID) peerSharedMemory := m.NewSharedMemory(vm.ctx.XChainID) - builder, _ := txBuilder.Builders(keys[0]) + builder, _ := factory.MakeWallet(keys[0]) _, err := builder.NewImportTx( vm.ctx.XChainID, &secp256k1fx.OutputOwners{ @@ -1098,7 +1098,7 @@ func TestAtomicImport(t *testing.T) { }, })) - builder, txSigner := txBuilder.Builders(recipientKey) + builder, txSigner := factory.MakeWallet(recipientKey) utx, err := builder.NewImportTx( vm.ctx.XChainID, &secp256k1fx.OutputOwners{ @@ -2084,7 +2084,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() @@ -2096,7 +2096,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) uAddValTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2163,7 +2163,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { require.NoError(createSubnetBlock.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - builder, txSigner = txBuilder.Builders(key, keys[1]) + builder, txSigner = factory.MakeWallet(key, keys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2183,7 +2183,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { addSubnetValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddSubnetValTx) require.NoError(err) - builder, txSigner = txBuilder.Builders(key, keys[2]) + builder, txSigner = factory.MakeWallet(key, keys[2]) uRemoveSubnetValTx, err := builder.NewRemoveSubnetValidatorTx( nodeID, createSubnetTx.ID(), @@ -2220,11 +2220,11 @@ 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() - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) uCreateSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, @@ -2309,14 +2309,14 @@ 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 - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { @@ -2395,7 +2395,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() @@ -2403,7 +2403,7 @@ func TestPruneMempool(t *testing.T) { sendAmt := uint64(100000) changeAddr := ids.ShortEmpty - builder, txSigner := txBuilder.Builders(keys[0]) + builder, txSigner := factory.MakeWallet(keys[0]) utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { @@ -2446,7 +2446,7 @@ func TestPruneMempool(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner = txBuilder.Builders(keys[1]) + builder, txSigner = factory.MakeWallet(keys[1]) uAddValTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ From eb0da35ad9fe1a1a4ef3229ae0b9b3f5c972a392 Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Wed, 5 Jun 2024 23:07:51 -0400 Subject: [PATCH 13/14] nit --- vms/platformvm/txs/executor/create_chain_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index a25151366eea..74c598312e39 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -210,7 +210,7 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { cfg.StaticFeeConfig.CreateBlockchainTxFee = test.fee factory := txstest.NewWalletFactory(env.ctx, &cfg, env.state) builder, signer := factory.MakeWallet(preFundedKeys...) - tx, err := builder.NewCreateChainTx( + utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, ids.GenerateTestID(), From c556c82ac5fa9569d617deef71b7b0d918fabc9b Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Wed, 5 Jun 2024 23:46:02 -0400 Subject: [PATCH 14/14] `MakeWallet` -> `NewWallet` --- vms/platformvm/block/builder/builder_test.go | 12 ++-- vms/platformvm/block/builder/helpers_test.go | 2 +- .../block/builder/standard_block_test.go | 2 +- vms/platformvm/block/executor/helpers_test.go | 4 +- .../block/executor/proposal_block_test.go | 24 +++---- .../block/executor/standard_block_test.go | 8 +-- vms/platformvm/service_test.go | 14 ++-- .../txs/executor/advance_time_test.go | 12 ++-- .../txs/executor/create_chain_test.go | 10 +-- .../txs/executor/create_subnet_test.go | 2 +- vms/platformvm/txs/executor/export_test.go | 2 +- vms/platformvm/txs/executor/helpers_test.go | 2 +- vms/platformvm/txs/executor/import_test.go | 2 +- .../txs/executor/proposal_tx_executor_test.go | 40 +++++------ .../txs/executor/reward_validator_test.go | 8 +-- .../txs/executor/standard_tx_executor_test.go | 72 +++++++++---------- vms/platformvm/txs/txstest/builder.go | 2 +- vms/platformvm/validator_set_property_test.go | 6 +- vms/platformvm/vm_regression_test.go | 48 ++++++------- vms/platformvm/vm_test.go | 36 +++++----- 20 files changed, 154 insertions(+), 154 deletions(-) diff --git a/vms/platformvm/block/builder/builder_test.go b/vms/platformvm/block/builder/builder_test.go index f08787d7a634..eeddc5bc7f9b 100644 --- a/vms/platformvm/block/builder/builder_test.go +++ b/vms/platformvm/block/builder/builder_test.go @@ -39,7 +39,7 @@ func TestBuildBlockBasic(t *testing.T) { defer env.ctx.Lock.Unlock() // Create a valid transaction - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -111,7 +111,7 @@ func TestBuildBlockShouldReward(t *testing.T) { require.NoError(err) // Create a valid [AddPermissionlessValidatorTx] - builder, txSigner := env.factory.MakeWallet(preFundedKeys[0]) + builder, txSigner := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -251,7 +251,7 @@ func TestBuildBlockForceAdvanceTime(t *testing.T) { defer env.ctx.Lock.Unlock() // Create a valid transaction - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -320,7 +320,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder1, signer1 := env.factory.MakeWallet(preFundedKeys[0]) + builder1, signer1 := env.factory.NewWallet(preFundedKeys[0]) utx1, err := builder1.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -361,7 +361,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { sk, err = bls.NewSecretKey() require.NoError(err) - builder2, signer2 := env.factory.MakeWallet(preFundedKeys[2]) + builder2, signer2 := env.factory.NewWallet(preFundedKeys[2]) utx2, err := builder2.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -426,7 +426,7 @@ func TestPreviouslyDroppedTxsCannotBeReAddedToMempool(t *testing.T) { defer env.ctx.Lock.Unlock() // Create a valid transaction - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 5afacab54bcc..eb80a9ffc4d3 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -236,7 +236,7 @@ func newEnvironment(t *testing.T, f fork) *environment { //nolint:unparam func addSubnet(t *testing.T, env *environment) { require := require.New(t) - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, diff --git a/vms/platformvm/block/builder/standard_block_test.go b/vms/platformvm/block/builder/standard_block_test.go index 36547342bed9..18ca5bdb3582 100644 --- a/vms/platformvm/block/builder/standard_block_test.go +++ b/vms/platformvm/block/builder/standard_block_test.go @@ -63,7 +63,7 @@ func TestAtomicTxImports(t *testing.T) { }}}, })) - builder, signer := env.factory.MakeWallet(recipientKey) + builder, signer := env.factory.NewWallet(recipientKey) utx, err := builder.NewImportTx( env.ctx.XChainID, &secp256k1fx.OutputOwners{ diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index b1b76fcb6cae..a8c276579c08 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -252,7 +252,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f fork) *environment } func addSubnet(env *environment) { - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, @@ -497,7 +497,7 @@ func addPendingValidator( rewardAddress ids.ShortID, keys []*secp256k1.PrivateKey, ) (*txs.Tx, error) { - builder, signer := env.factory.MakeWallet(keys...) + builder, signer := env.factory.NewWallet(keys...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index d37f99fc6791..3a3f45fd7c0d 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -538,7 +538,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { env.config.TrackedSubnets.Add(subnetID) for _, staker := range test.stakers { - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: staker.nodeID, @@ -572,7 +572,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { } for _, subStaker := range test.subnetStakers { - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -609,7 +609,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0.endTime = newTime - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: staker0.nodeID, @@ -719,7 +719,7 @@ func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { subnetValidatorNodeID := genesisNodeIDs[0] subnetVdr1StartTime := defaultValidateStartTime subnetVdr1EndTime := defaultValidateStartTime.Add(defaultMinStakingDuration) - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -879,7 +879,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { subnetVdr1StartTime := defaultGenesisTime.Add(1 * time.Minute) subnetVdr1EndTime := defaultGenesisTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1003,7 +1003,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // just to allow proposalBlk issuance (with a reward Tx) staker0StartTime := defaultGenesisTime staker0EndTime := pendingValidatorStartTime - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1074,7 +1074,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - builder, signer = env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, signer = env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -1105,7 +1105,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0EndTime = pendingDelegatorStartTime - builder, signer = env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer = env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err = builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1200,7 +1200,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // so to allow proposalBlk issuance staker0StartTime := defaultGenesisTime staker0EndTime := pendingValidatorStartTime - builder, txSigner := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, txSigner := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1270,7 +1270,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // Add delegator pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(defaultMinStakingDuration) - builder, txSigner = env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, txSigner = env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) uDelTx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -1301,7 +1301,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // add Staker0 (with the right end time) to state // so to allow proposalBlk issuance staker0EndTime = pendingDelegatorStartTime - builder, txSigner = env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, txSigner = env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err = builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), @@ -1385,7 +1385,7 @@ func TestAddValidatorProposalBlock(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, txSigner := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index 8aafd34f12dd..af8d469c48c3 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -510,7 +510,7 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { } for _, staker := range test.subnetStakers { - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -604,7 +604,7 @@ func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { subnetValidatorNodeID := genesisNodeIDs[0] subnetVdr1StartTime := defaultValidateStartTime subnetVdr1EndTime := defaultValidateStartTime.Add(defaultMinStakingDuration) - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -710,7 +710,7 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { subnetValidatorNodeID := genesisNodeIDs[0] subnetVdr1StartTime := defaultGenesisTime.Add(1 * time.Minute) subnetVdr1EndTime := defaultGenesisTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -805,7 +805,7 @@ func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index a8819bdcbe92..3d4aac61770e 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -169,7 +169,7 @@ func TestGetTxStatus(t *testing.T) { mutableSharedMemory.SharedMemory = sm - builder, signer := factory.MakeWallet(recipientKey) + builder, signer := factory.NewWallet(recipientKey) utx, err := builder.NewImportTx( service.vm.ctx.XChainID, &secp256k1fx.OutputOwners{ @@ -222,7 +222,7 @@ func TestGetTx(t *testing.T) { { "standard block", func(_ *Service, factory *txstest.WalletFactory) (*txs.Tx, error) { - builder, signer := factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), []byte{}, @@ -249,7 +249,7 @@ func TestGetTx(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, } - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -277,7 +277,7 @@ func TestGetTx(t *testing.T) { { "atomic block", func(service *Service, factory *txstest.WalletFactory) (*txs.Tx, error) { - builder, signer := factory.MakeWallet(keys[0]) + builder, signer := factory.NewWallet(keys[0]) utx, err := builder.NewExportTx( service.vm.ctx.XChainID, []*avax.TransferableOutput{{ @@ -479,7 +479,7 @@ func TestGetStake(t *testing.T) { delegatorNodeID := genesisNodeIDs[0] delegatorStartTime := defaultValidateStartTime delegatorEndTime := defaultGenesisTime.Add(defaultMinStakingDuration) - builder, signer := factory.MakeWallet(keys[0]) + builder, signer := factory.NewWallet(keys[0]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: delegatorNodeID, @@ -630,7 +630,7 @@ func TestGetCurrentValidators(t *testing.T) { service.vm.ctx.Lock.Lock() - builder, signer := factory.MakeWallet(keys[0]) + builder, signer := factory.NewWallet(keys[0]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: validatorNodeID, @@ -772,7 +772,7 @@ func TestGetBlock(t *testing.T) { service.vm.StaticFeeConfig.CreateAssetTxFee = 100 * defaultTxFee - builder, signer := factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), []byte{}, diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index 96e9227c7a58..48f4426276b2 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -379,7 +379,7 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { } for _, staker := range test.subnetStakers { - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -479,7 +479,7 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { subnetVdr1StartTime := defaultValidateStartTime subnetVdr1EndTime := defaultValidateStartTime.Add(defaultMinStakingDuration) - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -593,7 +593,7 @@ func TestTrackedSubnet(t *testing.T) { subnetVdr1StartTime := defaultValidateStartTime.Add(1 * time.Minute) subnetVdr1EndTime := defaultValidateStartTime.Add(10 * defaultMinStakingDuration).Add(1 * time.Minute) - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -700,7 +700,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(1 * time.Second) - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -800,7 +800,7 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { // Add delegator pendingDelegatorStartTime := pendingValidatorStartTime.Add(1 * time.Second) pendingDelegatorEndTime := pendingDelegatorStartTime.Add(defaultMinStakingDuration) - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1], preFundedKeys[4]) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -918,7 +918,7 @@ func addPendingValidator( nodeID ids.NodeID, keys []*secp256k1.PrivateKey, ) (*txs.Tx, error) { - builder, signer := env.factory.MakeWallet(keys...) + builder, signer := env.factory.NewWallet(keys...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index 74c598312e39..4d52432ab8fa 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -33,7 +33,7 @@ func TestCreateChainTxInsufficientControlSigs(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - builder, signer := env.factory.MakeWallet(preFundedKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(preFundedKeys[0], preFundedKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -67,7 +67,7 @@ func TestCreateChainTxWrongControlSig(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -108,7 +108,7 @@ func TestCreateChainTxNoSuchSubnet(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -141,7 +141,7 @@ func TestCreateChainTxValid(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -209,7 +209,7 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { cfg.StaticFeeConfig.CreateBlockchainTxFee = test.fee factory := txstest.NewWalletFactory(env.ctx, &cfg, env.state) - builder, signer := factory.MakeWallet(preFundedKeys...) + builder, signer := factory.NewWallet(preFundedKeys...) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, diff --git a/vms/platformvm/txs/executor/create_subnet_test.go b/vms/platformvm/txs/executor/create_subnet_test.go index 2d2718bb5fca..8ba9b529d565 100644 --- a/vms/platformvm/txs/executor/create_subnet_test.go +++ b/vms/platformvm/txs/executor/create_subnet_test.go @@ -67,7 +67,7 @@ func TestCreateSubnetTxAP3FeeChange(t *testing.T) { cfg := *env.config cfg.StaticFeeConfig.CreateSubnetTxFee = test.fee factory := txstest.NewWalletFactory(env.ctx, &cfg, env.state) - builder, signer := factory.MakeWallet(preFundedKeys...) + builder, signer := factory.NewWallet(preFundedKeys...) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{}, ) diff --git a/vms/platformvm/txs/executor/export_test.go b/vms/platformvm/txs/executor/export_test.go index ec83b3777549..f962c1af8814 100644 --- a/vms/platformvm/txs/executor/export_test.go +++ b/vms/platformvm/txs/executor/export_test.go @@ -53,7 +53,7 @@ func TestNewExportTx(t *testing.T) { t.Run(tt.description, func(t *testing.T) { require := require.New(t) - builder, signer := env.factory.MakeWallet(tt.sourceKeys...) + builder, signer := env.factory.NewWallet(tt.sourceKeys...) utx, err := builder.NewExportTx( tt.destinationChainID, []*avax.TransferableOutput{{ diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index a34bfa4b0dd1..557fb691417c 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -208,7 +208,7 @@ func newEnvironment(t *testing.T, f fork) *environment { func addSubnet(t *testing.T, env *environment) { require := require.New(t) - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, diff --git a/vms/platformvm/txs/executor/import_test.go b/vms/platformvm/txs/executor/import_test.go index 389f0c5cdbf9..7e8db3da48f0 100644 --- a/vms/platformvm/txs/executor/import_test.go +++ b/vms/platformvm/txs/executor/import_test.go @@ -124,7 +124,7 @@ func TestNewImportTx(t *testing.T) { env.msm.SharedMemory = tt.sharedMemory - builder, signer := env.factory.MakeWallet(tt.sourceKeys...) + builder, signer := env.factory.NewWallet(tt.sourceKeys...) utx, err := builder.NewImportTx( tt.sourceChainID, to, diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index d073727b3f35..cb547d4d589d 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -38,7 +38,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { addMinStakeValidator := func(env *environment) { require := require.New(t) - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -76,7 +76,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { addMaxStakeValidator := func(env *environment) { require := require.New(t) - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -244,7 +244,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { env := newEnvironment(t, apricotPhase5) env.config.UpgradeConfig.ApricotPhase3Time = tt.AP3Time - builder, signer := env.factory.MakeWallet(tt.feeKeys...) + builder, signer := env.factory.NewWallet(tt.feeKeys...) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: tt.nodeID, @@ -294,7 +294,7 @@ 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) - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -331,7 +331,7 @@ 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) - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -368,7 +368,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { dsStartTime := defaultValidateStartTime.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingDSValidatorID, @@ -388,7 +388,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Proposed validator isn't in pending or current validator sets - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -440,7 +440,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Proposed validator is pending validator of primary network // but starts validating subnet before primary network - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -475,7 +475,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Proposed validator is pending validator of primary network // but stops validating subnet after primary network - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -510,7 +510,7 @@ 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 - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -547,7 +547,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { env.state.SetTimestamp(newTimestamp) { - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -584,7 +584,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { // Case: Proposed validator already validating the subnet // First, add validator as validator of subnet - builder, signer = env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer = env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) uSubnetTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -616,7 +616,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Node with ID nodeIDKey.PublicKey().Address() now validating subnet with ID testSubnet1.ID - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -654,7 +654,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Too few signatures - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -695,7 +695,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Control Signature from invalid key (keys[3] is not a control key) - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -735,7 +735,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { { // Case: Proposed validator in pending validator set for subnet // First, add validator to pending validator set of subnet - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -793,7 +793,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator's start time too early - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -831,7 +831,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { nodeID := genesisNodeIDs[0] // Case: Validator already validating primary network - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -868,7 +868,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator in pending validator set of primary network startTime := defaultValidateStartTime.Add(1 * time.Second) - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -919,7 +919,7 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { { // Case: Validator doesn't have enough tokens to cover stake amount - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.GenerateTestNodeID(), diff --git a/vms/platformvm/txs/executor/reward_validator_test.go b/vms/platformvm/txs/executor/reward_validator_test.go index 9c9a2d7a7344..88b7b0b8a368 100644 --- a/vms/platformvm/txs/executor/reward_validator_test.go +++ b/vms/platformvm/txs/executor/reward_validator_test.go @@ -241,7 +241,7 @@ func TestRewardDelegatorTxExecuteOnCommitPreDelegateeDeferral(t *testing.T) { vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, @@ -373,7 +373,7 @@ func TestRewardDelegatorTxExecuteOnCommitPostDelegateeDeferral(t *testing.T) { vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, @@ -600,7 +600,7 @@ func TestRewardDelegatorTxAndValidatorTxExecuteOnCommitPostDelegateeDeferral(t * vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, @@ -773,7 +773,7 @@ func TestRewardDelegatorTxExecuteOnAbort(t *testing.T) { vdrEndTime := uint64(defaultValidateStartTime.Add(2 * defaultMinStakingDuration).Unix()) vdrNodeID := ids.GenerateTestNodeID() - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) uVdrTx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: vdrNodeID, diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index d53fdc3a1490..1de00365723f 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -77,7 +77,7 @@ func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { // Case: Empty validator node ID after banff env.config.UpgradeConfig.BanffTime = test.banffTime - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: ids.EmptyNodeID, @@ -122,7 +122,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { addMinStakeValidator := func(env *environment) { require := require.New(t) - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -160,7 +160,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { addMaxStakeValidator := func(env *environment) { require := require.New(t) - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: newValidatorID, @@ -328,7 +328,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { env := newEnvironment(t, apricotPhase5) env.config.UpgradeConfig.ApricotPhase3Time = tt.AP3Time - builder, signer := env.factory.MakeWallet(tt.feeKeys...) + builder, signer := env.factory.NewWallet(tt.feeKeys...) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: tt.nodeID, @@ -378,7 +378,7 @@ 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) - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -411,7 +411,7 @@ 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) - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -444,7 +444,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { dsStartTime := defaultGenesisTime.Add(10 * time.Second) dsEndTime := dsStartTime.Add(5 * defaultMinStakingDuration) - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: pendingDSValidatorID, @@ -464,7 +464,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Proposed validator isn't in pending or current validator sets - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -512,7 +512,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Proposed validator is pending validator of primary network // but starts validating subnet before primary network - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -543,7 +543,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Proposed validator is pending validator of primary network // but stops validating subnet after primary network - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -574,7 +574,7 @@ 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 - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -606,7 +606,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { env.state.SetTimestamp(newTimestamp) { - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -639,7 +639,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { // Case: Proposed validator already validating the subnet // First, add validator as validator of subnet - builder, signer = env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer = env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) uSubnetTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -672,7 +672,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Node with ID nodeIDKey.PublicKey().Address() now validating subnet with ID testSubnet1.ID startTime := defaultValidateStartTime.Add(time.Second) - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -707,7 +707,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Duplicate signatures startTime := defaultValidateStartTime.Add(time.Second) - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -745,7 +745,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Too few signatures startTime := defaultValidateStartTime.Add(time.Second) - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[2]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[2]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -783,7 +783,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { { // Case: Control Signature from invalid key (keys[3] is not a control key) startTime := defaultValidateStartTime.Add(time.Second) - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], preFundedKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], preFundedKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -820,7 +820,7 @@ 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) - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -873,7 +873,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator's start time too early - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -906,7 +906,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator in current validator set of primary network startTime := defaultValidateStartTime.Add(1 * time.Second) - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -951,7 +951,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator in pending validator set of primary network startTime := defaultValidateStartTime.Add(1 * time.Second) - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -993,7 +993,7 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { { // Case: Validator doesn't have enough tokens to cover stake amount startTime := defaultValidateStartTime.Add(1 * time.Second) - builder, signer := env.factory.MakeWallet(preFundedKeys[0]) + builder, signer := env.factory.NewWallet(preFundedKeys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1050,7 +1050,7 @@ func TestDurangoDisabledTransactions(t *testing.T) { endTime = chainTime.Add(defaultMaxStakingDuration) ) - builder, signer := env.factory.MakeWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(preFundedKeys...) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1088,7 +1088,7 @@ func TestDurangoDisabledTransactions(t *testing.T) { } it.Release() - builder, signer := env.factory.MakeWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(preFundedKeys...) utx, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: primaryValidator.NodeID, @@ -1158,7 +1158,7 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() - builder, signer := env.factory.MakeWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(preFundedKeys...) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1183,7 +1183,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "CreateChainTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.MakeWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(preFundedKeys...) utx, err := builder.NewCreateChainTx( testSubnet1.TxID, []byte{}, @@ -1205,7 +1205,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "CreateSubnetTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.MakeWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(preFundedKeys...) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, @@ -1247,7 +1247,7 @@ func TestDurangoMemoField(t *testing.T) { ) env.msm.SharedMemory = sharedMemory - builder, signer := env.factory.MakeWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(preFundedKeys...) utx, err := builder.NewImportTx( sourceChain, &secp256k1fx.OutputOwners{ @@ -1270,7 +1270,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "ExportTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.MakeWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(preFundedKeys...) utx, err := builder.NewExportTx( env.ctx.XChainID, []*avax.TransferableOutput{{ @@ -1313,7 +1313,7 @@ func TestDurangoMemoField(t *testing.T) { it.Release() endTime := primaryValidator.EndTime - builder, signer := env.factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, signer := env.factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1338,7 +1338,7 @@ func TestDurangoMemoField(t *testing.T) { Tx: subnetValTx, })) - builder, signer = env.factory.MakeWallet(preFundedKeys...) + builder, signer = env.factory.NewWallet(preFundedKeys...) utx2, err := builder.NewRemoveSubnetValidatorTx( primaryValidator.NodeID, testSubnet1.ID(), @@ -1354,7 +1354,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "TransformSubnetTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.MakeWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(preFundedKeys...) utx, err := builder.NewTransformSubnetTx( testSubnet1.TxID, // subnetID ids.GenerateTestID(), // assetID @@ -1393,7 +1393,7 @@ func TestDurangoMemoField(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(t, err) - builder, txSigner := env.factory.MakeWallet(preFundedKeys...) + builder, txSigner := env.factory.NewWallet(preFundedKeys...) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1443,7 +1443,7 @@ func TestDurangoMemoField(t *testing.T) { } it.Release() - builder, signer := env.factory.MakeWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(preFundedKeys...) utx, err := builder.NewAddPermissionlessDelegatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1474,7 +1474,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "TransferSubnetOwnershipTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.MakeWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(preFundedKeys...) utx, err := builder.NewTransferSubnetOwnershipTx( testSubnet1.TxID, &secp256k1fx.OutputOwners{ @@ -1496,7 +1496,7 @@ func TestDurangoMemoField(t *testing.T) { { name: "BaseTx", setupTest: func(env *environment, memoField []byte) (*txs.Tx, state.Diff) { - builder, signer := env.factory.MakeWallet(preFundedKeys...) + builder, signer := env.factory.NewWallet(preFundedKeys...) utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { diff --git a/vms/platformvm/txs/txstest/builder.go b/vms/platformvm/txs/txstest/builder.go index 86750ed3757b..532720be981f 100644 --- a/vms/platformvm/txs/txstest/builder.go +++ b/vms/platformvm/txs/txstest/builder.go @@ -31,7 +31,7 @@ type WalletFactory struct { state state.State } -func (w *WalletFactory) MakeWallet(keys ...*secp256k1.PrivateKey) (builder.Builder, signer.Signer) { +func (w *WalletFactory) NewWallet(keys ...*secp256k1.PrivateKey) (builder.Builder, signer.Signer) { var ( kc = secp256k1fx.NewKeychain(keys...) addrs = kc.Addresses() diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index 6b3250933206..9ed3dc7cbd4d 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -259,7 +259,7 @@ func takeValidatorsSnapshotAtCurrentHeight(vm *VM, validatorsSetByHeightAndSubne func addSubnetValidator(vm *VM, data *validatorInputData, subnetID ids.ID) (*state.Staker, error) { factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) - builder, signer := factory.MakeWallet(keys[0], keys[1]) + builder, signer := factory.NewWallet(keys[0], keys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -294,7 +294,7 @@ func addPrimaryValidatorWithBLSKey(vm *VM, data *validatorInputData) (*state.Sta } factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) - builder, txSigner := factory.MakeWallet(keys[0], keys[1]) + builder, txSigner := factory.NewWallet(keys[0], keys[1]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -719,7 +719,7 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { // Note: following Banff activation, block acceptance will move // chain time ahead factory := txstest.NewWalletFactory(vm.ctx, &vm.Config, vm.state) - builder, signer := factory.MakeWallet(keys[len(keys)-1]) + builder, signer := factory.NewWallet(keys[len(keys)-1]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 9e4b90afbae7..629be17fe1ba 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -66,7 +66,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { changeAddr := keys[0].PublicKey().Address() // create valid tx - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -111,7 +111,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { firstDelegatorEndTime := firstDelegatorStartTime.Add(vm.MinStakeDuration) // create valid tx - builder, txSigner = factory.MakeWallet(keys[0], keys[1]) + builder, txSigner = factory.NewWallet(keys[0], keys[1]) uDelTx1, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -157,7 +157,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { vm.clock.Set(secondDelegatorStartTime.Add(-10 * executor.SyncBound)) // create valid tx - builder, txSigner = factory.MakeWallet(keys[0], keys[1], keys[3]) + builder, txSigner = factory.NewWallet(keys[0], keys[1], keys[3]) uDelTx2, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -193,7 +193,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) { thirdDelegatorEndTime := thirdDelegatorStartTime.Add(vm.MinStakeDuration) // create valid tx - builder, txSigner = factory.MakeWallet(keys[0], keys[1], keys[4]) + builder, txSigner = factory.NewWallet(keys[0], keys[1], keys[4]) uDelTx3, err := builder.NewAddDelegatorTx( &txs.Validator{ NodeID: nodeID, @@ -274,7 +274,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { changeAddr := keys[0].PublicKey().Address() // create valid tx - builder, txSigner := factory.MakeWallet(keys[0], keys[1]) + builder, txSigner := factory.NewWallet(keys[0], keys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -506,7 +506,7 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { vm.state, ) - builder, txSigner := factory.MakeWallet(key0) + builder, txSigner := factory.NewWallet(key0) utx0, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, @@ -521,7 +521,7 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { addSubnetTx0, err := walletsigner.SignUnsigned(context.Background(), txSigner, utx0) require.NoError(err) - builder, txSigner = factory.MakeWallet(key1) + builder, txSigner = factory.NewWallet(key1) utx1, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, @@ -611,7 +611,7 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { newValidatorEndTime := newValidatorStartTime.Add(defaultMinStakingDuration) // Create the tx to add a new validator - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -825,7 +825,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { nodeID0 := ids.GenerateTestNodeID() // Create the tx to add the first new validator - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID0, @@ -1003,7 +1003,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { nodeID1 := ids.GenerateTestNodeID() // Create the tx to add the second new validator - builder, txSigner = factory.MakeWallet(keys[1]) + builder, txSigner = factory.NewWallet(keys[1]) utx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID1, @@ -1164,7 +1164,7 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { extraNodeID := ids.GenerateTestNodeID() // Create the tx to add the first new validator - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: extraNodeID, @@ -1291,7 +1291,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { changeAddr := keys[0].PublicKey().Address() // create valid tx - builder, txSigner := factory.MakeWallet(keys[0], keys[1]) + builder, txSigner := factory.NewWallet(keys[0], keys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1404,7 +1404,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t nodeID := ids.GenerateTestNodeID() changeAddr := keys[0].PublicKey().Address() - builder, txSigner := factory.MakeWallet(keys[0], keys[1]) + builder, txSigner := factory.NewWallet(keys[0], keys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1553,7 +1553,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t nodeID := ids.GenerateTestNodeID() changeAddr := keys[0].PublicKey().Address() - builder, txSigner := factory.MakeWallet(keys[0], keys[1]) + builder, txSigner := factory.NewWallet(keys[0], keys[1]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -1704,7 +1704,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) // build primary network validator with BLS key - builder, txSigner := factory.MakeWallet(keys...) + builder, txSigner := factory.NewWallet(keys...) uPrimaryTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1753,7 +1753,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = factory.MakeWallet(keys[0], keys[1]) + builder, txSigner = factory.NewWallet(keys[0], keys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1834,7 +1834,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { require.NoError(err) require.NotEqual(sk1, sk2) - builder, txSigner = factory.MakeWallet(keys...) + builder, txSigner = factory.NewWallet(keys...) uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -1960,7 +1960,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { nodeID := ids.GenerateTestNodeID() addr := keys[0].PublicKey().Address() - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) uAddValTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -2030,7 +2030,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { sk2, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner = factory.MakeWallet(keys...) + builder, txSigner = factory.NewWallet(keys...) uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2120,7 +2120,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { nodeID := ids.GenerateTestNodeID() addr := keys[0].PublicKey().Address() - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) uPrimaryTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -2160,7 +2160,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = factory.MakeWallet(keys[0], keys[1]) + builder, txSigner = factory.NewWallet(keys[0], keys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2240,7 +2240,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { sk2, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner = factory.MakeWallet(keys...) + builder, txSigner = factory.NewWallet(keys...) uPrimaryRestartTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2337,7 +2337,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { nodeID := ids.GenerateTestNodeID() addr := keys[0].PublicKey().Address() - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) uPrimaryTx1, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -2374,7 +2374,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) { require.NoError(err) // insert the subnet validator - builder, txSigner = factory.MakeWallet(keys[0], keys[1]) + builder, txSigner = factory.NewWallet(keys[0], keys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index c68861e25fb0..e6e645d74242 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -319,7 +319,7 @@ func defaultVM(t *testing.T, f fork) (*VM, *txstest.WalletFactory, database.Data // Create a subnet and store it in testSubnet1 // Note: following Banff activation, block acceptance will move // chain time ahead - builder, signer := factory.MakeWallet(keys[0]) + builder, signer := factory.NewWallet(keys[0]) utx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 2, @@ -428,7 +428,7 @@ func TestAddValidatorCommit(t *testing.T) { require.NoError(err) // create valid tx - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -487,7 +487,7 @@ func TestInvalidAddValidatorCommit(t *testing.T) { endTime := startTime.Add(defaultMinStakingDuration) // create invalid tx - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -546,7 +546,7 @@ func TestAddValidatorReject(t *testing.T) { ) // create valid tx - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) utx, err := builder.NewAddValidatorTx( &txs.Validator{ NodeID: nodeID, @@ -599,7 +599,7 @@ func TestAddValidatorInvalidNotReissued(t *testing.T) { require.NoError(err) // create valid tx - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) utx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -649,7 +649,7 @@ 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]) - builder, txSigner := factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, txSigner := factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -701,7 +701,7 @@ 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]) - builder, txSigner := factory.MakeWallet(testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) + builder, txSigner := factory.NewWallet(testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]) utx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -892,7 +892,7 @@ func TestCreateChain(t *testing.T) { vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - builder, txSigner := factory.MakeWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) + builder, txSigner := factory.NewWallet(testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]) utx, err := builder.NewCreateChainTx( testSubnet1.ID(), nil, @@ -942,7 +942,7 @@ func TestCreateSubnet(t *testing.T) { vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) uCreateSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, @@ -1056,7 +1056,7 @@ func TestAtomicImport(t *testing.T) { mutableSharedMemory.SharedMemory = m.NewSharedMemory(vm.ctx.ChainID) peerSharedMemory := m.NewSharedMemory(vm.ctx.XChainID) - builder, _ := factory.MakeWallet(keys[0]) + builder, _ := factory.NewWallet(keys[0]) _, err := builder.NewImportTx( vm.ctx.XChainID, &secp256k1fx.OutputOwners{ @@ -1097,7 +1097,7 @@ func TestAtomicImport(t *testing.T) { }, })) - builder, txSigner := factory.MakeWallet(recipientKey) + builder, txSigner := factory.NewWallet(recipientKey) utx, err := builder.NewImportTx( vm.ctx.XChainID, &secp256k1fx.OutputOwners{ @@ -2119,7 +2119,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) uAddValTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2186,7 +2186,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { require.NoError(createSubnetBlock.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - builder, txSigner = factory.MakeWallet(key, keys[1]) + builder, txSigner = factory.NewWallet(key, keys[1]) uAddSubnetValTx, err := builder.NewAddSubnetValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{ @@ -2206,7 +2206,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { addSubnetValidatorTx, err := walletsigner.SignUnsigned(context.Background(), txSigner, uAddSubnetValTx) require.NoError(err) - builder, txSigner = factory.MakeWallet(key, keys[2]) + builder, txSigner = factory.NewWallet(key, keys[2]) uRemoveSubnetValTx, err := builder.NewRemoveSubnetValidatorTx( nodeID, createSubnetTx.ID(), @@ -2247,7 +2247,7 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) uCreateSubnetTx, err := builder.NewCreateSubnetTx( &secp256k1fx.OutputOwners{ Threshold: 1, @@ -2339,7 +2339,7 @@ func TestBaseTx(t *testing.T) { sendAmt := uint64(100000) changeAddr := ids.ShortEmpty - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { @@ -2426,7 +2426,7 @@ func TestPruneMempool(t *testing.T) { sendAmt := uint64(100000) changeAddr := ids.ShortEmpty - builder, txSigner := factory.MakeWallet(keys[0]) + builder, txSigner := factory.NewWallet(keys[0]) utx, err := builder.NewBaseTx( []*avax.TransferableOutput{ { @@ -2469,7 +2469,7 @@ func TestPruneMempool(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - builder, txSigner = factory.MakeWallet(keys[1]) + builder, txSigner = factory.NewWallet(keys[1]) uAddValTx, err := builder.NewAddPermissionlessValidatorTx( &txs.SubnetValidator{ Validator: txs.Validator{