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