github.com/MetalBlockchain/metalgo@v1.11.9/tests/e2e/banff/suites.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 // Implements tests for the banff network upgrade. 5 package banff 6 7 import ( 8 "github.com/stretchr/testify/require" 9 10 "github.com/MetalBlockchain/metalgo/ids" 11 "github.com/MetalBlockchain/metalgo/tests" 12 "github.com/MetalBlockchain/metalgo/tests/fixture/e2e" 13 "github.com/MetalBlockchain/metalgo/utils/constants" 14 "github.com/MetalBlockchain/metalgo/utils/units" 15 "github.com/MetalBlockchain/metalgo/vms/components/avax" 16 "github.com/MetalBlockchain/metalgo/vms/components/verify" 17 "github.com/MetalBlockchain/metalgo/vms/secp256k1fx" 18 19 ginkgo "github.com/onsi/ginkgo/v2" 20 ) 21 22 var _ = ginkgo.Describe("[Banff]", func() { 23 require := require.New(ginkgo.GinkgoT()) 24 25 ginkgo.It("can send custom assets X->P and P->X", 26 func() { 27 keychain := e2e.Env.NewKeychain(1) 28 wallet := e2e.NewWallet(keychain, e2e.Env.GetRandomNodeURI()) 29 30 // Get the P-chain and the X-chain wallets 31 pWallet := wallet.P() 32 xWallet := wallet.X() 33 xBuilder := xWallet.Builder() 34 xContext := xBuilder.Context() 35 36 // Pull out useful constants to use when issuing transactions. 37 xChainID := xContext.BlockchainID 38 owner := &secp256k1fx.OutputOwners{ 39 Threshold: 1, 40 Addrs: []ids.ShortID{ 41 keychain.Keys[0].Address(), 42 }, 43 } 44 45 var assetID ids.ID 46 ginkgo.By("create new X-chain asset", func() { 47 assetTx, err := xWallet.IssueCreateAssetTx( 48 "RnM", 49 "RNM", 50 9, 51 map[uint32][]verify.State{ 52 0: { 53 &secp256k1fx.TransferOutput{ 54 Amt: 100 * units.Schmeckle, 55 OutputOwners: *owner, 56 }, 57 }, 58 }, 59 e2e.WithDefaultContext(), 60 ) 61 require.NoError(err) 62 assetID = assetTx.ID() 63 64 tests.Outf("{{green}}created new X-chain asset{{/}}: %s\n", assetID) 65 }) 66 67 ginkgo.By("export new X-chain asset to P-chain", func() { 68 tx, err := xWallet.IssueExportTx( 69 constants.PlatformChainID, 70 []*avax.TransferableOutput{ 71 { 72 Asset: avax.Asset{ 73 ID: assetID, 74 }, 75 Out: &secp256k1fx.TransferOutput{ 76 Amt: 100 * units.Schmeckle, 77 OutputOwners: *owner, 78 }, 79 }, 80 }, 81 e2e.WithDefaultContext(), 82 ) 83 require.NoError(err) 84 85 tests.Outf("{{green}}issued X-chain export{{/}}: %s\n", tx.ID()) 86 }) 87 88 ginkgo.By("import new asset from X-chain on the P-chain", func() { 89 tx, err := pWallet.IssueImportTx( 90 xChainID, 91 owner, 92 e2e.WithDefaultContext(), 93 ) 94 require.NoError(err) 95 96 tests.Outf("{{green}}issued P-chain import{{/}}: %s\n", tx.ID()) 97 }) 98 99 ginkgo.By("export asset from P-chain to the X-chain", func() { 100 tx, err := pWallet.IssueExportTx( 101 xChainID, 102 []*avax.TransferableOutput{ 103 { 104 Asset: avax.Asset{ 105 ID: assetID, 106 }, 107 Out: &secp256k1fx.TransferOutput{ 108 Amt: 100 * units.Schmeckle, 109 OutputOwners: *owner, 110 }, 111 }, 112 }, 113 e2e.WithDefaultContext(), 114 ) 115 require.NoError(err) 116 117 tests.Outf("{{green}}issued P-chain export{{/}}: %s\n", tx.ID()) 118 }) 119 120 ginkgo.By("import asset from P-chain on the X-chain", func() { 121 tx, err := xWallet.IssueImportTx( 122 constants.PlatformChainID, 123 owner, 124 e2e.WithDefaultContext(), 125 ) 126 require.NoError(err) 127 128 tests.Outf("{{green}}issued X-chain import{{/}}: %s\n", tx.ID()) 129 }) 130 }) 131 })