github.com/ava-labs/avalanchego@v1.11.11/vms/avm/vm_regression_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 avm
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"github.com/ava-labs/avalanchego/ids"
    12  	"github.com/ava-labs/avalanchego/upgrade/upgradetest"
    13  	"github.com/ava-labs/avalanchego/vms/components/avax"
    14  	"github.com/ava-labs/avalanchego/vms/components/verify"
    15  	"github.com/ava-labs/avalanchego/vms/nftfx"
    16  	"github.com/ava-labs/avalanchego/vms/secp256k1fx"
    17  )
    18  
    19  func TestVerifyFxUsage(t *testing.T) {
    20  	require := require.New(t)
    21  
    22  	env := setup(t, &envConfig{fork: upgradetest.Latest})
    23  	env.vm.ctx.Lock.Unlock()
    24  
    25  	var (
    26  		key = keys[0]
    27  		kc  = secp256k1fx.NewKeychain(key)
    28  	)
    29  
    30  	initialStates := map[uint32][]verify.State{
    31  		0: {
    32  			&secp256k1fx.TransferOutput{
    33  				Amt: 1,
    34  				OutputOwners: secp256k1fx.OutputOwners{
    35  					Threshold: 1,
    36  					Addrs:     []ids.ShortID{keys[0].PublicKey().Address()},
    37  				},
    38  			},
    39  		},
    40  		1: {
    41  			&nftfx.MintOutput{
    42  				GroupID: 1,
    43  				OutputOwners: secp256k1fx.OutputOwners{
    44  					Threshold: 1,
    45  					Addrs:     []ids.ShortID{keys[0].PublicKey().Address()},
    46  				},
    47  			},
    48  		},
    49  	}
    50  
    51  	// Create the asset
    52  	createAssetTx, err := env.txBuilder.CreateAssetTx(
    53  		"Team Rocket", // name
    54  		"TR",          // symbol
    55  		0,             // denomination
    56  		initialStates,
    57  		kc,
    58  		key.Address(),
    59  	)
    60  	require.NoError(err)
    61  	issueAndAccept(require, env.vm, env.issuer, createAssetTx)
    62  
    63  	// Mint the NFT
    64  	mintNFTTx, err := env.txBuilder.MintNFT(
    65  		createAssetTx.ID(),
    66  		[]byte{'h', 'e', 'l', 'l', 'o'}, // payload
    67  		[]*secp256k1fx.OutputOwners{{
    68  			Threshold: 1,
    69  			Addrs:     []ids.ShortID{key.Address()},
    70  		}},
    71  		kc,
    72  		key.Address(),
    73  	)
    74  	require.NoError(err)
    75  	issueAndAccept(require, env.vm, env.issuer, mintNFTTx)
    76  
    77  	// move the NFT
    78  	to := keys[2].PublicKey().Address()
    79  	spendTx, err := env.txBuilder.BaseTx(
    80  		[]*avax.TransferableOutput{{
    81  			Asset: avax.Asset{ID: createAssetTx.ID()},
    82  			Out: &secp256k1fx.TransferOutput{
    83  				Amt: 1,
    84  				OutputOwners: secp256k1fx.OutputOwners{
    85  					Threshold: 1,
    86  					Addrs:     []ids.ShortID{to},
    87  				},
    88  			},
    89  		}},
    90  		nil, // memo
    91  		kc,
    92  		key.Address(),
    93  	)
    94  	require.NoError(err)
    95  	issueAndAccept(require, env.vm, env.issuer, spendTx)
    96  }