From 2c2d32d537ccfc824b9f01df0c8fc19e0ca3088b Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 19 Jan 2024 17:03:01 -0500 Subject: [PATCH 1/2] nits --- .../txs/executor/standard_tx_executor_test.go | 1556 +++++++---------- 1 file changed, 596 insertions(+), 960 deletions(-) diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 677c22c3d486..0e0231648918 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -34,6 +34,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/utxo" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + "github.com/ava-labs/avalanchego/vms/types" ) // This tests that the math performed during TransformSubnetTx execution can @@ -952,1024 +953,659 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { } } -func TestDurangoStandardTxExecutorAddValidatorTx(t *testing.T) { - require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) - env.ctx.Lock.Lock() - defer env.ctx.Lock.Unlock() - - var ( - nodeID = ids.GenerateTestNodeID() - chainTime = env.state.GetTimestamp() - endTime = chainTime.Add(defaultMaxStakingDuration) - ) - - // Build the AddValidatorTx - ins, unstakedOuts, stakedOuts, signers, err := env.utxosHandler.Spend( - env.state, - preFundedKeys, - defaultMinValidatorStake, - env.config.AddPrimaryNetworkValidatorFee, - ids.ShortEmpty, - ) - require.NoError(err) - - utx := &txs.AddValidatorTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: env.ctx.NetworkID, - BlockchainID: env.ctx.ChainID, - Ins: ins, - Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, // non-empty memo must err - }}, - Validator: txs.Validator{ - NodeID: nodeID, - Start: 0, - End: uint64(endTime.Unix()), - Wght: env.config.MinValidatorStake, - }, - StakeOuts: stakedOuts, - RewardsOwner: &secp256k1fx.OutputOwners{ - Locktime: 0, - Threshold: 1, - Addrs: []ids.ShortID{ids.ShortEmpty}, - }, - DelegationShares: reward.PercentDenominator, +func setMemo(tx txs.UnsignedTx, memo types.JSONByteSlice) { + switch castTx := tx.(type) { + case *txs.AddValidatorTx: + castTx.Memo = memo + case *txs.AddSubnetValidatorTx: + castTx.Memo = memo + case *txs.AddDelegatorTx: + castTx.Memo = memo + case *txs.CreateChainTx: + castTx.Memo = memo + case *txs.CreateSubnetTx: + castTx.Memo = memo + case *txs.ImportTx: + castTx.Memo = memo + case *txs.ExportTx: + castTx.Memo = memo + case *txs.RemoveSubnetValidatorTx: + castTx.Memo = memo + case *txs.TransformSubnetTx: + castTx.Memo = memo + case *txs.AddPermissionlessValidatorTx: + castTx.Memo = memo + case *txs.AddPermissionlessDelegatorTx: + castTx.Memo = memo + case *txs.TransferSubnetOwnershipTx: + castTx.Memo = memo + case *txs.BaseTx: + castTx.Memo = memo } - addValTx, err := txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) - require.NoError(err) - - err = addValTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: addValTx, - }) - require.ErrorIs(err, avax.ErrMemoTooLarge) - - // empty memo won't err - utx.Memo = []byte{} - addValTx, err = txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - require.NoError(addValTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: addValTx, - })) - - // Check that a current validator is added - val, err := onAcceptState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) - require.NoError(err) - - require.Equal(addValTx.ID(), val.TxID) - require.Equal(chainTime, val.StartTime) - require.Equal(endTime, val.EndTime) } -func TestDurangoStandardTxExecutorAddPermissionlessValidatorTx(t *testing.T) { - require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) - env.ctx.Lock.Lock() - defer func() { - require.NoError(shutdownEnvironment(env)) - env.ctx.Lock.Unlock() - }() - - var ( - nodeID = ids.GenerateTestNodeID() - chainTime = env.state.GetTimestamp() - endTime = chainTime.Add(defaultMaxStakingDuration) - ) - - // Build the AddValidatorTx - ins, unstakedOuts, stakedOuts, signers, err := env.utxosHandler.Spend( - env.state, - preFundedKeys, - defaultMinValidatorStake, - env.config.AddPrimaryNetworkValidatorFee, - ids.ShortEmpty, - ) - require.NoError(err) - - sk, err := bls.NewSecretKey() - require.NoError(err) - - utx := &txs.AddPermissionlessValidatorTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: env.ctx.NetworkID, - BlockchainID: env.ctx.ChainID, - Ins: ins, - Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, - }}, - Validator: txs.Validator{ - NodeID: nodeID, - End: uint64(endTime.Unix()), - Wght: env.config.MinValidatorStake, - }, - Subnet: constants.PrimaryNetworkID, - Signer: signer.NewProofOfPossession(sk), - StakeOuts: stakedOuts, - ValidatorRewardsOwner: &secp256k1fx.OutputOwners{ - Locktime: 0, - Threshold: 1, - Addrs: []ids.ShortID{ - ids.ShortEmpty, - }, - }, - DelegatorRewardsOwner: &secp256k1fx.OutputOwners{ - Locktime: 0, - Threshold: 1, - Addrs: []ids.ShortID{ - ids.ShortEmpty, - }, - }, - DelegationShares: reward.PercentDenominator, +// Verifies that the Memo field is required to be empty post-Durango +func TestDurangoStandardTxExecutor(t *testing.T) { + type test struct { + name string + setupTest func(*environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) } - addValTx, err := txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) - require.NoError(err) - - err = addValTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: addValTx, - }) - require.ErrorIs(err, avax.ErrMemoTooLarge) - - // empty memo won't err - utx.Memo = []byte{} - addValTx, err = txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - require.NoError(addValTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: addValTx, - })) - - // Check that a current validator is added - val, err := onAcceptState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) - require.NoError(err) - - require.Equal(addValTx.ID(), val.TxID) - require.Equal(chainTime, val.StartTime) - require.Equal(endTime, val.EndTime) -} - -func TestDurangoStandardTxExecutorAddDelegator(t *testing.T) { - require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) - env.ctx.Lock.Lock() - defer func() { - require.NoError(shutdownEnvironment(env)) - env.ctx.Lock.Unlock() - }() - - // retrieve a primary network validator to test delegators - var primaryNetworkVal *state.Staker - it, err := env.state.GetCurrentStakerIterator() - require.NoError(err) - for it.Next() { - staker := it.Value() - if staker.Priority != txs.PrimaryNetworkValidatorCurrentPriority { - continue - } - primaryNetworkVal = staker - break - } - it.Release() + tests := []test{ + { + name: "AddValidatorTx", + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + ins, unstakedOuts, stakedOuts, signers, err := env.utxosHandler.Spend( + env.state, + preFundedKeys, + defaultMinValidatorStake, + env.config.AddPrimaryNetworkValidatorFee, + ids.ShortEmpty, + ) + require.NoError(t, err) - var ( - chainTime = env.state.GetTimestamp() - endTime = primaryNetworkVal.EndTime - ) + var ( + nodeID = ids.GenerateTestNodeID() + chainTime = env.state.GetTimestamp() + endTime = chainTime.Add(defaultMaxStakingDuration) + ) - // Build the AddDelegatorTx - ins, unstakedOuts, stakedOuts, signers, err := env.utxosHandler.Spend( - env.state, - preFundedKeys, - defaultMinValidatorStake, - env.config.AddPrimaryNetworkDelegatorFee, - ids.ShortEmpty, - ) - require.NoError(err) + onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) + require.NoError(t, err) - utx := &txs.AddDelegatorTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: env.ctx.NetworkID, - BlockchainID: env.ctx.ChainID, - Ins: ins, - Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, - }}, - Validator: txs.Validator{ - NodeID: primaryNetworkVal.NodeID, - End: uint64(endTime.Unix()), - Wght: defaultMinValidatorStake, - }, - StakeOuts: stakedOuts, - DelegationRewardsOwner: &secp256k1fx.OutputOwners{ - Locktime: 0, - Threshold: 1, - Addrs: []ids.ShortID{ids.ShortEmpty}, + return &txs.AddValidatorTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: env.ctx.NetworkID, + BlockchainID: env.ctx.ChainID, + Ins: ins, + Outs: unstakedOuts, + }}, + Validator: txs.Validator{ + NodeID: nodeID, + Start: 0, + End: uint64(endTime.Unix()), + Wght: env.config.MinValidatorStake, + }, + StakeOuts: stakedOuts, + RewardsOwner: &secp256k1fx.OutputOwners{ + Locktime: 0, + Threshold: 1, + Addrs: []ids.ShortID{ids.ShortEmpty}, + }, + DelegationShares: reward.PercentDenominator, + }, signers, onAcceptState + }, }, - } - addDelTx, err := txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) - require.NoError(err) - - err = addDelTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: addDelTx, - }) - require.ErrorIs(err, avax.ErrMemoTooLarge) - - // empty memo won't err - utx.Memo = []byte{} - addDelTx, err = txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - require.NoError(addDelTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: addDelTx, - })) - - // Check that a current validator is added - it, err = onAcceptState.GetCurrentDelegatorIterator(primaryNetworkVal.SubnetID, primaryNetworkVal.NodeID) - require.NoError(err) - - var retrievedDel *state.Staker - for it.Next() { - if it.Value().Priority != txs.PrimaryNetworkDelegatorCurrentPriority { - continue - } - retrievedDel = it.Value() - } - it.Release() - - require.Equal(addDelTx.ID(), retrievedDel.TxID) - require.Equal(chainTime, retrievedDel.StartTime) - require.Equal(endTime, retrievedDel.EndTime) -} - -func TestDurangoStandardTxExecutorAddPermissionlessDelegatorTx(t *testing.T) { - require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) - env.ctx.Lock.Lock() - defer func() { - require.NoError(shutdownEnvironment(env)) - env.ctx.Lock.Unlock() - }() - - // retrieve a primary network validator to test delegators - var primaryNetworkVal *state.Staker - it, err := env.state.GetCurrentStakerIterator() - require.NoError(err) - for it.Next() { - staker := it.Value() - if staker.Priority != txs.PrimaryNetworkValidatorCurrentPriority { - continue - } - primaryNetworkVal = staker - break - } - it.Release() + { + name: "AddSubnetValidatorTx", + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + var primaryValidator *state.Staker + it, err := env.state.GetCurrentStakerIterator() + require.NoError(t, err) + for it.Next() { + staker := it.Value() + if staker.Priority != txs.PrimaryNetworkValidatorCurrentPriority { + continue + } + primaryValidator = staker + break + } + it.Release() + + ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( + env.state, + preFundedKeys, + defaultMinValidatorStake, + env.config.TxFee, + ids.ShortEmpty, + ) + require.NoError(t, err) - var ( - chainTime = env.state.GetTimestamp() - endTime = primaryNetworkVal.EndTime - ) + subnetAuth, subnetSigners, err := env.utxosHandler.Authorize(env.state, testSubnet1.TxID, preFundedKeys) + require.NoError(t, err) + signers = append(signers, subnetSigners) - // Build the AddDelegatorTx - ins, unstakedOuts, stakedOuts, signers, err := env.utxosHandler.Spend( - env.state, - preFundedKeys, - defaultMinValidatorStake, - env.config.AddPrimaryNetworkDelegatorFee, - ids.ShortEmpty, - ) - require.NoError(err) + onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) + require.NoError(t, err) - utx := &txs.AddPermissionlessDelegatorTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: env.ctx.NetworkID, - BlockchainID: env.ctx.ChainID, - Ins: ins, - Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, - }}, - Validator: txs.Validator{ - NodeID: primaryNetworkVal.NodeID, - End: uint64(endTime.Unix()), - Wght: defaultMinValidatorStake, - }, - StakeOuts: stakedOuts, - DelegationRewardsOwner: &secp256k1fx.OutputOwners{ - Locktime: 0, - Threshold: 1, - Addrs: []ids.ShortID{ids.ShortEmpty}, + return &txs.AddSubnetValidatorTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: env.ctx.NetworkID, + BlockchainID: env.ctx.ChainID, + Ins: ins, + Outs: unstakedOuts, + Memo: []byte{'a', 'b', 'c'}, + }}, + SubnetValidator: txs.SubnetValidator{ + Validator: txs.Validator{ + NodeID: primaryValidator.NodeID, + End: uint64(primaryValidator.EndTime.Unix()), + Wght: defaultMinValidatorStake, + }, + Subnet: testSubnet1.TxID, + }, + SubnetAuth: subnetAuth, + }, signers, onAcceptState + }, }, - } - addDelTx, err := txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) - require.NoError(err) - - err = addDelTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: addDelTx, - }) - require.ErrorIs(err, avax.ErrMemoTooLarge) - - // empty memo won't err - utx.Memo = []byte{} - addDelTx, err = txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - require.NoError(addDelTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: addDelTx, - })) - - // Check that a current validator is added - it, err = onAcceptState.GetCurrentDelegatorIterator(primaryNetworkVal.SubnetID, primaryNetworkVal.NodeID) - require.NoError(err) - - var retrievedDel *state.Staker - for it.Next() { - if it.Value().Priority != txs.PrimaryNetworkDelegatorCurrentPriority { - continue - } - retrievedDel = it.Value() - } - it.Release() - - require.Equal(addDelTx.ID(), retrievedDel.TxID) - require.Equal(chainTime, retrievedDel.StartTime) - require.Equal(endTime, retrievedDel.EndTime) -} - -func TestDurangoStandardTxExecutorAddSubnetValidator(t *testing.T) { - require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) - env.ctx.Lock.Lock() - defer func() { - require.NoError(shutdownEnvironment(env)) - env.ctx.Lock.Unlock() - }() - - // retrieve a primary network validator to test subnet validators - var primaryNetworkVal *state.Staker - it, err := env.state.GetCurrentStakerIterator() - require.NoError(err) - for it.Next() { - staker := it.Value() - if staker.Priority != txs.PrimaryNetworkValidatorCurrentPriority { - continue - } - primaryNetworkVal = staker - break - } - it.Release() - - var ( - chainTime = env.state.GetTimestamp() - endTime = primaryNetworkVal.EndTime - ) + { + name: "AddDelegatorTx", + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + var primaryValidator *state.Staker + it, err := env.state.GetCurrentStakerIterator() + require.NoError(t, err) + for it.Next() { + staker := it.Value() + if staker.Priority != txs.PrimaryNetworkValidatorCurrentPriority { + continue + } + primaryValidator = staker + break + } + it.Release() + + ins, unstakedOuts, stakedOuts, signers, err := env.utxosHandler.Spend( + env.state, + preFundedKeys, + defaultMinValidatorStake, + env.config.AddPrimaryNetworkDelegatorFee, + ids.ShortEmpty, + ) + require.NoError(t, err) - // Build the AddSubnetValidatorTx - ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( - env.state, - preFundedKeys, - defaultMinValidatorStake, - env.config.TxFee, - ids.ShortEmpty, - ) - require.NoError(err) + onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) + require.NoError(t, err) - subnetAuth, subnetSigners, err := env.utxosHandler.Authorize(env.state, testSubnet1.TxID, preFundedKeys) - require.NoError(err) - signers = append(signers, subnetSigners) - - // Create the tx - utx := &txs.AddSubnetValidatorTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: env.ctx.NetworkID, - BlockchainID: env.ctx.ChainID, - Ins: ins, - Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, - }}, - SubnetValidator: txs.SubnetValidator{ - Validator: txs.Validator{ - NodeID: primaryNetworkVal.NodeID, - End: uint64(endTime.Unix()), - Wght: defaultMinValidatorStake, + return &txs.AddDelegatorTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: env.ctx.NetworkID, + BlockchainID: env.ctx.ChainID, + Ins: ins, + Outs: unstakedOuts, + Memo: []byte{'a', 'b', 'c'}, + }}, + Validator: txs.Validator{ + NodeID: primaryValidator.NodeID, + End: uint64(primaryValidator.EndTime.Unix()), + Wght: defaultMinValidatorStake, + }, + StakeOuts: stakedOuts, + DelegationRewardsOwner: &secp256k1fx.OutputOwners{ + Locktime: 0, + Threshold: 1, + Addrs: []ids.ShortID{ids.ShortEmpty}, + }, + }, signers, onAcceptState }, - Subnet: testSubnet1.TxID, }, - SubnetAuth: subnetAuth, - } - - addSubnetVal, err := txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) - require.NoError(err) - - err = addSubnetVal.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: addSubnetVal, - }) - require.ErrorIs(err, avax.ErrMemoTooLarge) - - // empty memo won't err - utx.Memo = []byte{} - addSubnetVal, err = txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - require.NoError(addSubnetVal.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: addSubnetVal, - })) - - // Check that a current subnet validator is added - val, err := onAcceptState.GetCurrentValidator(utx.Subnet, utx.Validator.NodeID) - require.NoError(err) - - require.Equal(addSubnetVal.ID(), val.TxID) - require.Equal(chainTime, val.StartTime) - require.Equal(endTime, val.EndTime) -} - -func TestDurangoStandardTxExecutorRemoveSubnetValidatorTx(t *testing.T) { - require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) - env.ctx.Lock.Lock() - defer func() { - require.NoError(shutdownEnvironment(env)) - env.ctx.Lock.Unlock() - }() - - // retrieve a primary network validator to test subnet validators - var primaryNetworkVal *state.Staker - it, err := env.state.GetCurrentStakerIterator() - require.NoError(err) - for it.Next() { - staker := it.Value() - if staker.Priority != txs.PrimaryNetworkValidatorCurrentPriority { - continue - } - primaryNetworkVal = staker - break - } - it.Release() - - // add subnet validator - endTime := primaryNetworkVal.EndTime - subnetValTx, err := env.txBuilder.NewAddSubnetValidatorTx( - defaultWeight, - 0, - uint64(endTime.Unix()), - primaryNetworkVal.NodeID, - testSubnet1.ID(), - []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, - ids.ShortEmpty, // change addr - ) - require.NoError(err) - - onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) - require.NoError(err) - - require.NoError(subnetValTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: subnetValTx, - })) - - // Build the RemoveSubnetValidatorTx - ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( - env.state, - preFundedKeys, - defaultMinValidatorStake, - env.config.TxFee, - ids.ShortEmpty, - ) - require.NoError(err) - - subnetAuth, subnetSigners, err := env.utxosHandler.Authorize(env.state, testSubnet1.TxID, preFundedKeys) - require.NoError(err) - signers = append(signers, subnetSigners) - - // Create the tx - utx := &txs.RemoveSubnetValidatorTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: env.ctx.NetworkID, - BlockchainID: env.ctx.ChainID, - Ins: ins, - Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, - }}, - Subnet: testSubnet1.ID(), - NodeID: primaryNetworkVal.NodeID, - SubnetAuth: subnetAuth, - } - removeSubnetVal, err := txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - err = removeSubnetVal.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: removeSubnetVal, - }) - require.ErrorIs(err, avax.ErrMemoTooLarge) - - // empty memo won't err - utx.Memo = []byte{} - removeSubnetVal, err = txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - require.NoError(removeSubnetVal.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: removeSubnetVal, - })) - - // Check that a current subnet validator is added - _, err = onAcceptState.GetCurrentValidator(utx.Subnet, utx.NodeID) - require.ErrorIs(err, database.ErrNotFound) -} - -func TestDurangoStandardTxExecutorTransformSubnetTx(t *testing.T) { - require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) - env.ctx.Lock.Lock() - defer func() { - require.NoError(shutdownEnvironment(env)) - env.ctx.Lock.Unlock() - }() - - // Build the TransformSubnetTx - ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( - env.state, - preFundedKeys, - defaultMinValidatorStake, - env.config.TxFee, - ids.ShortEmpty, - ) - require.NoError(err) - - subnetAuth, subnetSigners, err := env.utxosHandler.Authorize(env.state, testSubnet1.TxID, preFundedKeys) - require.NoError(err) - signers = append(signers, subnetSigners) - - // Create the tx - utx := &txs.TransformSubnetTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: env.ctx.NetworkID, - BlockchainID: env.ctx.ChainID, - Ins: ins, - Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, - }}, - Subnet: testSubnet1.TxID, - AssetID: ids.GenerateTestID(), - InitialSupply: 10, - MaximumSupply: 10, - MinConsumptionRate: 0, - MaxConsumptionRate: reward.PercentDenominator, - MinValidatorStake: 2, - MaxValidatorStake: 10, - MinStakeDuration: 1, - MaxStakeDuration: 2, - MinDelegationFee: reward.PercentDenominator, - MinDelegatorStake: 1, - MaxValidatorWeightFactor: 1, - UptimeRequirement: reward.PercentDenominator, - SubnetAuth: subnetAuth, - } - transformSubnetTx, err := txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) - require.NoError(err) - - err = transformSubnetTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: transformSubnetTx, - }) - require.ErrorIs(err, avax.ErrMemoTooLarge) - - // empty memo won't err - utx.Memo = []byte{} - transformSubnetTx, err = txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) + { + name: "CreateChainTx", + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + chainTime := env.state.GetTimestamp() + createBlockchainTxFee := env.config.GetCreateBlockchainTxFee(chainTime) + + ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( + env.state, + preFundedKeys, + defaultMinValidatorStake, + createBlockchainTxFee, + ids.ShortEmpty, + ) + require.NoError(t, err) - require.NoError(transformSubnetTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: transformSubnetTx, - })) -} + subnetAuth, subnetSigners, err := env.utxosHandler.Authorize(env.state, testSubnet1.TxID, preFundedKeys) + require.NoError(t, err) + signers = append(signers, subnetSigners) -func TestDurangoStandardTxExecutorTransferSubnetOwnershipTx(t *testing.T) { - require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) - env.ctx.Lock.Lock() - defer func() { - require.NoError(shutdownEnvironment(env)) - env.ctx.Lock.Unlock() - }() - - // Build the TransformSubnetTx - ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( - env.state, - preFundedKeys, - defaultMinValidatorStake, - env.config.TxFee, - ids.ShortEmpty, - ) - require.NoError(err) + onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) + require.NoError(t, err) - subnetAuth, subnetSigners, err := env.utxosHandler.Authorize(env.state, testSubnet1.TxID, preFundedKeys) - require.NoError(err) - signers = append(signers, subnetSigners) - - // Create the tx - utx := &txs.TransferSubnetOwnershipTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: env.ctx.NetworkID, - BlockchainID: env.ctx.ChainID, - Ins: ins, - Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, - }}, - Subnet: testSubnet1.TxID, - SubnetAuth: subnetAuth, - Owner: &secp256k1fx.OutputOwners{ - Threshold: 1, - Addrs: []ids.ShortID{ids.ShortEmpty}, + return &txs.CreateChainTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: env.ctx.NetworkID, + BlockchainID: env.ctx.ChainID, + Ins: ins, + Outs: unstakedOuts, + Memo: []byte{'a', 'b', 'c'}, + }}, + SubnetID: testSubnet1.TxID, + ChainName: "aaa", + VMID: ids.GenerateTestID(), + FxIDs: []ids.ID{}, + GenesisData: []byte{}, + SubnetAuth: subnetAuth, + }, signers, onAcceptState + }, }, - } - transferSubnetTx, err := txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) - require.NoError(err) - - err = transferSubnetTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: transferSubnetTx, - }) - require.ErrorIs(err, avax.ErrMemoTooLarge) - - // empty memo won't err - utx.Memo = []byte{} - transferSubnetTx, err = txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - require.NoError(transferSubnetTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: transferSubnetTx, - })) -} + { + name: "CreateSubnetTx", + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + chainTime := env.state.GetTimestamp() + createSubnetTxFee := env.config.GetCreateSubnetTxFee(chainTime) + + ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( + env.state, + preFundedKeys, + defaultMinValidatorStake, + createSubnetTxFee, + ids.ShortEmpty, + ) + require.NoError(t, err) -func TestDurangoStandardTxExecutorCreateChainTx(t *testing.T) { - require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) - env.ctx.Lock.Lock() - defer func() { - require.NoError(shutdownEnvironment(env)) - env.ctx.Lock.Unlock() - }() + onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) + require.NoError(t, err) - chainTime := env.state.GetTimestamp() - createBlockchainTxFee := env.config.GetCreateBlockchainTxFee(chainTime) - - // Build the CreateChainTx - ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( - env.state, - preFundedKeys, - defaultMinValidatorStake, - createBlockchainTxFee, - ids.ShortEmpty, - ) - require.NoError(err) + return &txs.CreateSubnetTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: env.ctx.NetworkID, + BlockchainID: env.ctx.ChainID, + Ins: ins, + Outs: unstakedOuts, + }}, + Owner: &secp256k1fx.OutputOwners{ + Threshold: 1, + Addrs: []ids.ShortID{ids.ShortEmpty}, + }, + }, signers, onAcceptState + }, + }, + { + name: "ImportTx", + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + // Skip shared memory checks + env.backend.Bootstrapped.Set(false) + + utxoID := avax.UTXOID{ + TxID: ids.Empty.Prefix(1), + OutputIndex: 1, + } + amount := uint64(50000) + recipientKey := preFundedKeys[1] + + utxo := &avax.UTXO{ + UTXOID: utxoID, + Asset: avax.Asset{ID: env.ctx.AVAXAssetID}, + Out: &secp256k1fx.TransferOutput{ + Amt: amount, + OutputOwners: secp256k1fx.OutputOwners{ + Threshold: 1, + Addrs: []ids.ShortID{recipientKey.PublicKey().Address()}, + }, + }, + } - subnetAuth, subnetSigners, err := env.utxosHandler.Authorize(env.state, testSubnet1.TxID, preFundedKeys) - require.NoError(err) - signers = append(signers, subnetSigners) - - utx := &txs.CreateChainTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: env.ctx.NetworkID, - BlockchainID: env.ctx.ChainID, - Ins: ins, - Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, // non-empty memo must err - }}, - SubnetID: testSubnet1.TxID, - ChainName: "aaa", - VMID: ids.GenerateTestID(), - FxIDs: []ids.ID{}, - GenesisData: []byte{}, - SubnetAuth: subnetAuth, - } - createChainTx, err := txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) + signers := [][]*secp256k1.PrivateKey{{recipientKey}} - onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) - require.NoError(err) + onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) + require.NoError(t, err) - err = createChainTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: createChainTx, - }) - require.ErrorIs(err, avax.ErrMemoTooLarge) + return &txs.ImportTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: env.ctx.NetworkID, + BlockchainID: env.ctx.ChainID, + }}, + SourceChain: env.ctx.XChainID, + ImportedInputs: []*avax.TransferableInput{ + { + UTXOID: utxo.UTXOID, + Asset: utxo.Asset, + In: &secp256k1fx.TransferInput{ + Amt: env.config.TxFee, + }, + }, + }, + }, signers, onAcceptState + }, + }, + { + name: "ExportTx", + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + amount := units.Avax + ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( + env.state, + preFundedKeys, + amount, + env.config.TxFee, + ids.ShortEmpty, + ) + require.NoError(t, err) - // empty memo won't err - utx.Memo = []byte{} - createChainTx, err = txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) + onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) + require.NoError(t, err) - require.NoError(createChainTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: createChainTx, - })) -} + return &txs.ExportTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: env.ctx.NetworkID, + BlockchainID: env.ctx.ChainID, + Ins: ins, + Outs: unstakedOuts, + }}, + DestinationChain: env.ctx.XChainID, + ExportedOutputs: []*avax.TransferableOutput{{ + Asset: avax.Asset{ID: env.ctx.AVAXAssetID}, + Out: &secp256k1fx.TransferOutput{ + Amt: amount, + OutputOwners: secp256k1fx.OutputOwners{ + Locktime: 0, + Threshold: 1, + Addrs: []ids.ShortID{ids.GenerateTestShortID()}, + }, + }, + }}, + }, signers, onAcceptState + }, + }, + { + name: "RemoveSubnetValidatorTx", + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + var primaryValidator *state.Staker + it, err := env.state.GetCurrentStakerIterator() + require.NoError(t, err) + for it.Next() { + staker := it.Value() + if staker.Priority != txs.PrimaryNetworkValidatorCurrentPriority { + continue + } + primaryValidator = staker + break + } + it.Release() + + endTime := primaryValidator.EndTime + subnetValTx, err := env.txBuilder.NewAddSubnetValidatorTx( + defaultWeight, + 0, + uint64(endTime.Unix()), + primaryValidator.NodeID, + testSubnet1.ID(), + []*secp256k1.PrivateKey{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, + ids.ShortEmpty, + ) + require.NoError(t, err) -func TestDurangoStandardTxExecutorCreateSubnetTx(t *testing.T) { - require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) - env.ctx.Lock.Lock() - defer func() { - require.NoError(shutdownEnvironment(env)) - env.ctx.Lock.Unlock() - }() + onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) + require.NoError(t, err) - chainTime := env.state.GetTimestamp() - createSubnetTxFee := env.config.GetCreateSubnetTxFee(chainTime) - - // Build the CreateSubnetTx - ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( - env.state, - preFundedKeys, - defaultMinValidatorStake, - createSubnetTxFee, - ids.ShortEmpty, - ) - require.NoError(err) + require.NoError(t, subnetValTx.Unsigned.Visit(&StandardTxExecutor{ + Backend: &env.backend, + State: onAcceptState, + Tx: subnetValTx, + })) + + ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( + env.state, + preFundedKeys, + defaultMinValidatorStake, + env.config.TxFee, + ids.ShortEmpty, + ) + require.NoError(t, err) - utx := &txs.CreateSubnetTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: env.ctx.NetworkID, - BlockchainID: env.ctx.ChainID, - Ins: ins, - Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, // non-empty memo must err - }}, - Owner: &secp256k1fx.OutputOwners{ - Threshold: 1, - Addrs: []ids.ShortID{ids.ShortEmpty}, + subnetAuth, subnetSigners, err := env.utxosHandler.Authorize(env.state, testSubnet1.TxID, preFundedKeys) + require.NoError(t, err) + signers = append(signers, subnetSigners) + + return &txs.RemoveSubnetValidatorTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: env.ctx.NetworkID, + BlockchainID: env.ctx.ChainID, + Ins: ins, + Outs: unstakedOuts, + }}, + Subnet: testSubnet1.ID(), + NodeID: primaryValidator.NodeID, + SubnetAuth: subnetAuth, + }, signers, onAcceptState + }, }, - } + { + name: "TransformSubnetTx", + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( + env.state, + preFundedKeys, + defaultMinValidatorStake, + env.config.TxFee, + ids.ShortEmpty, + ) + require.NoError(t, err) - createSubnetTx, err := txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) + subnetAuth, subnetSigners, err := env.utxosHandler.Authorize(env.state, testSubnet1.TxID, preFundedKeys) + require.NoError(t, err) + signers = append(signers, subnetSigners) - onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) - require.NoError(err) + onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) + require.NoError(t, err) - err = createSubnetTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: createSubnetTx, - }) - require.ErrorIs(err, avax.ErrMemoTooLarge) + return &txs.TransformSubnetTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: env.ctx.NetworkID, + BlockchainID: env.ctx.ChainID, + Ins: ins, + Outs: unstakedOuts, + }}, + Subnet: testSubnet1.TxID, + AssetID: ids.GenerateTestID(), + InitialSupply: 10, + MaximumSupply: 10, + MinConsumptionRate: 0, + MaxConsumptionRate: reward.PercentDenominator, + MinValidatorStake: 2, + MaxValidatorStake: 10, + MinStakeDuration: 1, + MaxStakeDuration: 2, + MinDelegationFee: reward.PercentDenominator, + MinDelegatorStake: 1, + MaxValidatorWeightFactor: 1, + UptimeRequirement: reward.PercentDenominator, + SubnetAuth: subnetAuth, + }, signers, onAcceptState + }, + }, + { + name: "AddPermissionlessValidatorTx", + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + ins, unstakedOuts, stakedOuts, signers, err := env.utxosHandler.Spend( + env.state, + preFundedKeys, + defaultMinValidatorStake, + env.config.AddPrimaryNetworkValidatorFee, + ids.ShortEmpty, + ) + require.NoError(t, err) - // empty memo won't err - utx.Memo = []byte{} - createSubnetTx, err = txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) + sk, err := bls.NewSecretKey() + require.NoError(t, err) - require.NoError(createSubnetTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: createSubnetTx, - })) -} + var ( + nodeID = ids.GenerateTestNodeID() + chainTime = env.state.GetTimestamp() + endTime = chainTime.Add(defaultMaxStakingDuration) + ) -func TestDurangoStandardTxExecutorBaseTx(t *testing.T) { - require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) - env.ctx.Lock.Lock() - defer func() { - require.NoError(shutdownEnvironment(env)) - env.ctx.Lock.Unlock() - }() - - // Build the BaseTx - ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( - env.state, - preFundedKeys, - defaultMinValidatorStake, - env.config.TxFee, - ids.ShortEmpty, - ) - require.NoError(err) + onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) + require.NoError(t, err) - utx := &txs.BaseTx{ - BaseTx: avax.BaseTx{ - NetworkID: env.ctx.NetworkID, - BlockchainID: env.ctx.ChainID, - Ins: ins, - Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, // non-empty memo must err + return &txs.AddPermissionlessValidatorTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: env.ctx.NetworkID, + BlockchainID: env.ctx.ChainID, + Ins: ins, + Outs: unstakedOuts, + Memo: []byte{'a', 'b', 'c'}, + }}, + Validator: txs.Validator{ + NodeID: nodeID, + End: uint64(endTime.Unix()), + Wght: env.config.MinValidatorStake, + }, + Subnet: constants.PrimaryNetworkID, + Signer: signer.NewProofOfPossession(sk), + StakeOuts: stakedOuts, + ValidatorRewardsOwner: &secp256k1fx.OutputOwners{ + Locktime: 0, + Threshold: 1, + Addrs: []ids.ShortID{ + ids.ShortEmpty, + }, + }, + DelegatorRewardsOwner: &secp256k1fx.OutputOwners{ + Locktime: 0, + Threshold: 1, + Addrs: []ids.ShortID{ + ids.ShortEmpty, + }, + }, + DelegationShares: reward.PercentDenominator, + }, signers, onAcceptState + }, }, - } - - baseTx, err := txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) - - onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) - require.NoError(err) - - err = baseTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: baseTx, - }) - require.ErrorIs(err, avax.ErrMemoTooLarge) + { + name: "AddPermissionlessDelegatorTx", + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + var primaryValidator *state.Staker + it, err := env.state.GetCurrentStakerIterator() + require.NoError(t, err) + for it.Next() { + staker := it.Value() + if staker.Priority != txs.PrimaryNetworkValidatorCurrentPriority { + continue + } + primaryValidator = staker + break + } + it.Release() + + ins, unstakedOuts, stakedOuts, signers, err := env.utxosHandler.Spend( + env.state, + preFundedKeys, + defaultMinValidatorStake, + env.config.AddPrimaryNetworkDelegatorFee, + ids.ShortEmpty, + ) + require.NoError(t, err) - // empty memo won't err - utx.Memo = []byte{} - baseTx, err = txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) + onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) + require.NoError(t, err) - require.NoError(baseTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: baseTx, - })) -} + return &txs.AddPermissionlessDelegatorTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: env.ctx.NetworkID, + BlockchainID: env.ctx.ChainID, + Ins: ins, + Outs: unstakedOuts, + }}, + Validator: txs.Validator{ + NodeID: primaryValidator.NodeID, + End: uint64(primaryValidator.EndTime.Unix()), + Wght: defaultMinValidatorStake, + }, + StakeOuts: stakedOuts, + DelegationRewardsOwner: &secp256k1fx.OutputOwners{ + Locktime: 0, + Threshold: 1, + Addrs: []ids.ShortID{ids.ShortEmpty}, + }, + }, signers, onAcceptState + }, + }, + { + name: "TransferSubnetOwnershipTx", + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( + env.state, + preFundedKeys, + defaultMinValidatorStake, + env.config.TxFee, + ids.ShortEmpty, + ) + require.NoError(t, err) -func TestDurangoStandardTxExecutorImportTx(t *testing.T) { - require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) - env.ctx.Lock.Lock() - defer func() { - require.NoError(shutdownEnvironment(env)) - env.ctx.Lock.Unlock() - }() + subnetAuth, subnetSigners, err := env.utxosHandler.Authorize(env.state, testSubnet1.TxID, preFundedKeys) + require.NoError(t, err) + signers = append(signers, subnetSigners) - env.backend.Bootstrapped.Set(false) // skip shared memory checks + onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) + require.NoError(t, err) - // Provide the avm UTXO - utxoID := avax.UTXOID{ - TxID: ids.Empty.Prefix(1), - OutputIndex: 1, - } - amount := uint64(50000) - recipientKey := preFundedKeys[1] - - utxo := &avax.UTXO{ - UTXOID: utxoID, - Asset: avax.Asset{ID: env.ctx.AVAXAssetID}, - Out: &secp256k1fx.TransferOutput{ - Amt: amount, - OutputOwners: secp256k1fx.OutputOwners{ - Threshold: 1, - Addrs: []ids.ShortID{recipientKey.PublicKey().Address()}, + return &txs.TransferSubnetOwnershipTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: env.ctx.NetworkID, + BlockchainID: env.ctx.ChainID, + Ins: ins, + Outs: unstakedOuts, + Memo: []byte{'a', 'b', 'c'}, + }}, + Subnet: testSubnet1.TxID, + SubnetAuth: subnetAuth, + Owner: &secp256k1fx.OutputOwners{ + Threshold: 1, + Addrs: []ids.ShortID{ids.ShortEmpty}, + }, + }, signers, onAcceptState }, }, - } + { + name: "BaseTx", + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( + env.state, + preFundedKeys, + defaultMinValidatorStake, + env.config.TxFee, + ids.ShortEmpty, + ) + require.NoError(t, err) - utx := &txs.ImportTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: env.ctx.NetworkID, - BlockchainID: env.ctx.ChainID, - Memo: []byte{'a', 'b', 'c'}, - }}, - SourceChain: env.ctx.XChainID, - ImportedInputs: []*avax.TransferableInput{ - { - UTXOID: utxo.UTXOID, - Asset: utxo.Asset, - In: &secp256k1fx.TransferInput{ - Amt: env.config.TxFee, - }, + onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) + require.NoError(t, err) + + return &txs.BaseTx{ + BaseTx: avax.BaseTx{ + NetworkID: env.ctx.NetworkID, + BlockchainID: env.ctx.ChainID, + Ins: ins, + Outs: unstakedOuts, + }, + }, signers, onAcceptState }, }, } - exportTx, err := txs.NewSigned(utx, txs.Codec, [][]*secp256k1.PrivateKey{{recipientKey}}) - require.NoError(err) - onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) - require.NoError(err) - - err = exportTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: exportTx, - }) - require.ErrorIs(err, avax.ErrMemoTooLarge) - - // empty memo won't err - utx.Memo = []byte{} - exportTx, err = txs.NewSigned(utx, txs.Codec, [][]*secp256k1.PrivateKey{{recipientKey}}) - require.NoError(err) - - require.NoError(exportTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: exportTx, - })) -} + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require := require.New(t) -func TestDurangoStandardTxExecutorExportTx(t *testing.T) { - require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) - env.ctx.Lock.Lock() - defer func() { - require.NoError(shutdownEnvironment(env)) - env.ctx.Lock.Unlock() - }() - - // Build the ExportTx - amount := units.Avax - ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( - env.state, - preFundedKeys, - amount, - env.config.TxFee, - ids.ShortEmpty, - ) - require.NoError(err) + env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) + env.ctx.Lock.Lock() + defer env.ctx.Lock.Unlock() - utx := &txs.ExportTx{ - BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: env.ctx.NetworkID, - BlockchainID: env.ctx.ChainID, - Ins: ins, - Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, // non-empty memo must err - }}, - DestinationChain: env.ctx.XChainID, - ExportedOutputs: []*avax.TransferableOutput{{ // Exported to X-Chain - Asset: avax.Asset{ID: env.ctx.AVAXAssetID}, - Out: &secp256k1fx.TransferOutput{ - Amt: amount, - OutputOwners: secp256k1fx.OutputOwners{ - Locktime: 0, - Threshold: 1, - Addrs: []ids.ShortID{ids.GenerateTestShortID()}, - }, - }, - }}, - } - exportTx, err := txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) + utx, signers, onAcceptState := tt.setupTest(env) - onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) - require.NoError(err) + // Populated memo field should error + setMemo(utx, []byte{'m', 'e', 'm', 'o'}) + tx, err := txs.NewSigned(utx, txs.Codec, signers) + require.NoError(err) - err = exportTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: exportTx, - }) - require.ErrorIs(err, avax.ErrMemoTooLarge) + err = tx.Unsigned.Visit(&StandardTxExecutor{ + Backend: &env.backend, + State: onAcceptState, + Tx: tx, + }) + require.ErrorIs(err, avax.ErrMemoTooLarge) - // empty memo won't err - utx.Memo = []byte{} - exportTx, err = txs.NewSigned(utx, txs.Codec, signers) - require.NoError(err) + // Empty memo field should not error + setMemo(utx, []byte{}) + tx, err = txs.NewSigned(utx, txs.Codec, signers) + require.NoError(err) - require.NoError(exportTx.Unsigned.Visit(&StandardTxExecutor{ - Backend: &env.backend, - State: onAcceptState, - Tx: exportTx, - })) + require.NoError(tx.Unsigned.Visit(&StandardTxExecutor{ + Backend: &env.backend, + State: onAcceptState, + Tx: tx, + })) + }) + } } // Returns a RemoveSubnetValidatorTx that passes syntactic verification. From ca9ce4221e3727409c96335c493f1f0b6601fc0f Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 19 Jan 2024 17:09:30 -0500 Subject: [PATCH 2/2] nits on nits --- .../txs/executor/standard_tx_executor_test.go | 137 ++++++++---------- 1 file changed, 57 insertions(+), 80 deletions(-) diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 0e0231648918..f9c54367facd 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -953,48 +953,17 @@ func TestBanffStandardTxExecutorAddValidator(t *testing.T) { } } -func setMemo(tx txs.UnsignedTx, memo types.JSONByteSlice) { - switch castTx := tx.(type) { - case *txs.AddValidatorTx: - castTx.Memo = memo - case *txs.AddSubnetValidatorTx: - castTx.Memo = memo - case *txs.AddDelegatorTx: - castTx.Memo = memo - case *txs.CreateChainTx: - castTx.Memo = memo - case *txs.CreateSubnetTx: - castTx.Memo = memo - case *txs.ImportTx: - castTx.Memo = memo - case *txs.ExportTx: - castTx.Memo = memo - case *txs.RemoveSubnetValidatorTx: - castTx.Memo = memo - case *txs.TransformSubnetTx: - castTx.Memo = memo - case *txs.AddPermissionlessValidatorTx: - castTx.Memo = memo - case *txs.AddPermissionlessDelegatorTx: - castTx.Memo = memo - case *txs.TransferSubnetOwnershipTx: - castTx.Memo = memo - case *txs.BaseTx: - castTx.Memo = memo - } -} - // Verifies that the Memo field is required to be empty post-Durango -func TestDurangoStandardTxExecutor(t *testing.T) { +func TestDurangoMemoField(t *testing.T) { type test struct { name string - setupTest func(*environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) + setupTest func(*environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff, *types.JSONByteSlice) } tests := []test{ { name: "AddValidatorTx", - setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff, *types.JSONByteSlice) { ins, unstakedOuts, stakedOuts, signers, err := env.utxosHandler.Spend( env.state, preFundedKeys, @@ -1013,7 +982,7 @@ func TestDurangoStandardTxExecutor(t *testing.T) { onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) - return &txs.AddValidatorTx{ + tx := &txs.AddValidatorTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: env.ctx.NetworkID, BlockchainID: env.ctx.ChainID, @@ -1033,12 +1002,13 @@ func TestDurangoStandardTxExecutor(t *testing.T) { Addrs: []ids.ShortID{ids.ShortEmpty}, }, DelegationShares: reward.PercentDenominator, - }, signers, onAcceptState + } + return tx, signers, onAcceptState, &tx.Memo }, }, { name: "AddSubnetValidatorTx", - setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff, *types.JSONByteSlice) { var primaryValidator *state.Staker it, err := env.state.GetCurrentStakerIterator() require.NoError(t, err) @@ -1068,13 +1038,12 @@ func TestDurangoStandardTxExecutor(t *testing.T) { onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) - return &txs.AddSubnetValidatorTx{ + tx := &txs.AddSubnetValidatorTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: env.ctx.NetworkID, BlockchainID: env.ctx.ChainID, Ins: ins, Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, }}, SubnetValidator: txs.SubnetValidator{ Validator: txs.Validator{ @@ -1085,12 +1054,13 @@ func TestDurangoStandardTxExecutor(t *testing.T) { Subnet: testSubnet1.TxID, }, SubnetAuth: subnetAuth, - }, signers, onAcceptState + } + return tx, signers, onAcceptState, &tx.Memo }, }, { name: "AddDelegatorTx", - setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff, *types.JSONByteSlice) { var primaryValidator *state.Staker it, err := env.state.GetCurrentStakerIterator() require.NoError(t, err) @@ -1116,13 +1086,12 @@ func TestDurangoStandardTxExecutor(t *testing.T) { onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) - return &txs.AddDelegatorTx{ + tx := &txs.AddDelegatorTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: env.ctx.NetworkID, BlockchainID: env.ctx.ChainID, Ins: ins, Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, }}, Validator: txs.Validator{ NodeID: primaryValidator.NodeID, @@ -1135,12 +1104,13 @@ func TestDurangoStandardTxExecutor(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }, - }, signers, onAcceptState + } + return tx, signers, onAcceptState, &tx.Memo }, }, { name: "CreateChainTx", - setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff, *types.JSONByteSlice) { chainTime := env.state.GetTimestamp() createBlockchainTxFee := env.config.GetCreateBlockchainTxFee(chainTime) @@ -1160,13 +1130,12 @@ func TestDurangoStandardTxExecutor(t *testing.T) { onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) - return &txs.CreateChainTx{ + tx := &txs.CreateChainTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: env.ctx.NetworkID, BlockchainID: env.ctx.ChainID, Ins: ins, Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, }}, SubnetID: testSubnet1.TxID, ChainName: "aaa", @@ -1174,12 +1143,13 @@ func TestDurangoStandardTxExecutor(t *testing.T) { FxIDs: []ids.ID{}, GenesisData: []byte{}, SubnetAuth: subnetAuth, - }, signers, onAcceptState + } + return tx, signers, onAcceptState, &tx.Memo }, }, { name: "CreateSubnetTx", - setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff, *types.JSONByteSlice) { chainTime := env.state.GetTimestamp() createSubnetTxFee := env.config.GetCreateSubnetTxFee(chainTime) @@ -1195,7 +1165,7 @@ func TestDurangoStandardTxExecutor(t *testing.T) { onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) - return &txs.CreateSubnetTx{ + tx := &txs.CreateSubnetTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: env.ctx.NetworkID, BlockchainID: env.ctx.ChainID, @@ -1206,12 +1176,13 @@ func TestDurangoStandardTxExecutor(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }, - }, signers, onAcceptState + } + return tx, signers, onAcceptState, &tx.Memo }, }, { name: "ImportTx", - setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff, *types.JSONByteSlice) { // Skip shared memory checks env.backend.Bootstrapped.Set(false) @@ -1239,7 +1210,7 @@ func TestDurangoStandardTxExecutor(t *testing.T) { onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) - return &txs.ImportTx{ + tx := &txs.ImportTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: env.ctx.NetworkID, BlockchainID: env.ctx.ChainID, @@ -1254,12 +1225,13 @@ func TestDurangoStandardTxExecutor(t *testing.T) { }, }, }, - }, signers, onAcceptState + } + return tx, signers, onAcceptState, &tx.Memo }, }, { name: "ExportTx", - setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff, *types.JSONByteSlice) { amount := units.Avax ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( env.state, @@ -1273,7 +1245,7 @@ func TestDurangoStandardTxExecutor(t *testing.T) { onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) - return &txs.ExportTx{ + tx := &txs.ExportTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: env.ctx.NetworkID, BlockchainID: env.ctx.ChainID, @@ -1292,12 +1264,13 @@ func TestDurangoStandardTxExecutor(t *testing.T) { }, }, }}, - }, signers, onAcceptState + } + return tx, signers, onAcceptState, &tx.Memo }, }, { name: "RemoveSubnetValidatorTx", - setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff, *types.JSONByteSlice) { var primaryValidator *state.Staker it, err := env.state.GetCurrentStakerIterator() require.NoError(t, err) @@ -1345,7 +1318,7 @@ func TestDurangoStandardTxExecutor(t *testing.T) { require.NoError(t, err) signers = append(signers, subnetSigners) - return &txs.RemoveSubnetValidatorTx{ + tx := &txs.RemoveSubnetValidatorTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: env.ctx.NetworkID, BlockchainID: env.ctx.ChainID, @@ -1355,12 +1328,13 @@ func TestDurangoStandardTxExecutor(t *testing.T) { Subnet: testSubnet1.ID(), NodeID: primaryValidator.NodeID, SubnetAuth: subnetAuth, - }, signers, onAcceptState + } + return tx, signers, onAcceptState, &tx.Memo }, }, { name: "TransformSubnetTx", - setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff, *types.JSONByteSlice) { ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( env.state, preFundedKeys, @@ -1377,7 +1351,7 @@ func TestDurangoStandardTxExecutor(t *testing.T) { onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) - return &txs.TransformSubnetTx{ + tx := &txs.TransformSubnetTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: env.ctx.NetworkID, BlockchainID: env.ctx.ChainID, @@ -1399,12 +1373,13 @@ func TestDurangoStandardTxExecutor(t *testing.T) { MaxValidatorWeightFactor: 1, UptimeRequirement: reward.PercentDenominator, SubnetAuth: subnetAuth, - }, signers, onAcceptState + } + return tx, signers, onAcceptState, &tx.Memo }, }, { name: "AddPermissionlessValidatorTx", - setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff, *types.JSONByteSlice) { ins, unstakedOuts, stakedOuts, signers, err := env.utxosHandler.Spend( env.state, preFundedKeys, @@ -1426,13 +1401,12 @@ func TestDurangoStandardTxExecutor(t *testing.T) { onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) - return &txs.AddPermissionlessValidatorTx{ + tx := &txs.AddPermissionlessValidatorTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: env.ctx.NetworkID, BlockchainID: env.ctx.ChainID, Ins: ins, Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, }}, Validator: txs.Validator{ NodeID: nodeID, @@ -1457,12 +1431,13 @@ func TestDurangoStandardTxExecutor(t *testing.T) { }, }, DelegationShares: reward.PercentDenominator, - }, signers, onAcceptState + } + return tx, signers, onAcceptState, &tx.Memo }, }, { name: "AddPermissionlessDelegatorTx", - setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff, *types.JSONByteSlice) { var primaryValidator *state.Staker it, err := env.state.GetCurrentStakerIterator() require.NoError(t, err) @@ -1488,7 +1463,7 @@ func TestDurangoStandardTxExecutor(t *testing.T) { onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) - return &txs.AddPermissionlessDelegatorTx{ + tx := &txs.AddPermissionlessDelegatorTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: env.ctx.NetworkID, BlockchainID: env.ctx.ChainID, @@ -1506,12 +1481,13 @@ func TestDurangoStandardTxExecutor(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }, - }, signers, onAcceptState + } + return tx, signers, onAcceptState, &tx.Memo }, }, { name: "TransferSubnetOwnershipTx", - setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff, *types.JSONByteSlice) { ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( env.state, preFundedKeys, @@ -1528,13 +1504,12 @@ func TestDurangoStandardTxExecutor(t *testing.T) { onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) - return &txs.TransferSubnetOwnershipTx{ + tx := &txs.TransferSubnetOwnershipTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: env.ctx.NetworkID, BlockchainID: env.ctx.ChainID, Ins: ins, Outs: unstakedOuts, - Memo: []byte{'a', 'b', 'c'}, }}, Subnet: testSubnet1.TxID, SubnetAuth: subnetAuth, @@ -1542,12 +1517,13 @@ func TestDurangoStandardTxExecutor(t *testing.T) { Threshold: 1, Addrs: []ids.ShortID{ids.ShortEmpty}, }, - }, signers, onAcceptState + } + return tx, signers, onAcceptState, &tx.Memo }, }, { name: "BaseTx", - setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff) { + setupTest: func(env *environment) (txs.UnsignedTx, [][]*secp256k1.PrivateKey, state.Diff, *types.JSONByteSlice) { ins, unstakedOuts, _, signers, err := env.utxosHandler.Spend( env.state, preFundedKeys, @@ -1560,14 +1536,15 @@ func TestDurangoStandardTxExecutor(t *testing.T) { onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env) require.NoError(t, err) - return &txs.BaseTx{ + tx := &txs.BaseTx{ BaseTx: avax.BaseTx{ NetworkID: env.ctx.NetworkID, BlockchainID: env.ctx.ChainID, Ins: ins, Outs: unstakedOuts, }, - }, signers, onAcceptState + } + return tx, signers, onAcceptState, &tx.Memo }, }, } @@ -1580,10 +1557,10 @@ func TestDurangoStandardTxExecutor(t *testing.T) { env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() - utx, signers, onAcceptState := tt.setupTest(env) + utx, signers, onAcceptState, memo := tt.setupTest(env) // Populated memo field should error - setMemo(utx, []byte{'m', 'e', 'm', 'o'}) + *memo = []byte{'m', 'e', 'm', 'o'} tx, err := txs.NewSigned(utx, txs.Codec, signers) require.NoError(err) @@ -1595,7 +1572,7 @@ func TestDurangoStandardTxExecutor(t *testing.T) { require.ErrorIs(err, avax.ErrMemoTooLarge) // Empty memo field should not error - setMemo(utx, []byte{}) + *memo = []byte{} tx, err = txs.NewSigned(utx, txs.Codec, signers) require.NoError(err)