github.com/ava-labs/avalanchego@v1.11.11/vms/platformvm/txs/executor/export_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  	"testing"
     8  	"time"
     9  
    10  	"github.com/stretchr/testify/require"
    11  
    12  	"github.com/ava-labs/avalanchego/ids"
    13  	"github.com/ava-labs/avalanchego/upgrade/upgradetest"
    14  	"github.com/ava-labs/avalanchego/vms/components/avax"
    15  	"github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest"
    16  	"github.com/ava-labs/avalanchego/vms/platformvm/state"
    17  	"github.com/ava-labs/avalanchego/vms/secp256k1fx"
    18  )
    19  
    20  func TestNewExportTx(t *testing.T) {
    21  	env := newEnvironment(t, upgradetest.Banff)
    22  	env.ctx.Lock.Lock()
    23  	defer env.ctx.Lock.Unlock()
    24  
    25  	tests := []struct {
    26  		description        string
    27  		destinationChainID ids.ID
    28  		timestamp          time.Time
    29  	}{
    30  		{
    31  			description:        "P->X export",
    32  			destinationChainID: env.ctx.XChainID,
    33  			timestamp:          genesistest.DefaultValidatorStartTime,
    34  		},
    35  		{
    36  			description:        "P->C export",
    37  			destinationChainID: env.ctx.CChainID,
    38  			timestamp:          env.config.UpgradeConfig.ApricotPhase5Time,
    39  		},
    40  	}
    41  
    42  	for _, tt := range tests {
    43  		t.Run(tt.description, func(t *testing.T) {
    44  			require := require.New(t)
    45  
    46  			wallet := newWallet(t, env, walletConfig{})
    47  
    48  			tx, err := wallet.IssueExportTx(
    49  				tt.destinationChainID,
    50  				[]*avax.TransferableOutput{{
    51  					Asset: avax.Asset{ID: env.ctx.AVAXAssetID},
    52  					Out: &secp256k1fx.TransferOutput{
    53  						Amt: genesistest.DefaultInitialBalance - defaultTxFee,
    54  						OutputOwners: secp256k1fx.OutputOwners{
    55  							Threshold: 1,
    56  							Addrs:     []ids.ShortID{ids.GenerateTestShortID()},
    57  						},
    58  					},
    59  				}},
    60  			)
    61  			require.NoError(err)
    62  
    63  			stateDiff, err := state.NewDiff(lastAcceptedID, env)
    64  			require.NoError(err)
    65  
    66  			stateDiff.SetTimestamp(tt.timestamp)
    67  
    68  			feeCalculator := state.PickFeeCalculator(env.config, stateDiff)
    69  			verifier := StandardTxExecutor{
    70  				Backend:       &env.backend,
    71  				FeeCalculator: feeCalculator,
    72  				State:         stateDiff,
    73  				Tx:            tx,
    74  			}
    75  			require.NoError(tx.Unsigned.Visit(&verifier))
    76  		})
    77  	}
    78  }