github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/txs/executor/create_subnet_test.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package executor 5 6 import ( 7 "context" 8 "testing" 9 "time" 10 11 "github.com/stretchr/testify/require" 12 13 "github.com/MetalBlockchain/metalgo/ids" 14 "github.com/MetalBlockchain/metalgo/utils/set" 15 "github.com/MetalBlockchain/metalgo/utils/units" 16 "github.com/MetalBlockchain/metalgo/vms/platformvm/state" 17 "github.com/MetalBlockchain/metalgo/vms/platformvm/txs/txstest" 18 "github.com/MetalBlockchain/metalgo/vms/platformvm/utxo" 19 "github.com/MetalBlockchain/metalgo/vms/secp256k1fx" 20 21 walletsigner "github.com/MetalBlockchain/metalgo/wallet/chain/p/signer" 22 ) 23 24 func TestCreateSubnetTxAP3FeeChange(t *testing.T) { 25 ap3Time := defaultGenesisTime.Add(time.Hour) 26 tests := []struct { 27 name string 28 time time.Time 29 fee uint64 30 expectedErr error 31 }{ 32 { 33 name: "pre-fork - correctly priced", 34 time: defaultGenesisTime, 35 fee: 0, 36 expectedErr: nil, 37 }, 38 { 39 name: "post-fork - incorrectly priced", 40 time: ap3Time, 41 fee: 100*defaultTxFee - 1*units.NanoAvax, 42 expectedErr: utxo.ErrInsufficientUnlockedFunds, 43 }, 44 { 45 name: "post-fork - correctly priced", 46 time: ap3Time, 47 fee: 100 * defaultTxFee, 48 expectedErr: nil, 49 }, 50 } 51 for _, test := range tests { 52 t.Run(test.name, func(t *testing.T) { 53 require := require.New(t) 54 55 env := newEnvironment(t, apricotPhase3) 56 env.config.UpgradeConfig.ApricotPhase3Time = ap3Time 57 env.ctx.Lock.Lock() 58 defer env.ctx.Lock.Unlock() 59 60 env.state.SetTimestamp(test.time) // to duly set fee 61 62 addrs := set.NewSet[ids.ShortID](len(preFundedKeys)) 63 for _, key := range preFundedKeys { 64 addrs.Add(key.Address()) 65 } 66 67 cfg := *env.config 68 cfg.StaticFeeConfig.CreateSubnetTxFee = test.fee 69 factory := txstest.NewWalletFactory(env.ctx, &cfg, env.state) 70 builder, signer := factory.NewWallet(preFundedKeys...) 71 utx, err := builder.NewCreateSubnetTx( 72 &secp256k1fx.OutputOwners{}, 73 ) 74 require.NoError(err) 75 tx, err := walletsigner.SignUnsigned(context.Background(), signer, utx) 76 require.NoError(err) 77 78 stateDiff, err := state.NewDiff(lastAcceptedID, env) 79 require.NoError(err) 80 81 stateDiff.SetTimestamp(test.time) 82 83 executor := StandardTxExecutor{ 84 Backend: &env.backend, 85 State: stateDiff, 86 Tx: tx, 87 } 88 err = tx.Unsigned.Visit(&executor) 89 require.ErrorIs(err, test.expectedErr) 90 }) 91 } 92 }